Compare commits

..

No commits in common. "d1e6898290566d2b6b6c11410c47390f06407358" and "d0e2cc9442ce9556b4025ffea6ed9446d95a2ff4" have entirely different histories.

10 changed files with 24168 additions and 384 deletions

View file

@ -1,7 +1,7 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<Version>7.10.5</Version> <Version>7.10.4</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

View file

@ -9,8 +9,8 @@
<PackageVersion Include="Avalonia.Desktop" Version="11.2.5" /> <PackageVersion Include="Avalonia.Desktop" Version="11.2.5" />
<PackageVersion Include="Avalonia.Diagnostics" Version="11.2.5" /> <PackageVersion Include="Avalonia.Diagnostics" Version="11.2.5" />
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.2.5" /> <PackageVersion Include="Avalonia.ReactiveUI" Version="11.2.5" />
<PackageVersion Include="CliWrap" Version="3.8.2" /> <PackageVersion Include="CliWrap" Version="3.8.1" />
<PackageVersion Include="Downloader" Version="3.3.4" /> <PackageVersion Include="Downloader" Version="3.3.3" />
<PackageVersion Include="H.NotifyIcon.Wpf" Version="2.3.0" /> <PackageVersion Include="H.NotifyIcon.Wpf" Version="2.3.0" />
<PackageVersion Include="MaterialDesignThemes" Version="5.2.1" /> <PackageVersion Include="MaterialDesignThemes" Version="5.2.1" />
<PackageVersion Include="MessageBox.Avalonia" Version="3.2.0" /> <PackageVersion Include="MessageBox.Avalonia" Version="3.2.0" />
@ -22,7 +22,7 @@
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.5" /> <PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.5" />
<PackageVersion Include="Splat.NLog" Version="15.3.1" /> <PackageVersion Include="Splat.NLog" Version="15.3.1" />
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" /> <PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
<PackageVersion Include="TaskScheduler" Version="2.12.1" /> <PackageVersion Include="TaskScheduler" Version="2.12.0" />
<PackageVersion Include="WebDav.Client" Version="2.8.0" /> <PackageVersion Include="WebDav.Client" Version="2.8.0" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" /> <PackageVersion Include="YamlDotNet" Version="16.3.0" />
<PackageVersion Include="ZXing.Net.Bindings.SkiaSharp" Version="0.16.14" /> <PackageVersion Include="ZXing.Net.Bindings.SkiaSharp" Version="0.16.14" />

View file

