PathEntryCollectionExtensions - remove use of Global.MovieSession

This commit is contained in:
adelikat 2020-05-31 14:47:09 -05:00
parent e7f26232b9
commit 926b735de1
4 changed files with 17 additions and 19 deletions

View File

@ -30,7 +30,7 @@ namespace BizHawk.Client.Common
// Poop
public string GetRetroSaveRAMDirectory(GameInfo game)
=> _pathEntries.RetroSaveRamAbsolutePath(game, Global.MovieSession.Movie.IsActive(), Global.MovieSession.Movie.Filename);
=> _pathEntries.RetroSaveRamAbsolutePath(game, Global.MovieSession.Movie);
// Poop
public string GetRetroSystemPath(GameInfo game)

View File

@ -222,12 +222,12 @@ namespace BizHawk.Client.Common
return collection.AbsolutePathFor(path.Path, systemId);
}
public static string SaveRamAbsolutePath(this PathEntryCollection collection, GameInfo game, bool movieIsActive)
public static string SaveRamAbsolutePath(this PathEntryCollection collection, GameInfo game, IMovie movie)
{
var name = game.FilesystemSafeName();
if (movieIsActive)
if (movie.IsActive())
{
name += $".{Path.GetFileNameWithoutExtension(Global.MovieSession.Movie.Filename)}";
name += $".{Path.GetFileNameWithoutExtension(movie.Filename)}";
}
var pathEntry = collection[game.System, "Save RAM"]
@ -237,7 +237,7 @@ namespace BizHawk.Client.Common
}
// Shenanigans
public static string RetroSaveRamAbsolutePath(this PathEntryCollection collection, GameInfo game, bool movieIsActive, string movieFilename)
public static string RetroSaveRamAbsolutePath(this PathEntryCollection collection, GameInfo game, IMovie movie)
{
var name = game.FilesystemSafeName();
name = Path.GetDirectoryName(name);
@ -248,9 +248,9 @@ namespace BizHawk.Client.Common
name ??= "";
if (movieIsActive)
if (movie.IsActive())
{
name = Path.Combine(name, $"movie-{Path.GetFileNameWithoutExtension(movieFilename)}");
name = Path.Combine(name, $"movie-{Path.GetFileNameWithoutExtension(movie.Filename)}");
}
var pathEntry = collection[game.System, "Save RAM"]
@ -275,9 +275,9 @@ namespace BizHawk.Client.Common
return Path.Combine(collection.AbsolutePathFor(pathEntry.Path, game.System), name);
}
public static string AutoSaveRamAbsolutePath(this PathEntryCollection collection, GameInfo game, bool movieIsActive)
public static string AutoSaveRamAbsolutePath(this PathEntryCollection collection, GameInfo game, IMovie movie)
{
var path = collection.SaveRamAbsolutePath(game, movieIsActive);
var path = collection.SaveRamAbsolutePath(game, movie);
return path.Insert(path.Length - 8, ".AutoSaveRAM");
}

View File

@ -2634,7 +2634,7 @@ namespace BizHawk.Client.EmuHawk
ConfigContextMenuItem.Visible = _inFullscreen;
ClearSRAMContextMenuItem.Visible = File.Exists(Config.PathEntries.SaveRamAbsolutePath(Game, movieIsActive));
ClearSRAMContextMenuItem.Visible = File.Exists(Config.PathEntries.SaveRamAbsolutePath(Game, MovieSession.Movie));
ContextSeparator_AfterROM.Visible = OpenRomContextMenuItem.Visible || LoadLastRomContextMenuItem.Visible;

View File

@ -1624,11 +1624,11 @@ namespace BizHawk.Client.EmuHawk
{
try // zero says: this is sort of sketchy... but this is no time for rearchitecting
{
var saveRamPath = Config.PathEntries.SaveRamAbsolutePath(Game, MovieSession.Movie.IsActive());
var saveRamPath = Config.PathEntries.SaveRamAbsolutePath(Game, MovieSession.Movie);
if (Config.AutosaveSaveRAM)
{
var saveram = new FileInfo(saveRamPath);
var autosave = new FileInfo(Config.PathEntries.AutoSaveRamAbsolutePath(Game, MovieSession.Movie.IsActive()));
var autosave = new FileInfo(Config.PathEntries.AutoSaveRamAbsolutePath(Game, MovieSession.Movie));
if (autosave.Exists && autosave.LastWriteTime > saveram.LastWriteTime)
{
AddOnScreenMessage("AutoSaveRAM is newer than last saved SaveRAM");
@ -1673,16 +1673,15 @@ namespace BizHawk.Client.EmuHawk
{
if (Emulator.HasSaveRam())
{
bool movieIsActive = MovieSession.Movie.IsActive();
string path;
if (autosave)
{
path = Config.PathEntries.AutoSaveRamAbsolutePath(Game, movieIsActive);
path = Config.PathEntries.AutoSaveRamAbsolutePath(Game, MovieSession.Movie);
AutoFlushSaveRamIn = Config.FlushSaveRamFrames;
}
else
{
path = Config.PathEntries.SaveRamAbsolutePath(Game, movieIsActive);
path = Config.PathEntries.SaveRamAbsolutePath(Game, MovieSession.Movie);
}
var file = new FileInfo(path);
@ -3718,12 +3717,11 @@ namespace BizHawk.Client.EmuHawk
// Don't load Save Ram if a movie is being loaded
if (!MovieSession.NewMovieQueued)
{
var movieIsActive = MovieSession.Movie.IsActive();
if (File.Exists(Config.PathEntries.SaveRamAbsolutePath(loader.Game, movieIsActive)))
if (File.Exists(Config.PathEntries.SaveRamAbsolutePath(loader.Game, MovieSession.Movie)))
{
LoadSaveRam();
}
else if (Config.AutosaveSaveRAM && File.Exists(Config.PathEntries.SaveRamAbsolutePath(loader.Game, movieIsActive)))
else if (Config.AutosaveSaveRAM && File.Exists(Config.PathEntries.SaveRamAbsolutePath(loader.Game, MovieSession.Movie)))
{
AddOnScreenMessage("AutoSaveRAM found, but SaveRAM was not saved");
}
@ -3838,7 +3836,7 @@ namespace BizHawk.Client.EmuHawk
GameIsClosing = true;
if (clearSram)
{
var path = Config.PathEntries.SaveRamAbsolutePath(Game, MovieSession.Movie.IsActive());
var path = Config.PathEntries.SaveRamAbsolutePath(Game, MovieSession.Movie);
if (File.Exists(path))
{
File.Delete(path);