This commit is contained in:
Давид Чернопятов
2024-07-08 16:20:28 +03:00
parent 6a1b03163c
commit c8aa7ba8e7
5 changed files with 101 additions and 129 deletions
+37 -1
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using AchiesUtilities.Collections;
using AchiesUtilities.Web.Proxy;
@@ -69,6 +70,41 @@ public static class ProxyStorage
Save();
}
public static void SetProxies(IEnumerable<KeyValuePair<int?, ProxyData>> proxies)
{
foreach (var (key, proxyData) in proxies)
{
var id = key;
if (id == null)
{
if (Proxies.Count == 0)
{
id = 0;
}
else
{
id = Proxies.Keys.Max() + 1;
}
}
Proxies[id] = proxyData;
}
Save();
}
public static void OrderCollection() //RETHINK: maybe there is better way to handle it
{
var proxies = Proxies.OrderBy(p => p.Key)
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Proxies.Clear();
foreach (var kvp in proxies)
{
Proxies.Add(kvp.Key, kvp.Value);
}
}
public static void RemoveProxy(int id)
{
Proxies.Remove(id);
@@ -76,7 +112,7 @@ public static class ProxyStorage
}
public static bool CompareProxy(ProxyData proxyData1, ProxyData proxyData2)
{
return proxyData1.Address == proxyData2.Address && proxyData1.Port == proxyData2.Port;
return proxyData1.Equals(proxyData2);
}
-58
View File
@@ -1,58 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<LangVersion>latest</LangVersion>
<SatelliteResourceLanguages>ru</SatelliteResourceLanguages>
<ApplicationIcon>Theme\nebula lock.ico</ApplicationIcon>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<AssemblyVersion>1.4.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<None Remove="Theme\Background.jpg" />
<None Remove="Theme\nebula lock.ico" />
<None Remove="Theme\nebula.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
<PackageReference Include="MaterialDesignColors" Version="2.1.4" />
<PackageReference Include="MaterialDesignExtensions" Version="3.3.0" />
<PackageReference Include="MaterialDesignThemes" Version="4.9.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="NLog" Version="5.1.2" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
</ItemGroup>
<ItemGroup>
<Resource Include="Theme\Background.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Theme\nebula lock.ico" />
<Resource Include="Theme\nebula.ico" />
</ItemGroup>
<ItemGroup>
<Folder Include="Model\Utility\" />
<Folder Include="Model\Exceptions\" />
<Folder Include="Theme\Fonts\Новая папка\" />
<Folder Include="ViewModel\Other\" />
<Folder Include="Utility\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SteamLib\SteamLib\SteamLib.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
+2 -2
View File
@@ -76,7 +76,7 @@ public partial class MainVM
var selectedId = SelectedProxy.Id;
ProxyExist = ProxyStorage.Proxies.TryGetValue(selectedId, out var existedProxy)
&& ProxyStorage.CompareProxy(SelectedProxy.Data, existedProxy);
&& SelectedProxy.Data.Equals(existedProxy); //Id is not important in 'Equals()' as we extract it from the dictionary
}
[RelayCommand]
@@ -98,7 +98,7 @@ public partial class MainVM
[RelayCommand]
private void RemoveProxy()
{
if(SelectedProxy == null) return;
if (SelectedProxy == null) return;
if (SelectedMafile == null) return;
if (!ValidateCanSaveAndWarn(SelectedMafile)) return;
SelectedMafile.Proxy = null;
+28 -36
View File
@@ -21,7 +21,7 @@ public partial class ProxyManagerVM : ObservableObject
[ObservableProperty] private KeyValuePair<int, ProxyData>? _defaultProxy;
public ObservableDictionary<int, ProxyData> Proxies => ProxyStorage.Proxies;
private static readonly Regex IdRegex = new(@"(?:\{(\d+)\})");
private static readonly Regex IdRegex = new(@"\{(\d+)\}$");
public ProxyManagerVM()
@@ -33,27 +33,36 @@ public partial class ProxyManagerVM : ObservableObject
[RelayCommand]
private void AddProxy()
{
if (string.IsNullOrEmpty(AddProxyField)) return;
if (AddProxyField.Contains(Environment.NewLine))
{
var split = AddProxyField.Split(Environment.NewLine);
var idPresent = (bool?)null;
var input = AddProxyField;
if (string.IsNullOrEmpty(input)) return;
var split = input
.Split(Environment.NewLine)
.Where(s => string.IsNullOrWhiteSpace(s) == false)
.ToArray();
if (split.Length == 0) return;
bool? idPresent = null;
var proxies = new List<KeyValuePair<int?, ProxyData>>();
var i = 0;
foreach (var s in split.Where(s => string.IsNullOrWhiteSpace(s) == false))
{
i++;
var str = s;
int? id = null;
var match = IdRegex.Match(str);
if (match.Success)
var idMatch = IdRegex.Match(str);
if (idMatch.Success)
{
id = int.Parse(match.Groups[1].Value);
id = int.Parse(idMatch.Groups[1].Value);
str = IdRegex.Replace(str, "");
}
idPresent ??= match.Success;
if (idPresent.Value != match.Success)
idPresent ??= idMatch.Success;
if (idPresent.Value != idMatch.Success)
{
SnackbarController.SendSnackbar(GetLocalizationOrDefault("WrongFormatSomeIdsMissing"));
return;
@@ -72,40 +81,23 @@ public partial class ProxyManagerVM : ObservableObject
}
else
{
if (split.Length == 1)
{
SnackbarController.SendSnackbar(GetLocalizationOrDefault("WrongFormat"));
return;
}
SnackbarController.SendSnackbar(string.Format(GetLocalizationOrDefault("WrongFormatOnLine"), i));
return;
}
}
foreach (var kvp in proxies)
{
ProxyStorage.SetProxy(kvp.Key, kvp.Value);
}
}
else
{
int? id = null;
var input = AddProxyField;
if (IdRegex.IsMatch(AddProxyField))
{
id = int.Parse(IdRegex.Match(AddProxyField).Groups[1].Value);
input = IdRegex.Replace(input, "");
}
if (ProxyStorage.DefaultScheme.TryParse(input, out var data))
{
ProxyStorage.SetProxy(id, data);
}
else
{
SnackbarController.SendSnackbar(GetLocalizationOrDefault("WrongFormat"));
return;
}
}
ProxyStorage.SetProxies(proxies);
ProxyStorage.OrderCollection();
AddProxyField = string.Empty;
CheckIfDefaultProxyStay();
}
private void CheckIfDefaultProxyStay()
{
if (!DefaultProxy.HasValue || Proxies.Any(kvp => kvp.Equals(DefaultProxy.Value))) return;
+5 -3
View File
@@ -63,16 +63,18 @@
</head>
<body>
<div class="changelog-container">
<div class="changelog-container">
<!-- Changelog entry -->
<div class="change">
<div class="version">Version 1.5.1</div>
<div class="date">DATE</div>
<div class="description">
- FIX: Fixed proxy problem when {id} was parsed as a part of password when using 'ip:port:username:password{id}' proxy format
- FIX: Fixed proxy error (407) when {id} was parsed as a part of password when using 'ip:port:username:password{id}' proxy format <br />
- IMPROVEMENT: Now proxies always ordered by ID <br />
- FIX: Small fix in the proxy comparison method (sometimes proxy red indicator was not shown)
</div>
</div>
</div>
</div>
</body>
</html>