From e04ae4505505f82afed64d0ae794fb272c528cf7 Mon Sep 17 00:00:00 2001 From: Mindaugas Veblauskas Date: Fri, 31 Mar 2023 06:36:54 +0000 Subject: [PATCH] Fix build time errors [VPNWIN-1391] --- Setup/setup.iss | 3 +- .../Retries/RetryCountProviderTest.cs | 4 +- src/ProtonVPN.App/Config/Url/ActiveUrl.cs | 11 +++--- src/ProtonVPN.App/ProtonVPN.App.csproj | 2 +- .../Resources/Assets/Styles/OxyPlot.xaml | 37 +------------------ .../Net/Http/HttpRequestMessageExtensions.cs | 26 ++++--------- src/ProtonVPN.Common/ProtonVPN.Common.csproj | 6 --- src/ProtonVPN.Common/Vpn/VpnHost.cs | 8 +++- src/ProtonVPN.Crypto/X25519KeyGenerator.cs | 2 +- .../ProtonVPN.Translations.csproj | 3 +- .../TranslationSource.cs | 9 +++-- .../Files/Validatable/FileCheckSum.cs | 11 ++++-- 12 files changed, 43 insertions(+), 79 deletions(-) diff --git a/Setup/setup.iss b/Setup/setup.iss index afadaf8fe..042ca859f 100644 --- a/Setup/setup.iss +++ b/Setup/setup.iss @@ -104,10 +104,10 @@ Source: "..\src\bin\Microsoft.Windows.SDK.NET.dll"; DestDir: "{app}\{#VersionFol Source: "..\src\bin\Newtonsoft.Json.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\OxyPlot.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\OxyPlot.Wpf.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; +Source: "..\src\bin\OxyPlot.Wpf.Shared.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\PInvoke.Kernel32.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\PInvoke.Windows.Core.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\PInvoke.Windows.ShellScalingApi.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; -Source: "..\src\bin\PluralNet.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\Polly.Contrib.WaitAndRetry.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\Polly.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\ProtonVPN.Announcements.Contracts.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; @@ -198,6 +198,7 @@ Source: "..\src\bin\ProtonVPN.Vpn.dll"; DestDir: "{app}\{#VersionFolder}"; Flags Source: "..\src\bin\ProtonVPN.Vpn.deps.json"; DestDir: "{app}\{#VersionFolder}"; Source: "..\src\bin\ProtonVPN.WireGuardDriver.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\ProtonVPN.WireGuardDriver.deps.json"; DestDir: "{app}\{#VersionFolder}"; +Source: "..\src\bin\ReswPlusLib.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\Sentry.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\System.Configuration.ConfigurationManager.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; Source: "..\src\bin\System.Diagnostics.EventLog.dll"; DestDir: "{app}\{#VersionFolder}"; Flags: signonce; diff --git a/src/Api/ProtonVPN.Api.Tests/Handlers/Retries/RetryCountProviderTest.cs b/src/Api/ProtonVPN.Api.Tests/Handlers/Retries/RetryCountProviderTest.cs index 115950133..c58537bc0 100644 --- a/src/Api/ProtonVPN.Api.Tests/Handlers/Retries/RetryCountProviderTest.cs +++ b/src/Api/ProtonVPN.Api.Tests/Handlers/Retries/RetryCountProviderTest.cs @@ -34,7 +34,7 @@ public void ItShouldUseDefaultRetryCount() { // Arrange int retryCount = 3; - IConfiguration config = new Config() { ApiRetries = retryCount }; + IConfiguration config = new Config { ApiRetries = retryCount }; RetryCountProvider sut = new(config); // Assert @@ -45,7 +45,7 @@ public void ItShouldUseDefaultRetryCount() public void ItShouldUseCustomRetryCount() { // Arrange - IConfiguration config = new Config() { ApiRetries = 3 }; + IConfiguration config = new Config { ApiRetries = 3 }; RetryCountProvider sut = new(config); HttpRequestMessage request = new(); int retryCount = 10; diff --git a/src/ProtonVPN.App/Config/Url/ActiveUrl.cs b/src/ProtonVPN.App/Config/Url/ActiveUrl.cs index 85e3004b8..fa24be817 100644 --- a/src/ProtonVPN.App/Config/Url/ActiveUrl.cs +++ b/src/ProtonVPN.App/Config/Url/ActiveUrl.cs @@ -17,11 +17,12 @@ * along with ProtonVPN. If not, see . */ -using ProtonVPN.Common.OS.Processes; using System; using System.Collections.Generic; -using System.Collections.Specialized; -using System.Web; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.WebUtilities; +using Microsoft.Extensions.Primitives; +using ProtonVPN.Common.OS.Processes; namespace ProtonVPN.Config.Url { @@ -41,13 +42,13 @@ public ActiveUrl WithQueryParams(Dictionary parameters) try { UriBuilder uriBuilder = new UriBuilder(_url); - NameValueCollection query = HttpUtility.ParseQueryString(uriBuilder.Query); + Dictionary query = QueryHelpers.ParseQuery(uriBuilder.Query); foreach (KeyValuePair item in parameters) { query[item.Key] = item.Value; } - uriBuilder.Query = query.ToString(); + uriBuilder.Query = QueryString.Create(query).ToString(); _url = uriBuilder.ToString(); } catch (UriFormatException) diff --git a/src/ProtonVPN.App/ProtonVPN.App.csproj b/src/ProtonVPN.App/ProtonVPN.App.csproj index 542811358..803c8c9a2 100644 --- a/src/ProtonVPN.App/ProtonVPN.App.csproj +++ b/src/ProtonVPN.App/ProtonVPN.App.csproj @@ -591,7 +591,7 @@ all - + diff --git a/src/ProtonVPN.App/Resources/Assets/Styles/OxyPlot.xaml b/src/ProtonVPN.App/Resources/Assets/Styles/OxyPlot.xaml index 9b8f43242..41ef461b6 100644 --- a/src/ProtonVPN.App/Resources/Assets/Styles/OxyPlot.xaml +++ b/src/ProtonVPN.App/Resources/Assets/Styles/OxyPlot.xaml @@ -93,39 +93,4 @@ along with ProtonVPN. If not, see . - - - + \ No newline at end of file diff --git a/src/ProtonVPN.Common/OS/Net/Http/HttpRequestMessageExtensions.cs b/src/ProtonVPN.Common/OS/Net/Http/HttpRequestMessageExtensions.cs index ad4a78a8a..bfe2d1a2b 100644 --- a/src/ProtonVPN.Common/OS/Net/Http/HttpRequestMessageExtensions.cs +++ b/src/ProtonVPN.Common/OS/Net/Http/HttpRequestMessageExtensions.cs @@ -26,8 +26,8 @@ namespace ProtonVPN.Common.OS.Net.Http { public static class HttpRequestMessageExtensions { - private const string CUSTOM_TIMEOUT_PROPERTY_NAME = "CustomTimeout"; - private const string RETRY_COUNT_PROPERTY_NAME = "RetryCount"; + private static readonly HttpRequestOptionsKey CustomTimeoutOptionsKey = new("CustomTimeout"); + private static readonly HttpRequestOptionsKey RetryCountOptionsKey = new("RetryCount"); public static bool AuthHeadersInvalid(this HttpRequestMessage request) { @@ -36,38 +36,28 @@ public static bool AuthHeadersInvalid(this HttpRequestMessage request) public static TimeSpan? GetCustomTimeout(this HttpRequestMessage request) { - if (request.Properties.TryGetValue(CUSTOM_TIMEOUT_PROPERTY_NAME, out object timeout)) - { - return (TimeSpan)timeout; - } - - return null; + return request.Options.TryGetValue(CustomTimeoutOptionsKey, out TimeSpan timeout) ? timeout : null; } public static void SetCustomTimeout(this HttpRequestMessage request, TimeSpan timeout) { - if (!request.Properties.ContainsKey(CUSTOM_TIMEOUT_PROPERTY_NAME)) + if (!request.Options.TryGetValue(CustomTimeoutOptionsKey, out _)) { - request.Properties.Add(CUSTOM_TIMEOUT_PROPERTY_NAME, timeout); + request.Options.Set(CustomTimeoutOptionsKey, timeout); } } public static void SetRetryCount(this HttpRequestMessage request, int retryCount) { - if (!request.Properties.ContainsKey(RETRY_COUNT_PROPERTY_NAME)) + if (!request.Options.TryGetValue(RetryCountOptionsKey, out _)) { - request.Properties.Add(RETRY_COUNT_PROPERTY_NAME, retryCount); + request.Options.Set(RetryCountOptionsKey, retryCount); } } public static int? GetRetryCount(this HttpRequestMessage request) { - if (request.Properties.TryGetValue(RETRY_COUNT_PROPERTY_NAME, out object timeout)) - { - return (int)timeout; - } - - return null; + return request.Options.TryGetValue(RetryCountOptionsKey, out int timeout) ? timeout : null; } private static bool AuthHeaderSet(this HttpRequestMessage request) diff --git a/src/ProtonVPN.Common/ProtonVPN.Common.csproj b/src/ProtonVPN.Common/ProtonVPN.Common.csproj index 8f1440f76..c3cc4c34e 100644 --- a/src/ProtonVPN.Common/ProtonVPN.Common.csproj +++ b/src/ProtonVPN.Common/ProtonVPN.Common.csproj @@ -7,12 +7,6 @@ false true - - - - - - Properties\GlobalAssemblyInfo.cs diff --git a/src/ProtonVPN.Common/Vpn/VpnHost.cs b/src/ProtonVPN.Common/Vpn/VpnHost.cs index 41ca4aafa..18fe208c4 100644 --- a/src/ProtonVPN.Common/Vpn/VpnHost.cs +++ b/src/ProtonVPN.Common/Vpn/VpnHost.cs @@ -78,9 +78,15 @@ private static void AssertIpAddressIsValid(string ip) public override bool Equals(object o) { + if (o == null) + { + return false; + } + VpnHost vpnHost = (VpnHost)o; - return vpnHost != null && Ip == vpnHost.Ip && + return Ip == vpnHost.Ip && (Label == vpnHost.Label || (string.IsNullOrEmpty(Label) && string.IsNullOrEmpty(vpnHost.Label))); + } public override int GetHashCode() diff --git a/src/ProtonVPN.Crypto/X25519KeyGenerator.cs b/src/ProtonVPN.Crypto/X25519KeyGenerator.cs index 4b834230c..41eb851cf 100644 --- a/src/ProtonVPN.Crypto/X25519KeyGenerator.cs +++ b/src/ProtonVPN.Crypto/X25519KeyGenerator.cs @@ -31,7 +31,7 @@ public SecretKey FromEd25519SecretKey(SecretKey secretKey) byte[] secretKeyLast32Bytes = secretKey.Bytes.Skip(secretKey.Bytes.Length - 32).Take(32).ToArray(); byte[] x25519SecretKey; - using (SHA512 shaM = new SHA512Managed()) + using (SHA512 shaM = SHA512.Create()) { x25519SecretKey = shaM.ComputeHash(secretKeyLast32Bytes); } diff --git a/src/ProtonVPN.Translations/ProtonVPN.Translations.csproj b/src/ProtonVPN.Translations/ProtonVPN.Translations.csproj index 168cd7b6f..6582d4816 100644 --- a/src/ProtonVPN.Translations/ProtonVPN.Translations.csproj +++ b/src/ProtonVPN.Translations/ProtonVPN.Translations.csproj @@ -15,7 +15,8 @@ - + + all diff --git a/src/ProtonVPN.Translations/TranslationSource.cs b/src/ProtonVPN.Translations/TranslationSource.cs index 27758512d..3cce669d9 100644 --- a/src/ProtonVPN.Translations/TranslationSource.cs +++ b/src/ProtonVPN.Translations/TranslationSource.cs @@ -25,15 +25,16 @@ using System.Windows; using System.Windows.Data; using System.Windows.Markup; -using Huyn.PluralNet; +using ProtonVPN.Translations.Properties; +using ReswPlusLib; namespace ProtonVPN.Translations { public class TranslationSource : INotifyPropertyChanged { - public static TranslationSource Instance { get; } = new TranslationSource(); + public static TranslationSource Instance { get; } = new(); - public string this[string key] => Properties.Resources.ResourceManager.GetString(GetStringName(key), _currentCulture); + public string this[string key] => Resources.ResourceManager.GetString(GetStringName(key), _currentCulture); private CultureInfo _currentCulture = CultureInfo.CurrentUICulture; @@ -66,7 +67,7 @@ public string GetPlural(string key, decimal number) ResetPluralProvider(); } - return Properties.Resources.ResourceManager.GetPlural(GetStringName(key), number); + return Resources.ResourceManager.GetPlural(GetStringName(key), Convert.ToDouble(number)); } private void ResetPluralProvider() diff --git a/src/Update/ProtonVPN.Update/Files/Validatable/FileCheckSum.cs b/src/Update/ProtonVPN.Update/Files/Validatable/FileCheckSum.cs index eb1bf0f30..5a82a6a6c 100644 --- a/src/Update/ProtonVPN.Update/Files/Validatable/FileCheckSum.cs +++ b/src/Update/ProtonVPN.Update/Files/Validatable/FileCheckSum.cs @@ -38,8 +38,8 @@ public FileCheckSum(string filename) public async Task Value() { - using var stream = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read, Config.FILE_BUFFER_SIZE, true); - using var sha512 = new SHA512CryptoServiceProvider(); + using FileStream stream = new(_filename, FileMode.Open, FileAccess.Read, FileShare.Read, Config.FILE_BUFFER_SIZE, true); + using SHA512 sha512 = SHA512.Create(); byte[] buffer = new byte[Config.FILE_BUFFER_SIZE]; int bytesRead; @@ -50,7 +50,12 @@ public async Task Value() } sha512.TransformFinalBlock(buffer, 0, 0); - return BitConverter.ToString(sha512.Hash).Replace("-", "").ToLowerInvariant(); + if (sha512.Hash != null) + { + return BitConverter.ToString(sha512.Hash).Replace("-", "").ToLowerInvariant(); + } + + return string.Empty; } } } \ No newline at end of file