diff --git a/ArchiSteamFarm/GlobalConfig.cs b/ArchiSteamFarm/GlobalConfig.cs index 879e624b6..75e753871 100644 --- a/ArchiSteamFarm/GlobalConfig.cs +++ b/ArchiSteamFarm/GlobalConfig.cs @@ -110,86 +110,65 @@ namespace ArchiSteamFarm { [JsonProperty(Required = Required.DisallowNull)] internal readonly ushort WebLimiterDelay = 200; + [JsonProperty(PropertyName = nameof(WebProxy))] + internal readonly string WebProxyText; + + [JsonProperty] + internal readonly string WebProxyUsername; + + internal WebProxy WebProxy { + get { + if (_WebProxy != null) { + return _WebProxy; + } + + if (string.IsNullOrEmpty(WebProxyText)) { + return null; + } + + Uri uri; + + try { + uri = new Uri(WebProxyText); + } catch (UriFormatException e) { + ASF.ArchiLogger.LogGenericException(e); + return null; + } + + _WebProxy = new WebProxy { + Address = uri, + BypassProxyOnLocal = true + }; + + if (!string.IsNullOrEmpty(WebProxyUsername) || !string.IsNullOrEmpty(WebProxyPassword)) { + NetworkCredential credentials = new NetworkCredential(); + + if (!string.IsNullOrEmpty(WebProxyUsername)) { + credentials.UserName = WebProxyUsername; + } + + if (!string.IsNullOrEmpty(WebProxyPassword)) { + credentials.Password = WebProxyPassword; + } + + _WebProxy.Credentials = credentials; + } + + return _WebProxy; + } + } + [JsonProperty(Required = Required.DisallowNull)] internal ulong SteamOwnerID { get; private set; } [JsonProperty(Required = Required.DisallowNull)] internal ProtocolTypes SteamProtocols { get; private set; } = ProtocolTypes.All; - internal WebProxy WebProxy { get; private set; } - [JsonProperty] - internal string WebProxyPassword { - get => WebProxyCredentials?.Password; - set { - if (string.IsNullOrEmpty(value)) { - if (WebProxyCredentials == null) { - return; - } - - WebProxyCredentials.Password = null; - - if (!string.IsNullOrEmpty(WebProxyCredentials.UserName)) { - return; - } - - WebProxyCredentials = null; - if (WebProxy != null) { - WebProxy.Credentials = null; - } - - return; - } - - if (WebProxyCredentials == null) { - WebProxyCredentials = new NetworkCredential(); - } - - WebProxyCredentials.Password = value; - - if ((WebProxy != null) && (WebProxy.Credentials != WebProxyCredentials)) { - WebProxy.Credentials = WebProxyCredentials; - } - } - } - - [JsonProperty] - internal string WebProxyUsername { - get => WebProxyCredentials?.UserName; - set { - if (string.IsNullOrEmpty(value)) { - if (WebProxyCredentials == null) { - return; - } - - WebProxyCredentials.UserName = null; - - if (!string.IsNullOrEmpty(WebProxyCredentials.Password)) { - return; - } - - WebProxyCredentials = null; - if (WebProxy != null) { - WebProxy.Credentials = null; - } - - return; - } - - if (WebProxyCredentials == null) { - WebProxyCredentials = new NetworkCredential(); - } - - WebProxyCredentials.UserName = value; - - if ((WebProxy != null) && (WebProxy.Credentials != WebProxyCredentials)) { - WebProxy.Credentials = WebProxyCredentials; - } - } - } + internal string WebProxyPassword { get; set; } + private WebProxy _WebProxy; private bool ShouldSerializeSensitiveDetails = true; - private NetworkCredential WebProxyCredentials; [JsonProperty(PropertyName = SharedInfo.UlongCompatibilityStringPrefix + nameof(SteamOwnerID), Required = Required.DisallowNull)] private string SSteamOwnerID { @@ -204,39 +183,6 @@ namespace ArchiSteamFarm { } } - [JsonProperty(PropertyName = nameof(WebProxy))] - private string WebProxyText { - get => WebProxy?.Address.OriginalString; - set { - if (string.IsNullOrEmpty(value)) { - if (WebProxy != null) { - WebProxy = null; - } - - return; - } - - Uri uri; - - try { - uri = new Uri(value); - } catch (UriFormatException e) { - ASF.ArchiLogger.LogGenericException(e); - return; - } - - if (WebProxy == null) { - WebProxy = new WebProxy { BypassProxyOnLocal = true }; - } - - WebProxy.Address = uri; - - if ((WebProxyCredentials != null) && (WebProxy.Credentials != WebProxyCredentials)) { - WebProxy.Credentials = WebProxyCredentials; - } - } - } - public bool ShouldSerializeWebProxyPassword() => ShouldSerializeSensitiveDetails; internal static async Task Load(string filePath) { @@ -339,4 +285,4 @@ namespace ArchiSteamFarm { Experimental } } -} \ No newline at end of file +} diff --git a/ArchiSteamFarm/IPC.cs b/ArchiSteamFarm/IPC.cs index 21deef35e..ac29f5cc8 100644 --- a/ArchiSteamFarm/IPC.cs +++ b/ArchiSteamFarm/IPC.cs @@ -724,11 +724,19 @@ namespace ArchiSteamFarm { if (targetType.IsClass) { foreach (FieldInfo field in targetType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(field => !field.IsPrivate)) { - body[field.Name] = field.FieldType.GetUnifiedName(); + JsonPropertyAttribute jsonProperty = field.GetCustomAttribute(); + + if (jsonProperty != null) { + body[jsonProperty.PropertyName ?? field.Name] = field.FieldType.GetUnifiedName(); + } } foreach (PropertyInfo property in targetType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(property => property.CanRead && !property.GetMethod.IsPrivate)) { - body[property.Name] = property.PropertyType.GetUnifiedName(); + JsonPropertyAttribute jsonProperty = property.GetCustomAttribute(); + + if (jsonProperty != null) { + body[jsonProperty.PropertyName ?? property.Name] = property.PropertyType.GetUnifiedName(); + } } } else if (targetType.IsEnum) { Type enumType = Enum.GetUnderlyingType(targetType); @@ -1283,4 +1291,4 @@ namespace ArchiSteamFarm { } } } -} \ No newline at end of file +} diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 6132321a1..b85ddd9d3 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -496,4 +496,4 @@ namespace ArchiSteamFarm { ShutdownResetEvent.TrySetResult(exitCode); } } -} \ No newline at end of file +} diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index 7125f7447..647df4130 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -79,8 +79,7 @@ namespace ArchiSteamFarm { return null; } - string result = type.GenericTypeArguments.Length == 0 ? type.FullName : type.Namespace + "." + type.Name + string.Join("", type.GenericTypeArguments.Select(innerType => '[' + innerType.GetUnifiedName() + ']')); - return result; + return type.GenericTypeArguments.Length == 0 ? type.FullName : type.Namespace + "." + type.Name + string.Join("", type.GenericTypeArguments.Select(innerType => '[' + innerType.GetUnifiedName() + ']')); } internal static uint GetUnixTime() => (uint) DateTimeOffset.UtcNow.ToUnixTimeSeconds(); @@ -186,4 +185,4 @@ namespace ArchiSteamFarm { internal static string ToHumanReadable(this TimeSpan timeSpan) => timeSpan.Humanize(3, maxUnit: TimeUnit.Year, minUnit: TimeUnit.Second); } -} \ No newline at end of file +}