From bba93b33d6cb6f9c40216d5f3131b3bc7763af7b Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 25 May 2025 00:56:19 +1000 Subject: [PATCH] Replace direct `CoreComm` usage in `RomLoader` w/ `IDialogParent` resolves #4208 partially reverts ddd14d527 --- src/BizHawk.Client.Common/RomLoader.cs | 12 +++++++++--- src/BizHawk.Client.EmuHawk/MainForm.cs | 3 +-- src/BizHawk.Client.EmuHawk/tools/BatchRun.cs | 2 +- src/BizHawk.Client.EmuHawk/tools/BatchRunner.cs | 9 +++++++-- src/BizHawk.Emulation.Common/CoreComms.cs | 4 ---- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index 2217934f23..334e8ea4ab 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -58,11 +58,17 @@ namespace BizHawk.Client.Common } private readonly Config _config; - public RomLoader(Config config) + private readonly IDialogParent _dialogParent; + + public RomLoader(Config config, IDialogParent dialogParent) { _config = config; + _dialogParent = dialogParent; } + private bool? Question(string text) + => _dialogParent.ModalMessageBox3(icon: EMsgBoxIcon.Question, caption: "ROM loader", text: text); + public enum LoadErrorType { Unknown, @@ -591,7 +597,7 @@ namespace BizHawk.Client.Common HawkFile hfMatching = new(binFilePath.RemoveSuffix(".bin") + ".cue"); if (hfMatching.Exists) { - var result = nextComm.Question(string.Format(FMT_STR_ASK, hfMatching.Name)); + var result = Question(string.Format(FMT_STR_ASK, hfMatching.Name)); if (result is null) { cancel = true; @@ -612,7 +618,7 @@ namespace BizHawk.Client.Common HawkFile hfSoleSibling = soleCueSiblingPath is null ? null : new(soleCueSiblingPath); if (hfSoleSibling is { Exists: true }) { - var result = nextComm.Question(string.Format(FMT_STR_ASK, hfSoleSibling.Name)); + var result = Question(string.Format(FMT_STR_ASK, hfSoleSibling.Name)); if (result is null) { cancel = true; diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 0f0dcaa70d..405d03c375 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -306,7 +306,6 @@ namespace BizHawk.Client.EmuHawk return new CoreComm( message => this.ModalMessageBox(message, "Warning", EMsgBoxIcon.Warning), AddOnScreenMessage, - text => this.ModalMessageBox3(icon: EMsgBoxIcon.Question, caption: "ROM loader", text: text), cfp, prefs, new OpenGLProvider()); @@ -3773,7 +3772,7 @@ namespace BizHawk.Client.EmuHawk return false; } - var loader = new RomLoader(Config) + var loader = new RomLoader(Config, this) { ChooseArchive = LoadArchiveChooser, ChoosePlatform = ChoosePlatformForRom, diff --git a/src/BizHawk.Client.EmuHawk/tools/BatchRun.cs b/src/BizHawk.Client.EmuHawk/tools/BatchRun.cs index 9477f35a95..d324a9bb21 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BatchRun.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BatchRun.cs @@ -94,7 +94,7 @@ namespace BizHawk.Client.EmuHawk try { var pp = (Tuple>)o; - BatchRunner br = new BatchRunner(_config, _createCoreComm(), pp.Item2, pp.Item1); + BatchRunner br = new(_createCoreComm(), _config, this, pp.Item2, pp.Item1); br.OnProgress += BrOnProgress; var results = br.Run(); this.Invoke(() => { label3.Text = "Status: Finished!"; _mostRecentResults = results; }); diff --git a/src/BizHawk.Client.EmuHawk/tools/BatchRunner.cs b/src/BizHawk.Client.EmuHawk/tools/BatchRunner.cs index 521cd2a555..145c01ff82 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BatchRunner.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BatchRunner.cs @@ -63,12 +63,17 @@ namespace BizHawk.Client.EmuHawk } } - public BatchRunner(Config config, CoreComm comm, IEnumerable files, int numFrames) + public BatchRunner( + CoreComm comm, + Config config, + IDialogParent dialogParent, + IEnumerable files, + int numFrames) { _files = new List(files); _numFrames = numFrames; - _ldr = new RomLoader(config); + _ldr = new RomLoader(config, dialogParent); _ldr.OnLoadError += OnLoadError; _ldr.ChooseArchive = ChooseArchive; _comm = comm; diff --git a/src/BizHawk.Emulation.Common/CoreComms.cs b/src/BizHawk.Emulation.Common/CoreComms.cs index 6ddde06743..24e209a959 100644 --- a/src/BizHawk.Emulation.Common/CoreComms.cs +++ b/src/BizHawk.Emulation.Common/CoreComms.cs @@ -8,12 +8,9 @@ namespace BizHawk.Emulation.Common /// public class CoreComm { - public readonly Func Question; - public CoreComm( Action showMessage, Action notifyMessage, - Func question, ICoreFileProvider coreFileProvider, CorePreferencesFlags prefs, IOpenGLProvider oglProvider @@ -21,7 +18,6 @@ namespace BizHawk.Emulation.Common { ShowMessage = showMessage; Notify = notifyMessage; - Question = question; CoreFileProvider = coreFileProvider; CorePreferences = prefs; OpenGLProvider = oglProvider;