internal static BotConfig Load(string filePath)
{
if (string.IsNullOrEmpty(filePath))
{
ASF.ArchiLogger.LogNullError(nameof(filePath));
return(null);
}
if (!File.Exists(filePath))
{
return(null);
}
BotConfig botConfig;
try {
botConfig = JsonConvert.DeserializeObject <BotConfig>(File.ReadAllText(filePath));
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
return(null);
}
if (botConfig == null)
{
ASF.ArchiLogger.LogNullError(nameof(botConfig));
return(null);
}
botConfig.ShouldSerializeSensitiveDetails = false;
// Support encrypted passwords
if ((botConfig.PasswordFormat != CryptoHelper.ECryptoMethod.PlainText) && !string.IsNullOrEmpty(botConfig.SteamPassword))
{
// In worst case password will result in null, which will have to be corrected by user during runtime
botConfig.SteamPassword = CryptoHelper.Decrypt(botConfig.PasswordFormat, botConfig.SteamPassword);
}
// User might not know what he's doing
// Ensure that he can't screw core ASF variables
if (botConfig.GamesPlayedWhileIdle.Count <= ArchiHandler.MaxGamesPlayedConcurrently)
{
return(botConfig);
}
ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningTooManyGamesToPlay, ArchiHandler.MaxGamesPlayedConcurrently, nameof(botConfig.GamesPlayedWhileIdle)));
HashSet <uint> validGames = new HashSet <uint>(botConfig.GamesPlayedWhileIdle.Take(ArchiHandler.MaxGamesPlayedConcurrently));
botConfig.GamesPlayedWhileIdle.IntersectWith(validGames);
botConfig.GamesPlayedWhileIdle.TrimExcess();
return(botConfig);
}