From d5e865dff3367f6781ae00770f8a047247f7f14a Mon Sep 17 00:00:00 2001 From: JustArchi Date: Wed, 1 Feb 2017 00:49:49 +0100 Subject: [PATCH] Misc --- GUI/Program.cs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/GUI/Program.cs b/GUI/Program.cs index fd5128717..e53b82dc0 100644 --- a/GUI/Program.cs +++ b/GUI/Program.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using ArchiSteamFarm.Localization; using SteamKit2; namespace ArchiSteamFarm { @@ -19,8 +19,12 @@ namespace ArchiSteamFarm { private static bool ShutdownSequenceInitialized; - internal static async Task Exit(int exitCode = 0) { - await InitShutdownSequence().ConfigureAwait(false); + internal static async Task Exit(byte exitCode = 0) { + if (exitCode != 0) { + ASF.ArchiLogger.LogGenericError(Strings.ErrorExitingWithNonZeroErrorCode); + } + + await Shutdown().ConfigureAwait(false); Environment.Exit(exitCode); } @@ -42,15 +46,11 @@ namespace ArchiSteamFarm { } internal static async Task Restart() { - await InitShutdownSequence().ConfigureAwait(false); - - try { - Process.Start(Assembly.GetEntryAssembly().Location, string.Join(" ", Environment.GetCommandLineArgs().Skip(1))); - } catch (Exception e) { - ArchiLogger.LogGenericException(e); + if (!await InitShutdownSequence().ConfigureAwait(false)) { + return; } - Environment.Exit(0); + Application.Restart(); } private static async Task Init() { @@ -139,6 +139,14 @@ namespace ArchiSteamFarm { Application.Run(new MainForm()); } + private static async Task Shutdown() { + if (!await InitShutdownSequence().ConfigureAwait(false)) { + return; + } + + Application.Exit(); + } + private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) { if (args?.ExceptionObject == null) { ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject));