mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Code cleanup
This commit is contained in:
parent
1e6ab11d9f
commit
d46e532458
9 changed files with 99 additions and 82 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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<MvcJsonOptions> 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<MvcJsonOptions> setupAction) {
|
||||
if (mvc == null) {
|
||||
throw new ArgumentNullException(nameof(mvc));
|
||||
}
|
||||
|
||||
internal static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action<RequestLocalizationOptions> 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<RequestLocalizationOptions> 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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue