Replace direct `CoreComm` usage in `RomLoader` w/ `IDialogParent`

resolves #4208
partially reverts ddd14d527
This commit is contained in:
YoshiRulz 2025-05-25 00:56:19 +10:00
parent c0f93b05fc
commit bba93b33d6
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
5 changed files with 18 additions and 12 deletions

View File

@ -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;

View File

@ -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,

View File

@ -94,7 +94,7 @@ namespace BizHawk.Client.EmuHawk
try
{
var pp = (Tuple<int, List<string>>)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; });

View File

@ -63,12 +63,17 @@ namespace BizHawk.Client.EmuHawk
}
}
public BatchRunner(Config config, CoreComm comm, IEnumerable<string> files, int numFrames)
public BatchRunner(
CoreComm comm,
Config config,
IDialogParent dialogParent,
IEnumerable<string> files,
int numFrames)
{
_files = new List<string>(files);
_numFrames = numFrames;
_ldr = new RomLoader(config);
_ldr = new RomLoader(config, dialogParent);
_ldr.OnLoadError += OnLoadError;
_ldr.ChooseArchive = ChooseArchive;
_comm = comm;

View File

@ -8,12 +8,9 @@ namespace BizHawk.Emulation.Common
/// </summary>
public class CoreComm
{
public readonly Func<string, bool?> Question;
public CoreComm(
Action<string> showMessage,
Action<string, int?> notifyMessage,
Func<string, bool?> 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;