From 24edf7efe577aef172892b834f54ebd2f31a1ee3 Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 16 Apr 2020 13:15:35 -0700 Subject: [PATCH] Improve detected savefile load speeds Don't discard the initially detected data just to re-load it from the path; keep a reference and load the reference. --- PKHeX.WinForms/MainWindow/Main.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 6b9457a70..8894ba7c1 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -188,13 +188,13 @@ private void FormLoadInitialFiles(string[] args) #endif { string path = null; - if (Settings.Default.DetectSaveOnStartup && !DetectSaveFile(out path) && path != null) + SaveFile sav = null; + if (Settings.Default.DetectSaveOnStartup && !DetectSaveFile(out path, out sav) && path != null) WinFormsUtil.Error(path); // `path` contains the error message bool savLoaded = false; - if (path != null && File.Exists(path)) + if (sav != null) { - var sav = SaveUtil.GetVariantSAV(path); savLoaded = OpenSAV(sav, path); } if (!savLoaded) @@ -1204,16 +1204,16 @@ private void ClickExportSAV(object sender, EventArgs e) private void ClickSaveFileName(object sender, EventArgs e) { - if (!DetectSaveFile(out string path)) + if (!DetectSaveFile(out string path, out var sav)) return; if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgFileLoadSaveDetectReload, path) == DialogResult.Yes) - OpenQuick(path); // load save + LoadFile(sav, path); // load save } - private static bool DetectSaveFile(out string path) + private static bool DetectSaveFile(out string path, out SaveFile sav) { string msg = null; - var sav = SaveFinder.FindMostRecentSaveFile(Environment.GetLogicalDrives(), ref msg); + sav = SaveFinder.FindMostRecentSaveFile(Environment.GetLogicalDrives(), ref msg); if (sav == null && !string.IsNullOrWhiteSpace(msg)) WinFormsUtil.Error(msg);