Abort startup if config directory could not be found

We do not require any config files, but config directory - yes, we won't bother creating it manually as it heavily suggests user mistake, such as --path to the wrong directory.
This commit is contained in:
JustArchi
2020-11-28 23:55:09 +01:00
parent ba702a1dae
commit 835d567fec
4 changed files with 22 additions and 3 deletions

View File

@@ -405,7 +405,7 @@ namespace ArchiSteamFarm {
}
private static void InitEvents() {
if ((FileSystemWatcher != null) || (LastWriteEvents != null) || !Directory.Exists(SharedInfo.ConfigDirectory)) {
if ((FileSystemWatcher != null) || (LastWriteEvents != null)) {
return;
}
@@ -850,7 +850,7 @@ namespace ArchiSteamFarm {
HashSet<string> botNames;
try {
botNames = Directory.Exists(SharedInfo.ConfigDirectory) ? Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*" + SharedInfo.JsonConfigExtension).Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName) && IsValidBotName(botName)).ToHashSet(Bot.BotsComparer)! : new HashSet<string>(0);
botNames = Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*" + SharedInfo.JsonConfigExtension).Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName) && IsValidBotName(botName)).ToHashSet(Bot.BotsComparer)!;
} catch (Exception e) {
ArchiLogger.LogGenericException(e);

View File

@@ -845,6 +845,15 @@ namespace ArchiSteamFarm.Localization {
}
}
/// <summary>
/// Looks up a localized string similar to Config directory could not be found, aborting!.
/// </summary>
public static string ErrorConfigDirectoryNotFound {
get {
return ResourceManager.GetString("ErrorConfigDirectoryNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Configured {0} property is invalid: {1}.
/// </summary>

View File

@@ -742,4 +742,7 @@ Process uptime: {1}</value>
<data name="WarningUnknownCommandLineArgument" xml:space="preserve">
<value>Unknown command-line argument: {0}</value>
</data>
<data name="ErrorConfigDirectoryNotFound" xml:space="preserve">
<value>Config directory could not be found, aborting!</value>
</data>
</root>

View File

@@ -176,7 +176,7 @@ namespace ArchiSteamFarm {
if (!uniqueInstance) {
ASF.ArchiLogger.LogGenericError(Strings.ErrorSingleInstanceRequired);
await Task.Delay(5000).ConfigureAwait(false);
await Task.Delay(10000).ConfigureAwait(false);
return false;
}
@@ -195,6 +195,13 @@ namespace ArchiSteamFarm {
}
}
if (!Directory.Exists(SharedInfo.ConfigDirectory)) {
ASF.ArchiLogger.LogGenericError(Strings.ErrorConfigDirectoryNotFound);
await Task.Delay(10000).ConfigureAwait(false);
return false;
}
return true;
}