From d46e5324584d89cd225b7b9bc2ce88542f2f5974 Mon Sep 17 00:00:00 2001 From: Archi Date: Wed, 10 Nov 2021 21:47:42 +0100 Subject: [PATCH] Code cleanup --- .editorconfig | 13 +++++ .../SteamTokenDumperPlugin.cs | 2 +- ArchiSteamFarm/Core/Debugging.cs | 2 +- ArchiSteamFarm/Core/OS.cs | 38 ++++++------- ArchiSteamFarm/Core/Utilities.cs | 2 +- ArchiSteamFarm/IPC/Startup.cs | 18 +++--- ArchiSteamFarm/IPC/WebUtilities.cs | 56 ++++++++++--------- ArchiSteamFarm/SharedInfo.cs | 36 ++++++------ ArchiSteamFarm/Web/WebBrowser.cs | 14 ++--- 9 files changed, 99 insertions(+), 82 deletions(-) diff --git a/.editorconfig b/.editorconfig index 715ba34d0..08b3fe5ac 100644 --- a/.editorconfig +++ b/.editorconfig @@ -212,3 +212,16 @@ dotnet_style_qualification_for_property = false:warning dotnet_style_readonly_field = true:warning dotnet_style_require_accessibility_modifiers = always:warning + +############################### +# Jetbrains / IntelliJ # +############################### + +[*.{csproj,props,xml}] +ij_xml_keep_blank_lines = 1 +ij_xml_keep_line_breaks = false +ij_xml_keep_line_breaks_in_text = false +ij_xml_space_inside_empty_tag = true + +[*.{json,json5}] +ij_json_keep_line_breaks = false diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs index bb9165576..ebd9218e1 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs @@ -513,7 +513,7 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotS ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, ArchiSteamFarm.Localization.Strings.WarningFailedWithError, response.StatusCode)); #if NETFRAMEWORK - if (response.StatusCode == (HttpStatusCode) 429) { + if (response.StatusCode == (HttpStatusCode) 429) { #else if (response.StatusCode == HttpStatusCode.TooManyRequests) { #endif diff --git a/ArchiSteamFarm/Core/Debugging.cs b/ArchiSteamFarm/Core/Debugging.cs index 235fb2b4f..2cd845010 100644 --- a/ArchiSteamFarm/Core/Debugging.cs +++ b/ArchiSteamFarm/Core/Debugging.cs @@ -28,7 +28,7 @@ internal static class Debugging { #if DEBUG internal static bool IsDebugBuild => true; #else - internal static bool IsDebugBuild => false; + internal static bool IsDebugBuild => false; #endif internal static bool IsDebugConfigured => ASF.GlobalConfig?.Debug ?? throw new InvalidOperationException(nameof(ASF.GlobalConfig)); diff --git a/ArchiSteamFarm/Core/OS.cs b/ArchiSteamFarm/Core/OS.cs index bf232bf21..7f21ad54e 100644 --- a/ArchiSteamFarm/Core/OS.cs +++ b/ArchiSteamFarm/Core/OS.cs @@ -43,7 +43,7 @@ internal static class OS { internal static DateTime ProcessStartTime { #if NETFRAMEWORK - get => RuntimeMadness.ProcessStartTime.ToUniversalTime(); + get => RuntimeMadness.ProcessStartTime.ToUniversalTime(); #else get { using Process process = Process.GetCurrentProcess(); @@ -67,7 +67,7 @@ internal static class OS { } #if NETFRAMEWORK - string runtime = RuntimeInformation.OSArchitecture.ToString(); + string runtime = RuntimeInformation.OSArchitecture.ToString(); #else string runtime = RuntimeInformation.RuntimeIdentifier.Trim(); @@ -231,28 +231,28 @@ internal static class OS { internal static bool VerifyEnvironment() { #if NETFRAMEWORK - // This is .NET Framework build, we support that one only on mono for platforms not supported by .NET Core + // This is .NET Framework build, we support that one only on mono for platforms not supported by .NET Core - // We're not going to analyze source builds, as we don't know what changes the author has made, assume they have a point - if (SharedInfo.BuildInfo.IsCustomBuild) { - return true; - } + // We're not going to analyze source builds, as we don't know what changes the author has made, assume they have a point + if (SharedInfo.BuildInfo.IsCustomBuild) { + return true; + } - // All windows variants have valid .NET Core build, and generic-netf is supported only on mono - if (OperatingSystem.IsWindows() || !RuntimeMadness.IsRunningOnMono) { - return false; - } + // All windows variants have valid .NET Core build, and generic-netf is supported only on mono + if (OperatingSystem.IsWindows() || !RuntimeMadness.IsRunningOnMono) { + return false; + } - return RuntimeInformation.OSArchitecture switch { - // Sadly we can't tell a difference between ARMv6 and ARMv7 reliably, we'll believe that this linux-arm user knows what he's doing and he's indeed in need of generic-netf on ARMv6 - Architecture.Arm => true, + return RuntimeInformation.OSArchitecture switch { + // Sadly we can't tell a difference between ARMv6 and ARMv7 reliably, we'll believe that this linux-arm user knows what he's doing and he's indeed in need of generic-netf on ARMv6 + Architecture.Arm => true, - // Apart from real x86, this also covers all unknown architectures, such as sparc, ppc64, and anything else Mono might support, we're fine with that - Architecture.X86 => true, + // Apart from real x86, this also covers all unknown architectures, such as sparc, ppc64, and anything else Mono might support, we're fine with that + Architecture.X86 => true, - // Everything else is covered by .NET Core - _ => false - }; + // Everything else is covered by .NET Core + _ => false + }; #else // This is .NET Core build, we support all scenarios diff --git a/ArchiSteamFarm/Core/Utilities.cs b/ArchiSteamFarm/Core/Utilities.cs index 60013ce7d..bb48fe429 100644 --- a/ArchiSteamFarm/Core/Utilities.cs +++ b/ArchiSteamFarm/Core/Utilities.cs @@ -97,7 +97,7 @@ public static class Utilities { CookieCollection cookies = cookieContainer.GetCookies(uri); #if NETFRAMEWORK - return cookies.Count > 0 ? (from Cookie cookie in cookies where cookie.Name == name select cookie.Value).FirstOrDefault() : null; + return cookies.Count > 0 ? (from Cookie cookie in cookies where cookie.Name == name select cookie.Value).FirstOrDefault() : null; #else return cookies.Count > 0 ? cookies.FirstOrDefault(cookie => cookie.Name == name)?.Value : null; #endif diff --git a/ArchiSteamFarm/IPC/Startup.cs b/ArchiSteamFarm/IPC/Startup.cs index 8eb387dc8..7ccdefa58 100644 --- a/ArchiSteamFarm/IPC/Startup.cs +++ b/ArchiSteamFarm/IPC/Startup.cs @@ -166,7 +166,7 @@ internal sealed class Startup { // Finally register proper API endpoints once we're done with routing #if NETFRAMEWORK - app.UseMvcWithDefaultRoute(); + app.UseMvcWithDefaultRoute(); #else app.UseEndpoints(static endpoints => endpoints.MapControllers()); #endif @@ -345,14 +345,14 @@ internal sealed class Startup { mvc.AddControllersAsServices(); #if NETFRAMEWORK - // Use latest compatibility version for MVC - mvc.SetCompatibilityVersion(CompatibilityVersion.Latest); + // Use latest compatibility version for MVC + mvc.SetCompatibilityVersion(CompatibilityVersion.Latest); - // Add standard formatters - mvc.AddFormatterMappings(); + // Add standard formatters + mvc.AddFormatterMappings(); - // Add API explorer for swagger - mvc.AddApiExplorer(); + // Add API explorer for swagger + mvc.AddApiExplorer(); #endif mvc.AddNewtonsoftJson( @@ -365,8 +365,8 @@ internal sealed class Startup { } #if NETFRAMEWORK - // .NET Framework serializes Version as object by default, serialize it as string just like .NET Core - options.SerializerSettings.Converters.Add(new VersionConverter()); + // .NET Framework serializes Version as object by default, serialize it as string just like .NET Core + options.SerializerSettings.Converters.Add(new VersionConverter()); #endif } ); diff --git a/ArchiSteamFarm/IPC/WebUtilities.cs b/ArchiSteamFarm/IPC/WebUtilities.cs index 99574d9c8..8b2e03349 100644 --- a/ArchiSteamFarm/IPC/WebUtilities.cs +++ b/ArchiSteamFarm/IPC/WebUtilities.cs @@ -36,38 +36,42 @@ namespace ArchiSteamFarm.IPC; internal static class WebUtilities { #if NETFRAMEWORK - internal static IMvcCoreBuilder AddControllers(this IServiceCollection services) { - if (services == null) { - throw new ArgumentNullException(nameof(services)); - } - - return services.AddMvcCore(); + internal static IMvcCoreBuilder AddControllers(this IServiceCollection services) { + if (services == null) { + throw new ArgumentNullException(nameof(services)); } - internal static IMvcCoreBuilder AddNewtonsoftJson(this IMvcCoreBuilder mvc, Action setupAction) { - if (mvc == null) { - throw new ArgumentNullException(nameof(mvc)); - } + return services.AddMvcCore(); + } - if (setupAction == null) { - throw new ArgumentNullException(nameof(setupAction)); - } - - // Add JSON formatters that will be used as default ones if no specific formatters are asked for - mvc.AddJsonFormatters(); - - mvc.AddJsonOptions(setupAction); - - return mvc; + internal static IMvcCoreBuilder AddNewtonsoftJson(this IMvcCoreBuilder mvc, Action setupAction) { + if (mvc == null) { + throw new ArgumentNullException(nameof(mvc)); } - internal static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action action) { - if (services == null) { - throw new ArgumentNullException(nameof(services)); - } - - return services.Configure(action); + if (setupAction == null) { + throw new ArgumentNullException(nameof(setupAction)); } + + // Add JSON formatters that will be used as default ones if no specific formatters are asked for + mvc.AddJsonFormatters(); + + mvc.AddJsonOptions(setupAction); + + return mvc; + } + + internal static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action action) { + if (services == null) { + throw new ArgumentNullException(nameof(services)); + } + + if (action == null) { + throw new ArgumentNullException(nameof(action)); + } + + return services.Configure(action); + } #endif internal static string? GetUnifiedName(this Type type) { diff --git a/ArchiSteamFarm/SharedInfo.cs b/ArchiSteamFarm/SharedInfo.cs index 4a86f05d4..3f035def6 100644 --- a/ArchiSteamFarm/SharedInfo.cs +++ b/ArchiSteamFarm/SharedInfo.cs @@ -97,32 +97,32 @@ public static class SharedInfo { internal static class BuildInfo { #if ASF_VARIANT_DOCKER - internal static bool CanUpdate => false; - internal static string Variant => "docker"; + internal static bool CanUpdate => false; + internal static string Variant => "docker"; #elif ASF_VARIANT_GENERIC - internal static bool CanUpdate => true; - internal static string Variant => "generic"; + internal static bool CanUpdate => true; + internal static string Variant => "generic"; #elif ASF_VARIANT_GENERIC_NETF - internal static bool CanUpdate => true; - internal static string Variant => "generic-netf"; + internal static bool CanUpdate => true; + internal static string Variant => "generic-netf"; #elif ASF_VARIANT_LINUX_ARM - internal static bool CanUpdate => true; - internal static string Variant => "linux-arm"; + internal static bool CanUpdate => true; + internal static string Variant => "linux-arm"; #elif ASF_VARIANT_LINUX_ARM64 - internal static bool CanUpdate => true; - internal static string Variant => "linux-arm64"; + internal static bool CanUpdate => true; + internal static string Variant => "linux-arm64"; #elif ASF_VARIANT_LINUX_X64 - internal static bool CanUpdate => true; - internal static string Variant => "linux-x64"; + internal static bool CanUpdate => true; + internal static string Variant => "linux-x64"; #elif ASF_VARIANT_OSX_ARM64 - internal static bool CanUpdate => true; - internal static string Variant => "osx-arm64"; + internal static bool CanUpdate => true; + internal static string Variant => "osx-arm64"; #elif ASF_VARIANT_OSX_X64 - internal static bool CanUpdate => true; - internal static string Variant => "osx-x64"; + internal static bool CanUpdate => true; + internal static string Variant => "osx-x64"; #elif ASF_VARIANT_WIN_X64 - internal static bool CanUpdate => true; - internal static string Variant => "win-x64"; + internal static bool CanUpdate => true; + internal static string Variant => "win-x64"; #else internal static bool CanUpdate => false; internal static string Variant => SourceVariant; diff --git a/ArchiSteamFarm/Web/WebBrowser.cs b/ArchiSteamFarm/Web/WebBrowser.cs index ff7843d4c..3355769f2 100644 --- a/ArchiSteamFarm/Web/WebBrowser.cs +++ b/ArchiSteamFarm/Web/WebBrowser.cs @@ -66,7 +66,7 @@ public sealed class WebBrowser : IDisposable { AllowAutoRedirect = false, // This must be false if we want to handle custom redirection schemes such as "steammobile://" #if NETFRAMEWORK - AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, + AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, #else AutomaticDecompression = DecompressionMethods.All, #endif @@ -80,9 +80,9 @@ public sealed class WebBrowser : IDisposable { } #if NETFRAMEWORK - if (!RuntimeMadness.IsRunningOnMono) { - HttpClientHandler.MaxConnectionsPerServer = MaxConnections; - } + if (!RuntimeMadness.IsRunningOnMono) { + HttpClientHandler.MaxConnectionsPerServer = MaxConnections; + } #else HttpClientHandler.MaxConnectionsPerServer = MaxConnections; #endif @@ -719,9 +719,9 @@ public sealed class WebBrowser : IDisposable { // Reuse ports if possible #if NETFRAMEWORK - if (!RuntimeMadness.IsRunningOnMono) { - ServicePointManager.ReusePort = true; - } + if (!RuntimeMadness.IsRunningOnMono) { + ServicePointManager.ReusePort = true; + } #else ServicePointManager.ReusePort = true; #endif