Skip to content

Commit ec6fe5f

Browse files
committed
Change loadstate methods to return a bool indicating success
1 parent 250b839 commit ec6fe5f

16 files changed

+100
-113
lines changed

src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ public void FrameSkip(int numFrames)
103103

104104
public bool IsTurbo() => _mainForm.IsTurboing;
105105

106-
public void LoadState(string name) => _mainForm.LoadState(Path.Combine(_config.PathEntries.SaveStateAbsolutePath(Game.System), $"{name}.State"), name, suppressOSD: false);
106+
public bool LoadState(string name)
107+
=> _mainForm.LoadState(
108+
path: Path.Combine(_config.PathEntries.SaveStateAbsolutePath(Game.System), $"{name}.State"),
109+
userFriendlyStateName: name,
110+
suppressOSD: false);
107111

108112
public void OnBeforeQuickLoad(object sender, string quickSaveSlotName, out bool eventHandled)
109113
{

src/BizHawk.Client.Common/Api/Classes/SaveStateApi.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,25 @@ public SaveStateApi(Action<string> logCallback, IMainFormForApi mainForm)
1919
_mainForm = mainForm;
2020
}
2121

22-
public void Load(string path, bool suppressOSD)
22+
public bool Load(string path, bool suppressOSD)
2323
{
2424
if (!File.Exists(path))
2525
{
2626
LogCallback($"could not find file: {path}");
27-
return;
27+
return false;
2828
}
29-
30-
_mainForm.LoadState(path, Path.GetFileName(path), suppressOSD);
29+
return _mainForm.LoadState(path: path, userFriendlyStateName: Path.GetFileName(path), suppressOSD);
3130
}
3231

33-
public void LoadSlot(int slotNum, bool suppressOSD)
32+
public bool LoadSlot(int slotNum, bool suppressOSD)
3433
{
3534
if (slotNum is < 0 or > 10) throw new ArgumentOutOfRangeException(paramName: nameof(slotNum), message: ERR_MSG_NOT_A_SLOT);
3635
if (slotNum is 0)
3736
{
3837
LogCallback(ERR_MSG_USE_SLOT_10);
3938
slotNum = 10;
4039
}
41-
_mainForm.LoadQuickSave(slotNum, suppressOSD: suppressOSD);
40+
return _mainForm.LoadQuickSave(slotNum, suppressOSD: suppressOSD);
4241
}
4342

4443
public void Save(string path, bool suppressOSD) => _mainForm.SaveState(path, path, true, suppressOSD);

src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public interface IEmuClientApi : IExternalApi
8888
/// Load a savestate specified by its name
8989
/// </summary>
9090
/// <param name="name">Savestate friendly name</param>
91-
void LoadState(string name);
91+
bool LoadState(string name);
9292

9393
/// <summary>
9494
/// Raised before a quickload is done (just after pressing shortcut button)

