From adf7f5529ab094626c8a6d0fb0b24b2559e60f05 Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Wed, 19 Oct 2016 19:47:43 -0500 Subject: [PATCH] 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 --- PKHeX/MainWindow/Main.cs | 3 +++ PKHeX/Misc/ErrorWindow.cs | 2 +- PKHeX/Saves/SaveUtil.cs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/PKHeX/MainWindow/Main.cs b/PKHeX/MainWindow/Main.cs index 376998540..baac26f8a 100644 --- a/PKHeX/MainWindow/Main.cs +++ b/PKHeX/MainWindow/Main.cs @@ -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. diff --git a/PKHeX/Misc/ErrorWindow.cs b/PKHeX/Misc/ErrorWindow.cs index ba03d6f23..ed617697e 100644 --- a/PKHeX/Misc/ErrorWindow.cs +++ b/PKHeX/Misc/ErrorWindow.cs @@ -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; } diff --git a/PKHeX/Saves/SaveUtil.cs b/PKHeX/Saves/SaveUtil.cs index 3b80c2820..791107953 100644 --- a/PKHeX/Saves/SaveUtil.cs +++ b/PKHeX/Saves/SaveUtil.cs @@ -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); } /// /// Retrieves the full path of the most recent file based on LastWriteTime.