Skip to content

Commit bba93b3

Browse files
committed
Replace direct CoreComm usage in RomLoader w/ IDialogParent
resolves #4208 partially reverts ddd14d5
1 parent c0f93b0 commit bba93b3

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

src/BizHawk.Client.Common/RomLoader.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ public object FetchSyncSettings(Type emulatorType, Type syncSettingsType)
5858
}
5959
private readonly Config _config;
6060

61-
public RomLoader(Config config)
61+
private readonly IDialogParent _dialogParent;
62+
63+
public RomLoader(Config config, IDialogParent dialogParent)
6264
{
6365
_config = config;
66+
_dialogParent = dialogParent;
6467
}
6568

69+
private bool? Question(string text)
70+
=> _dialogParent.ModalMessageBox3(icon: EMsgBoxIcon.Question, caption: "ROM loader", text: text);
71+
6672
public enum LoadErrorType
6773
{
6874
Unknown,
@@ -591,7 +597,7 @@ private bool TryLoadSiblingCue(
591597
HawkFile hfMatching = new(binFilePath.RemoveSuffix(".bin") + ".cue");
592598
if (hfMatching.Exists)
593599
{
594-
var result = nextComm.Question(string.Format(FMT_STR_ASK, hfMatching.Name));
600+
var result = Question(string.Format(FMT_STR_ASK, hfMatching.Name));
595601
if (result is null)
596602
{
597603
cancel = true;
@@ -612,7 +618,7 @@ private bool TryLoadSiblingCue(
612618
HawkFile hfSoleSibling = soleCueSiblingPath is null ? null : new(soleCueSiblingPath);
613619
if (hfSoleSibling is { Exists: true })
614620
{
615-
var result = nextComm.Question(string.Format(FMT_STR_ASK, hfSoleSibling.Name));
621+
var result = Question(string.Format(FMT_STR_ASK, hfSoleSibling.Name));
616622
if (result is null)
617623
{
618624
cancel = true;

src/BizHawk.Client.EmuHawk/MainForm.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ public CoreComm CreateCoreComm()
306306
return new CoreComm(
307307
message => this.ModalMessageBox(message, "Warning", EMsgBoxIcon.Warning),
308308
AddOnScreenMessage,
309-
text => this.ModalMessageBox3(icon: EMsgBoxIcon.Question, caption: "ROM loader", text: text),
310309
cfp,
311310
prefs,
312311
new OpenGLProvider());
@@ -3773,7 +3772,7 @@ private bool LoadRomInternal(string path, LoadRomArgs args, out bool failureIsFr
37733772
return false;
37743773
}
37753774

3776-
var loader = new RomLoader(Config)
3775+
var loader = new RomLoader(Config, this)
37773776
{
37783777
ChooseArchive = LoadArchiveChooser,
37793778
ChoosePlatform = ChoosePlatformForRom,

src/BizHawk.Client.EmuHawk/tools/BatchRun.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void ThreadProc(object o)
9494
try
9595
{
9696
var pp = (Tuple<int, List<string>>)o;
97-
BatchRunner br = new BatchRunner(_config, _createCoreComm(), pp.Item2, pp.Item1);
97+
BatchRunner br = new(_createCoreComm(), _config, this, pp.Item2, pp.Item1);
9898
br.OnProgress += BrOnProgress;
9999
var results = br.Run();
100100
this.Invoke(() => { label3.Text = "Status: Finished!"; _mostRecentResults = results; });

src/BizHawk.Client.EmuHawk/tools/BatchRunner.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,17 @@ public void DumpTo(TextWriter tw)
6363
}
6464
}
6565

66-
public BatchRunner(Config config, CoreComm comm, IEnumerable<string> files, int numFrames)
66+
public BatchRunner(
67+
CoreComm comm,
68+
Config config,
69+
IDialogParent dialogParent,
70+
IEnumerable<string> files,
71+
int numFrames)
6772
{
6873
_files = new List<string>(files);
6974
_numFrames = numFrames;
7075

71-
_ldr = new RomLoader(config);
76+
_ldr = new RomLoader(config, dialogParent);
7277
_ldr.OnLoadError += OnLoadError;
7378
_ldr.ChooseArchive = ChooseArchive;
7479
_comm = comm;

src/BizHawk.Emulation.Common/CoreComms.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@ namespace BizHawk.Emulation.Common
88
/// </summary>
99
public class CoreComm
1010
{
11-
public readonly Func<string, bool?> Question;
12-
1311
public CoreComm(
1412
Action<string> showMessage,
1513
Action<string, int?> notifyMessage,
16-
Func<string, bool?> question,
1714
ICoreFileProvider coreFileProvider,
1815
CorePreferencesFlags prefs,
1916
IOpenGLProvider oglProvider
2017
)
2118
{
2219
ShowMessage = showMessage;
2320
Notify = notifyMessage;
24-
Question = question;
2521
CoreFileProvider = coreFileProvider;
2622
CorePreferences = prefs;
2723
OpenGLProvider = oglProvider;

0 commit comments

Comments
 (0)