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.
This commit is contained in:
Kurt
2020-04-16 13:15:35 -07:00
parent e9406599e0
commit 24edf7efe5

View File

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