From 72fa98cb8943b10b968d26096c3fc8a2964c8c57 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 2 Apr 2016 13:08:43 +0200 Subject: [PATCH] Improve exit/restart --- ArchiSteamFarm/Bot.cs | 6 +++--- ArchiSteamFarm/Program.cs | 17 +++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 5be68b6f7..f0ea3e03c 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -682,8 +682,8 @@ namespace ArchiSteamFarm { return null; } - Environment.Exit(0); - return null; + Program.Exit(0); + return "Done!"; } private string ResponseFarm(ulong steamID) { @@ -900,7 +900,7 @@ namespace ArchiSteamFarm { } Program.Restart(); - return null; + return "Done!"; } private async Task ResponseAddLicense(ulong steamID, HashSet gameIDs) { diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 749ace02a..58156ee9c 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -247,10 +247,15 @@ namespace ArchiSteamFarm { Restart(); } + internal static void Exit(int exitCode = 0) { + WCF.StopServer(); + Environment.Exit(exitCode); + } + internal static void Restart() { try { Process.Start(ExecutableFile, string.Join(" ", Environment.GetCommandLineArgs().Skip(1))); - Environment.Exit(0); + Exit(); } catch (Exception e) { Logging.LogGenericException(e); } @@ -337,14 +342,14 @@ namespace ArchiSteamFarm { if (GlobalConfig == null) { Logging.LogGenericError("Global config could not be loaded, please make sure that ASF.json exists and is valid!"); Thread.Sleep(5000); - Environment.Exit(1); + Exit(1); } GlobalDatabase = GlobalDatabase.Load(); if (GlobalDatabase == null) { Logging.LogGenericError("Global database could not be loaded!"); Thread.Sleep(5000); - Environment.Exit(1); + Exit(1); } ArchiWebHandler.Init(); @@ -445,7 +450,7 @@ namespace ArchiSteamFarm { // If we ran ASF as a client, we're done by now if (Mode == EMode.Client) { - Environment.Exit(0); + Exit(); } // From now on it's server mode @@ -454,7 +459,7 @@ namespace ArchiSteamFarm { if (!Directory.Exists(ConfigDirectory)) { Logging.LogGenericError("Config directory doesn't exist!"); Thread.Sleep(5000); - Environment.Exit(1); + Exit(1); } CheckForUpdate().Wait(); @@ -494,7 +499,7 @@ namespace ArchiSteamFarm { ShutdownResetEvent.WaitOne(); // We got a signal to shutdown - Environment.Exit(0); + Exit(); } } }