Merge pull request #121 from Cyberboss/SafeInstall

Installer will now prompt to kill TGCommandLine and TGControlPanel
This commit is contained in:
Jordan Brown
2017-07-05 15:19:29 -04:00
committed by GitHub
+40 -1
View File
@@ -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)