Improve global config events handling, #520

This commit is contained in:
JustArchi
2017-04-01 16:41:01 +02:00
parent 16509b9958
commit 97c1d136c7

View File

@@ -316,7 +316,7 @@ namespace ArchiSteamFarm {
bot.OnNewConfigLoaded(new BotConfigEventArgs(BotConfig.Load(e.FullPath))).Forget();
}
private static void OnCreated(object sender, FileSystemEventArgs e) {
private static async void OnCreated(object sender, FileSystemEventArgs e) {
if ((sender == null) || (e == null)) {
ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e));
return;
@@ -327,6 +327,12 @@ namespace ArchiSteamFarm {
return;
}
if (botName.Equals(SharedInfo.ASF)) {
ArchiLogger.LogGenericInfo(Strings.GlobalConfigChanged);
await RestartOrExit().ConfigureAwait(false);
return;
}
CreateBot(botName).Forget();
}
@@ -342,6 +348,13 @@ namespace ArchiSteamFarm {
}
if (botName.Equals(SharedInfo.ASF)) {
// Some editors might decide to delete file and re-create it in order to modify it
// If that's the case, we wait for maximum of 5 seconds before shutting down
await Task.Delay(5000).ConfigureAwait(false);
if (File.Exists(e.FullPath)) {
return;
}
ArchiLogger.LogGenericError(Strings.ErrorGlobalConfigRemoved);
await Program.Exit(1).ConfigureAwait(false);
return;