src/BizHawk.Client.Common/Api/Interfaces/ISaveStateApi.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
{
33
public interface ISaveStateApi : IExternalApi
44
{
5-
void Load(string path, bool suppressOSD = false);
6-
void LoadSlot(int slotNum, bool suppressOSD = false);
5+
bool Load(string path, bool suppressOSD = false);
6+
7+
bool LoadSlot(int slotNum, bool suppressOSD = false);
8+
79
void Save(string path, bool suppressOSD = false);
810
void SaveSlot(int slotNum, bool suppressOSD = false);
911
}

src/BizHawk.Client.Common/IMainFormForApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ public interface IMainFormForApi
6969
bool LoadMovie(string filename, string archive = null);
7070

7171
/// <remarks>only referenced from <see cref="SaveStateApi"/></remarks>
72-
void LoadQuickSave(int slot, bool suppressOSD = false);
72+
bool LoadQuickSave(int slot, bool suppressOSD = false);
7373

7474
/// <remarks>only referenced from <c>EmuClientApi</c></remarks>
7575
bool LoadRom(string path, LoadRomArgs args);
7676

77-
void LoadState(string combine, string name, bool suppressOSD = false);
77+
bool LoadState(string path, string userFriendlyStateName, bool suppressOSD = false);
7878

7979
/// <remarks>only referenced from <c>EmuClientApi</c></remarks>
8080
void PauseEmulator();

src/BizHawk.Client.Common/lua/CommonLibs/SaveStateLuaLibrary.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,22 @@ public SaveStateLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer,
1111

1212
[LuaMethodExample("savestate.load( \"C:\\state.bin\" );")]
1313
[LuaMethod("load", "Loads a savestate with the given path. If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes (and the path is ignored).")]
14-
public void Load(string path, bool suppressOSD = false)
14+
public bool Load(string path, bool suppressOSD = false)
1515
{
1616
_luaLibsImpl.IsUpdateSupressed = true;
17-
18-
APIs.SaveState.Load(path, suppressOSD);
19-
17+
var success = APIs.SaveState.Load(path, suppressOSD);
2018
_luaLibsImpl.IsUpdateSupressed = false;
19+
return success;
2120
}
2221

2322
[LuaMethodExample("savestate.loadslot( 7 );")]
2423
[LuaMethod("loadslot", "Loads the savestate at the given slot number (must be an integer between 0 and 9). If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes with the slot number.")]
25-
public void LoadSlot(int slotNum, bool suppressOSD = false)
24+
public bool LoadSlot(int slotNum, bool suppressOSD = false)
2625
{
2726
_luaLibsImpl.IsUpdateSupressed = true;
28-
29-
APIs.SaveState.LoadSlot(slotNum, suppressOSD);
30-
27+
var success = APIs.SaveState.LoadSlot(slotNum, suppressOSD: suppressOSD);
3128
_luaLibsImpl.IsUpdateSupressed = false;
29+
return success;
3230
}
3331

3432
[LuaMethodExample("savestate.save( \"C:\\state.bin\" );")]

src/BizHawk.Client.EmuHawk/IControlMainform.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ public interface IControlMainform
88
bool WantsToControlSavestates { get; }
99

1010
void SaveState();
11-
void LoadState();
11+
12+
bool LoadState();
13+
1214
void SaveStateAs();
13-
void LoadStateAs();
15+
16+
bool LoadStateAs();
17+
1418
void SaveQuickSave(int slot);
15-
void LoadQuickSave(int slot);
19+
20+
bool LoadQuickSave(int slot);
1621

1722
/// <summary>
1823
/// Overrides the select slot method

src/BizHawk.Client.EmuHawk/IMainFormForTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public interface IMainFormForTools : IDialogController
6565
void FrameBufferResized();
6666

6767
/// <remarks>only referenced from <see cref="BasicBot"/></remarks>
68-
void LoadQuickSave(int slot, bool suppressOSD = false);
68+
bool LoadQuickSave(int slot, bool suppressOSD = false);
6969

7070
/// <remarks>only referenced from <see cref="MultiDiskBundler"/></remarks>
7171
bool LoadRom(string path, LoadRomArgs args);

src/BizHawk.Client.EmuHawk/MainForm.Events.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ private void SavestateCurrentSlot()
406406
private void LoadCurrentSlotMenuItem_Click(object sender, EventArgs e)
407407
=> LoadstateCurrentSlot();
408408

409-
private void LoadstateCurrentSlot()
409+
private bool LoadstateCurrentSlot()
410410
=> LoadQuickSave(Config.SaveSlot);
411411

412412
private void FlushSaveRAMMenuItem_Click(object sender, EventArgs e)
@@ -2522,7 +2522,7 @@ private void SlotStatusButtons_MouseUp(object sender, MouseEventArgs e)
25222522
if (sender == Slot0StatusButton) slot = 10;
25232523

25242524
if (e.Button is MouseButtons.Right) SaveQuickSave(slot);
2525-
else if (e.Button is MouseButtons.Left && HasSlot(slot)) LoadQuickSave(slot);
2525+
else if (e.Button is MouseButtons.Left && HasSlot(slot)) _ = LoadQuickSave(slot);
25262526
}
25272527

25282528
private void KeyPriorityStatusLabel_Click(object sender, EventArgs e)

src/BizHawk.Client.EmuHawk/MainForm.FileLoader.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,8 @@ private void LoadRom(string filename, string archive = null)
108108
LoadRom(filename, args);
109109
}
110110

111-
private void LoadStateFile(string filename, string archive = null)
112-
{
113-
LoadState(filename, Path.GetFileName(filename));
114-
}
111+
private bool LoadStateFile(string filename, string archive = null)
112+
=> LoadState(path: filename, userFriendlyStateName: Path.GetFileName(filename));
115113

116114
private void LoadWatch(string filename, string archive = null)
117115
{
@@ -267,7 +265,7 @@ private void FormDragDrop_internal()
267265
LoadRom(filename, fileInformation.ArchiveName);
268266
break;
269267
case LoadOrdering.State:
270-
LoadStateFile(filename, fileInformation.ArchiveName);
268+
_ = LoadStateFile(filename, fileInformation.ArchiveName);
271269
break;
272270
case LoadOrdering.Watch:
273271
LoadWatch(filename, fileInformation.ArchiveName);

0 commit comments

Comments
 (0)