@ -225,54 +225,15 @@ namespace ServiceLib.Common
public static string GetMd5(string str) public static string GetMd5(string str)
{ {
if (string.IsNullOrEmpty(str)) var byteOld = Encoding.UTF8.GetBytes(str);
var byteNew = MD5.HashData(byteOld);
StringBuilder sb = new(32);
foreach (var b in byteNew)
{ {
return string.Empty; sb.Append(b.ToString("x2"));
} }
try return sb.ToString();
{
var byteOld = Encoding.UTF8.GetBytes(str);
var byteNew = MD5.HashData(byteOld);
StringBuilder sb = new(32);
foreach (var b in byteNew)
{
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
catch (Exception ex)
{
Logging.SaveLog(_tag, ex);
return string.Empty;
}
}
public static string GetFileHash(string filePath)
{
if (string.IsNullOrEmpty(filePath))
{
return string.Empty;
}
if (!File.Exists(filePath))
{
return string.Empty;
}
try
{
using var md5 = MD5.Create();
using var stream = File.OpenRead(filePath);
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
catch (Exception ex)
{
Logging.SaveLog(_tag, ex);
return string.Empty;
}
} }
/// <summary> /// <summary>

View file

@ -871,19 +871,13 @@ namespace ServiceLib.Handler
public static async Task<Tuple<int, int>> DedupServerList(Config config, string subId) public static async Task<Tuple<int, int>> DedupServerList(Config config, string subId)
{ {
var lstProfile = await AppHandler.Instance.ProfileItems(subId); var lstProfile = await AppHandler.Instance.ProfileItems(subId);
if (lstProfile == null)
{
return new Tuple<int, int>(0, 0);
}
List<ProfileItem> lstKeep = new(); List<ProfileItem> lstKeep = new();
List<ProfileItem> lstRemove = new(); List<ProfileItem> lstRemove = new();
if (!config.GuiItem.KeepOlderDedupl) if (!config.GuiItem.KeepOlderDedupl)
{
lstProfile.Reverse(); lstProfile.Reverse();
}
foreach (var item in lstProfile) foreach (ProfileItem item in lstProfile)
{ {
if (!lstKeep.Exists(i => CompareProfileItem(i, item, false))) if (!lstKeep.Exists(i => CompareProfileItem(i, item, false)))
{ {
@ -950,35 +944,35 @@ namespace ServiceLib.Handler
return 0; return 0;
} }
private static bool CompareProfileItem(ProfileItem? o, ProfileItem? n, bool remarks) private static bool CompareProfileItem(ProfileItem o, ProfileItem n, bool remarks)
{ {
if (o == null || n == null) if (o == null || n == null)
{ {
return false; return false;
} }
return o.ConfigType == n.ConfigType
&& AreEqual(o.Address, n.Address)
&& o.Port == n.Port
&& AreEqual(o.Id, n.Id)
&& AreEqual(o.Security, n.Security)
&& AreEqual(o.Network, n.Network)
&& AreEqual(o.HeaderType, n.HeaderType)
&& AreEqual(o.RequestHost, n.RequestHost)
&& AreEqual(o.Path, n.Path)
&& (o.ConfigType == EConfigType.Trojan || o.StreamSecurity == n.StreamSecurity)
&& AreEqual(o.Flow, n.Flow)
&& AreEqual(o.Sni, n.Sni)
&& AreEqual(o.Alpn, n.Alpn)
&& AreEqual(o.Fingerprint, n.Fingerprint)
&& AreEqual(o.PublicKey, n.PublicKey)
&& AreEqual(o.ShortId, n.ShortId)
&& (!remarks || o.Remarks == n.Remarks);
static bool AreEqual(string? a, string? b) static bool AreEqual(string? a, string? b)
{ {
return string.Equals(a, b) || (string.IsNullOrEmpty(a) && string.IsNullOrEmpty(b)); return string.Equals(a, b) || (string.IsNullOrEmpty(a) && string.IsNullOrEmpty(b));
} }
return o.ConfigType == n.ConfigType
&& AreEqual(o.Address, n.Address)
&& o.Port == n.Port
&& AreEqual(o.Id, n.Id)
&& AreEqual(o.Security, n.Security)
&& AreEqual(o.Network, n.Network)
&& AreEqual(o.HeaderType, n.HeaderType)
&& AreEqual(o.RequestHost, n.RequestHost)
&& AreEqual(o.Path, n.Path)
&& (o.ConfigType == EConfigType.Trojan || o.StreamSecurity == n.StreamSecurity)
&& AreEqual(o.Flow, n.Flow)
&& AreEqual(o.Sni, n.Sni)
&& AreEqual(o.Alpn, n.Alpn)
&& AreEqual(o.Fingerprint, n.Fingerprint)
&& AreEqual(o.PublicKey, n.PublicKey)
&& AreEqual(o.ShortId, n.ShortId)
&& (!remarks || o.Remarks == n.Remarks);
} }
private static async Task<int> RemoveProfileItem(Config config, string indexId) private static async Task<int> RemoveProfileItem(Config config, string indexId)
@ -1016,7 +1010,8 @@ namespace ServiceLib.Handler
return result; return result;
} }
if (!File.Exists(configPath)) var fileName = configPath;
if (!File.Exists(fileName))
{ {
return result; return result;
} }

View file

@ -33,13 +33,6 @@ namespace ServiceLib.Handler
private static async Task InitText() private static async Task InitText()
{ {
var path = Path.Combine(_configPath, "pac.txt"); var path = Path.Combine(_configPath, "pac.txt");
// Delete the old pac file
if (File.Exists(path) && Utils.GetFileHash(path).Equals("b590c07280f058ef05d5394aa2f927fe"))
{
File.Delete(path);
}
if (!File.Exists(path)) if (!File.Exists(path))
{ {
var pac = EmbedUtils.GetEmbedText(Global.PacFileName); var pac = EmbedUtils.GetEmbedText(Global.PacFileName);

File diff suppressed because it is too large Load diff

View file

@ -80,19 +80,13 @@ set_kde_proxy() {
# Detect the current desktop environment # Detect the current desktop environment
detect_desktop_environment() { detect_desktop_environment() {
if [[ "$XDG_CURRENT_DESKTOP" == *"GNOME"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"GNOME"* ]]; then if [ "$XDG_CURRENT_DESKTOP" == "GNOME" ] || [ "$XDG_CURRENT_DESKTOP" == "ubuntu:GNOME" ] || [ "$XDG_SESSION_DESKTOP" == "GNOME" ] || [ "$XDG_SESSION_DESKTOP" == "ubuntu:GNOME" ]; then
echo "gnome" echo "gnome"
return elif [ "$XDG_CURRENT_DESKTOP" == "KDE" ] || [ "$XDG_CURRENT_DESKTOP" == "plasma" ] || [ "$XDG_SESSION_DESKTOP" == "KDE" ] || [ "$XDG_SESSION_DESKTOP" == "plasma" ]; then
echo "kde"
else
echo "unsupported"
fi fi
local KDE_ENVIRONMENTS=("KDE" "plasma")
for ENV in "${KDE_ENVIRONMENTS[@]}"; do
if [ "$XDG_CURRENT_DESKTOP" == "$ENV" ] || [ "$XDG_SESSION_DESKTOP" == "$ENV" ]; then
echo "kde"
return
fi
done
echo "unsupported"
} }
# Main script logic # Main script logic

View file

@ -53,7 +53,7 @@ namespace ServiceLib.ViewModels
private async Task Init() private async Task Init()
{ {
await DelayTestTask(); _ = DelayTestTask();
} }
private async Task GetClashConnections() private async Task GetClashConnections()

View file

@ -95,7 +95,7 @@ namespace ServiceLib.ViewModels
private async Task Init() private async Task Init()
{ {
await DelayTestTask(); _ = DelayTestTask();
} }
private async Task DoRuleModeSelected(bool c) private async Task DoRuleModeSelected(bool c)
@ -366,7 +366,7 @@ namespace ServiceLib.ViewModels
private async Task ProxiesDelayTest(bool blAll = true) private async Task ProxiesDelayTest(bool blAll = true)
{ {
ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), (item, result) => ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), async (item, result) =>
{ {
if (item == null || result.IsNullOrEmpty()) if (item == null || result.IsNullOrEmpty())
{ {

View file

@ -448,7 +448,7 @@ namespace ServiceLib.ViewModels
private async Task<List<ProfileItem>?> GetProfileItems(bool latest) private async Task<List<ProfileItem>?> GetProfileItems(bool latest)
{ {
var lstSelected = new List<ProfileItem>(); var lstSelecteds = new List<ProfileItem>();
if (SelectedProfiles == null || SelectedProfiles.Count <= 0) if (SelectedProfiles == null || SelectedProfiles.Count <= 0)
{ {
return null; return null;
@ -462,16 +462,16 @@ namespace ServiceLib.ViewModels
var item = await AppHandler.Instance.GetProfileItem(profile.IndexId); var item = await AppHandler.Instance.GetProfileItem(profile.IndexId);
if (item is not null) if (item is not null)
{ {
lstSelected.Add(item); lstSelecteds.Add(item);
} }
} }
} }
else else
{ {
lstSelected = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(orderProfiles)); lstSelecteds = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(orderProfiles));
} }
return lstSelected; return lstSelecteds;
} }
public async Task EditServerAsync(EConfigType eConfigType) public async Task EditServerAsync(EConfigType eConfigType)
@ -509,8 +509,8 @@ namespace ServiceLib.ViewModels
public async Task RemoveServerAsync() public async Task RemoveServerAsync()
{ {
var lstSelected = await GetProfileItems(true); var lstSelecteds = await GetProfileItems(true);
if (lstSelected == null) if (lstSelecteds == null)
{ {
return; return;
} }
@ -518,11 +518,11 @@ namespace ServiceLib.ViewModels
{ {
return; return;
} }
var exists = lstSelected.Exists(t => t.IndexId == _config.IndexId); var exists = lstSelecteds.Exists(t => t.IndexId == _config.IndexId);
await ConfigHandler.RemoveServers(_config, lstSelected); await ConfigHandler.RemoveServers(_config, lstSelecteds);
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
if (lstSelected.Count == _profileItems.Count) if (lstSelecteds.Count == _profileItems.Count)
{ {
_profileItems.Clear(); _profileItems.Clear();
} }
@ -536,22 +536,19 @@ namespace ServiceLib.ViewModels
private async Task RemoveDuplicateServer() private async Task RemoveDuplicateServer()
{ {
var tuple = await ConfigHandler.DedupServerList(_config, _config.SubIndexId); var tuple = await ConfigHandler.DedupServerList(_config, _config.SubIndexId);
if (tuple.Item1 > 0 || tuple.Item2 > 0) RefreshServers();
{ Reload();
RefreshServers();
Reload();
}
NoticeHandler.Instance.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2)); NoticeHandler.Instance.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2));
} }
private async Task CopyServer() private async Task CopyServer()
{ {
var lstSelected = await GetProfileItems(false); var lstSelecteds = await GetProfileItems(false);
if (lstSelected == null) if (lstSelecteds == null)
{ {
return; return;
} }
if (await ConfigHandler.CopyServer(_config, lstSelected) == 0) if (await ConfigHandler.CopyServer(_config, lstSelecteds) == 0)
{ {
RefreshServers(); RefreshServers();
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
@ -567,7 +564,7 @@ namespace ServiceLib.ViewModels
await SetDefaultServer(SelectedProfile.IndexId); await SetDefaultServer(SelectedProfile.IndexId);
} }
public async Task SetDefaultServer(string? indexId) public async Task SetDefaultServer(string indexId)
{ {
if (indexId.IsNullOrEmpty()) if (indexId.IsNullOrEmpty())
{ {
@ -597,7 +594,11 @@ namespace ServiceLib.ViewModels
{ {
return; return;
} }
if (SelectedServer == null || SelectedServer.ID.IsNullOrEmpty()) if (SelectedServer == null)
{
return;
}
if (SelectedServer.ID.IsNullOrEmpty())
{ {
return; return;
} }
@ -623,13 +624,13 @@ namespace ServiceLib.ViewModels
private async Task SetDefaultMultipleServer(ECoreType coreType) private async Task SetDefaultMultipleServer(ECoreType coreType)
{ {
var lstSelected = await GetProfileItems(true); var lstSelecteds = await GetProfileItems(true);
if (lstSelected == null) if (lstSelecteds == null)
{ {
return; return;
} }
var ret = await ConfigHandler.AddCustomServer4Multiple(_config, lstSelected, coreType); var ret = await ConfigHandler.AddCustomServer4Multiple(_config, lstSelecteds, coreType);
if (ret.Success != true) if (ret.Success != true)
{ {
NoticeHandler.Instance.Enqueue(ResUI.OperationFailed); NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
@ -678,18 +679,19 @@ namespace ServiceLib.ViewModels
return; return;
} }
var lstSelected = await GetProfileItems(true); var lstSelecteds = await GetProfileItems(true);
if (lstSelected == null) if (lstSelecteds == null)
{ {
return; return;
} }
await ConfigHandler.MoveToGroup(_config, lstSelected, SelectedMoveToGroup.Id); await ConfigHandler.MoveToGroup(_config, lstSelecteds, SelectedMoveToGroup.Id);
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
RefreshServers(); RefreshServers();
SelectedMoveToGroup = null; SelectedMoveToGroup = null;
SelectedMoveToGroup = new(); SelectedMoveToGroup = new();
//Reload();
} }
public async Task MoveServer(EMove eMove) public async Task MoveServer(EMove eMove)
@ -701,7 +703,7 @@ namespace ServiceLib.ViewModels
return; return;
} }
var index = _lstProfile.IndexOf(item); int index = _lstProfile.IndexOf(item);
if (index < 0) if (index < 0)
{ {
return; return;
@ -730,14 +732,14 @@ namespace ServiceLib.ViewModels
{ {
SelectedProfiles = _profileItems; SelectedProfiles = _profileItems;
} }
var lstSelected = await GetProfileItems(false); var lstSelecteds = await GetProfileItems(false);
if (lstSelected == null) if (lstSelecteds == null)
{ {
return; return;
} }
_speedtestService ??= new SpeedtestService(_config, (SpeedTestResult result) => _updateView?.Invoke(EViewAction.DispatcherSpeedTest, result)); _speedtestService ??= new SpeedtestService(_config, (SpeedTestResult result) => _updateView?.Invoke(EViewAction.DispatcherSpeedTest, result));
_speedtestService?.RunLoop(actionType, lstSelected); _speedtestService?.RunLoop(actionType, lstSelecteds);
} }
public void ServerSpeedtestStop() public void ServerSpeedtestStop()
@ -791,14 +793,14 @@ namespace ServiceLib.ViewModels
public async Task Export2ShareUrlAsync(bool blEncode) public async Task Export2ShareUrlAsync(bool blEncode)
{ {
var lstSelected = await GetProfileItems(true); var lstSelecteds = await GetProfileItems(true);
if (lstSelected == null) if (lstSelecteds == null)
{ {
return; return;
} }
StringBuilder sb = new(); StringBuilder sb = new();
foreach (var it in lstSelected) foreach (var it in lstSelecteds)
{ {
var url = FmtHandler.GetShareUri(it); var url = FmtHandler.GetShareUri(it);
if (url.IsNullOrEmpty()) if (url.IsNullOrEmpty())