From 926b735de1ddd9c3bb037f1b0bddb0fb38deaf19 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 31 May 2020 14:47:09 -0500 Subject: [PATCH] PathEntryCollectionExtensions - remove use of Global.MovieSession --- src/BizHawk.Client.Common/CoreFileProvider.cs | 2 +- .../config/PathEntryCollectionExtensions.cs | 16 ++++++++-------- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 2 +- src/BizHawk.Client.EmuHawk/MainForm.cs | 16 +++++++--------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/BizHawk.Client.Common/CoreFileProvider.cs b/src/BizHawk.Client.Common/CoreFileProvider.cs index 532cba5926..1da69b1aff 100644 --- a/src/BizHawk.Client.Common/CoreFileProvider.cs +++ b/src/BizHawk.Client.Common/CoreFileProvider.cs @@ -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) diff --git a/src/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs b/src/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs index e577ab8f79..ca7afef481 100644 --- a/src/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs +++ b/src/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs @@ -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"); } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 4fd04b2174..69f9ef17b5 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -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; diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index ad9934654a..01a4cff481 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -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);