mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-17 05:48:44 +00:00
Revise save detect logic flow
Double-Clicking SAV tab no longer hides any error message; now shows it like the auto-detect would. Move high-level detection method to Core
This commit is contained in:
parent
83171ab133
commit
14a678b57d
2 changed files with 31 additions and 23 deletions
|
@ -159,5 +159,23 @@ namespace PKHeX.Core
|
||||||
possible = possiblePaths;
|
possible = possiblePaths;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool DetectSaveFile(out string path, out SaveFile? sav) => DetectSaveFile(out path, out sav, Environment.GetLogicalDrives());
|
||||||
|
|
||||||
|
public static bool DetectSaveFile(out string path, out SaveFile? sav, IReadOnlyList<string> drives)
|
||||||
|
{
|
||||||
|
string errorMsg = string.Empty;
|
||||||
|
var result = FindMostRecentSaveFile(drives, ref errorMsg);
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
path = errorMsg;
|
||||||
|
sav = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = result.FilePath!;
|
||||||
|
sav = result;
|
||||||
|
return File.Exists(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,13 +187,16 @@ namespace PKHeX.WinForms
|
||||||
try
|
try
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
string? path = null;
|
string path = string.Empty;
|
||||||
SaveFile? sav = null;
|
SaveFile? sav = null;
|
||||||
if (Settings.Default.DetectSaveOnStartup && !DetectSaveFile(out path, out sav))
|
if (Settings.Default.DetectSaveOnStartup && !SaveFinder.DetectSaveFile(out path, out sav))
|
||||||
WinFormsUtil.Error(path); // `path` contains the error message
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(path))
|
||||||
|
WinFormsUtil.Error(path); // `path` contains the error message
|
||||||
|
}
|
||||||
|
|
||||||
bool savLoaded = false;
|
bool savLoaded = false;
|
||||||
if (sav != null && path != null)
|
if (sav != null && path.Length != 0)
|
||||||
{
|
{
|
||||||
savLoaded = OpenSAV(sav, path);
|
savLoaded = OpenSAV(sav, path);
|
||||||
}
|
}
|
||||||
|
@ -1204,28 +1207,15 @@ namespace PKHeX.WinForms
|
||||||
|
|
||||||
private void ClickSaveFileName(object sender, EventArgs e)
|
private void ClickSaveFileName(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!DetectSaveFile(out string path, out var sav))
|
if (!SaveFinder.DetectSaveFile(out string path, out var sav))
|
||||||
return;
|
|
||||||
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgFileLoadSaveDetectReload, path) == DialogResult.Yes)
|
|
||||||
LoadFile(sav, path); // load save
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool DetectSaveFile(out string path, out SaveFile? sav)
|
|
||||||
{
|
|
||||||
string msg = string.Empty;
|
|
||||||
var result = SaveFinder.FindMostRecentSaveFile(Environment.GetLogicalDrives(), ref msg);
|
|
||||||
if (result == null)
|
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(msg))
|
if (!string.IsNullOrWhiteSpace(path))
|
||||||
WinFormsUtil.Error(msg);
|
WinFormsUtil.Error(path); // `path` contains the error message
|
||||||
path = string.Empty;
|
return;
|
||||||
sav = null;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path = result.FilePath!;
|
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgFileLoadSaveDetectReload, path) == DialogResult.Yes)
|
||||||
sav = result;
|
LoadFile(sav, path); // load save
|
||||||
return File.Exists(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PromptBackup()
|
private static void PromptBackup()
|
||||||
|
|
Loading…
Add table
Reference in a new issue