Skip to content

Commit

Permalink
Closes #3007 (#3008)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi authored Sep 20, 2023
1 parent 9163b57 commit af4a64b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
25 changes: 23 additions & 2 deletions ArchiSteamFarm/Core/ASF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,28 @@ private static async Task OnChangedKeysFile(string name, string fullPath) {
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);
Expand Down Expand Up @@ -666,8 +688,7 @@ private static async Task OnCreatedJsonFile(string name, string fullPath) {
}

if (botName.Equals(SharedInfo.ASF, StringComparison.OrdinalIgnoreCase)) {
ArchiLogger.LogGenericInfo(Strings.GlobalConfigChanged);
await RestartOrExit().ConfigureAwait(false);
await OnConfigChanged().ConfigureAwait(false);

return;
}
Expand Down
7 changes: 2 additions & 5 deletions ArchiSteamFarm/Steam/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,16 +1402,13 @@ internal async Task OnConfigChanged(bool deleted) {
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;
}

Expand Down

0 comments on commit af4a64b

Please sign in to comment.