diff --git a/.editorconfig b/.editorconfig index 92a4a939a..0409ee801 100644 --- a/.editorconfig +++ b/.editorconfig @@ -108,7 +108,6 @@ dotnet_analyzer_diagnostic.severity = warning dotnet_code_quality_unused_parameters = all:warning # TODO - one at a time -dotnet_diagnostic.ca1002.severity = silent dotnet_diagnostic.ca1027.severity = silent dotnet_diagnostic.ca1028.severity = silent dotnet_diagnostic.ca1031.severity = silent diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 2ae2a2d60..7795f440a 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -1725,15 +1725,16 @@ namespace ArchiSteamFarm { return 0; } - List htmlNodes = htmlDocument.SelectNodes("//div[@class='badge_card_set_cards']/div[starts-with(@class, 'badge_card_set_card')]"); + IEnumerable htmlNodes = htmlDocument.SelectNodes("//div[@class='badge_card_set_cards']/div[starts-with(@class, 'badge_card_set_card')]"); - if (htmlNodes.Count == 0) { - Bot.ArchiLogger.LogNullError(nameof(htmlNodes)); + result = (byte) htmlNodes.Count(); + + if (result == 0) { + Bot.ArchiLogger.LogNullError(nameof(result)); return 0; } - result = (byte) htmlNodes.Count; CachedCardCountsForGame.TryAdd(appID, result); return result; @@ -1782,13 +1783,9 @@ namespace ArchiSteamFarm { return null; } - List htmlNodes = response.Content.SelectNodes("//div[@class='pending_gift']/div[starts-with(@id, 'pending_gift_')][count(div[@class='pending_giftcard_leftcol']) > 0]/@id"); + IEnumerable htmlNodes = response.Content.SelectNodes("//div[@class='pending_gift']/div[starts-with(@id, 'pending_gift_')][count(div[@class='pending_giftcard_leftcol']) > 0]/@id"); - if (htmlNodes.Count == 0) { - return new HashSet(0); - } - - HashSet results = new(htmlNodes.Count); + HashSet results = new(); foreach (string? giftCardIDText in htmlNodes.Select(node => node.GetAttribute("id"))) { if (string.IsNullOrEmpty(giftCardIDText)) { @@ -1832,14 +1829,9 @@ namespace ArchiSteamFarm { return null; } - List htmlNodes = response.Content.SelectNodes("(//table[@class='accountTable'])[2]//a/@data-miniprofile"); + IEnumerable htmlNodes = response.Content.SelectNodes("(//table[@class='accountTable'])[2]//a/@data-miniprofile"); - if (htmlNodes.Count == 0) { - // OK, no authorized steamIDs - return new HashSet(0); - } - - HashSet result = new(htmlNodes.Count); + HashSet result = new(); foreach (string? miniProfile in htmlNodes.Select(htmlNode => htmlNode.GetAttribute("data-miniprofile"))) { if (string.IsNullOrEmpty(miniProfile)) { diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 92c14cfb4..308e40a90 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1925,17 +1925,11 @@ namespace ArchiSteamFarm { throw new ArgumentNullException(nameof(badgePage)); } - List linkElements = badgePage.SelectNodes("//a[@class='badge_craft_button']"); - - // We need to also select all badges that we have max level, as those will not display with a craft button + // We select badges that are ready to craft, as well as those that are already crafted to a maximum level, as those will not display with a craft button // Level 5 is maximum level for card badges according to https://steamcommunity.com/tradingcards/faq - linkElements.AddRange(badgePage.SelectNodes("//div[@class='badges_sheet']/div[contains(@class, 'badge_row') and .//div[@class='badge_info_description']/div[contains(text(), 'Level 5')]]/a[@class='badge_row_overlay']")); + IEnumerable linkElements = badgePage.SelectNodes("//a[@class='badge_craft_button'] | //div[@class='badges_sheet']/div[contains(@class, 'badge_row') and .//div[@class='badge_info_description']/div[contains(text(), 'Level 5')]]/a[@class='badge_row_overlay']"); - if (linkElements.Count == 0) { - return new HashSet(0); - } - - HashSet result = new(linkElements.Count); + HashSet result = new(); foreach (string? badgeUri in linkElements.Select(htmlNode => htmlNode.GetAttribute("href"))) { if (string.IsNullOrEmpty(badgeUri)) { diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index ea690b1f0..dec2582a1 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -391,12 +391,7 @@ namespace ArchiSteamFarm { throw new ArgumentNullException(nameof(parsedAppIDs)); } - List htmlNodes = htmlDocument.SelectNodes("//div[@class='badge_row_inner']"); - - if (htmlNodes.Count == 0) { - // No eligible badges whatsoever - return; - } + IEnumerable htmlNodes = htmlDocument.SelectNodes("//div[@class='badge_row_inner']"); HashSet? backgroundTasks = null; diff --git a/ArchiSteamFarm/GitHub.cs b/ArchiSteamFarm/GitHub.cs index 7868ba9e8..119739a13 100644 --- a/ArchiSteamFarm/GitHub.cs +++ b/ArchiSteamFarm/GitHub.cs @@ -81,9 +81,9 @@ namespace ArchiSteamFarm { }; } - List revisionNodes = response.Content.SelectNodes("//li[contains(@class, 'wiki-history-revision')]"); + IEnumerable revisionNodes = response.Content.SelectNodes("//li[contains(@class, 'wiki-history-revision')]"); - Dictionary result = new(revisionNodes.Count); + Dictionary result = new(); foreach (IElement revisionNode in revisionNodes) { IElement? versionNode = revisionNode.SelectSingleElementNode(".//input/@value"); diff --git a/ArchiSteamFarm/MobileAuthenticator.cs b/ArchiSteamFarm/MobileAuthenticator.cs index b83231745..3754aa2b9 100644 --- a/ArchiSteamFarm/MobileAuthenticator.cs +++ b/ArchiSteamFarm/MobileAuthenticator.cs @@ -117,14 +117,10 @@ namespace ArchiSteamFarm { return null; } + IEnumerable confirmationNodes = htmlDocument.SelectNodes("//div[@class='mobileconf_list_entry']"); + HashSet result = new(); - List confirmationNodes = htmlDocument.SelectNodes("//div[@class='mobileconf_list_entry']"); - - if (confirmationNodes.Count == 0) { - return result; - } - foreach (IElement confirmationNode in confirmationNodes) { string? idText = confirmationNode.GetAttribute("data-confid"); diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index 33fc21f32..181269441 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -232,10 +232,10 @@ namespace ArchiSteamFarm { } [PublicAPI] - public static List SelectElementNodes(this IElement element, string xpath) => element.SelectNodes(xpath).OfType().ToList(); + public static IEnumerable SelectElementNodes(this IElement element, string xpath) => element.SelectNodes(xpath).OfType(); [PublicAPI] - public static List SelectNodes(this IDocument document, string xpath) => document.Body.SelectNodes(xpath).OfType().ToList(); + public static IEnumerable SelectNodes(this IDocument document, string xpath) => document.Body.SelectNodes(xpath).OfType(); [PublicAPI] public static IElement? SelectSingleElementNode(this IElement element, string xpath) => (IElement?) element.SelectSingleNode(xpath); diff --git a/Directory.Build.props b/Directory.Build.props index 262ec52be..b5d78f5a4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 5.0.7.0 + 5.1.0.0