mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Correct WebProxy type for #855
This commit is contained in:
@@ -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<GlobalConfig> Load(string filePath) {
|
||||
@@ -339,4 +285,4 @@ namespace ArchiSteamFarm {
|
||||
Experimental
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<JsonPropertyAttribute>();
|
||||
|
||||
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<JsonPropertyAttribute>();
|
||||
|
||||
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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,4 +496,4 @@ namespace ArchiSteamFarm {
|
||||
ShutdownResetEvent.TrySetResult(exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user