Skip to content

Commit

Permalink
Fix weirdness in a specific rom loading scenario (fixes #2024)
Browse files Browse the repository at this point in the history
Without this commit, choosing "Cancel" from a tool form's "Save changes?" dialog
(i.e. AskSaveChanges) while trying to load a rom from `File` > `Recent ROM`
would treat that recent rom as though it were missing. With this commit, an OSD
message is displayed instead.
This isn't the best fix. The return value from LoadRomInternal isn't even used
anywhere apart from LoadRomFromRecent, which is the only place the new out param
is used.
  • Loading branch information
YoshiRulz committed Sep 27, 2020
1 parent 3adcc26 commit 96f4f24
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/BizHawk.Client.EmuHawk/MainForm.cs
Expand Up @@ -2019,9 +2019,10 @@ private void LoadRomFromRecent(string rom)
// if(ioa is this or that) - for more complex behaviour
string romPath = ioa.SimplePath;

if (!LoadRom(romPath, args))
if (!LoadRom(romPath, args, out var failureIsFromAskSave))
{
Config.RecentRoms.HandleLoadError(romPath, rom);
if (failureIsFromAskSave) OSD.AddMessage("ROM loading cancelled; a tool had unsaved changes");
else Config.RecentRoms.HandleLoadError(romPath, rom);
}
}

Expand Down Expand Up @@ -3507,9 +3508,11 @@ private string ChoosePlatformForRom(RomGame rom)
private LoadRomArgs _currentLoadRomArgs;
private bool _isLoadingRom;

public bool LoadRom(string path, LoadRomArgs args)
public bool LoadRom(string path, LoadRomArgs args) => LoadRom(path, args, out _);

public bool LoadRom(string path, LoadRomArgs args, out bool failureIsFromAskSave)
{
if (!LoadRomInternal(path, args))
if (!LoadRomInternal(path, args, out failureIsFromAskSave))
return false;

// what's the meaning of the last rom path when opening an archive? based on the archive file location
Expand All @@ -3523,8 +3526,9 @@ public bool LoadRom(string path, LoadRomArgs args)
}

// Still needs a good bit of refactoring
private bool LoadRomInternal(string path, LoadRomArgs args)
private bool LoadRomInternal(string path, LoadRomArgs args, out bool failureIsFromAskSave)
{
failureIsFromAskSave = false;
if (path == null)
throw new ArgumentNullException(nameof(path));
if (args == null)
Expand Down Expand Up @@ -3554,6 +3558,7 @@ private bool LoadRomInternal(string path, LoadRomArgs args)

if (!Tools.AskSave())
{
failureIsFromAskSave = true;
return false;
}

Expand Down

0 comments on commit 96f4f24

Please sign in to comment.