From 761d73eb90f719d3a343faf98fe3ac08afbf5bcb Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 26 Mar 2016 22:23:35 +0100 Subject: [PATCH] Remove old converter, closes #153 Decided to remove it faster --- ArchiSteamFarm/Bot.cs | 39 ---------- ArchiSteamFarm/BotConfig.cs | 142 +--------------------------------- ArchiSteamFarm/BotDatabase.cs | 4 + ArchiSteamFarm/Program.cs | 13 ---- 4 files changed, 5 insertions(+), 193 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 0e0529e39..58657fe49 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -113,51 +113,12 @@ namespace ArchiSteamFarm { string botPath = Path.Combine(Program.ConfigDirectory, botName); - // CONVERSION START - if (File.Exists(botPath + ".xml")) { - BotConfig = BotConfig.LoadOldFormat(botPath + ".xml"); - if (BotConfig == null) { - return; - } - - if (BotConfig.Convert(botPath + ".json")) { - try { - File.Delete(botPath + ".xml"); - } catch (Exception e) { - Logging.LogGenericException(e, botName); - return; - } - } - } - // CONVERSION END - BotConfig = BotConfig.Load(botPath + ".json"); if (BotConfig == null) { Logging.LogGenericError("Your bot config is invalid, refusing to start this bot instance!", botName); return; } - // CONVERSION START - if (File.Exists(botPath + ".key")) { - BotDatabase = BotDatabase.Load(botPath + ".db"); - try { - BotDatabase.LoginKey = File.ReadAllText(botPath + ".key"); - File.Delete(botPath + ".key"); - } catch (Exception e) { - Logging.LogGenericException(e, BotName); - } - } - if (File.Exists(botPath + ".auth")) { - BotDatabase = BotDatabase.Load(botPath + ".db"); - try { - BotDatabase.SteamGuardAccount = JsonConvert.DeserializeObject(File.ReadAllText(botPath + ".auth")); - File.Delete(botPath + ".auth"); - } catch (Exception e) { - Logging.LogGenericException(e, BotName); - } - } - // CONVERSION END - if (!BotConfig.Enabled) { return; } diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index 81c7d4dad..fcb33332e 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -26,7 +26,6 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; -using System.Xml; namespace ArchiSteamFarm { internal sealed class BotConfig { @@ -98,7 +97,7 @@ namespace ArchiSteamFarm { internal static BotConfig Load(string path) { - if (!File.Exists(path)) { + if (string.IsNullOrEmpty(path) || !File.Exists(path)) { return null; } @@ -113,146 +112,7 @@ namespace ArchiSteamFarm { return botConfig; } - // TODO: This should be removed soon - internal static BotConfig LoadOldFormat(string path) { - if (!File.Exists(path)) { - return null; - } - - BotConfig botConfig = new BotConfig(); - - try { - using (XmlReader reader = XmlReader.Create(path)) { - while (reader.Read()) { - if (reader.NodeType != XmlNodeType.Element) { - continue; - } - - string key = reader.Name; - if (string.IsNullOrEmpty(key)) { - continue; - } - - string value = reader.GetAttribute("value"); - if (string.IsNullOrEmpty(value)) { - continue; - } - - switch (key) { - case "Enabled": - botConfig.Enabled = bool.Parse(value); - break; - case "SteamLogin": - botConfig.SteamLogin = value; - break; - case "SteamPassword": - botConfig.SteamPassword = value; - break; - case "SteamApiKey": - botConfig.SteamApiKey = value; - break; - case "SteamTradeToken": - botConfig.SteamTradeToken = value; - break; - case "SteamParentalPIN": - botConfig.SteamParentalPIN = value; - break; - case "SteamMasterID": - botConfig.SteamMasterID = ulong.Parse(value); - break; - case "SteamMasterClanID": - botConfig.SteamMasterClanID = ulong.Parse(value); - break; - case "StartOnLaunch": - botConfig.StartOnLaunch = bool.Parse(value); - break; - case "UseAsfAsMobileAuthenticator": - botConfig.UseAsfAsMobileAuthenticator = bool.Parse(value); - break; - case "CardDropsRestricted": - botConfig.CardDropsRestricted = bool.Parse(value); - break; - case "FarmOffline": - botConfig.FarmOffline = bool.Parse(value); - break; - case "HandleOfflineMessages": - botConfig.HandleOfflineMessages = bool.Parse(value); - break; - case "ForwardKeysToOtherBots": - botConfig.ForwardKeysToOtherBots = bool.Parse(value); - break; - case "DistributeKeys": - botConfig.DistributeKeys = bool.Parse(value); - break; - case "ShutdownOnFarmingFinished": - botConfig.ShutdownOnFarmingFinished = bool.Parse(value); - break; - case "SendOnFarmingFinished": - botConfig.SendOnFarmingFinished = bool.Parse(value); - break; - case "SendTradePeriod": - botConfig.SendTradePeriod = byte.Parse(value); - break; - case "GamesPlayedWhileIdle": - botConfig.GamesPlayedWhileIdle.Clear(); - foreach (string appID in value.Split(',')) { - botConfig.GamesPlayedWhileIdle.Add(uint.Parse(appID)); - } - break; - case "Statistics": - case "Blacklist": - case "SteamNickname": - break; - default: - Logging.LogGenericWarning("Unrecognized config value: " + key + "=" + value); - break; - } - } - } - } catch (Exception e) { - Logging.LogGenericException(e); - Logging.LogGenericError("Your config for this bot instance is invalid, it won't run!"); - return null; - } - - // Fixups for new format - if (botConfig.SteamLogin != null && botConfig.SteamLogin.Equals("null")) { - botConfig.SteamLogin = null; - } - - if (botConfig.SteamPassword != null && botConfig.SteamPassword.Equals("null")) { - botConfig.SteamPassword = null; - } - - if (botConfig.SteamApiKey != null && botConfig.SteamApiKey.Equals("null")) { - botConfig.SteamApiKey = null; - } - - if (botConfig.SteamParentalPIN != null && botConfig.SteamParentalPIN.Equals("null")) { - botConfig.SteamParentalPIN = null; - } - - if (botConfig.SteamTradeToken != null && botConfig.SteamTradeToken.Equals("null")) { - botConfig.SteamTradeToken = null; - } - - return botConfig; - } - // This constructor is used only by deserializer private BotConfig() { } - - // TODO: This should be removed soon - internal bool Convert(string path) { - try { - File.WriteAllText(path, JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented)); - } catch (Exception e) { - Logging.LogGenericException(e); - return false; - } - - Logging.LogGenericWarning("Your config was converted to new ASF V2.0 format"); - return true; - } } } diff --git a/ArchiSteamFarm/BotDatabase.cs b/ArchiSteamFarm/BotDatabase.cs index dad5c61d5..52c909267 100644 --- a/ArchiSteamFarm/BotDatabase.cs +++ b/ArchiSteamFarm/BotDatabase.cs @@ -66,6 +66,10 @@ namespace ArchiSteamFarm { private string FilePath; internal static BotDatabase Load(string filePath) { + if (string.IsNullOrEmpty(filePath)) { + return null; + } + if (!File.Exists(filePath)) { return new BotDatabase(filePath); } diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 7c707e6b7..749ace02a 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -481,19 +481,6 @@ namespace ArchiSteamFarm { } } - // CONVERSION START - foreach (var configFile in Directory.EnumerateFiles(ConfigDirectory, "*.xml")) { - string botName = Path.GetFileNameWithoutExtension(configFile); - Logging.LogGenericWarning("Found legacy " + botName + ".xml config file, it will now be converted to new ASF V2.0 format!"); - Bot bot = new Bot(botName); - if (bot.BotConfig != null && bot.BotConfig.Enabled) { - isRunning = true; - } else { - Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName); - } - } - // CONVERSION END - // Check if we got any bots running if (!isRunning) { OnBotShutdown();