From af4a64b99e9faeed345b6582de0f1c25290e9645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Domeradzki?= Date: Wed, 20 Sep 2023 13:53:15 +0200 Subject: [PATCH] Closes #3007 (#3008) --- ArchiSteamFarm/Core/ASF.cs | 25 +++++++++++++++++++++++-- ArchiSteamFarm/Steam/Bot.cs | 7 ++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ArchiSteamFarm/Core/ASF.cs b/ArchiSteamFarm/Core/ASF.cs index 6cf9d75c7..aa3664a70 100644 --- a/ArchiSteamFarm/Core/ASF.cs +++ b/ArchiSteamFarm/Core/ASF.cs @@ -580,6 +580,28 @@ public static class ASF { await OnCreatedKeysFile(name, fullPath).ConfigureAwait(false); } + private static async Task OnConfigChanged() { + string globalConfigFile = GetFilePath(EFileType.Config); + + if (string.IsNullOrEmpty(globalConfigFile)) { + throw new InvalidOperationException(nameof(globalConfigFile)); + } + + (GlobalConfig? globalConfig, _) = await GlobalConfig.Load(globalConfigFile).ConfigureAwait(false); + + if (globalConfig == null) { + // Invalid config file, we allow user to fix it without destroying the ASF instance right away + return; + } + + if (globalConfig == GlobalConfig) { + return; + } + + ArchiLogger.LogGenericInfo(Strings.GlobalConfigChanged); + await RestartOrExit().ConfigureAwait(false); + } + private static async void OnCreated(object sender, FileSystemEventArgs e) { ArgumentNullException.ThrowIfNull(sender); ArgumentNullException.ThrowIfNull(e); @@ -666,8 +688,7 @@ public static class ASF { } if (botName.Equals(SharedInfo.ASF, StringComparison.OrdinalIgnoreCase)) { - ArchiLogger.LogGenericInfo(Strings.GlobalConfigChanged); - await RestartOrExit().ConfigureAwait(false); + await OnConfigChanged().ConfigureAwait(false); return; } diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index f2d9e65be..6c5ec5315 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -1402,16 +1402,13 @@ public sealed class Bot : IAsyncDisposable, IDisposable { string configFile = GetFilePath(EFileType.Config); if (string.IsNullOrEmpty(configFile)) { - ArchiLogger.LogNullError(configFile); - - return; + throw new InvalidOperationException(nameof(configFile)); } (BotConfig? botConfig, _) = await BotConfig.Load(configFile, BotName).ConfigureAwait(false); if (botConfig == null) { - await Destroy().ConfigureAwait(false); - + // Invalid config file, we allow user to fix it without destroying the bot right away return; }