Fixed update when new mutex is used

- hardened installation
This commit is contained in:
MaxXor 2014-08-10 12:12:26 +02:00
parent 42abb29d14
commit 9d89f1cf56
1 changed files with 28 additions and 1 deletions

View File

@ -306,13 +306,40 @@ namespace Core
public static void Install()
{
bool isKilled = false;
// create target dir
if (!Directory.Exists(Path.Combine(Settings.DIR, Settings.SUBFOLDER)))
Directory.CreateDirectory(Path.Combine(Settings.DIR, Settings.SUBFOLDER));
// delete existing file
if (File.Exists(SystemCore.InstallPath))
File.Delete(SystemCore.InstallPath);
{
try
{
File.Delete(SystemCore.InstallPath);
}
catch (Exception ex)
{
if (ex is IOException || ex is UnauthorizedAccessException)
{
// kill old process if new mutex
Process[] foundProcesses = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(InstallPath));
int myPid = Process.GetCurrentProcess().Id;
foreach (var prc in foundProcesses)
{
if (prc.Id != myPid)
{
prc.Kill();
isKilled = true;
}
}
}
}
}
if (isKilled)
Thread.Sleep(5000);
//copy client to target dir
File.Copy(SystemCore.MyPath, SystemCore.InstallPath, true);