Skip to content

Commit 3f4aee0

Browse files
kalimagYoshiRulz
andauthored
Return success bool from OpenRom APIs (squashed PR #3514)
* Return success bool from `OpenRom` APIs * Finish propagating, update docs for other recently changed methods too Co-authored-by: YoshiRulz <[email protected]>
1 parent 0591d2e commit 3f4aee0

File tree

10 files changed

+27
-20
lines changed

10 files changed

+27
-20
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ public void OnRomLoaded()
142142

143143
public void OnStateSaved(object sender, string stateName) => StateSaved?.Invoke(sender, new StateSavedEventArgs(stateName));
144144

145-
public void OpenRom(string path) => _mainForm.LoadRom(path, new LoadRomArgs { OpenAdvanced = OpenAdvancedSerializer.ParseWithLegacy(path) });
145+
public bool OpenRom(string path)
146+
=> _mainForm.LoadRom(path, new LoadRomArgs { OpenAdvanced = OpenAdvancedSerializer.ParseWithLegacy(path) });
146147

147148
public void Pause() => _mainForm.PauseEmulator();
148149

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +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+
/// <returns><see langword="true"/> iff succeeded</returns>
9192
bool LoadState(string name);
9293

9394
/// <summary>
@@ -125,7 +126,7 @@ public interface IEmuClientApi : IExternalApi
125126
/// <param name="stateName">User friendly name for saved state</param>
126127
void OnStateSaved(object sender, string stateName);
127128

128-
void OpenRom(string path);
129+
bool OpenRom(string path);
129130

130131
void Pause();
131132

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
{
33
public interface ISaveStateApi : IExternalApi
44
{
5+
/// <param name="path">absolute path to <c>.State</c> file</param>
6+
/// <returns><see langword="true"/> iff succeeded</returns>
57
bool Load(string path, bool suppressOSD = false);
68

9+
/// <param name="slotNum"><c>1..10</c></param>
10+
/// <returns><see langword="true"/> iff succeeded</returns>
711
bool LoadSlot(int slotNum, bool suppressOSD = false);
812

913
void Save(string path, bool suppressOSD = false);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,14 @@ public void OpenRamWatch()
196196
public void OpenRamSearch()
197197
=> APIs.Tool.OpenRamSearch();
198198

199-
[LuaMethodExample("client.openrom( \"C:\\\" );")]
200-
[LuaMethod("openrom", "opens the Open ROM dialog")]
201-
public void OpenRom(string path)
199+
[LuaMethodExample("client.openrom( \"C:\\rom.bin\" );")]
200+
[LuaMethod("openrom", "Loads a ROM from the given path. Returns true if the ROM was successfully loaded, otherwise false.")]
201+
public bool OpenRom(string path)
202202
{
203203
_luaLibsImpl.IsRebootingCore = true;
204-
APIs.EmuClient.OpenRom(path);
204+
var success = APIs.EmuClient.OpenRom(path);
205205
_luaLibsImpl.IsRebootingCore = false;
206+
return success;
206207
}
207208

208209
[LuaMethodExample("client.opentasstudio( );")]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public SaveStateLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer,
1010
public override string Name => "savestate";
1111

1212
[LuaMethodExample("savestate.load( \"C:\\state.bin\" );")]
13-
[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).")]
13+
[LuaMethod("load", "Loads a savestate with the given path. Returns true iff succeeded. If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes (and the path is ignored).")]
1414
public bool Load(string path, bool suppressOSD = false)
1515
{
1616
_luaLibsImpl.IsUpdateSupressed = true;
@@ -20,7 +20,7 @@ public bool Load(string path, bool suppressOSD = false)
2020
}
2121

2222
[LuaMethodExample("savestate.loadslot( 7 );")]
23-
[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.")]
23+
[LuaMethod("loadslot", "Loads the savestate at the given slot number (must be an integer between 1 and 10). Returns true iff succeeded. If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes with the slot number.")]
2424
public bool LoadSlot(int slotNum, bool suppressOSD = false)
2525
{
2626
_luaLibsImpl.IsUpdateSupressed = true;
@@ -35,7 +35,7 @@ public void Save(string path, bool suppressOSD = false)
3535
=> APIs.SaveState.Save(path, suppressOSD);
3636

3737
[LuaMethodExample("savestate.saveslot( 7 );")]
38-
[LuaMethod("saveslot", "Saves a state at the given save slot (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.")]
38+
[LuaMethod("saveslot", "Saves a state at the given save slot (must be an integer between 1 and 10). If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes with the slot number.")]
3939
public void SaveSlot(int slotNum, bool suppressOSD = false)
4040
=> APIs.SaveState.SaveSlot(slotNum, suppressOSD);
4141
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ private void OpenAdvancedMenuItem_Click(object sender, EventArgs e)
307307
{
308308
OpenAdvanced = new OpenAdvanced_LibretroNoGame(Config.LibretroCore)
309309
};
310-
LoadRom("", argsNoGame);
310+
_ = LoadRom(string.Empty, argsNoGame);
311311
return;
312312
}
313313

@@ -341,7 +341,7 @@ private void OpenAdvancedMenuItem_Click(object sender, EventArgs e)
341341
if (result is null) return;
342342
FileInfo file = new(result);
343343
Config.PathEntries.LastRomPath = file.DirectoryName;
344-
LoadRom(file.FullName, args);
344+
_ = LoadRom(file.FullName, args);
345345
}
346346

347347
private void CloseRomMenuItem_Click(object sender, EventArgs e)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ public bool LoadMovie(string filename, string archive = null)
9999
: StartNewMovie(MovieSession.Get(filename), false);
100100
}
101101

102-
private void LoadRom(string filename, string archive = null)
102+
private bool LoadRom(string filename, string archive = null)
103103
{
104104
var args = new LoadRomArgs
105105
{
106106
OpenAdvanced = new OpenAdvanced_OpenRom {Path = filename}
107107
};
108-
LoadRom(filename, args);
108+
return LoadRom(filename, args);
109109
}
110110

111111
private bool LoadStateFile(string filename, string archive = null)
@@ -262,7 +262,7 @@ private void FormDragDrop_internal()
262262
switch (value)
263263
{
264264
case LoadOrdering.Rom:
265-
LoadRom(filename, fileInformation.ArchiveName);
265+
_ = LoadRom(filename, fileInformation.ArchiveName);
266266
break;
267267
case LoadOrdering.State:
268268
_ = LoadStateFile(filename, fileInformation.ArchiveName);

src/BizHawk.Client.EmuHawk/MainForm.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ _argParser.SocketAddress is var (socketIP, socketPort)
578578
// Commandline should always override auto-load
579579
var ioa = OpenAdvancedSerializer.ParseWithLegacy(_argParser.cmdRom);
580580
if (ioa is OpenAdvanced_OpenRom oaor) ioa = new OpenAdvanced_OpenRom { Path = oaor.Path.MakeAbsolute() }; // fixes #3224; should this be done for all the IOpenAdvanced types? --yoshi
581-
LoadRom(ioa.SimplePath, new LoadRomArgs { OpenAdvanced = ioa });
581+
_ = LoadRom(ioa.SimplePath, new LoadRomArgs { OpenAdvanced = ioa });
582582
if (Game.IsNullInstance())
583583
{
584584
ShowMessageBox(owner: null, $"Failed to load {_argParser.cmdRom} specified on commandline");
@@ -2424,7 +2424,7 @@ private void OpenRom()
24242424
initDir: Config.PathEntries.RomAbsolutePath(Emulator.SystemId));
24252425
if (result is null) return;
24262426
var filePath = new FileInfo(result).FullName;
2427-
LoadRom(filePath, new LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom { Path = filePath } });
2427+
_ = LoadRom(filePath, new LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom { Path = filePath } });
24282428
}
24292429

