From 2554794daa0e4790cd77021625de59b368b55a17 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 27 Mar 2016 15:08:43 +0200 Subject: [PATCH] Code review --- ArchiSteamFarm/CardsFarmer.cs | 45 +++++++++++++++++++++++------------ ArchiSteamFarm/Utilities.cs | 27 --------------------- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 7a3f4fec4..5cbf0d7e9 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -236,19 +236,17 @@ namespace ArchiSteamFarm { GamesToFarm.Clear(); - // Find APPIDs we need to farm - Logging.LogGenericInfo("Checking other pages...", Bot.BotName); + CheckPage(htmlDocument); - List tasks = new List(maxPages - 1); - for (byte page = 1; page <= maxPages; page++) { - if (page == 1) { - CheckPage(htmlDocument); // Because we fetched page number 1 already - } else { + if (maxPages > 1) { + Logging.LogGenericInfo("Checking other pages...", Bot.BotName); + List tasks = new List(maxPages - 1); + for (byte page = 2; page <= maxPages; page++) { byte currentPage = page; // We need a copy of variable being passed when in for loops tasks.Add(CheckPage(currentPage)); } + await Task.WhenAll(tasks).ConfigureAwait(false); } - await Task.WhenAll(tasks).ConfigureAwait(false); if (GamesToFarm.Count == 0) { return false; @@ -279,7 +277,26 @@ namespace ArchiSteamFarm { continue; } - uint appID = (uint) Utilities.OnlyNumbers(steamLink); + int index = steamLink.LastIndexOf('/'); + if (index < 0) { + Logging.LogNullError("index", Bot.BotName); + continue; + } + + index++; + if (steamLink.Length <= index) { + Logging.LogNullError("length", Bot.BotName); + continue; + } + + steamLink = steamLink.Substring(index); + + uint appID; + if (!uint.TryParse(steamLink, out appID)) { + Logging.LogNullError("appID", Bot.BotName); + continue; + } + if (appID == 0) { Logging.LogNullError("appID", Bot.BotName); continue; @@ -301,13 +318,11 @@ namespace ArchiSteamFarm { continue; } - hoursString = Regex.Match(hoursString, @"[0-9\.,]+").Value; + float hours = 0; - float hours; - if (string.IsNullOrEmpty(hoursString)) { - hours = 0; - } else { - hours = float.Parse(hoursString, CultureInfo.InvariantCulture); + Match match = Regex.Match(hoursString, @"[0-9\.,]+"); + if (match.Success) { + float.TryParse(match.Value, NumberStyles.Number, CultureInfo.InvariantCulture, out hours); } GamesToFarm[appID] = hours; diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index 00697ae50..e370c6377 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -22,7 +22,6 @@ */ -using System.Text.RegularExpressions; using System.Threading.Tasks; namespace ArchiSteamFarm { @@ -33,32 +32,6 @@ namespace ArchiSteamFarm { await Task.Delay(miliseconds).ConfigureAwait(false); } - internal static ulong OnlyNumbers(string inputString) { - if (string.IsNullOrEmpty(inputString)) { - return 0; - } - - string resultString = OnlyNumbersString(inputString); - if (string.IsNullOrEmpty(resultString)) { - return 0; - } - - ulong result; - if (!ulong.TryParse(resultString, out result)) { - return 0; - } - - return result; - } - - internal static string OnlyNumbersString(string text) { - if (string.IsNullOrEmpty(text)) { - return null; - } - - return Regex.Replace(text, @"[^\d]", ""); - } - internal static uint GetCharCountInString(string s, char c) { if (string.IsNullOrEmpty(s)) { return 0;