diff --git a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs index 8366f7358..3e8e6085a 100644 --- a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs +++ b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs @@ -52,7 +52,7 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin { return Uri.EscapeUriString(response.Content!.Link!); } -#pragma warning disable CA1812 // False positive +#pragma warning disable CA1812 // False positive, the class is used during json deserialization [SuppressMessage("ReSharper", "ClassCannotBeInstantiated")] private sealed class MeowResponse { [JsonProperty(PropertyName = "file", Required = Required.Always)] @@ -61,6 +61,6 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin { [JsonConstructor] private MeowResponse() { } } -#pragma warning restore CA1812 // False positive +#pragma warning restore CA1812 // False positive, the class is used during json deserialization } } diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/ResponseData.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/ResponseData.cs index b860d7e7c..e873e52b5 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/ResponseData.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/ResponseData.cs @@ -23,41 +23,41 @@ using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { -#pragma warning disable CA1812 // False positive +#pragma warning disable CA1812 // False positive, the class is used during json deserialization [SuppressMessage("ReSharper", "ClassCannotBeInstantiated")] internal sealed class ResponseData { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // False positive, the field is used during json deserialization [JsonProperty(PropertyName = "data", Required = Required.DisallowNull)] internal readonly InternalData? Data; -#pragma warning restore CS0649 +#pragma warning restore CS0649 // False positive, the field is used during json deserialization -#pragma warning disable CS0649 +#pragma warning disable CS0649 // False positive, the field is used during json deserialization [JsonProperty(PropertyName = "success", Required = Required.Always)] internal readonly bool Success; -#pragma warning restore CS0649 +#pragma warning restore CS0649 // False positive, the field is used during json deserialization [JsonConstructor] private ResponseData() { } internal sealed class InternalData { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // False positive, the field is used during json deserialization [JsonProperty(PropertyName = "new_apps", Required = Required.Always)] internal readonly uint NewAppsCount; -#pragma warning restore CS0649 +#pragma warning restore CS0649 // False positive, the field is used during json deserialization -#pragma warning disable CS0649 +#pragma warning disable CS0649 // False positive, the field is used during json deserialization [JsonProperty(PropertyName = "new_depots", Required = Required.Always)] internal readonly uint NewDepotsCount; -#pragma warning restore CS0649 +#pragma warning restore CS0649 // False positive, the field is used during json deserialization -#pragma warning disable CS0649 +#pragma warning disable CS0649 // False positive, the field is used during json deserialization [JsonProperty(PropertyName = "new_subs", Required = Required.Always)] internal readonly uint NewSubsCount; -#pragma warning restore CS0649 +#pragma warning restore CS0649 // False positive, the field is used during json deserialization [JsonConstructor] private InternalData() { } } } -#pragma warning restore CA1812 // False positive +#pragma warning restore CA1812 // False positive, the class is used during json deserialization } diff --git a/ArchiSteamFarm/ASF.cs b/ArchiSteamFarm/ASF.cs index 1bd7c07ab..316d8a791 100644 --- a/ArchiSteamFarm/ASF.cs +++ b/ArchiSteamFarm/ASF.cs @@ -351,17 +351,17 @@ namespace ArchiSteamFarm { ArchiLogger.LogGenericWarningException(e); } - MemoryStream memoryStream = new(response.Content as byte[] ?? response.Content.ToArray()); + MemoryStream ms = new(response.Content as byte[] ?? response.Content.ToArray()); try { #if NETFRAMEWORK -#pragma warning disable CA1508 // False positive - using (memoryStream) { -#pragma warning restore CA1508 // False positive +#pragma warning disable CA1508 // False positive, ms is not null here indeed, but using clause is needed for dispose + using (ms) { +#pragma warning restore CA1508 // False positive, ms is not null here indeed, but using clause is needed for dispose #else - await using (memoryStream.ConfigureAwait(false)) { + await using (ms.ConfigureAwait(false)) { #endif - using ZipArchive zipArchive = new(memoryStream); + using ZipArchive zipArchive = new(ms); if (!UpdateFromArchive(zipArchive, SharedInfo.HomeDirectory)) { ArchiLogger.LogGenericError(Strings.WarningFailed); diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 5b4c82eaf..17fe0aaa1 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -2608,9 +2608,9 @@ namespace ArchiSteamFarm { // Extra entry for sessionID Dictionary data = new(4, StringComparer.Ordinal) { { "agreeToTerms", "agreed" }, -#pragma warning disable CA1308 +#pragma warning disable CA1308 // False positive, we're intentionally converting this part to lowercase and it's not used for any security decisions based on the result of the normalization { "domain", "generated.by." + SharedInfo.AssemblyName.ToLowerInvariant() + ".localhost" }, -#pragma warning restore CA1308 +#pragma warning restore CA1308 // False positive, we're intentionally converting this part to lowercase and it's not used for any security decisions based on the result of the normalization { "Submit", "Register" } }; diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 603aecacd..44e53e8f1 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -720,9 +720,9 @@ namespace ArchiSteamFarm { throw new ArgumentNullException(nameof(appIDs)); } -#pragma warning disable CA1508 // False positive +#pragma warning disable CA1508 // False positive, not every IReadOnlyCollection is ISet, and this is public API ISet uniqueAppIDs = appIDs as ISet ?? appIDs.ToHashSet(); -#pragma warning restore CA1508 // False positive +#pragma warning restore CA1508 // False positive, not every IReadOnlyCollection is ISet, and this is public API switch (ASF.GlobalConfig?.OptimizationMode) { case GlobalConfig.EOptimizationMode.MinMemoryUsage: @@ -2197,15 +2197,15 @@ namespace ArchiSteamFarm { throw new ArgumentNullException(nameof(paymentMethod)); } -#pragma warning disable CA2248 +#pragma warning disable CA2248 // This is actually a fair warning, EPaymentMethod is not a flags enum on itself, but there is nothing we can do about Steam using it like that here return paymentMethod switch { EPaymentMethod.ActivationCode => false, EPaymentMethod.Complimentary => false, EPaymentMethod.GuestPass => false, EPaymentMethod.HardwarePromo => false, - _ => !paymentMethod.HasFlag(EPaymentMethod.Complimentary) // Complimentary is also a flag, for fuck sake + _ => !paymentMethod.HasFlag(EPaymentMethod.Complimentary) // Complimentary can also be a flag }; -#pragma warning restore CA2248 +#pragma warning restore CA2248 // This is actually a fair warning, EPaymentMethod is not a flags enum on itself, but there is nothing we can do about Steam using it like that here } private async Task JoinMasterChatGroupID() { @@ -3025,14 +3025,14 @@ namespace ArchiSteamFarm { byte[] sentryHash; try { - FileStream fileStream; +#pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose + FileStream fileStream = File.Open(sentryFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); +#pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose #if NETFRAMEWORK - using (fileStream = File.Open(sentryFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { + using (fileStream) { #else -#pragma warning disable CA2000 // False positive - await using ((fileStream = File.Open(sentryFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)).ConfigureAwait(false)) { -#pragma warning restore CA2000 // False positive + await using (fileStream.ConfigureAwait(false)) { #endif fileStream.Seek(callback.Offset, SeekOrigin.Begin); @@ -3045,11 +3045,11 @@ namespace ArchiSteamFarm { fileSize = fileStream.Length; fileStream.Seek(0, SeekOrigin.Begin); -#pragma warning disable CA5350 +#pragma warning disable CA5350 // This is actually a fair warning, but there is nothing we can do about Steam using weak cryptographic algorithms using SHA1CryptoServiceProvider sha = new(); sentryHash = await sha.ComputeHashAsync(fileStream).ConfigureAwait(false); -#pragma warning restore CA5350 +#pragma warning restore CA5350 // This is actually a fair warning, but there is nothing we can do about Steam using weak cryptographic algorithms } } catch (Exception e) { ArchiLogger.LogGenericException(e); @@ -3091,9 +3091,9 @@ namespace ArchiSteamFarm { string? avatarHash = null; if ((callback.AvatarHash.Length > 0) && callback.AvatarHash.Any(singleByte => singleByte != 0)) { -#pragma warning disable CA1308 +#pragma warning disable CA1308 // False positive, we're intentionally converting this part to lowercase and it's not used for any security decisions based on the result of the normalization avatarHash = BitConverter.ToString(callback.AvatarHash).Replace("-", "", StringComparison.Ordinal).ToLowerInvariant(); -#pragma warning restore CA1308 +#pragma warning restore CA1308 // False positive, we're intentionally converting this part to lowercase and it's not used for any security decisions based on the result of the normalization if (string.IsNullOrEmpty(avatarHash) || avatarHash.All(singleChar => singleChar == '0')) { avatarHash = null; diff --git a/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs b/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs index 465e9319a..41ab9e80e 100644 --- a/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs +++ b/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs @@ -179,9 +179,9 @@ namespace ArchiSteamFarm.Helpers { } try { -#pragma warning disable CA1508 // False positive +#pragma warning disable CA1508 // False positive, FileStream is not null here indeed, but using clause is needed for dispose using (new FileStream(FilePath, FileMode.CreateNew)) { } -#pragma warning restore CA1508 // False positive +#pragma warning restore CA1508 // False positive, FileStream is not null here indeed, but using clause is needed for dispose if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { FileInfo fileInfo = new(FilePath); diff --git a/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs b/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs index 27eb2962f..4d54d25db 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs @@ -152,9 +152,9 @@ namespace ArchiSteamFarm.IPC.Controllers.Api { } try { -#pragma warning disable CA1508 // False positive +#pragma warning disable CA1508 // False positive, webSocket state could change between our previous check and this one due to semaphore wait if (cancellationToken.IsCancellationRequested || (webSocket.State != WebSocketState.Open)) { -#pragma warning restore CA1508 // False positive +#pragma warning restore CA1508 // False positive, webSocket state could change between our previous check and this one due to semaphore wait return; } diff --git a/ArchiSteamFarm/MobileAuthenticator.cs b/ArchiSteamFarm/MobileAuthenticator.cs index c98fce17f..b596182d2 100644 --- a/ArchiSteamFarm/MobileAuthenticator.cs +++ b/ArchiSteamFarm/MobileAuthenticator.cs @@ -315,11 +315,11 @@ namespace ArchiSteamFarm { byte[] hash; -#pragma warning disable CA5350 +#pragma warning disable CA5350 // This is actually a fair warning, but there is nothing we can do about Steam using weak cryptographic algorithms using (HMACSHA1 hmac = new(identitySecret)) { hash = hmac.ComputeHash(buffer); } -#pragma warning restore CA5350 +#pragma warning restore CA5350 // This is actually a fair warning, but there is nothing we can do about Steam using weak cryptographic algorithms return Convert.ToBase64String(hash); } @@ -356,11 +356,11 @@ namespace ArchiSteamFarm { byte[] hash; -#pragma warning disable CA5350 +#pragma warning disable CA5350 // This is actually a fair warning, but there is nothing we can do about Steam using weak cryptographic algorithms using (HMACSHA1 hmac = new(sharedSecret)) { hash = hmac.ComputeHash(timeArray); } -#pragma warning restore CA5350 +#pragma warning restore CA5350 // This is actually a fair warning, but there is nothing we can do about Steam using weak cryptographic algorithms // The last 4 bits of the mac say where the code starts int start = hash[^1] & 0x0f; diff --git a/ArchiSteamFarm/NLog/Logging.cs b/ArchiSteamFarm/NLog/Logging.cs index e516e246a..380d31a99 100644 --- a/ArchiSteamFarm/NLog/Logging.cs +++ b/ArchiSteamFarm/NLog/Logging.cs @@ -160,9 +160,9 @@ namespace ArchiSteamFarm.NLog { ConfigurationItemFactory.Default.ParseMessageTemplates = false; LoggingConfiguration config = new(); -#pragma warning disable CA2000 // False positive +#pragma warning disable CA2000 // False positive, we're adding this disposable object to the global scope, so we can't dispose it ColoredConsoleTarget coloredConsoleTarget = new("ColoredConsole") { Layout = GeneralLayout }; -#pragma warning restore CA2000 // False positive +#pragma warning restore CA2000 // False positive, we're adding this disposable object to the global scope, so we can't dispose it config.AddTarget(coloredConsoleTarget); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, coloredConsoleTarget)); @@ -176,7 +176,7 @@ namespace ArchiSteamFarm.NLog { ASF.ArchiLogger.LogGenericException(e); } -#pragma warning disable CA2000 // False positive +#pragma warning disable CA2000 // False positive, we're adding this disposable object to the global scope, so we can't dispose it FileTarget fileTarget = new("File") { ArchiveFileName = Path.Combine("${currentdir}", SharedInfo.ArchivalLogsDirectory, SharedInfo.ArchivalLogFile), ArchiveNumbering = ArchiveNumberingMode.Rolling, @@ -188,7 +188,7 @@ namespace ArchiSteamFarm.NLog { Layout = GeneralLayout, MaxArchiveFiles = 10 }; -#pragma warning restore CA2000 // False positive +#pragma warning restore CA2000 // False positive, we're adding this disposable object to the global scope, so we can't dispose it config.AddTarget(fileTarget); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget)); diff --git a/ArchiSteamFarm/OS.cs b/ArchiSteamFarm/OS.cs index 013ad7ddc..57daa8b1c 100644 --- a/ArchiSteamFarm/OS.cs +++ b/ArchiSteamFarm/OS.cs @@ -254,11 +254,11 @@ namespace ArchiSteamFarm { internal const uint EnableQuickEditMode = 0x0040; internal const sbyte StandardInputHandle = -10; -#pragma warning disable CA2101 +#pragma warning disable CA2101 // False positive, we can't use unicode charset on Unix, and it uses UTF-8 by default anyway [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] [DllImport("libc", EntryPoint = "chmod", SetLastError = true)] internal static extern int Chmod(string path, int mode); -#pragma warning restore CA2101 +#pragma warning restore CA2101 // False positive, we can't use unicode charset on Unix, and it uses UTF-8 by default anyway [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] [DllImport("kernel32.dll")] diff --git a/ArchiSteamFarm/RuntimeCompatibility/File.cs b/ArchiSteamFarm/RuntimeCompatibility/File.cs index 10f7fcd5f..df10781c0 100644 --- a/ArchiSteamFarm/RuntimeCompatibility/File.cs +++ b/ArchiSteamFarm/RuntimeCompatibility/File.cs @@ -22,16 +22,18 @@ using System.Threading.Tasks; using JetBrains.Annotations; -#pragma warning disable CS1998 namespace ArchiSteamFarm.RuntimeCompatibility { [PublicAPI] public static class File { - public static async Task AppendAllTextAsync(string path, string contents) => + public static Task AppendAllTextAsync(string path, string contents) { #if NETFRAMEWORK System.IO.File.AppendAllText(path, contents); + + return Task.CompletedTask; #else - await System.IO.File.AppendAllTextAsync(path, contents).ConfigureAwait(false); + return System.IO.File.AppendAllTextAsync(path, contents); #endif + } public static void Move(string sourceFileName, string destFileName, bool overwrite) { #if NETFRAMEWORK @@ -45,26 +47,28 @@ namespace ArchiSteamFarm.RuntimeCompatibility { #endif } - public static async Task ReadAllBytesAsync(string path) => + public static Task ReadAllBytesAsync(string path) => #if NETFRAMEWORK - System.IO.File.ReadAllBytes(path); + Task.FromResult(System.IO.File.ReadAllBytes(path)); #else - await System.IO.File.ReadAllBytesAsync(path).ConfigureAwait(false); + System.IO.File.ReadAllBytesAsync(path); #endif - public static async Task ReadAllTextAsync(string path) => + public static Task ReadAllTextAsync(string path) => #if NETFRAMEWORK - System.IO.File.ReadAllText(path); + Task.FromResult(System.IO.File.ReadAllText(path)); #else - await System.IO.File.ReadAllTextAsync(path).ConfigureAwait(false); + System.IO.File.ReadAllTextAsync(path); #endif - public static async Task WriteAllTextAsync(string path, string contents) => + public static Task WriteAllTextAsync(string path, string contents) { #if NETFRAMEWORK System.IO.File.WriteAllText(path, contents); + + return Task.CompletedTask; #else - await System.IO.File.WriteAllTextAsync(path, contents).ConfigureAwait(false); + return System.IO.File.WriteAllTextAsync(path, contents); #endif + } } } -#pragma warning restore CS1998 diff --git a/ArchiSteamFarm/Statistics.cs b/ArchiSteamFarm/Statistics.cs index d969b2ccb..1400bee6c 100644 --- a/ArchiSteamFarm/Statistics.cs +++ b/ArchiSteamFarm/Statistics.cs @@ -345,9 +345,9 @@ namespace ArchiSteamFarm { break; } -#pragma warning disable CA2000 // False positive +#pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose using (await Bot.Actions.GetTradingLock().ConfigureAwait(false)) { -#pragma warning restore CA2000 // False positive +#pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose Bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.ActivelyMatchingItems, i)); (shouldContinueMatching, tradedSomething) = await MatchActivelyRound(acceptedMatchableTypes, triedSteamIDs).ConfigureAwait(false); Bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.DoneActivelyMatchingItems, i)); @@ -708,27 +708,27 @@ namespace ArchiSteamFarm { [SuppressMessage("ReSharper", "ClassCannotBeInstantiated")] private sealed class ListedUser { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // False positive, it's a field set during json deserialization [JsonProperty(PropertyName = "items_count", Required = Required.Always)] internal readonly ushort ItemsCount; -#pragma warning restore CS0649 +#pragma warning restore CS0649 // False positive, it's a field set during json deserialization internal readonly HashSet MatchableTypes = new(); -#pragma warning disable CS0649 +#pragma warning disable CS0649 // False positive, it's a field set during json deserialization [JsonProperty(PropertyName = "steam_id", Required = Required.Always)] internal readonly ulong SteamID; -#pragma warning restore CS0649 +#pragma warning restore CS0649 // False positive, it's a field set during json deserialization [JsonProperty(PropertyName = "trade_token", Required = Required.Always)] internal readonly string TradeToken = ""; internal float Score => GamesCount / (float) ItemsCount; -#pragma warning disable CS0649 +#pragma warning disable CS0649 // False positive, it's a field set during json deserialization [JsonProperty(PropertyName = "games_count", Required = Required.Always)] private readonly ushort GamesCount; -#pragma warning restore CS0649 +#pragma warning restore CS0649 // False positive, it's a field set during json deserialization internal bool MatchEverything { get; private set; } diff --git a/ArchiSteamFarm/SteamPICSChanges.cs b/ArchiSteamFarm/SteamPICSChanges.cs index 1040663e6..f85152255 100644 --- a/ArchiSteamFarm/SteamPICSChanges.cs +++ b/ArchiSteamFarm/SteamPICSChanges.cs @@ -96,9 +96,9 @@ namespace ArchiSteamFarm { LastChangeNumber = picsChanges.CurrentChangeNumber; -#pragma warning disable CA1508 // False positive +#pragma warning disable CA1508 // False positive, PackageChanges are not always empty if (picsChanges.RequiresFullAppUpdate || picsChanges.RequiresFullPackageUpdate || ((picsChanges.AppChanges.Count == 0) && (picsChanges.PackageChanges.Count == 0))) { -#pragma warning restore CA1508 // False positive +#pragma warning restore CA1508 // False positive, PackageChanges are not always empty if (ASF.GlobalDatabase != null) { await ASF.GlobalDatabase.OnPICSChangesRestart(picsChanges.CurrentChangeNumber).ConfigureAwait(false); } diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index 61e4c0ae0..0f31915ca 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -318,9 +318,9 @@ namespace ArchiSteamFarm { throw new ArgumentNullException(nameof(directory)); } -#pragma warning disable CA1508 // False positive +#pragma warning disable CA1508 // False positive, params could be null when explicitly set if ((prefixes == null) || (prefixes.Length == 0)) { -#pragma warning restore CA1508 // False positive +#pragma warning restore CA1508 // False positive, params could be null when explicitly set throw new ArgumentNullException(nameof(prefixes)); } diff --git a/ArchiSteamFarm/Web/WebBrowser.cs b/ArchiSteamFarm/Web/WebBrowser.cs index a930b0b84..0ecfe2ec1 100644 --- a/ArchiSteamFarm/Web/WebBrowser.cs +++ b/ArchiSteamFarm/Web/WebBrowser.cs @@ -140,14 +140,16 @@ namespace ArchiSteamFarm.Web { progressReporter?.Report(0); - MemoryStream ms; +#pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose + MemoryStream ms = new((int) response.Length); +#pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose #if NETFRAMEWORK - using (ms = new MemoryStream((int) response.Length)) { +#pragma warning disable CA1508 // False positive, ms is not null here indeed, but using clause is needed for dispose + using (ms) { +#pragma warning restore CA1508 // False positive, ms is not null here indeed, but using clause is needed for dispose #else -#pragma warning disable CA2000 // False positive - await using ((ms = new MemoryStream((int) response.Length)).ConfigureAwait(false)) { -#pragma warning restore CA2000 // False positive + await using (ms.ConfigureAwait(false)) { #endif try { byte batch = 0;