Remove single-instance feature (keeping config and UI)
This commit is contained in:
parent
ba3c2b275f
commit
fa07dc898f
|
@ -78,7 +78,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
-->
|
-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
|
|
||||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -9,8 +9,6 @@ using System.Windows.Forms;
|
||||||
using BizHawk.Bizware.BizwareGL;
|
using BizHawk.Bizware.BizwareGL;
|
||||||
using BizHawk.Bizware.DirectX;
|
using BizHawk.Bizware.DirectX;
|
||||||
|
|
||||||
using Microsoft.VisualBasic.ApplicationServices;
|
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
using BizHawk.Common.PathExtensions;
|
using BizHawk.Common.PathExtensions;
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
@ -210,41 +208,27 @@ namespace BizHawk.Client.EmuHawk
|
||||||
var exitCode = 0;
|
var exitCode = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!OSTC.IsUnixHost && initialConfig.SingleInstanceMode)
|
var mf = new MainForm(initialConfig, workingGL, newSound => globalSound = newSound, args, out var movieSession);
|
||||||
|
// var title = mf.Text;
|
||||||
|
mf.Show();
|
||||||
|
// mf.Text = title;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
exitCode = mf.ProgramRunLoop();
|
||||||
{
|
if (!mf.IsDisposed)
|
||||||
InitAndRunSingleInstance(initialConfig, workingGL, newSound => globalSound = newSound, i => exitCode = i, args);
|
mf.Dispose();
|
||||||
}
|
|
||||||
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
|
catch (Exception e) when (movieSession.Movie.IsActive() && !(Debugger.IsAttached || VersionInfo.DeveloperBuild))
|
||||||
{
|
{
|
||||||
var mf = new MainForm(initialConfig, workingGL, newSound => globalSound = newSound, args, out var movieSession);
|
var result = MessageBox.Show(
|
||||||
// var title = mf.Text;
|
"EmuHawk has thrown a fatal exception and is about to close.\nA movie has been detected. Would you like to try to save?\n(Note: Depending on what caused this error, this may or may not succeed)",
|
||||||
mf.Show();
|
$"Fatal error: {e.GetType().Name}",
|
||||||
// mf.Text = title;
|
MessageBoxButtons.YesNo,
|
||||||
try
|
MessageBoxIcon.Exclamation
|
||||||
|
);
|
||||||
|
if (result == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
exitCode = mf.ProgramRunLoop();
|
movieSession.Movie.Save();
|
||||||
if (!mf.IsDisposed)
|
|
||||||
mf.Dispose();
|
|
||||||
}
|
|
||||||
catch (Exception e) when (movieSession.Movie.IsActive() && !(Debugger.IsAttached || VersionInfo.DeveloperBuild))
|
|
||||||
{
|
|
||||||
var result = MessageBox.Show(
|
|
||||||
"EmuHawk has thrown a fatal exception and is about to close.\nA movie has been detected. Would you like to try to save?\n(Note: Depending on what caused this error, this may or may not succeed)",
|
|
||||||
$"Fatal error: {e.GetType().Name}",
|
|
||||||
MessageBoxButtons.YesNo,
|
|
||||||
MessageBoxIcon.Exclamation
|
|
||||||
);
|
|
||||||
if (result == DialogResult.Yes)
|
|
||||||
{
|
|
||||||
movieSession.Movie.Save();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,49 +298,5 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return File.Exists(fname) ? Assembly.LoadFile(fname) : null;
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue