B/detect save null reference (#333)

* 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
This commit is contained in:
Evan Dixon
2016-10-19 19:47:43 -05:00
committed by Kaphotics
parent 475aad5480
commit adf7f5529a
3 changed files with 5 additions and 2 deletions

View File

@@ -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.

View File

@@ -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;
}

View File

@@ -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.