From cc2289798e3aa8a497afd5bd3046ed658821ebe4 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Mon, 25 Jul 2016 06:44:10 +0200 Subject: [PATCH] Enable PortReuse on Windows + misc --- ArchiSteamFarm/JSON/GitHub.cs | 2 ++ ArchiSteamFarm/JSON/Steam.cs | 6 ++++++ ArchiSteamFarm/MobileAuthenticator.cs | 2 ++ ArchiSteamFarm/Runtime.cs | 3 ++- ArchiSteamFarm/WebBrowser.cs | 13 +++++++++++-- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ArchiSteamFarm/JSON/GitHub.cs b/ArchiSteamFarm/JSON/GitHub.cs index 2174e16f6..25b595ba0 100644 --- a/ArchiSteamFarm/JSON/GitHub.cs +++ b/ArchiSteamFarm/JSON/GitHub.cs @@ -31,6 +31,7 @@ namespace ArchiSteamFarm.JSON { [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] internal sealed class ReleaseResponse { +#pragma warning disable 649 internal sealed class Asset { [JsonProperty(PropertyName = "name", Required = Required.Always)] internal readonly string Name; @@ -44,6 +45,7 @@ namespace ArchiSteamFarm.JSON { [JsonProperty(PropertyName = "assets", Required = Required.Always)] internal readonly List Assets; +#pragma warning restore 649 } } } diff --git a/ArchiSteamFarm/JSON/Steam.cs b/ArchiSteamFarm/JSON/Steam.cs index 40856d9c4..c78c934ab 100644 --- a/ArchiSteamFarm/JSON/Steam.cs +++ b/ArchiSteamFarm/JSON/Steam.cs @@ -345,8 +345,10 @@ namespace ArchiSteamFarm.JSON { [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] internal sealed class ConfirmationResponse { // Deserialized from JSON +#pragma warning disable 649 [JsonProperty(PropertyName = "success", Required = Required.Always)] internal readonly bool Success; +#pragma warning restore 649 private ConfirmationResponse() { } } @@ -376,8 +378,10 @@ namespace ArchiSteamFarm.JSON { } } +#pragma warning disable 649 [JsonProperty(PropertyName = "success", Required = Required.Always)] internal readonly bool Success; +#pragma warning restore 649 private EType _Type; private EType Type { @@ -468,8 +472,10 @@ namespace ArchiSteamFarm.JSON { } } +#pragma warning disable 649 [JsonProperty(PropertyName = "html", Required = Required.DisallowNull)] private readonly string HTML; +#pragma warning restore 649 private uint _OtherSteamID3; private uint OtherSteamID3 { diff --git a/ArchiSteamFarm/MobileAuthenticator.cs b/ArchiSteamFarm/MobileAuthenticator.cs index 13b36cde5..912a631bb 100644 --- a/ArchiSteamFarm/MobileAuthenticator.cs +++ b/ArchiSteamFarm/MobileAuthenticator.cs @@ -68,11 +68,13 @@ namespace ArchiSteamFarm { internal bool HasDeviceID => !string.IsNullOrEmpty(DeviceID); +#pragma warning disable 649 [JsonProperty(PropertyName = "shared_secret", Required = Required.Always)] private readonly string SharedSecret; [JsonProperty(PropertyName = "identity_secret", Required = Required.Always)] private readonly string IdentitySecret; +#pragma warning restore 649 [JsonProperty(PropertyName = "device_id")] private string DeviceID; diff --git a/ArchiSteamFarm/Runtime.cs b/ArchiSteamFarm/Runtime.cs index c0f8e3329..3aa38933a 100644 --- a/ArchiSteamFarm/Runtime.cs +++ b/ArchiSteamFarm/Runtime.cs @@ -28,7 +28,8 @@ using System.Reflection; namespace ArchiSteamFarm { internal static class Runtime { private static readonly Type MonoRuntime = Type.GetType("Mono.Runtime"); - private static bool IsRunningOnMono => MonoRuntime != null; + + internal static bool IsRunningOnMono => MonoRuntime != null; private static bool? _IsUserInteractive; internal static bool IsUserInteractive { diff --git a/ArchiSteamFarm/WebBrowser.cs b/ArchiSteamFarm/WebBrowser.cs index 65354ff0b..e28ea53bb 100644 --- a/ArchiSteamFarm/WebBrowser.cs +++ b/ArchiSteamFarm/WebBrowser.cs @@ -55,11 +55,20 @@ namespace ArchiSteamFarm { ServicePointManager.Expect100Continue = false; #if !__MonoCS__ - // Reuse ports if possible (since .NET 4.6+) - //ServicePointManager.ReusePort = true; + // We run Windows-compiled ASF on both Windows and Mono and normally we'd simply put code in the if + // However, if we did that, then we would still crash on Mono due to potentially calling non-existing methods + // Therefore, call mono-incompatible options in their own function to avoid that, and just leave the function call here + // When compiling on Mono, this section is omitted entirely as we never run Mono-compiled ASF on Windows + if (!Runtime.IsRunningOnMono) { + InitNonMonoBehaviour(); + } #endif } +#if !__MonoCS__ + private static void InitNonMonoBehaviour() => ServicePointManager.ReusePort = true; +#endif + internal WebBrowser(string identifier) { if (string.IsNullOrEmpty(identifier)) { throw new ArgumentNullException(nameof(identifier));