Skip to content

Commit a382891

Browse files
committed
Fixed crash on startup due to invalid data cache
1 parent d418fa2 commit a382891

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Stardrop/ViewModels/MainWindowViewModel.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,28 @@ public void DiscoverMods(string modsFilePath)
253253
List<ModKeyInfo> modKeysCache = new List<ModKeyInfo>();
254254
if (File.Exists(Pathing.GetKeyCachePath()))
255255
{
256-
modKeysCache = JsonSerializer.Deserialize<List<ModKeyInfo>>(File.ReadAllText(Pathing.GetKeyCachePath()), new JsonSerializerOptions { AllowTrailingCommas = true });
256+
try
257+
{
258+
modKeysCache = JsonSerializer.Deserialize<List<ModKeyInfo>>(File.ReadAllText(Pathing.GetKeyCachePath()), new JsonSerializerOptions { AllowTrailingCommas = true });
259+
}
260+
catch (Exception ex)
261+
{
262+
Program.helper.Log($"Failed to parse cached mod keys: {ex}", Helper.Status.Alert);
263+
}
257264
}
258265

259266
// Get the local data
260267
ClientData localDataCache = new ClientData();
261268
if (File.Exists(Pathing.GetDataCachePath()))
262269
{
263-
localDataCache = JsonSerializer.Deserialize<ClientData>(File.ReadAllText(Pathing.GetDataCachePath()), new JsonSerializerOptions { AllowTrailingCommas = true });
270+
try
271+
{
272+
localDataCache = JsonSerializer.Deserialize<ClientData>(File.ReadAllText(Pathing.GetDataCachePath()), new JsonSerializerOptions { AllowTrailingCommas = true });
273+
}
274+
catch (Exception ex)
275+
{
276+
Program.helper.Log($"Failed to parse client data: {ex}", Helper.Status.Alert);
277+
}
264278
}
265279

266280
foreach (var fileInfo in GetManifestFiles(new DirectoryInfo(modsFilePath)))

0 commit comments

Comments
 (0)