mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +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;
|
||||
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
|
||||
#endif
|
||||
{
|
||||
string? path = null;
|
||||
string path = string.Empty;
|
||||
SaveFile? sav = null;
|
||||
if (Settings.Default.DetectSaveOnStartup && !DetectSaveFile(out path, out sav))
|
||||
WinFormsUtil.Error(path); // `path` contains the error message
|
||||
if (Settings.Default.DetectSaveOnStartup && !SaveFinder.DetectSaveFile(out path, out sav))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(path))
|
||||
WinFormsUtil.Error(path); // `path` contains the error message
|
||||
}
|
||||
|
||||
bool savLoaded = false;
|
||||
if (sav != null && path != null)
|
||||
if (sav != null && path.Length != 0)
|
||||
{
|
||||
savLoaded = OpenSAV(sav, path);
|
||||
}
|
||||
|
@ -1204,28 +1207,15 @@ namespace PKHeX.WinForms
|
|||
|
||||
private void ClickSaveFileName(object sender, EventArgs e)
|
||||
{
|
||||
if (!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 (!SaveFinder.DetectSaveFile(out string path, out var sav))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(msg))
|
||||
WinFormsUtil.Error(msg);
|
||||
path = string.Empty;
|
||||
sav = null;
|
||||
return false;
|
||||
if (!string.IsNullOrWhiteSpace(path))
|
||||
WinFormsUtil.Error(path); // `path` contains the error message
|
||||
return;
|
||||
}
|
||||
|
||||
path = result.FilePath!;
|
||||
sav = result;
|
||||
return File.Exists(path);
|
||||
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgFileLoadSaveDetectReload, path) == DialogResult.Yes)
|
||||
LoadFile(sav, path); // load save
|
||||
}
|
||||
|
||||
private static void PromptBackup()
|
||||
|
|
Loading…
Reference in a new issue