From e4df38602b644c1f938bbe9b416d4edf87b57dfa Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 29 Jun 2020 14:35:12 +1000 Subject: [PATCH] Pass delegates instead of MainForm to BatchRunner --- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 2 +- src/BizHawk.Client.EmuHawk/tools/BatchRun.cs | 16 ++++++++++------ src/BizHawk.Client.EmuHawk/tools/BatchRunner.cs | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index bef7fa8ab7..19fe64ff72 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -1371,7 +1371,7 @@ namespace BizHawk.Client.EmuHawk private void BatchRunnerMenuItem_Click(object sender, EventArgs e) { - using var form = new BatchRun(this); + using var form = new BatchRun(CreateCoreComm); form.ShowDialog(); } diff --git a/src/BizHawk.Client.EmuHawk/tools/BatchRun.cs b/src/BizHawk.Client.EmuHawk/tools/BatchRun.cs index fac654c1e4..57431cf8c3 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BatchRun.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BatchRun.cs @@ -4,17 +4,21 @@ using System.Windows.Forms; using System.Threading; using System.IO; +using BizHawk.Emulation.Common; + namespace BizHawk.Client.EmuHawk { public partial class BatchRun : Form { - private Thread _thread; - private List _mostRecentResults; - private MainForm _mainForm; + private readonly Func _createCoreComm; - public BatchRun(MainForm mainForm) + private List _mostRecentResults; + + private Thread _thread; + + public BatchRun(Func createCoreComm) { - this._mainForm = mainForm; + _createCoreComm = createCoreComm; InitializeComponent(); } @@ -83,7 +87,7 @@ namespace BizHawk.Client.EmuHawk try { var pp = (Tuple>)o; - BatchRunner br = new BatchRunner(_mainForm, pp.Item2, pp.Item1); + BatchRunner br = new BatchRunner(_createCoreComm(), pp.Item2, pp.Item1); br.OnProgress += br_OnProgress; 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 f4d0ddd8d7..196c796462 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BatchRunner.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BatchRunner.cs @@ -64,7 +64,7 @@ namespace BizHawk.Client.EmuHawk } } - public BatchRunner(MainForm mainForm, IEnumerable files, int numFrames) + public BatchRunner(CoreComm comm, IEnumerable files, int numFrames) { _files = new List(files); _numFrames = numFrames; @@ -72,7 +72,7 @@ namespace BizHawk.Client.EmuHawk _ldr = new RomLoader(GlobalWin.Config, GlobalWin.FirmwareManager); _ldr.OnLoadError += OnLoadError; _ldr.ChooseArchive = ChooseArchive; - _comm = mainForm.CreateCoreComm(); + _comm = comm; } private void OnLoadError(object sender, RomLoader.RomErrorArgs e)