Skip to content

Commit

Permalink
B/detect save null reference (#333)
Browse files Browse the repository at this point in the history
* Fixed null reference exception in certain cases in save auto-loading

* Fixed form close warning showing with no changes made since start

* Fixed abort button in ErrorWindow

* Simplified implementation
  • Loading branch information
evandixon authored and kwsch committed Oct 20, 2016
1 parent 475aad5 commit adf7f55
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions PKHeX/MainWindow/Main.cs
Expand Up @@ -181,7 +181,10 @@ public Main()
if (path != null && File.Exists(path))
openQuick(path, force: true);
else
{
openSAV(SAV, null);
SAV.Edited = false; // Prevents form close warning from showing until changes are made
}
}

// Splash Screen closes on its own.
Expand Down
2 changes: 1 addition & 1 deletion PKHeX/Misc/ErrorWindow.cs
Expand Up @@ -18,7 +18,7 @@ public static DialogResult ShowErrorDialog(string friendlyMessage, Exception ex,
var dialogResult = dialog.ShowDialog();
if (dialogResult == DialogResult.Abort)
{
Application.Exit();
Environment.Exit(1);
}
return dialogResult;
}
Expand Down
2 changes: 1 addition & 1 deletion PKHeX/Saves/SaveUtil.cs
Expand Up @@ -544,7 +544,7 @@ public static string detectSaveFile()
possiblePaths.AddRange(getSavesFromFolder(Path.Combine(pathCache), false));

// return newest save file path that is valid (oh man)
return possiblePaths.OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault(p => getVariantSAV(File.ReadAllBytes(p)).ChecksumsValid);
return possiblePaths.OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault(p => getVariantSAV(File.ReadAllBytes(p))?.ChecksumsValid ?? false);
}
/// <summary>
/// Retrieves the full path of the most recent file based on LastWriteTime.
Expand Down

0 comments on commit adf7f55

Please sign in to comment.