diff --git a/ArchiSteamFarm.sln.DotSettings b/ArchiSteamFarm.sln.DotSettings index c867e19e9..cbca2a286 100644 --- a/ArchiSteamFarm.sln.DotSettings +++ b/ArchiSteamFarm.sln.DotSettings @@ -1,5 +1,6 @@  False + True ExplicitlyExcluded CF84911C-2C4C-4195-8AF3-ABBB6D3DE9AA/d:www True @@ -41,6 +42,7 @@ SUGGESTION SUGGESTION SUGGESTION + HINT WARNING WARNING WARNING diff --git a/ArchiSteamFarm/ArchiLogger.cs b/ArchiSteamFarm/ArchiLogger.cs index 0db5b8d88..8a1994bb3 100644 --- a/ArchiSteamFarm/ArchiLogger.cs +++ b/ArchiSteamFarm/ArchiLogger.cs @@ -20,7 +20,6 @@ // limitations under the License. using System; -using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; using ArchiSteamFarm.Localization; diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index a8eb3beaa..e7c6604de 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -755,11 +755,7 @@ namespace ArchiSteamFarm { return null; } - if (resultInSeconds == 0) { - return 0; - } - - return (byte) (resultInSeconds / 86400); + return resultInSeconds == 0 ? (byte?) 0 : (byte) (resultInSeconds / 86400); } internal async Task GetTradeToken() { @@ -1042,11 +1038,7 @@ namespace ArchiSteamFarm { Dictionary data = new Dictionary(2) { { "wallet_code", key } }; Steam.RedeemWalletResponse response = await UrlPostToJsonObjectWithSession(SteamStoreURL, request, data).ConfigureAwait(false); - if (response == null) { - return null; - } - - return (response.Result, response.PurchaseResultDetail); + return response == null ? ((EResult Result, EPurchaseResultDetail? PurchaseResult)?) null : (response.Result, response.PurchaseResultDetail); } internal async Task SendTradeOffer(ulong partnerID, IReadOnlyCollection itemsToGive, string token = null) { @@ -1274,11 +1266,7 @@ namespace ArchiSteamFarm { } int index = hashName.IndexOf('-'); - if (index <= 0) { - return 0; - } - - return uint.TryParse(hashName.Substring(0, index), out uint appID) ? appID : 0; + return (index > 0) && uint.TryParse(hashName.Substring(0, index), out uint appID) && (appID != 0) ? appID : 0; } private static Steam.Asset.EType GetItemType(string name) { diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index f8fa29a36..9c57d78cb 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -492,11 +492,7 @@ namespace ArchiSteamFarm { return (appID, DateTime.MinValue); } - if (!productInfoResultSet.Complete || productInfoResultSet.Failed) { - return (optimisticDiscovery ? appID : 0, DateTime.MinValue); - } - - return (appID, DateTime.MinValue); + return ((productInfoResultSet.Complete && !productInfoResultSet.Failed) || optimisticDiscovery ? appID : 0, DateTime.MinValue); } internal static HashSet GetBots(string args) { @@ -737,11 +733,7 @@ namespace ArchiSteamFarm { return false; } - if (IsOwner(steamID)) { - return true; - } - - return GetSteamUserPermission(steamID) >= BotConfig.EPermission.Master; + return IsOwner(steamID) || (GetSteamUserPermission(steamID) >= BotConfig.EPermission.Master); } internal bool IsPriorityIdling(uint appID) { @@ -1557,11 +1549,7 @@ namespace ArchiSteamFarm { return false; } - if (IsOwner(steamID)) { - return true; - } - - return SteamFamilySharingIDs.Contains(steamID) || (GetSteamUserPermission(steamID) >= BotConfig.EPermission.FamilySharing); + return IsOwner(steamID) || SteamFamilySharingIDs.Contains(steamID) || (GetSteamUserPermission(steamID) >= BotConfig.EPermission.FamilySharing); } private bool IsMasterClanID(ulong steamID) { @@ -1579,11 +1567,7 @@ namespace ArchiSteamFarm { return false; } - if (IsOwner(steamID)) { - return true; - } - - return GetSteamUserPermission(steamID) >= BotConfig.EPermission.Operator; + return IsOwner(steamID) || (GetSteamUserPermission(steamID) >= BotConfig.EPermission.Operator); } private static bool IsOwner(ulong steamID) { @@ -3798,13 +3782,7 @@ namespace ArchiSteamFarm { await LimitGiftsRequestsAsync().ConfigureAwait(false); - Dictionary ownedGames; - if (await ArchiWebHandler.HasValidApiKey().ConfigureAwait(false)) { - ownedGames = await ArchiWebHandler.GetOwnedGames(CachedSteamID).ConfigureAwait(false); - } else { - ownedGames = await ArchiWebHandler.GetMyOwnedGames().ConfigureAwait(false); - } - + Dictionary ownedGames = await ArchiWebHandler.HasValidApiKey().ConfigureAwait(false) ? await ArchiWebHandler.GetOwnedGames(CachedSteamID).ConfigureAwait(false) : await ArchiWebHandler.GetMyOwnedGames().ConfigureAwait(false); if ((ownedGames == null) || (ownedGames.Count == 0)) { return (FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(ownedGames))), null); } @@ -3884,11 +3862,7 @@ namespace ArchiSteamFarm { Dictionary ownedGameCounts = new Dictionary(); foreach (uint gameID in validResults.Where(validResult => (validResult.OwnedGameIDs != null) && (validResult.OwnedGameIDs.Count > 0)).SelectMany(validResult => validResult.OwnedGameIDs)) { - if (ownedGameCounts.TryGetValue(gameID, out ushort count)) { - ownedGameCounts[gameID] = ++count; - } else { - ownedGameCounts[gameID] = 1; - } + ownedGameCounts[gameID] = ownedGameCounts.TryGetValue(gameID, out ushort count) ? ++count : (ushort) 1; } IEnumerable extraResponses = ownedGameCounts.Select(kv => FormatStaticResponse(string.Format(Strings.BotOwnsOverviewPerGame, kv.Value, validResults.Count, kv.Key))); diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index d81f3b9c0..cfbdca285 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Net; @@ -1042,31 +1043,10 @@ namespace ArchiSteamFarm { PlayableAppID = appID; } - public bool Equals(Game other) { - if (other == null) { - return false; - } - - // ReSharper disable once PossibleUnintendedReferenceComparison - we indeed want to compare those two by reference - if (other == this) { - return true; - } - - return AppID == other.AppID; - } - - public override bool Equals(object obj) { - if (obj == null) { - return false; - } - - if (obj == this) { - return true; - } - - return obj is Game game && Equals(game); - } + [SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] + public bool Equals(Game other) => (other != null) && ((other == this) || (AppID == other.AppID)); + public override bool Equals(object obj) => (obj != null) && ((obj == this) || (obj is Game game && Equals(game))); public override int GetHashCode() => (int) (AppID - 1 - int.MaxValue); } } diff --git a/ArchiSteamFarm/IPC.cs b/ArchiSteamFarm/IPC.cs index cd65cef4f..ac4974209 100644 --- a/ArchiSteamFarm/IPC.cs +++ b/ArchiSteamFarm/IPC.cs @@ -953,11 +953,7 @@ namespace ArchiSteamFarm { if (authorized) { FailedAuthorizations.TryRemove(ipAddress, out _); } else { - if (FailedAuthorizations.TryGetValue(ipAddress, out attempts)) { - FailedAuthorizations[ipAddress] = ++attempts; - } else { - FailedAuthorizations[ipAddress] = 1; - } + FailedAuthorizations[ipAddress] = FailedAuthorizations.TryGetValue(ipAddress, out attempts) ? ++attempts : (byte) 1; } } finally { AuthorizationSemaphore.Release(); diff --git a/ArchiSteamFarm/Json/Steam.cs b/ArchiSteamFarm/Json/Steam.cs index 5750b1356..3701958be 100644 --- a/ArchiSteamFarm/Json/Steam.cs +++ b/ArchiSteamFarm/Json/Steam.cs @@ -523,11 +523,7 @@ namespace ArchiSteamFarm.Json { itemsPerType = new Dictionary { [item.Type] = item.Amount }; itemsToGivePerGame[item.RealAppID] = itemsPerType; } else { - if (itemsPerType.TryGetValue(item.Type, out uint amount)) { - itemsPerType[item.Type] = amount + item.Amount; - } else { - itemsPerType[item.Type] = item.Amount; - } + itemsPerType[item.Type] = itemsPerType.TryGetValue(item.Type, out uint amount) ? amount + item.Amount : item.Amount; } } @@ -538,11 +534,7 @@ namespace ArchiSteamFarm.Json { itemsToReceivePerGame[item.RealAppID] = itemsPerType; } else { - if (itemsPerType.TryGetValue(item.Type, out uint amount)) { - itemsPerType[item.Type] = amount + item.Amount; - } else { - itemsPerType[item.Type] = item.Amount; - } + itemsPerType[item.Type] = itemsPerType.TryGetValue(item.Type, out uint amount) ? amount + item.Amount : item.Amount; } } diff --git a/ArchiSteamFarm/RuntimeCompatibility.cs b/ArchiSteamFarm/RuntimeCompatibility.cs index afaccdede..d89e21ade 100644 --- a/ArchiSteamFarm/RuntimeCompatibility.cs +++ b/ArchiSteamFarm/RuntimeCompatibility.cs @@ -33,49 +33,41 @@ namespace ArchiSteamFarm { #if NET472 internal static async Task ReceiveAsync(this WebSocket webSocket, byte[] buffer, CancellationToken cancellationToken) => await webSocket.ReceiveAsync(new ArraySegment(buffer), cancellationToken).ConfigureAwait(false); - - internal static async Task SendAsync(this WebSocket webSocket, byte[] buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) { - await webSocket.SendAsync(new ArraySegment(buffer), messageType, endOfMessage, cancellationToken).ConfigureAwait(false); - } - + internal static async Task SendAsync(this WebSocket webSocket, byte[] buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) => await webSocket.SendAsync(new ArraySegment(buffer), messageType, endOfMessage, cancellationToken).ConfigureAwait(false); internal static string[] Split(this string text, char separator, StringSplitOptions options = StringSplitOptions.None) => text.Split(new[] { separator }, options); #endif - internal static class File { #pragma warning disable 1998 - internal static async Task AppendAllTextAsync(string path, string contents) { + internal static class File { + internal static async Task AppendAllTextAsync(string path, string contents) => #if NET472 System.IO.File.AppendAllText(path, contents); #else await System.IO.File.AppendAllTextAsync(path, contents).ConfigureAwait(false); #endif - } - internal static async Task ReadAllBytesAsync(string path) { + internal static async Task ReadAllBytesAsync(string path) => #if NET472 - return System.IO.File.ReadAllBytes(path); + System.IO.File.ReadAllBytes(path); #else - return await System.IO.File.ReadAllBytesAsync(path).ConfigureAwait(false); + await System.IO.File.ReadAllBytesAsync(path).ConfigureAwait(false); #endif - } - internal static async Task ReadAllTextAsync(string path) { + internal static async Task ReadAllTextAsync(string path) => #if NET472 - return System.IO.File.ReadAllText(path); + System.IO.File.ReadAllText(path); #else - return await System.IO.File.ReadAllTextAsync(path).ConfigureAwait(false); + await System.IO.File.ReadAllTextAsync(path).ConfigureAwait(false); #endif - } - internal static async Task WriteAllTextAsync(string path, string contents) { + internal static async Task WriteAllTextAsync(string path, string contents) => #if NET472 System.IO.File.WriteAllText(path, contents); #else await System.IO.File.WriteAllTextAsync(path, contents).ConfigureAwait(false); #endif - } -#pragma warning restore 1998 } +#pragma warning restore 1998 internal static class Path { internal static string GetRelativePath(string relativeTo, string path) { @@ -86,14 +78,11 @@ namespace ArchiSteamFarm { } string result = path.Substring(relativeTo.Length); - - if ((result[0] == System.IO.Path.DirectorySeparatorChar) || (result[0] == System.IO.Path.AltDirectorySeparatorChar)) { - return result.Substring(1); - } - - return result; + return (result[0] == System.IO.Path.DirectorySeparatorChar) || (result[0] == System.IO.Path.AltDirectorySeparatorChar) ? result.Substring(1) : result; #else +#pragma warning disable IDE0022 return System.IO.Path.GetRelativePath(relativeTo, path); +#pragma warning restore IDE0022 #endif } } diff --git a/ArchiSteamFarm/ServerRecordEndPoint.cs b/ArchiSteamFarm/ServerRecordEndPoint.cs index 3b35394ed..05f4fb198 100644 --- a/ArchiSteamFarm/ServerRecordEndPoint.cs +++ b/ArchiSteamFarm/ServerRecordEndPoint.cs @@ -46,18 +46,7 @@ namespace ArchiSteamFarm { private ServerRecordEndPoint() { } - public override bool Equals(object obj) { - if (obj == null) { - return false; - } - - if (obj == this) { - return true; - } - - return obj is ServerRecordEndPoint serverRecord && Equals(serverRecord); - } - + public override bool Equals(object obj) => (obj != null) && ((obj == this) || (obj is ServerRecordEndPoint serverRecord && Equals(serverRecord))); public override int GetHashCode() => (Host, Port, ProtocolTypes).GetHashCode(); private bool Equals(ServerRecordEndPoint other) => string.Equals(Host, other.Host) && (Port == other.Port) && (ProtocolTypes == other.ProtocolTypes); diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index ba02642d9..ea9378d90 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -78,11 +78,7 @@ namespace ArchiSteamFarm { // This has to be done as we might have multiple items of given ClassID with multiple amounts Dictionary itemAmounts = new Dictionary(); foreach (Steam.Asset item in inventory) { - if (itemAmounts.TryGetValue(item.ClassID, out uint amount)) { - itemAmounts[item.ClassID] = amount + item.Amount; - } else { - itemAmounts[item.ClassID] = item.Amount; - } + itemAmounts[item.ClassID] = itemAmounts.TryGetValue(item.ClassID, out uint amount) ? amount + item.Amount : item.Amount; } // Calculate our value of items to give on per-game basis