From 2a7bf4df426d48b05d2df7d97d763ef3db5a135a Mon Sep 17 00:00:00 2001 From: Sour Date: Mon, 14 Oct 2019 15:05:36 -0400 Subject: [PATCH] Updates: Avoid Application.Exit usage, attempt to kill existing processes before upgrade --- GUI.NET/Forms/frmConfigWizard.cs | 2 +- GUI.NET/Forms/frmMain.Help.cs | 2 +- GUI.NET/Program.cs | 1 - UpdateHelper/Program.cs | 12 ++++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/GUI.NET/Forms/frmConfigWizard.cs b/GUI.NET/Forms/frmConfigWizard.cs index c64f3320..863644ad 100644 --- a/GUI.NET/Forms/frmConfigWizard.cs +++ b/GUI.NET/Forms/frmConfigWizard.cs @@ -148,7 +148,7 @@ namespace Mesen.GUI.Forms private void lblCancel_Click(object sender, EventArgs e) { - Application.Exit(); + Close(); } private void radStoragePortable_CheckedChanged(object sender, EventArgs e) diff --git a/GUI.NET/Forms/frmMain.Help.cs b/GUI.NET/Forms/frmMain.Help.cs index c8b96daf..6b0b5c26 100644 --- a/GUI.NET/Forms/frmMain.Help.cs +++ b/GUI.NET/Forms/frmMain.Help.cs @@ -120,7 +120,7 @@ namespace Mesen.GUI.Forms this.BeginInvoke((MethodInvoker)(() => { using(frmUpdatePrompt frmUpdate = new frmUpdatePrompt(currentVersion, latestVersion, changeLog, fileHash, donateText)) { if(frmUpdate.ShowDialog(null, this) == DialogResult.OK) { - Application.Exit(); + Close(); } } })); diff --git a/GUI.NET/Program.cs b/GUI.NET/Program.cs index b8be9e25..e20eb7a1 100644 --- a/GUI.NET/Program.cs +++ b/GUI.NET/Program.cs @@ -95,7 +95,6 @@ namespace Mesen.GUI Application.Run(new frmConfigWizard()); if(ConfigManager.GetConfigFile() == null) { - Application.Exit(); return; } } diff --git a/UpdateHelper/Program.cs b/UpdateHelper/Program.cs index 609ed9d2..b845ebd3 100644 --- a/UpdateHelper/Program.cs +++ b/UpdateHelper/Program.cs @@ -19,6 +19,18 @@ namespace MesenUpdater string backupDestFile = args[2]; bool isAdmin = args.Length > 3 && args[3] == "admin"; + //Wait a bit for the application to shut down before trying to kill it + System.Threading.Thread.Sleep(1000); + try { + foreach(Process process in Process.GetProcessesByName("Mesen-S")) { + try { + if(process.MainModule.FileName == destFile) { + process.Kill(); + } + } catch { } + } + } catch { } + int retryCount = 0; while(retryCount < 10) { try {