Skip to content

Commit

Permalink
Fix build time errors [VPNWIN-1391]
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindaugas Veblauskas committed Mar 31, 2023
1 parent 343de29 commit e04ae45
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 79 deletions.
3 changes: 2 additions & 1 deletion Setup/setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions src/ProtonVPN.App/Config/Url/ActiveUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
* along with ProtonVPN. If not, see <https://www.gnu.org/licenses/>.
*/

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
{
Expand All @@ -41,13 +42,13 @@ public ActiveUrl WithQueryParams(Dictionary<string, string> parameters)
try
{
UriBuilder uriBuilder = new UriBuilder(_url);
NameValueCollection query = HttpUtility.ParseQueryString(uriBuilder.Query);
Dictionary<string, StringValues> query = QueryHelpers.ParseQuery(uriBuilder.Query);
foreach (KeyValuePair<string, string> item in parameters)
{
query[item.Key] = item.Value;
}

uriBuilder.Query = query.ToString();
uriBuilder.Query = QueryString.Create(query).ToString();
_url = uriBuilder.ToString();
}
catch (UriFormatException)
Expand Down
2 changes: 1 addition & 1 deletion src/ProtonVPN.App/ProtonVPN.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Caliburn.Micro" Version="4.0.212" />
<PackageReference Include="OxyPlot.Wpf" Version="1.0.0" />
<PackageReference Include="OxyPlot.Wpf" Version="2.1.2" />
</ItemGroup>
<PropertyGroup />
<ItemGroup>
Expand Down
37 changes: 1 addition & 36 deletions src/ProtonVPN.App/Resources/Assets/Styles/OxyPlot.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,39 +93,4 @@ along with ProtonVPN. If not, see <https://www.gnu.org/licenses/>.
</Setter.Value>
</Setter>
</Style>

<Style TargetType="{x:Type oxy:Plot}">
<Setter Property="Background" Value="{StaticResource TextNormBrushColor}"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="DefaultTrackerTemplate">
<Setter.Value>
<ControlTemplate>
<oxy:TrackerControl Position="{Binding Position}" LineExtents="{Binding PlotModel.PlotArea}">
<oxy:TrackerControl.Content>
<TextBlock Text="{Binding}" Margin="7"/>
</oxy:TrackerControl.Content>
</oxy:TrackerControl>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ZoomRectangleTemplate">
<Setter.Value>
<ControlTemplate>
<Rectangle Fill="{StaticResource ZoomRectangleBackgroundColor}"
Stroke="{StaticResource ZoomRectangleStrokeColor}"
StrokeDashArray="3,1"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type oxy:Plot}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid x:Name="PART_Grid"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</ResourceDictionary>
26 changes: 8 additions & 18 deletions src/ProtonVPN.Common/OS/Net/Http/HttpRequestMessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeSpan> CustomTimeoutOptionsKey = new("CustomTimeout");
private static readonly HttpRequestOptionsKey<int> RetryCountOptionsKey = new("RetryCount");

public static bool AuthHeadersInvalid(this HttpRequestMessage request)
{
Expand All @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions src/ProtonVPN.Common/ProtonVPN.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Transactions" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
Expand Down
8 changes: 7 additions & 1 deletion src/ProtonVPN.Common/Vpn/VpnHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/ProtonVPN.Crypto/X25519KeyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/ProtonVPN.Translations/ProtonVPN.Translations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="PluralNet" Version="1.0.5" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.4" />
<PackageReference Include="ReswPlusLib" Version="2.0.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.355802">
<PrivateAssets>all</PrivateAssets>
Expand Down
9 changes: 5 additions & 4 deletions src/ProtonVPN.Translations/TranslationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand Down
11 changes: 8 additions & 3 deletions src/Update/ProtonVPN.Update/Files/Validatable/FileCheckSum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public FileCheckSum(string filename)

public async Task<string> 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;
Expand All @@ -50,7 +50,12 @@ public async Task<string> 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;
}
}
}

0 comments on commit e04ae45

Please sign in to comment.