Remove single-instance feature (keeping config and UI)

This commit is contained in:
YoshiRulz 2021-01-18 08:45:41 +10:00
parent ba3c2b275f
commit fa07dc898f
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 17 additions and 78 deletions

View File

@ -78,7 +78,6 @@
</ItemGroup>
-->
<ItemGroup>
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>

View File

@ -9,8 +9,6 @@ using System.Windows.Forms;
using BizHawk.Bizware.BizwareGL;
using BizHawk.Bizware.DirectX;
using Microsoft.VisualBasic.ApplicationServices;
using BizHawk.Common;
using BizHawk.Common.PathExtensions;
using BizHawk.Client.Common;
@ -209,19 +207,6 @@ namespace BizHawk.Client.EmuHawk
var exitCode = 0;
try
{
if (!OSTC.IsUnixHost && initialConfig.SingleInstanceMode)
{
try
{
InitAndRunSingleInstance(initialConfig, workingGL, newSound => globalSound = newSound, i => exitCode = i, args);
}
catch (ObjectDisposedException)
{
// Eat it, MainForm disposed itself and Run attempts to dispose of itself. Eventually we would want to figure out a way to prevent that, but in the meantime it is harmless, so just eat the error
}
}
else
{
var mf = new MainForm(initialConfig, workingGL, newSound => globalSound = newSound, args, out var movieSession);
// var title = mf.Text;
@ -247,7 +232,6 @@ namespace BizHawk.Client.EmuHawk
}
}
}
}
catch (Exception e) when (!Debugger.IsAttached)
{
new ExceptionBox(e).ShowDialog();
@ -314,49 +298,5 @@ namespace BizHawk.Client.EmuHawk
return File.Exists(fname) ? Assembly.LoadFile(fname) : null;
}
}
private class SingleInstanceController : WindowsFormsApplicationBase
{
private readonly Config _config;
private readonly IGL _gl;
private readonly Action<int> _setExitCode;
private readonly Action<Sound> _updateGlobalSound;
private readonly string[] cmdArgs;
public SingleInstanceController(Config config, IGL gl, Action<Sound> updateGlobalSound, Action<int> setExitCode, string[] args)
{
_config = config;
_gl = gl;
_setExitCode = setExitCode;
_updateGlobalSound = updateGlobalSound;
cmdArgs = args;
IsSingleInstance = true;
StartupNextInstance += this_StartupNextInstance;
}
public void Run() => Run(cmdArgs);
private void this_StartupNextInstance(object sender, StartupNextInstanceEventArgs e)
{
if (e.CommandLine.Count >= 1)
((MainForm)MainForm).LoadRom(e.CommandLine[0], new LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom() });
}
protected override void OnCreateMainForm()
{
MainForm = new MainForm(_config, _gl, _updateGlobalSound, cmdArgs, out _);
var title = MainForm.Text;
MainForm.Show();
MainForm.Text = title;
_setExitCode(((MainForm) MainForm).ProgramRunLoop());
}
}
private static void InitAndRunSingleInstance(Config config, IGL gl, Action<Sound> updateGlobalSound, Action<int> setExitCode, string[] args)
=> new SingleInstanceController(config, gl, updateGlobalSound, setExitCode, args).Run();
}
}