Skip to content

Commit e3bea52

Browse files
committed
cleanup libretro pathentry handling
- should close #4669 Presumably broke in 0681dd2 since that sets different game data before instantiating the libretro host. Relying on the game "name" when we actually want the core name was wrong to begin with imo, so I've simplified the logic to never rely on `GameInfo`.
1 parent 7a94ca5 commit e3bea52

File tree

7 files changed

+19
-36
lines changed

7 files changed

+19
-36
lines changed

src/BizHawk.Client.Common/CoreFileProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public CoreFileProvider(
2727
}
2828

2929
// Poop
30-
public string GetRetroSaveRAMDirectory(IGameInfo game)
31-
=> _pathEntries.RetroSaveRamAbsolutePath(game);
30+
public string GetRetroSaveRAMDirectory(string corePath)
31+
=> _pathEntries.RetroSaveRamAbsolutePath(Path.GetFileNameWithoutExtension(corePath));
3232

3333
// Poop
34-
public string GetRetroSystemPath(IGameInfo game)
35-
=> _pathEntries.RetroSystemAbsolutePath(game);
34+
public string GetRetroSystemPath(string corePath)
35+
=> _pathEntries.RetroSystemAbsolutePath(Path.GetFileNameWithoutExtension(corePath));
3636

3737
public string GetUserPath(string sysID, bool temp)
3838
{

src/BizHawk.Client.Common/RomLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ public bool LoadRom(string path, CoreComm nextComm, string launchLibretroCore, s
849849
game = new GameInfo { Name = Path.GetFileNameWithoutExtension(launchLibretroCore) };
850850
}
851851
game.System = VSystemID.Raw.Libretro;
852-
var retro = new LibretroHost(nextComm, game, launchLibretroCore);
852+
var retro = new LibretroHost(nextComm, launchLibretroCore);
853853
nextEmulator = retro;
854854

855855
if (retro.Description.SupportsNoGame && string.IsNullOrEmpty(path))

src/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,32 +245,19 @@ public static string SaveRamAbsolutePath(this PathEntryCollection collection, IG
245245
}
246246

247247
// Shenanigans
248-
public static string RetroSaveRamAbsolutePath(this PathEntryCollection collection, IGameInfo game)
248+
public static string RetroSaveRamAbsolutePath(this PathEntryCollection collection, string coreName)
249249
{
250-
var name = game.FilesystemSafeName();
251-
name = Path.GetDirectoryName(name);
252-
if (name is null) name = string.Empty;
253-
else if (name.Length is 0) name = game.FilesystemSafeName();
254-
var pathEntry = collection[game.System, "Save RAM"]
255-
?? collection[game.System, "Base"];
250+
var pathEntry = collection[VSystemID.Raw.Libretro, "Save RAM"];
256251

257-
return Path.Combine(collection.AbsolutePathFor(pathEntry.Path, game.System), name);
252+
return Path.Combine(collection.AbsolutePathFor(pathEntry.Path, VSystemID.Raw.Libretro), coreName);
258253
}
259254

260255
// Shenanigans
261-
public static string RetroSystemAbsolutePath(this PathEntryCollection collection, IGameInfo game)
256+
public static string RetroSystemAbsolutePath(this PathEntryCollection collection, string coreName)
262257
{
263-
var name = game.FilesystemSafeName();
264-
name = Path.GetDirectoryName(name);
265-
if (string.IsNullOrEmpty(name))
266-
{
267-
name = game.FilesystemSafeName();
268-
}
269-
270-
var pathEntry = collection[game.System, "System"]
271-
?? collection[game.System, "Base"];
258+
var pathEntry = collection[VSystemID.Raw.Libretro, "System"];
272259

273-
return Path.Combine(collection.AbsolutePathFor(pathEntry.Path, game.System), name);
260+
return Path.Combine(collection.AbsolutePathFor(pathEntry.Path, VSystemID.Raw.Libretro), coreName);
274261
}
275262

276263
public static string AutoSaveRamAbsolutePath(this PathEntryCollection collection, IGameInfo game, IMovie movie)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private void OpenRomMenuItem_Click(object sender, EventArgs e)
220220

221221
private void OpenAdvancedMenuItem_Click(object sender, EventArgs e)
222222
{
223-
using var oac = new OpenAdvancedChooser(this, Config, CreateCoreComm, Game, RunLibretroCoreChooser);
223+
using var oac = new OpenAdvancedChooser(this, Config, CreateCoreComm, RunLibretroCoreChooser);
224224
if (this.ShowDialogWithTempMute(oac) == DialogResult.Cancel) return;
225225

226226
if (oac.Result == AdvancedRomLoaderType.LibretroLaunchNoGame)

src/BizHawk.Client.EmuHawk/OpenAdvancedChooser.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public partial class OpenAdvancedChooser : Form, IDialogParent
2929

3030
private RetroDescription _currentDescription;
3131

32-
private readonly IGameInfo _game;
33-
3432
private readonly Func<bool> _libretroCoreChooserCallback;
3533

3634
public IDialogController DialogController { get; }
@@ -39,11 +37,10 @@ public partial class OpenAdvancedChooser : Form, IDialogParent
3937

4038
public FilesystemFilterSet SuggestedExtensionFilter = null;
4139

42-
public OpenAdvancedChooser(IDialogController dialogController, Config config, Func<CoreComm> createCoreComm, IGameInfo game, Func<bool> libretroCoreChooserCallback)
40+
public OpenAdvancedChooser(IDialogController dialogController, Config config, Func<CoreComm> createCoreComm, Func<bool> libretroCoreChooserCallback)
4341
{
4442
_config = config;
4543
_createCoreComm = createCoreComm;
46-
_game = game;
4744
_libretroCoreChooserCallback = libretroCoreChooserCallback;
4845
DialogController = dialogController;
4946

@@ -82,7 +79,7 @@ private void RefreshLibretroCore(bool bootstrap)
8279
try
8380
{
8481
var coreComm = _createCoreComm();
85-
using var retro = new LibretroHost(coreComm, _game, core, true);
82+
using var retro = new LibretroHost(coreComm, core, true);
8683
if (retro.Description.SupportsNoGame)
8784
btnLibretroLaunchNoGame.Enabled = true;
8885
if (!string.IsNullOrEmpty(retro.Description.ValidExtensions))

src/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public interface ICoreFileProvider
88
/// <summary>
99
/// produces a path that contains saveram... because libretro cores need it
1010
/// </summary>
11-
string GetRetroSaveRAMDirectory(IGameInfo game);
11+
string GetRetroSaveRAMDirectory(string corePath);
1212

1313
/// <summary>
1414
/// produces a path for use as a libretro system path (different for each core)
1515
/// </summary>
16-
string GetRetroSystemPath(IGameInfo game);
16+
string GetRetroSystemPath(string corePath);
1717

1818
/// <summary>
1919
/// produces a 'user' path for a given system id

src/BizHawk.Emulation.Cores/Libretro/Libretro.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,11 @@ public void Exit()
7373
}
7474
}
7575

76-
/// <remarks>does not keep a reference to <paramref name="game"/></remarks>
77-
public LibretroHost(CoreComm comm, IGameInfo game, string corePath, bool analysis = false)
76+
public LibretroHost(CoreComm comm, string corePath, bool analysis = false)
7877
: this(
7978
comm,
80-
libretroSystemDir: comm.CoreFileProvider.GetRetroSystemPath(game),
81-
libretroSaveRAMDir: comm.CoreFileProvider.GetRetroSaveRAMDirectory(game),
79+
libretroSystemDir: comm.CoreFileProvider.GetRetroSystemPath(corePath),
80+
libretroSaveRAMDir: comm.CoreFileProvider.GetRetroSaveRAMDirectory(corePath),
8281
corePath: corePath,
8382
analysis: analysis) {}
8483

0 commit comments

Comments
 (0)