24302430
private void CoreSyncSettings(object sender, RomLoader.SettingsLoadArgs e)
@@ -3677,7 +3677,7 @@ private void ShowLoadError(object sender, RomLoader.RomErrorArgs e)
36773677
// Retry loading the ROM here. This leads to recursion, as the original call to LoadRom has not exited yet,
36783678
// but unless the user tries and fails to set his firmware a lot of times, nothing should happen.
36793679
// Refer to how RomLoader implemented its LoadRom method for a potential fix on this.
3680-
LoadRom(e.RomPath, _currentLoadRomArgs);
3680+
_ = LoadRom(e.RomPath, _currentLoadRomArgs);
36813681
}
36823682
}
36833683
}
@@ -4828,7 +4828,7 @@ private void SingleInstanceProcessArgs(string[] args)
48284828
//in case this all sounds insanely sketchy to you, remember, the main 99% use case is double clicking roms in explorer
48294829

48304830
//BANZAIIIIIIIIIIIIIIIIIIIIIIIIIII
4831-
LoadRom(args[0]);
4831+
_ = LoadRom(args[0]);
48324832
}
48334833

48344834
public IQuickBmpFile QuickBmpFile { get; } = EmuHawk.QuickBmpFile.INSTANCE;

src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public RAIntegration(IMainFormForRetroAchievements mainForm, InputManager inputM
125125
Marshal.Copy(name, 0, buffer, Math.Min(name.Length, 256));
126126
};
127127
_resetEmulator = () => _mainForm.RebootCore();
128-
_loadROM = path => _mainForm.LoadRom(path, new LoadRomArgs { OpenAdvanced = OpenAdvancedSerializer.ParseWithLegacy(path) });
128+
_loadROM = path => _ = _mainForm.LoadRom(path, new LoadRomArgs { OpenAdvanced = OpenAdvancedSerializer.ParseWithLegacy(path) });
129129

130130
RA.InstallSharedFunctionsExt(_isActive, _unpause, _pause, _rebuildMenu, _estimateTitle, _resetEmulator, _loadROM);
131131

src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void SaveRunButton_Click(object sender, EventArgs e)
133133
Close();
134134

135135
var lra = new LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom { Path = fileInfo.FullName } };
136-
MainForm.LoadRom(fileInfo.FullName, lra);
136+
_ = MainForm.LoadRom(fileInfo.FullName, lra);
137137
}
138138

139139
private void AddButton_Click(object sender, EventArgs e)

0 commit comments

Comments
 (0)