From ba939466df8dba6d0df220b0f669dccf01a93b4a Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 11 Jun 2020 18:25:34 -0500 Subject: [PATCH] Pass an IGameInfo into ToolFormBase and use it in tools --- .../movie/MovieConversionExtensions.cs | 2 +- src/BizHawk.Client.EmuHawk/LogWindow.cs | 2 +- src/BizHawk.Client.EmuHawk/MainForm.cs | 6 +++--- src/BizHawk.Client.EmuHawk/tools/CDL.cs | 2 +- src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs | 4 ++-- src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs | 4 ++-- src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs | 6 +++--- src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs | 2 +- .../tools/MultiDiskBundler/MultiDiskBundler.cs | 6 +++--- .../tools/NES/NESNameTableViewer.cs | 4 ++-- src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs | 2 +- .../tools/TAStudio/TAStudio.IToolForm.cs | 2 +- src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs | 4 ++-- src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs | 1 + src/BizHawk.Client.EmuHawk/tools/ToolManager.cs | 9 +++++++-- src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs | 6 +++--- src/BizHawk.Emulation.Common/Database/GameInfo.cs | 4 ++-- 17 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/MovieConversionExtensions.cs b/src/BizHawk.Client.Common/movie/MovieConversionExtensions.cs index 8f88f39f7e..937b2d9861 100644 --- a/src/BizHawk.Client.Common/movie/MovieConversionExtensions.cs +++ b/src/BizHawk.Client.Common/movie/MovieConversionExtensions.cs @@ -185,7 +185,7 @@ namespace BizHawk.Client.Common public static void PopulateWithDefaultHeaderValues( this IMovie movie, IEmulator emulator, - GameInfo game, + IGameInfo game, FirmwareManager firmwareManager, string author) { diff --git a/src/BizHawk.Client.EmuHawk/LogWindow.cs b/src/BizHawk.Client.EmuHawk/LogWindow.cs index dc9ca03fc5..a76d3ca812 100644 --- a/src/BizHawk.Client.EmuHawk/LogWindow.cs +++ b/src/BizHawk.Client.EmuHawk/LogWindow.cs @@ -137,7 +137,7 @@ namespace BizHawk.Client.EmuHawk private void HideShowGameDbButton() { AddToGameDbBtn.Visible = Emulator.CanGenerateGameDBEntries() - && (GlobalWin.Game.Status == RomStatus.Unknown || GlobalWin.Game.Status == RomStatus.NotInDatabase); + && (Game.Status == RomStatus.Unknown || Game.Status == RomStatus.NotInDatabase); } private void AddToGameDbBtn_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 4153f3023e..2779723c16 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -299,7 +299,7 @@ namespace BizHawk.Client.EmuHawk _throttle = new Throttle(); Emulator = new NullEmulator(); - GlobalWin.Tools = new ToolManager(this, Config, Emulator, MovieSession); + GlobalWin.Tools = new ToolManager(this, Config, Emulator, MovieSession, Game); UpdateStatusSlots(); UpdateKeyPriorityIcon(); @@ -3786,7 +3786,7 @@ namespace BizHawk.Client.EmuHawk } } - Tools.Restart(Emulator); + Tools.Restart(Emulator, Game); if (Config.Cheats.LoadFileByGame && Emulator.HasMemoryDomains()) { @@ -3950,7 +3950,7 @@ namespace BizHawk.Client.EmuHawk Emulator = new NullEmulator(); GlobalWin.Game = GameInfo.NullInstance; CreateRewinder(); - Tools.Restart(Emulator); + Tools.Restart(Emulator, Game); RewireSound(); ClearHolds(); Tools.UpdateCheatRelatedTools(null, null); diff --git a/src/BizHawk.Client.EmuHawk/tools/CDL.cs b/src/BizHawk.Client.EmuHawk/tools/CDL.cs index 6fca6f6c7c..cde17d5bf3 100644 --- a/src/BizHawk.Client.EmuHawk/tools/CDL.cs +++ b/src/BizHawk.Client.EmuHawk/tools/CDL.cs @@ -481,7 +481,7 @@ namespace BizHawk.Client.EmuHawk try { _autoloading = true; - var autoResumeFile = $"{GlobalWin.Game.FilesystemSafeName()}.cdl"; + var autoResumeFile = $"{Game.FilesystemSafeName()}.cdl"; var autoResumeDir = Config.PathEntries.LogAbsolutePath(); var autoResumePath = Path.Combine(autoResumeDir, autoResumeFile); if (File.Exists(autoResumePath)) diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 46b0f757e5..97c2694182 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -118,7 +118,7 @@ namespace BizHawk.Client.EmuHawk { var file = SaveFileDialog( MainForm.CheatList.CurrentFileName, - Config.PathEntries.CheatsAbsolutePath(GlobalWin.Game.System), + Config.PathEntries.CheatsAbsolutePath(Game.System), "Cheat Files", "cht"); @@ -350,7 +350,7 @@ namespace BizHawk.Client.EmuHawk { var file = OpenFileDialog( MainForm.CheatList.CurrentFileName, - Config.PathEntries.CheatsAbsolutePath(GlobalWin.Game.System), + Config.PathEntries.CheatsAbsolutePath(Game.System), "Cheat Files", "cht"); diff --git a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index 6ca816ee0a..5517a76033 100644 --- a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -912,7 +912,7 @@ namespace BizHawk.Client.EmuHawk , FileName = _domain.Name == "File on Disk" ? RomName - : GlobalWin.Game.FilesystemSafeName() + : Game.FilesystemSafeName() }; var result = sfd.ShowHawkDialog(); @@ -925,7 +925,7 @@ namespace BizHawk.Client.EmuHawk { FileName = _domain.Name == "File on Disk" ? $"{Path.GetFileNameWithoutExtension(RomName)}.txt" - : GlobalWin.Game.FilesystemSafeName(), + : Game.FilesystemSafeName(), Filter = new FilesystemFilterSet(FilesystemFilter.TextFiles).ToString(), InitialDirectory = RomDirectory, RestoreDirectory = true diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 25a913d6ea..ab29342839 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -635,9 +635,9 @@ namespace BizHawk.Client.EmuHawk sfd.FileName = Path.GetFileNameWithoutExtension(LuaImp.ScriptList.Filename); sfd.InitialDirectory = Path.GetDirectoryName(LuaImp.ScriptList.Filename); } - else if (GlobalWin.Game != null) + else if (!Game.IsNullInstance()) { - sfd.FileName = GlobalWin.Game.FilesystemSafeName(); + sfd.FileName = Game.FilesystemSafeName(); sfd.InitialDirectory = Config.PathEntries.LuaAbsolutePath(); } else @@ -834,7 +834,7 @@ namespace BizHawk.Client.EmuHawk DefaultExt = ".lua", FileName = !string.IsNullOrWhiteSpace(LuaImp.ScriptList.Filename) ? Path.GetFileNameWithoutExtension(LuaImp.ScriptList.Filename) - : Path.GetFileNameWithoutExtension(GlobalWin.Game.Name), + : Path.GetFileNameWithoutExtension(Game.Name), OverwritePrompt = true, Filter = new FilesystemFilterSet(FilesystemFilter.LuaScripts).ToString() }; diff --git a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs index 5b9e26d240..9da10ee075 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs @@ -260,7 +260,7 @@ namespace BizHawk.Client.EmuHawk { return Config.PathEntries.AbsolutePathFor(Path.Combine( Config.PathEntries["Global", "Macros"].Path, - GlobalWin.Game.FilesystemSafeName()), null); + Game.FilesystemSafeName()), null); } public bool SaveMacroAs(MovieZone macro) diff --git a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs index c2d6df12e6..64875bc8ba 100644 --- a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs +++ b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs @@ -35,7 +35,7 @@ namespace BizHawk.Client.EmuHawk AddButton_Click(null, null); AddButton_Click(null, null); - if (!GlobalWin.Game.IsNullInstance() && !MainForm.CurrentlyOpenRom.EndsWith(".xml")) + if (!Game.IsNullInstance() && !MainForm.CurrentlyOpenRom.EndsWith(".xml")) { if (MainForm.CurrentlyOpenRom.Contains("|")) { @@ -215,12 +215,12 @@ namespace BizHawk.Client.EmuHawk string filename = ""; string initialDirectory = Config.PathEntries.MultiDiskAbsolutePath(); - if (!GlobalWin.Game.IsNullInstance()) + if (!Game.IsNullInstance()) { filename = NameBox.Text; if (string.IsNullOrWhiteSpace(filename)) { - filename = Path.ChangeExtension(GlobalWin.Game.FilesystemSafeName(), ".xml"); + filename = Path.ChangeExtension(Game.FilesystemSafeName(), ".xml"); } initialDirectory = Path.GetDirectoryName(filename); diff --git a/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs b/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs index 046feecd3b..33bae8eee2 100644 --- a/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs @@ -186,8 +186,8 @@ namespace BizHawk.Client.EmuHawk { using var sfd = new SaveFileDialog { - FileName = $"{GlobalWin.Game.FilesystemSafeName()}-Nametables", - InitialDirectory = GlobalWin.Config.PathEntries.ScreenshotAbsolutePathFor("NES"), + FileName = $"{Game.FilesystemSafeName()}-Nametables", + InitialDirectory = Config.PathEntries.ScreenshotAbsolutePathFor("NES"), Filter = FilesystemFilterSet.Screenshots.ToString(), RestoreDirectory = true }; diff --git a/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs b/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs index cbb25bf9ae..b759a88942 100644 --- a/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs +++ b/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs @@ -314,7 +314,7 @@ namespace BizHawk.Client.EmuHawk { var sfd = new SaveFileDialog { - FileName = $"{GlobalWin.Game.FilesystemSafeName()}-{suffix}", + FileName = $"{Game.FilesystemSafeName()}-{suffix}", InitialDirectory = Config.PathEntries.ScreenshotAbsolutePathFor("NES"), Filter = FilesystemFilterSet.Screenshots.ToString(), RestoreDirectory = true diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs index 1ae82dc589..f94fee7044 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs @@ -77,7 +77,7 @@ namespace BizHawk.Client.EmuHawk if (CurrentTasMovie != null) { - if (GlobalWin.Game.Hash != CurrentTasMovie.Hash) + if (Game.Hash != CurrentTasMovie.Hash) { TastudioStopMovie(); TasView.AllColumns.Clear(); diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index dbde92858f..2e4203638e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -685,7 +685,7 @@ namespace BizHawk.Client.EmuHawk tasMovie.PopulateWithDefaultHeaderValues( Emulator, - GlobalWin.Game, + Game, GlobalWin.FirmwareManager, Config.DefaultAuthor); @@ -813,7 +813,7 @@ namespace BizHawk.Client.EmuHawk { return Path.Combine( Config.PathEntries.MovieAbsolutePath(), - $"{GlobalWin.Game.FilesystemSafeName()}.{MovieService.TasMovieExtension}"); + $"{Game.FilesystemSafeName()}.{MovieService.TasMovieExtension}"); } private void SaveTas() diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs b/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs index e20af16676..5fab95a515 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs @@ -15,6 +15,7 @@ namespace BizHawk.Client.EmuHawk public MainForm MainForm { get; set; } public IMovieSession MovieSession { get; set; } + public IGameInfo Game { get; set; } public virtual bool AskSaveChanges() => true; diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs index 143c35876c..aef7a249c2 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -23,6 +23,7 @@ namespace BizHawk.Client.EmuHawk private IExternalApiProvider _apiProvider; private IEmulator _emulator; private IMovieSession _movieSession; + private IGameInfo _game; // TODO: merge ToolHelper code where logical // For instance, add an IToolForm property called UsesCheats, so that a UpdateCheatRelatedTools() method can update all tools of this type @@ -36,12 +37,14 @@ namespace BizHawk.Client.EmuHawk MainForm owner, Config config, IEmulator emulator, - IMovieSession movieSession) + IMovieSession movieSession, + IGameInfo game) { _owner = owner; _config = config; _emulator = emulator; _movieSession = movieSession; + _game = game; _apiProvider = ApiManager.Restart(_emulator.ServiceProvider); } @@ -74,6 +77,7 @@ namespace BizHawk.Client.EmuHawk tool.Config = _config; tool.MainForm = _owner; tool.MovieSession = _movieSession; + tool.Game = _game; } } @@ -479,9 +483,10 @@ namespace BizHawk.Client.EmuHawk } } - public void Restart(IEmulator emulator) + public void Restart(IEmulator emulator, IGameInfo game) { _emulator = emulator; + _game = game; _apiProvider = ApiManager.Restart(_emulator.ServiceProvider); // If Cheat tool is loaded, restarting will restart the list too anyway if (!Has()) diff --git a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs index a45ff99792..99d4f1a5b9 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs @@ -274,12 +274,12 @@ namespace BizHawk.Client.EmuHawk using var sfd = new SaveFileDialog(); if (LogFile == null) { - sfd.FileName = GlobalWin.Game.FilesystemSafeName() + _extension; + sfd.FileName = Game.FilesystemSafeName() + _extension; sfd.InitialDirectory = Config.PathEntries.LogAbsolutePath(); } else if (!string.IsNullOrWhiteSpace(LogFile.FullName)) { - sfd.FileName = GlobalWin.Game.FilesystemSafeName(); + sfd.FileName = Game.FilesystemSafeName(); sfd.InitialDirectory = Path.GetDirectoryName(LogFile.FullName); } else @@ -439,7 +439,7 @@ namespace BizHawk.Client.EmuHawk { FileBox.Visible = true; BrowseBox.Visible = true; - var name = GlobalWin.Game.FilesystemSafeName(); + var name = Game.FilesystemSafeName(); var filename = Path.Combine(Config.PathEntries.LogAbsolutePath(), name) + _extension; LogFile = new FileInfo(filename); if (LogFile.Directory != null && !LogFile.Directory.Exists) diff --git a/src/BizHawk.Emulation.Common/Database/GameInfo.cs b/src/BizHawk.Emulation.Common/Database/GameInfo.cs index 1473d32101..c8a4ce6f80 100644 --- a/src/BizHawk.Emulation.Common/Database/GameInfo.cs +++ b/src/BizHawk.Emulation.Common/Database/GameInfo.cs @@ -177,12 +177,12 @@ namespace BizHawk.Emulation.Common public static class GameInfoExtensions { - public static bool IsNullInstance(this GameInfo game) + public static bool IsNullInstance(this IGameInfo game) { return game == null || game.System == "NULL"; } - public static bool IsRomStatusBad(this GameInfo game) + public static bool IsRomStatusBad(this IGameInfo game) { return game.Status == RomStatus.BadDump || game.Status == RomStatus.Overdump; }