From 768aa8be84a5838d7dfc32fe7038ca956c704ca9 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Wed, 5 Jul 2017 14:57:12 -0400 Subject: [PATCH] Installer will now prompt to kill TGCommandLine and TGControlPanel --- TGInstallerWrapper/Main.cs | 41 +++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/TGInstallerWrapper/Main.cs b/TGInstallerWrapper/Main.cs index ed3c6f1993..09f1b8243b 100644 --- a/TGInstallerWrapper/Main.cs +++ b/TGInstallerWrapper/Main.cs @@ -35,7 +35,31 @@ namespace TGInstallerWrapper private void Main_FormClosing(object sender, FormClosingEventArgs e) { - e.Cancel = installing; //not allowed, nununu + e.Cancel = installing; //not allowed, nununu + } + + enum PKillType + { + Killed, + Aborted, + NoneFound, + } + + PKillType PromptKillProcess(string name) + { + foreach (var P in Process.GetProcessesByName(name)) + { + if (!P.HasExited && MessageBox.Show(String.Format("Found running {0}.exe! Shall I terminate it?", name), "Warning", MessageBoxButtons.YesNo) != DialogResult.Yes) + return PKillType.Aborted; + if (!P.HasExited) + { + P.Kill(); + P.WaitForExit(); + } + P.Dispose(); + return PKillType.Killed; + } + return PKillType.NoneFound; } async void DoInstall() @@ -90,6 +114,21 @@ namespace TGInstallerWrapper } } + while (true) + { + var res = PromptKillProcess("TGCommandLine"); + if (res == PKillType.Aborted) + return; + else if (res == PKillType.Killed) + continue; + res = PromptKillProcess("TGControlPanel"); + if (res == PKillType.Aborted) + return; + else if (res == PKillType.Killed) + continue; + break; + } + InstallCancelButton.Enabled = true; if (ShowLogCheckbox.Checked)