From ece3526b3108936fa8901bb7df23566ac18bff03 Mon Sep 17 00:00:00 2001 From: Souryo Date: Fri, 8 Sep 2017 20:10:30 -0400 Subject: [PATCH] Linux: Fixed crash when trying to start another instance (fixes file associations) --- GUI.NET/ResourceManager.cs | 10 +++++++++- GUI.NET/SingleInstance.cs | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/GUI.NET/ResourceManager.cs b/GUI.NET/ResourceManager.cs index 734763cc..6dbd80e3 100644 --- a/GUI.NET/ResourceManager.cs +++ b/GUI.NET/ResourceManager.cs @@ -14,8 +14,16 @@ namespace Mesen.GUI { private static void ExtractFile(ZipArchiveEntry entry, string outputFilename) { + if(File.Exists(outputFilename)) { + try { + File.Delete(outputFilename); + } catch { } + } try { - entry.ExtractToFile(outputFilename, true); + //On Mono, using overwrite = true for ExtractToFile crashes/kills any currently running instance that uses the file. + //This is probably a Mono bug? + //Better to attempt a delete & then extract, like now (and like it used to be) + entry.ExtractToFile(outputFilename); } catch { } } diff --git a/GUI.NET/SingleInstance.cs b/GUI.NET/SingleInstance.cs index 7311dbd6..dc43a458 100644 --- a/GUI.NET/SingleInstance.cs +++ b/GUI.NET/SingleInstance.cs @@ -36,6 +36,11 @@ namespace Mesen.GUI } catch { _firstInstance = false; } + try { + if(File.Exists("mesen.arguments")) { + File.Delete("mesen.arguments"); + } + } catch { } } else { this._identifier = new Guid("{A46606B7-2D1C-4CC5-A52F-43BCAF094AED}"); this._mutex = new Mutex(true, _identifier.ToString(), out _firstInstance); @@ -96,7 +101,7 @@ namespace Mesen.GUI if(File.Exists("mesen.arguments")) { try { string[] arguments = File.ReadAllLines("mesen.arguments"); - ThreadPool.QueueUserWorkItem(new WaitCallback(CallOnArgumentsReceived), arguments); + ThreadPool.QueueUserWorkItem(new WaitCallback(CallOnArgumentsReceived), arguments); File.Delete("mesen.arguments"); } catch { } }