Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24ccfb8077 | ||
|
|
204451db6c | ||
|
|
f553bbc41e | ||
|
|
8cb4f2f961 | ||
|
|
4d3db56065 | ||
|
|
d92540121f | ||
|
|
17d586ea26 | ||
|
|
9a096d31fc | ||
|
|
bf83dbdfea | ||
|
|
e31cd0e199 | ||
|
|
1e11477e27 | ||
|
|
e0750df96c | ||
|
|
e3580b05f7 | ||
|
|
6ad0762731 | ||
|
|
70b05d7812 | ||
|
|
5403fc9e21 | ||
|
|
5bffca9584 | ||
|
|
2060539c34 | ||
|
|
de3cdb4f7e | ||
|
|
2a4ba2a751 | ||
|
|
48747aabe0 | ||
|
|
7182be921d | ||
|
|
9d7dcd2c4f | ||
|
|
c3e56e84f1 | ||
|
|
f1ef5a1f51 | ||
|
|
d1e6898290 | ||
|
|
8597332b21 | ||
|
|
7cc42ae249 | ||
|
|
e054d4487d | ||
|
|
6ef36f521d | ||
|
|
a02a122dd1 | ||
|
|
701138617c | ||
|
|
d0e2cc9442 | ||
|
|
d561f10edc | ||
|
|
2df412476a | ||
|
|
e6011cfede | ||
|
|
bcf43e2928 | ||
|
|
3f0f895424 | ||
|
|
07a3bdc618 | ||
|
|
7e348c196e | ||
|
|
51e5885e76 | ||
|
|
50d7912f62 | ||
|
|
3869148fc8 | ||
|
|
a0af4fb30c | ||
|
|
c374b8565b | ||
|
|
7e8b405555 | ||
|
|
c3439c5abe | ||
|
|
d4a8787356 | ||
|
|
23b27575a0 | ||
|
|
8d8a887c42 | ||
|
|
1229c967ba | ||
|
|
d35f65f86d | ||
|
|
0a8ce0f961 | ||
|
|
8092481d26 | ||
|
|
764014e49a | ||
|
|
71cc6d7a88 | ||
|
|
f3af831cf2 |
4
.github/workflows/build-linux.yml
vendored
4
.github/workflows/build-linux.yml
vendored
@@ -32,7 +32,7 @@ jobs:
|
||||
fetch-depth: '0'
|
||||
|
||||
- name: Setup
|
||||
uses: actions/setup-dotnet@v4.3.0
|
||||
uses: actions/setup-dotnet@v4.3.1
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
@@ -45,7 +45,7 @@ jobs:
|
||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r linux-arm64 --self-contained=true -p:PublishTrimmed=true -o $OutputPathArm64
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4.6.1
|
||||
uses: actions/upload-artifact@v4.6.2
|
||||
with:
|
||||
name: v2rayN-linux
|
||||
path: |
|
||||
|
||||
4
.github/workflows/build-osx.yml
vendored
4
.github/workflows/build-osx.yml
vendored
@@ -32,7 +32,7 @@ jobs:
|
||||
fetch-depth: '0'
|
||||
|
||||
- name: Setup
|
||||
uses: actions/setup-dotnet@v4.3.0
|
||||
uses: actions/setup-dotnet@v4.3.1
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
@@ -45,7 +45,7 @@ jobs:
|
||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r osx-arm64 --self-contained=true -p:PublishTrimmed=true -o $OutputPathArm64
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4.6.1
|
||||
uses: actions/upload-artifact@v4.6.2
|
||||
with:
|
||||
name: v2rayN-macos
|
||||
path: |
|
||||
|
||||
4
.github/workflows/build-windows-desktop.yml
vendored
4
.github/workflows/build-windows-desktop.yml
vendored
@@ -32,7 +32,7 @@ jobs:
|
||||
fetch-depth: '0'
|
||||
|
||||
- name: Setup
|
||||
uses: actions/setup-dotnet@v4.3.0
|
||||
uses: actions/setup-dotnet@v4.3.1
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
@@ -45,7 +45,7 @@ jobs:
|
||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-arm64 --self-contained=true -p:EnableWindowsTargeting=true -p:PublishTrimmed=true -o $OutputPathArm64
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4.6.1
|
||||
uses: actions/upload-artifact@v4.6.2
|
||||
with:
|
||||
name: v2rayN-windows-desktop
|
||||
path: |
|
||||
|
||||
4
.github/workflows/build-windows.yml
vendored
4
.github/workflows/build-windows.yml
vendored
@@ -30,7 +30,7 @@ jobs:
|
||||
uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Setup
|
||||
uses: actions/setup-dotnet@v4.3.0
|
||||
uses: actions/setup-dotnet@v4.3.1
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4.6.1
|
||||
uses: actions/upload-artifact@v4.6.2
|
||||
with:
|
||||
name: v2rayN-windows
|
||||
path: |
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace AmazTool
|
||||
{
|
||||
namespace AmazTool;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
@@ -23,4 +23,3 @@ namespace AmazTool
|
||||
UpgradeApp.Upgrade(argData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
156
v2rayN/AmazTool/Resx/Resource.zh-Hant.resx
Normal file
156
v2rayN/AmazTool/Resx/Resource.zh-Hant.resx
Normal file
@@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Restartv2rayN" xml:space="preserve">
|
||||
<value>正在重啟,請等待...</value>
|
||||
</data>
|
||||
<data name="Guidelines" xml:space="preserve">
|
||||
<value>請從主應用程式運行。</value>
|
||||
</data>
|
||||
<data name="UpgradeFileNotFound" xml:space="preserve">
|
||||
<value>升級失敗,檔案不存在。</value>
|
||||
</data>
|
||||
<data name="InProgress" xml:space="preserve">
|
||||
<value>正在進行中,請等待...</value>
|
||||
</data>
|
||||
<data name="TryTerminateProcess" xml:space="preserve">
|
||||
<value>嘗試結束 v2rayN 進程...</value>
|
||||
</data>
|
||||
<data name="FailedTerminateProcess" xml:space="preserve">
|
||||
<value>請手動關閉正在執行的 v2rayN,否則可能會升級失敗。</value>
|
||||
</data>
|
||||
<data name="StartUnzipping" xml:space="preserve">
|
||||
<value>開始解壓縮更新包...</value>
|
||||
</data>
|
||||
<data name="SuccessUnzipping" xml:space="preserve">
|
||||
<value>解壓縮更新包成功。</value>
|
||||
</data>
|
||||
<data name="FailedUnzipping" xml:space="preserve">
|
||||
<value>解壓縮更新包失敗。</value>
|
||||
</data>
|
||||
<data name="FailedUpgrade" xml:space="preserve">
|
||||
<value>升級失敗。</value>
|
||||
</data>
|
||||
<data name="SuccessUpgrade" xml:space="preserve">
|
||||
<value>升級成功。</value>
|
||||
</data>
|
||||
<data name="Information" xml:space="preserve">
|
||||
<value>提示</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -2,8 +2,8 @@ using System.Diagnostics;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
|
||||
namespace AmazTool
|
||||
{
|
||||
namespace AmazTool;
|
||||
|
||||
internal class UpgradeApp
|
||||
{
|
||||
public static void Upgrade(string fileName)
|
||||
@@ -114,4 +114,3 @@ namespace AmazTool
|
||||
Utils.StartV2RayN();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace AmazTool
|
||||
{
|
||||
namespace AmazTool;
|
||||
|
||||
internal class Utils
|
||||
{
|
||||
public static string GetExePath()
|
||||
@@ -49,4 +49,3 @@ namespace AmazTool
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>7.10.3</Version>
|
||||
<Version>7.11.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
|
||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||
<NoWarn>CA1031;CS1591;NU1507;CA1416</NoWarn>
|
||||
<NoWarn>CA1031;CS1591;NU1507;CA1416;IDE0058</NoWarn>
|
||||
<Nullable>annotations</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Authors>2dust</Authors>
|
||||
|
||||
@@ -5,25 +5,25 @@
|
||||
<CentralPackageVersionOverrideEnabled>false</CentralPackageVersionOverrideEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.2.5" />
|
||||
<PackageVersion Include="Avalonia.Desktop" Version="11.2.5" />
|
||||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.2.5" />
|
||||
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.2.5" />
|
||||
<PackageVersion Include="CliWrap" Version="3.8.1" />
|
||||
<PackageVersion Include="Downloader" Version="3.3.3" />
|
||||
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.2.6" />
|
||||
<PackageVersion Include="Avalonia.Desktop" Version="11.2.6" />
|
||||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.2.6" />
|
||||
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.2.6" />
|
||||
<PackageVersion Include="CliWrap" Version="3.8.2" />
|
||||
<PackageVersion Include="Downloader" Version="3.3.4" />
|
||||
<PackageVersion Include="H.NotifyIcon.Wpf" Version="2.3.0" />
|
||||
<PackageVersion Include="MaterialDesignThemes" Version="5.2.1" />
|
||||
<PackageVersion Include="MessageBox.Avalonia" Version="3.2.0" />
|
||||
<PackageVersion Include="QRCoder" Version="1.6.0" />
|
||||
<PackageVersion Include="ReactiveUI" Version="20.1.63" />
|
||||
<PackageVersion Include="ReactiveUI" Version="20.2.45" />
|
||||
<PackageVersion Include="ReactiveUI.Fody" Version="19.5.41" />
|
||||
<PackageVersion Include="ReactiveUI.WPF" Version="20.1.63" />
|
||||
<PackageVersion Include="Semi.Avalonia" Version="11.2.1.5" />
|
||||
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.5" />
|
||||
<PackageVersion Include="ReactiveUI.WPF" Version="20.2.45" />
|
||||
<PackageVersion Include="Semi.Avalonia" Version="11.2.1.6" />
|
||||
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.6" />
|
||||
<PackageVersion Include="Splat.NLog" Version="15.3.1" />
|
||||
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
<PackageVersion Include="TaskScheduler" Version="2.12.0" />
|
||||
<PackageVersion Include="WebDav.Client" Version="2.8.0" />
|
||||
<PackageVersion Include="TaskScheduler" Version="2.12.1" />
|
||||
<PackageVersion Include="WebDav.Client" Version="2.9.0" />
|
||||
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
|
||||
<PackageVersion Include="ZXing.Net.Bindings.SkiaSharp" Version="0.16.14" />
|
||||
</ItemGroup>
|
||||
|
||||
Submodule v2rayN/GlobalHotKeys updated: b3b635ef46...ef73fa22c4
@@ -1,10 +1,9 @@
|
||||
using ReactiveUI;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace ServiceLib.Base;
|
||||
|
||||
namespace ServiceLib.Base
|
||||
{
|
||||
public class MyReactiveObject : ReactiveObject
|
||||
{
|
||||
protected static Config? _config;
|
||||
protected Func<EViewAction, object?, Task<bool>>? _updateView;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class AesUtils
|
||||
{
|
||||
private const int KeySize = 256; // AES-256
|
||||
@@ -98,4 +98,3 @@ namespace ServiceLib.Common
|
||||
return randomNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class DesUtils
|
||||
{
|
||||
/// <summary>
|
||||
@@ -72,4 +72,3 @@ namespace ServiceLib.Common
|
||||
return Utils.GetMd5(Utils.GetHomePath() + "DesUtils");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Net;
|
||||
using Downloader;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class DownloaderHelper
|
||||
{
|
||||
private static readonly Lazy<DownloaderHelper> _instance = new(() => new());
|
||||
@@ -10,7 +10,7 @@ namespace ServiceLib.Common
|
||||
|
||||
public async Task<string?> DownloadStringAsync(IWebProxy? webProxy, string url, string? userAgent, int timeout)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace ServiceLib.Common
|
||||
Uri uri = new(url);
|
||||
//Authorization Header
|
||||
var headers = new WebHeaderCollection();
|
||||
if (Utils.IsNotEmpty(uri.UserInfo))
|
||||
if (uri.UserInfo.IsNotEmpty())
|
||||
{
|
||||
headers.Add(HttpRequestHeader.Authorization, "Basic " + Utils.Base64Encode(uri.UserInfo));
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace ServiceLib.Common
|
||||
|
||||
public async Task DownloadDataAsync4Speed(IWebProxy webProxy, string url, IProgress<string> progress, int timeout)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
@@ -86,7 +86,7 @@ namespace ServiceLib.Common
|
||||
//};
|
||||
downloader.DownloadProgressChanged += (sender, value) =>
|
||||
{
|
||||
var ts = (DateTime.Now - totalDatetime);
|
||||
var ts = DateTime.Now - totalDatetime;
|
||||
if (progress != null && ts.Seconds > totalSecond)
|
||||
{
|
||||
hasValue = true;
|
||||
@@ -119,11 +119,11 @@ namespace ServiceLib.Common
|
||||
|
||||
public async Task DownloadFileAsync(IWebProxy? webProxy, string url, string fileName, IProgress<double> progress, int timeout)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
if (fileName.IsNullOrEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileName));
|
||||
}
|
||||
@@ -146,10 +146,7 @@ namespace ServiceLib.Common
|
||||
var progressPercentage = 0;
|
||||
var hasValue = false;
|
||||
await using var downloader = new Downloader.DownloadService(downloadOpt);
|
||||
downloader.DownloadStarted += (sender, value) =>
|
||||
{
|
||||
progress?.Report(0);
|
||||
};
|
||||
downloader.DownloadStarted += (sender, value) => progress?.Report(0);
|
||||
downloader.DownloadProgressChanged += (sender, value) =>
|
||||
{
|
||||
hasValue = true;
|
||||
@@ -181,4 +178,3 @@ namespace ServiceLib.Common
|
||||
downloadOpt = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Formats.Tar;
|
||||
using System.Formats.Tar;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public static class FileManager
|
||||
{
|
||||
private static readonly string _tag = "FileManager";
|
||||
@@ -99,7 +99,7 @@ namespace ServiceLib.Common
|
||||
}
|
||||
try
|
||||
{
|
||||
if (Utils.IsNotEmpty(ignoredName) && entry.Name.Contains(ignoredName))
|
||||
if (ignoredName.IsNotEmpty() && entry.Name.Contains(ignoredName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -163,18 +163,20 @@ namespace ServiceLib.Common
|
||||
|
||||
// Check if the source directory exists
|
||||
if (!dir.Exists)
|
||||
{
|
||||
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
|
||||
}
|
||||
|
||||
// Cache directories before we start copying
|
||||
var dirs = dir.GetDirectories();
|
||||
|
||||
// Create the destination directory
|
||||
Directory.CreateDirectory(destinationDir);
|
||||
_ = Directory.CreateDirectory(destinationDir);
|
||||
|
||||
// Get the files in the source directory and copy to the destination directory
|
||||
foreach (var file in dir.GetFiles())
|
||||
{
|
||||
if (Utils.IsNotEmpty(ignoredName) && file.Name.Contains(ignoredName))
|
||||
if (ignoredName.IsNotEmpty() && file.Name.Contains(ignoredName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -187,7 +189,7 @@ namespace ServiceLib.Common
|
||||
{
|
||||
continue;
|
||||
}
|
||||
file.CopyTo(targetFilePath, overwrite);
|
||||
_ = file.CopyTo(targetFilePath, overwrite);
|
||||
}
|
||||
|
||||
// If recursive and copying subdirectories, recursively call this method
|
||||
@@ -222,4 +224,3 @@ namespace ServiceLib.Common
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@ using System.Net.Http.Headers;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class HttpClientHelper
|
||||
@@ -18,12 +18,17 @@ namespace ServiceLib.Common
|
||||
public static HttpClientHelper Instance => _instance.Value;
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
private HttpClientHelper(HttpClient httpClient) => this.httpClient = httpClient;
|
||||
private HttpClientHelper(HttpClient httpClient)
|
||||
{
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async Task<string?> TryGetAsync(string url)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@@ -38,15 +43,19 @@ namespace ServiceLib.Common
|
||||
|
||||
public async Task<string?> GetAsync(string url)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return await httpClient.GetStringAsync(url);
|
||||
}
|
||||
|
||||
public async Task<string?> GetAsync(HttpClient client, string url, CancellationToken token = default)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return await client.GetStringAsync(url, token);
|
||||
}
|
||||
|
||||
@@ -55,13 +64,13 @@ namespace ServiceLib.Common
|
||||
var jsonContent = JsonUtils.Serialize(headers);
|
||||
var content = new StringContent(jsonContent, Encoding.UTF8, MediaTypeNames.Application.Json);
|
||||
|
||||
var result = await httpClient.PutAsync(url, content);
|
||||
await httpClient.PutAsync(url, content);
|
||||
}
|
||||
|
||||
public async Task PatchAsync(string url, Dictionary<string, string> headers)
|
||||
{
|
||||
var myContent = JsonUtils.Serialize(headers);
|
||||
var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);
|
||||
var buffer = Encoding.UTF8.GetBytes(myContent);
|
||||
var byteContent = new ByteArrayContent(buffer);
|
||||
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
|
||||
@@ -78,12 +87,16 @@ namespace ServiceLib.Common
|
||||
ArgumentNullException.ThrowIfNull(url);
|
||||
ArgumentNullException.ThrowIfNull(fileName);
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
File.Delete(fileName);
|
||||
}
|
||||
|
||||
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(response.StatusCode.ToString());
|
||||
}
|
||||
|
||||
var total = response.Content.Headers.ContentLength ?? -1L;
|
||||
var canReportProgress = total != -1 && progress != null;
|
||||
@@ -102,7 +115,9 @@ namespace ServiceLib.Common
|
||||
totalRead += read;
|
||||
|
||||
if (read == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
await file.WriteAsync(buffer.AsMemory(0, read), token);
|
||||
|
||||
if (canReportProgress)
|
||||
@@ -123,7 +138,7 @@ namespace ServiceLib.Common
|
||||
|
||||
public async Task DownloadDataAsync4Speed(HttpClient client, string url, IProgress<string> progress, CancellationToken token = default)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
@@ -173,7 +188,7 @@ namespace ServiceLib.Common
|
||||
|
||||
totalRead += read;
|
||||
|
||||
var ts = (DateTime.Now - totalDatetime);
|
||||
var ts = DateTime.Now - totalDatetime;
|
||||
if (progress != null && ts.Seconds > totalSecond)
|
||||
{
|
||||
totalSecond = ts.Seconds;
|
||||
@@ -188,4 +203,3 @@ namespace ServiceLib.Common
|
||||
} while (isMoreToRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
/*
|
||||
* See:
|
||||
* http://stackoverflow.com/questions/6266820/working-example-of-createjobobject-setinformationjobobject-pinvoke-in-net
|
||||
@@ -15,28 +14,30 @@ namespace ServiceLib.Common
|
||||
public Job()
|
||||
{
|
||||
handle = CreateJobObject(IntPtr.Zero, null);
|
||||
IntPtr extendedInfoPtr = IntPtr.Zero;
|
||||
JOBOBJECT_BASIC_LIMIT_INFORMATION info = new()
|
||||
var extendedInfoPtr = IntPtr.Zero;
|
||||
var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION
|
||||
{
|
||||
LimitFlags = 0x2000
|
||||
};
|
||||
|
||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedInfo = new()
|
||||
var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION
|
||||
{
|
||||
BasicLimitInformation = info
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
|
||||
var length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
|
||||
extendedInfoPtr = Marshal.AllocHGlobal(length);
|
||||
Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);
|
||||
|
||||
if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr,
|
||||
(uint)length))
|
||||
{
|
||||
throw new Exception(string.Format("Unable to set information. Error: {0}",
|
||||
Marshal.GetLastWin32Error()));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (extendedInfoPtr != IntPtr.Zero)
|
||||
@@ -48,7 +49,7 @@ namespace ServiceLib.Common
|
||||
|
||||
public bool AddProcess(IntPtr processHandle)
|
||||
{
|
||||
bool succ = AssignProcessToJobObject(handle, processHandle);
|
||||
var succ = AssignProcessToJobObject(handle, processHandle);
|
||||
|
||||
if (!succ)
|
||||
{
|
||||
@@ -76,7 +77,9 @@ namespace ServiceLib.Common
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
disposed = true;
|
||||
|
||||
if (disposing)
|
||||
@@ -104,7 +107,7 @@ namespace ServiceLib.Common
|
||||
private static extern IntPtr CreateJobObject(IntPtr a, string? lpName);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength);
|
||||
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
|
||||
@@ -121,34 +124,34 @@ namespace ServiceLib.Common
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct IO_COUNTERS
|
||||
{
|
||||
public UInt64 ReadOperationCount;
|
||||
public UInt64 WriteOperationCount;
|
||||
public UInt64 OtherOperationCount;
|
||||
public UInt64 ReadTransferCount;
|
||||
public UInt64 WriteTransferCount;
|
||||
public UInt64 OtherTransferCount;
|
||||
public ulong ReadOperationCount;
|
||||
public ulong WriteOperationCount;
|
||||
public ulong OtherOperationCount;
|
||||
public ulong ReadTransferCount;
|
||||
public ulong WriteTransferCount;
|
||||
public ulong OtherTransferCount;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct JOBOBJECT_BASIC_LIMIT_INFORMATION
|
||||
{
|
||||
public Int64 PerProcessUserTimeLimit;
|
||||
public Int64 PerJobUserTimeLimit;
|
||||
public UInt32 LimitFlags;
|
||||
public long PerProcessUserTimeLimit;
|
||||
public long PerJobUserTimeLimit;
|
||||
public uint LimitFlags;
|
||||
public UIntPtr MinimumWorkingSetSize;
|
||||
public UIntPtr MaximumWorkingSetSize;
|
||||
public UInt32 ActiveProcessLimit;
|
||||
public uint ActiveProcessLimit;
|
||||
public UIntPtr Affinity;
|
||||
public UInt32 PriorityClass;
|
||||
public UInt32 SchedulingClass;
|
||||
public uint PriorityClass;
|
||||
public uint SchedulingClass;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct SECURITY_ATTRIBUTES
|
||||
{
|
||||
public UInt32 nLength;
|
||||
public uint nLength;
|
||||
public IntPtr lpSecurityDescriptor;
|
||||
public Int32 bInheritHandle;
|
||||
public int bInheritHandle;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -174,4 +177,4 @@ namespace ServiceLib.Common
|
||||
}
|
||||
|
||||
#endregion Helper classes
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class JsonUtils
|
||||
{
|
||||
private static readonly string _tag = "JsonUtils";
|
||||
@@ -128,4 +128,3 @@ namespace ServiceLib.Common
|
||||
/// <returns></returns>
|
||||
public static JsonNode? SerializeToNode(object? obj) => JsonSerializer.SerializeToNode(obj);
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,13 @@ using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class Logging
|
||||
{
|
||||
private static readonly Logger _logger1 = LogManager.GetLogger("Log1");
|
||||
private static readonly Logger _logger2 = LogManager.GetLogger("Log2");
|
||||
|
||||
public static void Setup()
|
||||
{
|
||||
LoggingConfiguration config = new();
|
||||
@@ -28,23 +31,25 @@ namespace ServiceLib.Common
|
||||
public static void SaveLog(string strContent)
|
||||
{
|
||||
if (!LogManager.IsLoggingEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LogManager.GetLogger("Log1").Info(strContent);
|
||||
_logger1.Info(strContent);
|
||||
}
|
||||
|
||||
public static void SaveLog(string strTitle, Exception ex)
|
||||
{
|
||||
if (!LogManager.IsLoggingEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var logger = LogManager.GetLogger("Log2");
|
||||
logger.Debug($"{strTitle},{ex.Message}");
|
||||
logger.Debug(ex.StackTrace);
|
||||
_logger2.Debug($"{strTitle},{ex.Message}");
|
||||
_logger2.Debug(ex.StackTrace);
|
||||
if (ex?.InnerException != null)
|
||||
{
|
||||
logger.Error(ex.InnerException);
|
||||
}
|
||||
_logger2.Error(ex.InnerException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public static class ProcUtils
|
||||
|
||||
public static void ProcessStart(string? fileName, string arguments = "")
|
||||
{
|
||||
ProcessStart(fileName, arguments, null);
|
||||
_ = ProcessStart(fileName, arguments, null);
|
||||
}
|
||||
|
||||
public static int? ProcessStart(string? fileName, string arguments, string? dir)
|
||||
@@ -38,7 +38,7 @@ public static class ProcUtils
|
||||
WorkingDirectory = dir ?? string.Empty
|
||||
}
|
||||
};
|
||||
proc.Start();
|
||||
_ = proc.Start();
|
||||
return dir is null ? null : proc.Id;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -60,7 +60,7 @@ public static class ProcUtils
|
||||
FileName = Utils.GetExePath().AppendQuotes(),
|
||||
Verb = blAdmin ? "runas" : null,
|
||||
};
|
||||
Process.Start(startInfo);
|
||||
_ = Process.Start(startInfo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -138,7 +138,9 @@ public static class ProcUtils
|
||||
fileName = null;
|
||||
processName = null;
|
||||
if (!review)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
procId = proc?.Id;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using QRCoder;
|
||||
using QRCoder;
|
||||
using SkiaSharp;
|
||||
using ZXing.SkiaSharp;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class QRCodeHelper
|
||||
{
|
||||
public static byte[]? GenQRCode(string? url)
|
||||
@@ -60,7 +60,7 @@ namespace ServiceLib.Common
|
||||
var reader = new BarcodeReader();
|
||||
var result = reader.Decode(bitmap);
|
||||
|
||||
if (result != null && Utils.IsNotEmpty(result.Text))
|
||||
if (result != null && result.Text.IsNotEmpty())
|
||||
{
|
||||
return result.Text;
|
||||
}
|
||||
@@ -87,4 +87,3 @@ namespace ServiceLib.Common
|
||||
return flipped;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class SemanticVersion
|
||||
{
|
||||
private int major;
|
||||
private int minor;
|
||||
private int patch;
|
||||
private string version;
|
||||
private readonly int major;
|
||||
private readonly int minor;
|
||||
private readonly int patch;
|
||||
private readonly string version;
|
||||
|
||||
public SemanticVersion(int major, int minor, int patch)
|
||||
{
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.version = $"{major}.{minor}.{patch}";
|
||||
version = $"{major}.{minor}.{patch}";
|
||||
}
|
||||
|
||||
public SemanticVersion(string? version)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (version.IsNullOrEmpty())
|
||||
if (string.IsNullOrEmpty(version))
|
||||
{
|
||||
this.major = 0;
|
||||
this.minor = 0;
|
||||
this.patch = 0;
|
||||
major = 0;
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
return;
|
||||
}
|
||||
this.version = version.RemovePrefix('v');
|
||||
@@ -31,15 +31,15 @@
|
||||
var parts = this.version.Split('.');
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
this.major = int.Parse(parts.First());
|
||||
this.minor = int.Parse(parts.Last());
|
||||
this.patch = 0;
|
||||
major = int.Parse(parts.First());
|
||||
minor = int.Parse(parts.Last());
|
||||
patch = 0;
|
||||
}
|
||||
else if (parts.Length is 3 or 4)
|
||||
{
|
||||
this.major = int.Parse(parts[0]);
|
||||
this.minor = int.Parse(parts[1]);
|
||||
this.patch = int.Parse(parts[2]);
|
||||
major = int.Parse(parts[0]);
|
||||
minor = int.Parse(parts[1]);
|
||||
patch = int.Parse(parts[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -48,9 +48,9 @@
|
||||
}
|
||||
catch
|
||||
{
|
||||
this.major = 0;
|
||||
this.minor = 0;
|
||||
this.patch = 0;
|
||||
major = 0;
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
{
|
||||
if (obj is SemanticVersion other)
|
||||
{
|
||||
return this.major == other.major && this.minor == other.minor && this.patch == other.patch;
|
||||
return major == other.major && minor == other.minor && patch == other.patch;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.major.GetHashCode() ^ this.minor.GetHashCode() ^ this.patch.GetHashCode();
|
||||
return major.GetHashCode() ^ minor.GetHashCode() ^ patch.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,18 +77,18 @@
|
||||
/// <returns>major.minor.patch</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return this.version;
|
||||
return version;
|
||||
}
|
||||
|
||||
public string ToVersionString(string? prefix = null)
|
||||
{
|
||||
if (prefix == null)
|
||||
{
|
||||
return this.version;
|
||||
return version;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"{prefix}{this.version}";
|
||||
return $"{prefix}{version}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,31 +108,31 @@
|
||||
|
||||
private bool GreaterEquals(SemanticVersion other)
|
||||
{
|
||||
if (this.major < other.major)
|
||||
if (major < other.major)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (this.major > other.major)
|
||||
else if (major > other.major)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.minor < other.minor)
|
||||
if (minor < other.minor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (this.minor > other.minor)
|
||||
else if (minor > other.minor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.patch < other.patch)
|
||||
if (patch < other.patch)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (this.patch > other.patch)
|
||||
else if (patch > other.patch)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -146,31 +146,31 @@
|
||||
|
||||
private bool LessEquals(SemanticVersion other)
|
||||
{
|
||||
if (this.major < other.major)
|
||||
if (major < other.major)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (this.major > other.major)
|
||||
else if (major > other.major)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.minor < other.minor)
|
||||
if (minor < other.minor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (this.minor > other.minor)
|
||||
else if (minor > other.minor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.patch < other.patch)
|
||||
if (patch < other.patch)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (this.patch > other.patch)
|
||||
else if (patch > other.patch)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -184,4 +184,3 @@
|
||||
|
||||
#endregion Private
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using System.Collections;
|
||||
using SQLite;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public sealed class SQLiteHelper
|
||||
{
|
||||
private static readonly Lazy<SQLiteHelper> _instance = new(() => new());
|
||||
public static SQLiteHelper Instance => _instance.Value;
|
||||
private string _connstr;
|
||||
private readonly string _connstr;
|
||||
private SQLiteConnection _db;
|
||||
private SQLiteAsyncConnection _dbAsync;
|
||||
private readonly string _configDB = "guiNDB.db";
|
||||
@@ -88,4 +88,3 @@ namespace ServiceLib.Common
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public static class StringEx
|
||||
{
|
||||
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? value)
|
||||
{
|
||||
return string.IsNullOrEmpty(value);
|
||||
return string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value);
|
||||
}
|
||||
|
||||
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value)
|
||||
@@ -22,7 +22,9 @@ namespace ServiceLib.Common
|
||||
public static bool BeginWithAny(this string s, IEnumerable<char> chars)
|
||||
{
|
||||
if (s.IsNullOrEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return chars.Contains(s.First());
|
||||
}
|
||||
|
||||
@@ -36,7 +38,9 @@ namespace ServiceLib.Common
|
||||
while (reader.ReadLine() is { } line)
|
||||
{
|
||||
if (line.IsWhiteSpace())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
yield return line;
|
||||
}
|
||||
}
|
||||
@@ -70,5 +74,9 @@ namespace ServiceLib.Common
|
||||
{
|
||||
return string.IsNullOrEmpty(value) ? string.Empty : $"\"{value}\"";
|
||||
}
|
||||
|
||||
public static int ToInt(this string? value, int defaultValue = 0)
|
||||
{
|
||||
return int.TryParse(value, out var result) ? result : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ using System.Text;
|
||||
using CliWrap;
|
||||
using CliWrap.Buffered;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class Utils
|
||||
{
|
||||
private static readonly string _tag = "Utils";
|
||||
@@ -20,85 +20,69 @@ namespace ServiceLib.Common
|
||||
#region 转换函数
|
||||
|
||||
/// <summary>
|
||||
/// 转逗号分隔的字符串
|
||||
/// Convert to comma-separated string
|
||||
/// </summary>
|
||||
/// <param name="lst"></param>
|
||||
/// <param name="wrap"></param>
|
||||
/// <returns></returns>
|
||||
public static string List2String(List<string>? lst, bool wrap = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (lst == null)
|
||||
if (lst == null || lst.Count == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
if (wrap)
|
||||
|
||||
var separator = wrap ? "," + Environment.NewLine : ",";
|
||||
|
||||
try
|
||||
{
|
||||
return string.Join("," + Environment.NewLine, lst);
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Join(",", lst);
|
||||
}
|
||||
return string.Join(separator, lst);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 逗号分隔的字符串
|
||||
/// Comma-separated string
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string>? String2List(string? str)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (str == null)
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
str = str.Replace(Environment.NewLine, "");
|
||||
try
|
||||
{
|
||||
str = str.Replace(Environment.NewLine, string.Empty);
|
||||
return new List<string>(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 逗号分隔的字符串,先排序后转List
|
||||
/// Comma-separated string, sorted and then converted to List
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string>? String2ListSorted(string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
str = str.Replace(Environment.NewLine, "");
|
||||
List<string> list = new(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||||
list.Sort();
|
||||
return list;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
var lst = String2List(str);
|
||||
lst?.Sort();
|
||||
return lst;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64编码
|
||||
/// Base64 Encode
|
||||
/// </summary>
|
||||
/// <param name="plainText"></param>
|
||||
/// <returns></returns>
|
||||
@@ -118,7 +102,7 @@ namespace ServiceLib.Common
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64解码
|
||||
/// Base64 Decode
|
||||
/// </summary>
|
||||
/// <param name="plainText"></param>
|
||||
/// <returns></returns>
|
||||
@@ -127,7 +111,10 @@ namespace ServiceLib.Common
|
||||
try
|
||||
{
|
||||
if (plainText.IsNullOrEmpty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
plainText = plainText.Trim()
|
||||
.Replace(Environment.NewLine, "")
|
||||
.Replace("\n", "")
|
||||
@@ -152,18 +139,6 @@ namespace ServiceLib.Common
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static int ToInt(object? obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Convert.ToInt32(obj ?? string.Empty);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ToBool(object obj)
|
||||
{
|
||||
try
|
||||
@@ -188,55 +163,25 @@ namespace ServiceLib.Common
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToHumanReadable(long amount, out double result, out string unit)
|
||||
{
|
||||
var factor = 1024u;
|
||||
//long KBs = amount / factor;
|
||||
var KBs = amount;
|
||||
if (KBs > 0)
|
||||
{
|
||||
// multi KB
|
||||
var MBs = KBs / factor;
|
||||
if (MBs > 0)
|
||||
{
|
||||
// multi MB
|
||||
var GBs = MBs / factor;
|
||||
if (GBs > 0)
|
||||
{
|
||||
// multi GB
|
||||
var TBs = GBs / factor;
|
||||
if (TBs > 0)
|
||||
{
|
||||
result = TBs + ((GBs % factor) / (factor + 0.0));
|
||||
unit = "TB";
|
||||
return;
|
||||
}
|
||||
|
||||
result = GBs + ((MBs % factor) / (factor + 0.0));
|
||||
unit = "GB";
|
||||
return;
|
||||
}
|
||||
|
||||
result = MBs + ((KBs % factor) / (factor + 0.0));
|
||||
unit = "MB";
|
||||
return;
|
||||
}
|
||||
|
||||
result = KBs + ((amount % factor) / (factor + 0.0));
|
||||
unit = "KB";
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = amount;
|
||||
unit = "B";
|
||||
}
|
||||
}
|
||||
|
||||
public static string HumanFy(long amount)
|
||||
{
|
||||
ToHumanReadable(amount, out var result, out var unit);
|
||||
return $"{result:f1} {unit}";
|
||||
if (amount <= 0)
|
||||
{
|
||||
return $"{amount:f1} B";
|
||||
}
|
||||
|
||||
string[] units = ["KB", "MB", "GB", "TB", "PB"];
|
||||
var unitIndex = 0;
|
||||
double size = amount;
|
||||
|
||||
// Loop and divide by 1024 until a suitable unit is found
|
||||
while (size >= 1024 && unitIndex < units.Length - 1)
|
||||
{
|
||||
size /= 1024;
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
return $"{size:f1} {units[unitIndex]}";
|
||||
}
|
||||
|
||||
public static string UrlEncode(string url)
|
||||
@@ -252,7 +197,7 @@ namespace ServiceLib.Common
|
||||
public static NameValueCollection ParseQueryString(string query)
|
||||
{
|
||||
var result = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
|
||||
if (IsNullOrEmpty(query))
|
||||
if (query.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
@@ -279,6 +224,13 @@ namespace ServiceLib.Common
|
||||
}
|
||||
|
||||
public static string GetMd5(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var byteOld = Encoding.UTF8.GetBytes(str);
|
||||
var byteNew = MD5.HashData(byteOld);
|
||||
@@ -290,6 +242,38 @@ namespace ServiceLib.Common
|
||||
|
||||
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>
|
||||
/// idn to idc
|
||||
@@ -298,7 +282,7 @@ namespace ServiceLib.Common
|
||||
/// <returns></returns>
|
||||
public static string GetPunycode(string url)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
return url;
|
||||
}
|
||||
@@ -331,7 +315,7 @@ namespace ServiceLib.Common
|
||||
|
||||
public static string Convert2Comma(string text)
|
||||
{
|
||||
if (IsNullOrEmpty(text))
|
||||
if (text.IsNullOrEmpty())
|
||||
{
|
||||
return text;
|
||||
}
|
||||
@@ -344,7 +328,7 @@ namespace ServiceLib.Common
|
||||
#region 数据检查
|
||||
|
||||
/// <summary>
|
||||
/// 判断输入的是否是数字
|
||||
/// Determine if the input is a number
|
||||
/// </summary>
|
||||
/// <param name="oText"></param>
|
||||
/// <returns></returns>
|
||||
@@ -353,28 +337,13 @@ namespace ServiceLib.Common
|
||||
return oText.All(char.IsNumber);
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty(string? text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return text == "null";
|
||||
}
|
||||
|
||||
public static bool IsNotEmpty(string? text)
|
||||
{
|
||||
return !string.IsNullOrEmpty(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证Domain地址是否合法
|
||||
/// Validate if the domain address is valid
|
||||
/// </summary>
|
||||
/// <param name="domain"></param>
|
||||
public static bool IsDomain(string? domain)
|
||||
{
|
||||
if (IsNullOrEmpty(domain))
|
||||
if (domain.IsNullOrEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -491,7 +460,7 @@ namespace ServiceLib.Common
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得版本
|
||||
/// Get version
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetVersion(bool blFull = true)
|
||||
@@ -529,7 +498,7 @@ namespace ServiceLib.Common
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得GUID
|
||||
/// GUID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetGuid(bool full = true)
|
||||
@@ -634,13 +603,20 @@ namespace ServiceLib.Common
|
||||
{
|
||||
try
|
||||
{
|
||||
var basePath = GetBaseDirectory();
|
||||
//When this file exists, it is equivalent to having no permission to read and write
|
||||
if (File.Exists(Path.Combine(GetBaseDirectory(), "NotStoreConfigHere.txt")))
|
||||
if (File.Exists(Path.Combine(basePath, "NotStoreConfigHere.txt")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var tempPath = Path.Combine(GetBaseDirectory(), "guiTemps");
|
||||
//Check if it is installed by Windows WinGet
|
||||
if (IsWindows() && basePath.Contains("Users") && basePath.Contains("WinGet"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var tempPath = Path.Combine(basePath, "guiTemps");
|
||||
if (!Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(tempPath);
|
||||
@@ -660,7 +636,7 @@ namespace ServiceLib.Common
|
||||
public static string GetPath(string fileName)
|
||||
{
|
||||
var startupPath = StartupPath();
|
||||
if (IsNullOrEmpty(fileName))
|
||||
if (fileName.IsNullOrEmpty())
|
||||
{
|
||||
return startupPath;
|
||||
}
|
||||
@@ -696,7 +672,7 @@ namespace ServiceLib.Common
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (IsNullOrEmpty(filename))
|
||||
if (filename.IsNullOrEmpty())
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
@@ -725,7 +701,7 @@ namespace ServiceLib.Common
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (Utils.IsNullOrEmpty(filename))
|
||||
if (filename.IsNullOrEmpty())
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
@@ -752,7 +728,7 @@ namespace ServiceLib.Common
|
||||
}
|
||||
}
|
||||
|
||||
if (IsNullOrEmpty(filename))
|
||||
if (filename.IsNullOrEmpty())
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
@@ -770,7 +746,7 @@ namespace ServiceLib.Common
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (Utils.IsNullOrEmpty(filename))
|
||||
if (filename.IsNullOrEmpty())
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
@@ -788,7 +764,7 @@ namespace ServiceLib.Common
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (Utils.IsNullOrEmpty(filename))
|
||||
if (filename.IsNullOrEmpty())
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
@@ -806,7 +782,7 @@ namespace ServiceLib.Common
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (Utils.IsNullOrEmpty(filename))
|
||||
if (filename.IsNullOrEmpty())
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
@@ -887,4 +863,3 @@ namespace ServiceLib.Common
|
||||
|
||||
#endregion Platform
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
internal static class WindowsUtils
|
||||
{
|
||||
private static readonly string _tag = "WindowsUtils";
|
||||
@@ -15,7 +15,7 @@ namespace ServiceLib.Common
|
||||
{
|
||||
regKey = Registry.CurrentUser.OpenSubKey(path, false);
|
||||
var value = regKey?.GetValue(name) as string;
|
||||
return Utils.IsNullOrEmpty(value) ? def : value;
|
||||
return value.IsNullOrEmpty() ? def : value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -34,7 +34,7 @@ namespace ServiceLib.Common
|
||||
try
|
||||
{
|
||||
regKey = Registry.CurrentUser.CreateSubKey(path);
|
||||
if (Utils.IsNullOrEmpty(value.ToString()))
|
||||
if (value.ToString().IsNullOrEmpty())
|
||||
{
|
||||
regKey?.DeleteValue(name, false);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace ServiceLib.Common
|
||||
var arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" """;
|
||||
|
||||
// Try to remove the device
|
||||
await Utils.GetCliWrapOutput(pnpUtilPath, arg);
|
||||
_ = await Utils.GetCliWrapOutput(pnpUtilPath, arg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -71,4 +71,3 @@ namespace ServiceLib.Common
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class YamlUtils
|
||||
{
|
||||
private static readonly string _tag = "YamlUtils";
|
||||
@@ -62,9 +62,6 @@ namespace ServiceLib.Common
|
||||
|
||||
public static string? PreprocessYaml(string str)
|
||||
{
|
||||
var deserializer = new DeserializerBuilder()
|
||||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
||||
.Build();
|
||||
try
|
||||
{
|
||||
var mergingParser = new MergingParser(new Parser(new StringReader(str)));
|
||||
@@ -80,4 +77,3 @@ namespace ServiceLib.Common
|
||||
|
||||
#endregion YAML
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EConfigType
|
||||
{
|
||||
VMess = 1,
|
||||
@@ -13,4 +13,3 @@
|
||||
WireGuard = 9,
|
||||
HTTP = 10
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum ECoreType
|
||||
{
|
||||
v2fly = 1,
|
||||
@@ -16,4 +16,3 @@ namespace ServiceLib.Enums
|
||||
overtls = 28,
|
||||
v2rayN = 99
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EGirdOrientation
|
||||
{
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Tab,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EGlobalHotkey
|
||||
{
|
||||
ShowForm = 0,
|
||||
@@ -8,4 +8,3 @@
|
||||
SystemProxyUnchanged = 3,
|
||||
SystemProxyPac = 4,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EInboundProtocol
|
||||
{
|
||||
socks = 0,
|
||||
@@ -11,4 +11,3 @@
|
||||
mixed,
|
||||
speedtest = 21
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EMove
|
||||
{
|
||||
Top = 1,
|
||||
@@ -8,4 +8,3 @@
|
||||
Bottom = 4,
|
||||
Position = 5
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EMsgCommand
|
||||
{
|
||||
ClearMsg,
|
||||
@@ -8,4 +8,3 @@ namespace ServiceLib.Enums
|
||||
RefreshProfiles,
|
||||
AppExit
|
||||
}
|
||||
}
|
||||
|
||||
9
v2rayN/ServiceLib/Enums/EMultipleLoad.cs
Normal file
9
v2rayN/ServiceLib/Enums/EMultipleLoad.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EMultipleLoad
|
||||
{
|
||||
Random,
|
||||
RoundRobin,
|
||||
LeastPing,
|
||||
LeastLoad
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EPresetType
|
||||
{
|
||||
Default = 0,
|
||||
Russia = 1,
|
||||
Iran = 2,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum ERuleMode
|
||||
{
|
||||
Rule = 0,
|
||||
@@ -7,4 +7,3 @@
|
||||
Direct = 2,
|
||||
Unchanged = 3
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EServerColName
|
||||
{
|
||||
Def = 0,
|
||||
@@ -18,4 +18,3 @@
|
||||
TotalDown,
|
||||
TotalUp
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum ESpeedActionType
|
||||
{
|
||||
Tcping,
|
||||
@@ -7,4 +7,3 @@
|
||||
Speedtest,
|
||||
Mixedtest
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum ESysProxyType
|
||||
{
|
||||
ForcedClear = 0,
|
||||
@@ -7,4 +7,3 @@
|
||||
Unchanged = 2,
|
||||
Pac = 3
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum ETheme
|
||||
{
|
||||
FollowSystem,
|
||||
@@ -10,4 +10,3 @@
|
||||
Dusk,
|
||||
NightSky
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum ETransport
|
||||
{
|
||||
tcp,
|
||||
@@ -12,4 +12,3 @@
|
||||
quic,
|
||||
grpc
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Enums
|
||||
{
|
||||
namespace ServiceLib.Enums;
|
||||
|
||||
public enum EViewAction
|
||||
{
|
||||
CloseWindow,
|
||||
@@ -43,4 +43,3 @@
|
||||
DispatcherCheckUpdateFinished,
|
||||
DispatcherShowMsg,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib
|
||||
{
|
||||
namespace ServiceLib;
|
||||
|
||||
public class Global
|
||||
{
|
||||
#region const
|
||||
@@ -72,6 +72,7 @@ namespace ServiceLib
|
||||
public const string LocalAppData = "V2RAYN_LOCAL_APPLICATION_DATA_V2";
|
||||
public const string V2RayLocalAsset = "V2RAY_LOCATION_ASSET";
|
||||
public const string XrayLocalAsset = "XRAY_LOCATION_ASSET";
|
||||
public const string XrayLocalCert = "XRAY_LOCATION_CERT";
|
||||
public const int SpeedTestPageSize = 1000;
|
||||
public const string LinuxBash = "/bin/bash";
|
||||
|
||||
@@ -520,4 +521,3 @@ namespace ServiceLib
|
||||
|
||||
#endregion const
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public sealed class AppHandler
|
||||
{
|
||||
#region Property
|
||||
@@ -80,6 +80,10 @@ namespace ServiceLib.Handler
|
||||
Logging.SaveLog($"v2rayN start up | {Utils.GetRuntimeInfo()}");
|
||||
Logging.LoggingEnabled(_config.GuiItem.EnableLog);
|
||||
|
||||
//First determine the port value
|
||||
_ = StatePort;
|
||||
_ = StatePort2;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -131,7 +135,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public async Task<List<ProfileItem>?> ProfileItems(string subid)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(subid))
|
||||
if (subid.IsNullOrEmpty())
|
||||
{
|
||||
return await SQLiteHelper.Instance.TableAsync<ProfileItem>().ToListAsync();
|
||||
}
|
||||
@@ -153,11 +157,11 @@ namespace ServiceLib.Handler
|
||||
from ProfileItem a
|
||||
left join SubItem b on a.subid = b.id
|
||||
where 1=1 ";
|
||||
if (Utils.IsNotEmpty(subid))
|
||||
if (subid.IsNotEmpty())
|
||||
{
|
||||
sql += $" and a.subid = '{subid}'";
|
||||
}
|
||||
if (Utils.IsNotEmpty(filter))
|
||||
if (filter.IsNotEmpty())
|
||||
{
|
||||
if (filter.Contains('\''))
|
||||
{
|
||||
@@ -171,7 +175,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public async Task<ProfileItem?> GetProfileItem(string indexId)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(indexId))
|
||||
if (indexId.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -180,7 +184,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public async Task<ProfileItem?> GetProfileItemViaRemarks(string? remarks)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(remarks))
|
||||
if (remarks.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -241,4 +245,3 @@ namespace ServiceLib.Handler
|
||||
|
||||
#endregion Core Type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Security.Principal;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public static class AutoStartupHandler
|
||||
{
|
||||
private static readonly string _tag = "AutoStartupHandler";
|
||||
@@ -85,7 +85,7 @@ namespace ServiceLib.Handler
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public static void AutoStartTaskService(string taskName, string fileName, string description)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(taskName))
|
||||
if (taskName.IsNullOrEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ namespace ServiceLib.Handler
|
||||
var logonUser = WindowsIdentity.GetCurrent().Name;
|
||||
using var taskService = new Microsoft.Win32.TaskScheduler.TaskService();
|
||||
var tasks = taskService.RootFolder.GetTasks(new Regex(taskName));
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
if (fileName.IsNullOrEmpty())
|
||||
{
|
||||
foreach (var t in tasks)
|
||||
{
|
||||
@@ -239,4 +239,3 @@ namespace ServiceLib.Handler
|
||||
|
||||
#endregion macOS
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using static ServiceLib.Models.ClashProxies;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public sealed class ClashApiHandler
|
||||
{
|
||||
private static readonly Lazy<ClashApiHandler> instance = new(() => new());
|
||||
@@ -11,9 +11,9 @@ namespace ServiceLib.Handler
|
||||
private Dictionary<string, ProxiesItem>? _proxies;
|
||||
public Dictionary<string, object> ProfileContent { get; set; }
|
||||
|
||||
public async Task<Tuple<ClashProxies, ClashProviders>?> GetClashProxiesAsync(Config config)
|
||||
public async Task<Tuple<ClashProxies, ClashProviders>?> GetClashProxiesAsync()
|
||||
{
|
||||
for (var i = 0; i < 5; i++)
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
var url = $"{GetApiUrl()}/proxies";
|
||||
var result = await HttpClientHelper.Instance.TryGetAsync(url);
|
||||
@@ -37,38 +37,30 @@ namespace ServiceLib.Handler
|
||||
|
||||
public void ClashProxiesDelayTest(bool blAll, List<ClashProxyModel> lstProxy, Action<ClashProxyModel?, string> updateFunc)
|
||||
{
|
||||
Task.Run(() =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (blAll)
|
||||
{
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
if (_proxies != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Task.Delay(5000).Wait();
|
||||
}
|
||||
if (_proxies == null)
|
||||
{
|
||||
return;
|
||||
await GetClashProxiesAsync();
|
||||
}
|
||||
lstProxy = new List<ClashProxyModel>();
|
||||
foreach (var kv in _proxies)
|
||||
foreach (var kv in _proxies ?? [])
|
||||
{
|
||||
if (Global.notAllowTestType.Contains(kv.Value.type.ToLower()))
|
||||
if (Global.notAllowTestType.Contains(kv.Value.type?.ToLower()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
lstProxy.Add(new ClashProxyModel()
|
||||
{
|
||||
Name = kv.Value.name,
|
||||
Type = kv.Value.type.ToLower(),
|
||||
Type = kv.Value.type?.ToLower(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (lstProxy == null)
|
||||
if (lstProxy is not { Count: > 0 })
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -90,9 +82,8 @@ namespace ServiceLib.Handler
|
||||
updateFunc?.Invoke(it, result);
|
||||
}));
|
||||
}
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
|
||||
Task.Delay(1000).Wait();
|
||||
await Task.WhenAll(tasks);
|
||||
await Task.Delay(1000);
|
||||
updateFunc?.Invoke(null, "");
|
||||
});
|
||||
}
|
||||
@@ -158,7 +149,7 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ClashConnections?> GetClashConnectionsAsync(Config config)
|
||||
public async Task<ClashConnections?> GetClashConnectionsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -194,4 +185,3 @@ namespace ServiceLib.Handler
|
||||
return $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort2}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Data;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
/// <summary>
|
||||
/// 本软件配置文件处理类
|
||||
/// </summary>
|
||||
@@ -22,7 +22,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
Config? config = null;
|
||||
var result = EmbedUtils.LoadResource(Utils.GetConfigPath(_configRes));
|
||||
if (Utils.IsNotEmpty(result))
|
||||
if (result.IsNotEmpty())
|
||||
{
|
||||
config = JsonUtils.Deserialize<Config>(result);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
config.RoutingBasicItem ??= new();
|
||||
if (Utils.IsNullOrEmpty(config.RoutingBasicItem.DomainStrategy))
|
||||
if (config.RoutingBasicItem.DomainStrategy.IsNullOrEmpty())
|
||||
{
|
||||
config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies.First();
|
||||
}
|
||||
@@ -103,7 +103,7 @@ namespace ServiceLib.Handler
|
||||
};
|
||||
config.UiItem.MainColumnItem ??= new();
|
||||
|
||||
if (Utils.IsNullOrEmpty(config.UiItem.CurrentLanguage))
|
||||
if (config.UiItem.CurrentLanguage.IsNullOrEmpty())
|
||||
{
|
||||
config.UiItem.CurrentLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Equals("zh", StringComparison.CurrentCultureIgnoreCase)
|
||||
? Global.Languages.First()
|
||||
@@ -117,11 +117,11 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
config.SpeedTestItem.SpeedTestTimeout = 10;
|
||||
}
|
||||
if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedTestUrl))
|
||||
if (config.SpeedTestItem.SpeedTestUrl.IsNullOrEmpty())
|
||||
{
|
||||
config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls.First();
|
||||
}
|
||||
if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedPingTestUrl))
|
||||
if (config.SpeedTestItem.SpeedPingTestUrl.IsNullOrEmpty())
|
||||
{
|
||||
config.SpeedTestItem.SpeedPingTestUrl = Global.SpeedPingTestUrl;
|
||||
}
|
||||
@@ -354,7 +354,7 @@ namespace ServiceLib.Handler
|
||||
/// <returns></returns>
|
||||
public static async Task<int> SetDefaultServerIndex(Config config, string? indexId)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(indexId))
|
||||
if (indexId.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -506,7 +506,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
profileItem.Address = newFileName;
|
||||
profileItem.ConfigType = EConfigType.Custom;
|
||||
if (Utils.IsNullOrEmpty(profileItem.Remarks))
|
||||
if (profileItem.Remarks.IsNullOrEmpty())
|
||||
{
|
||||
profileItem.Remarks = $"import custom@{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}";
|
||||
}
|
||||
@@ -624,7 +624,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
profileItem.Address = profileItem.Address.TrimEx();
|
||||
profileItem.Id = profileItem.Id.TrimEx();
|
||||
if (Utils.IsNullOrEmpty(profileItem.StreamSecurity))
|
||||
if (profileItem.StreamSecurity.IsNullOrEmpty())
|
||||
{
|
||||
profileItem.StreamSecurity = Global.StreamSecurity;
|
||||
}
|
||||
@@ -654,7 +654,7 @@ namespace ServiceLib.Handler
|
||||
profileItem.Path = profileItem.Path.TrimEx();
|
||||
profileItem.Network = string.Empty;
|
||||
|
||||
if (Utils.IsNullOrEmpty(profileItem.StreamSecurity))
|
||||
if (profileItem.StreamSecurity.IsNullOrEmpty())
|
||||
{
|
||||
profileItem.StreamSecurity = Global.StreamSecurity;
|
||||
}
|
||||
@@ -689,11 +689,11 @@ namespace ServiceLib.Handler
|
||||
profileItem.HeaderType = Global.TuicCongestionControls.FirstOrDefault()!;
|
||||
}
|
||||
|
||||
if (Utils.IsNullOrEmpty(profileItem.StreamSecurity))
|
||||
if (profileItem.StreamSecurity.IsNullOrEmpty())
|
||||
{
|
||||
profileItem.StreamSecurity = Global.StreamSecurity;
|
||||
}
|
||||
if (Utils.IsNullOrEmpty(profileItem.Alpn))
|
||||
if (profileItem.Alpn.IsNullOrEmpty())
|
||||
{
|
||||
profileItem.Alpn = "h3";
|
||||
}
|
||||
@@ -858,7 +858,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (Utils.IsNotEmpty(profileItem.Security) && profileItem.Security != Global.None)
|
||||
if (profileItem.Security.IsNotEmpty() && profileItem.Security != Global.None)
|
||||
{
|
||||
profileItem.Security = Global.None;
|
||||
}
|
||||
@@ -871,13 +871,19 @@ namespace ServiceLib.Handler
|
||||
public static async Task<Tuple<int, int>> DedupServerList(Config config, string subId)
|
||||
{
|
||||
var lstProfile = await AppHandler.Instance.ProfileItems(subId);
|
||||
if (lstProfile == null)
|
||||
{
|
||||
return new Tuple<int, int>(0, 0);
|
||||
}
|
||||
|
||||
List<ProfileItem> lstKeep = new();
|
||||
List<ProfileItem> lstRemove = new();
|
||||
if (!config.GuiItem.KeepOlderDedupl)
|
||||
{
|
||||
lstProfile.Reverse();
|
||||
}
|
||||
|
||||
foreach (ProfileItem item in lstProfile)
|
||||
foreach (var item in lstProfile)
|
||||
{
|
||||
if (!lstKeep.Exists(i => CompareProfileItem(i, item, false)))
|
||||
{
|
||||
@@ -897,7 +903,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
profileItem.ConfigVersion = 2;
|
||||
|
||||
if (Utils.IsNotEmpty(profileItem.StreamSecurity))
|
||||
if (profileItem.StreamSecurity.IsNotEmpty())
|
||||
{
|
||||
if (profileItem.StreamSecurity != Global.StreamSecurity
|
||||
&& profileItem.StreamSecurity != Global.StreamSecurityReality)
|
||||
@@ -906,24 +912,24 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(profileItem.AllowInsecure))
|
||||
if (profileItem.AllowInsecure.IsNullOrEmpty())
|
||||
{
|
||||
profileItem.AllowInsecure = config.CoreBasicItem.DefAllowInsecure.ToString().ToLower();
|
||||
}
|
||||
if (Utils.IsNullOrEmpty(profileItem.Fingerprint) && profileItem.StreamSecurity == Global.StreamSecurityReality)
|
||||
if (profileItem.Fingerprint.IsNullOrEmpty() && profileItem.StreamSecurity == Global.StreamSecurityReality)
|
||||
{
|
||||
profileItem.Fingerprint = config.CoreBasicItem.DefFingerprint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Utils.IsNotEmpty(profileItem.Network) && !Global.Networks.Contains(profileItem.Network))
|
||||
if (profileItem.Network.IsNotEmpty() && !Global.Networks.Contains(profileItem.Network))
|
||||
{
|
||||
profileItem.Network = Global.DefaultNetwork;
|
||||
}
|
||||
|
||||
var maxSort = -1;
|
||||
if (Utils.IsNullOrEmpty(profileItem.IndexId))
|
||||
if (profileItem.IndexId.IsNullOrEmpty())
|
||||
{
|
||||
profileItem.IndexId = Utils.GetGuid(false);
|
||||
maxSort = ProfileExHandler.Instance.GetMaxSort();
|
||||
@@ -944,7 +950,7 @@ namespace ServiceLib.Handler
|
||||
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)
|
||||
{
|
||||
@@ -952,22 +958,27 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
return o.ConfigType == n.ConfigType
|
||||
&& o.Address == n.Address
|
||||
&& AreEqual(o.Address, n.Address)
|
||||
&& o.Port == n.Port
|
||||
&& o.Id == n.Id
|
||||
&& o.Security == n.Security
|
||||
&& o.Network == n.Network
|
||||
&& o.HeaderType == n.HeaderType
|
||||
&& o.RequestHost == n.RequestHost
|
||||
&& o.Path == n.Path
|
||||
&& 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)
|
||||
&& o.Flow == n.Flow
|
||||
&& o.Sni == n.Sni
|
||||
&& o.Alpn == n.Alpn
|
||||
&& o.Fingerprint == n.Fingerprint
|
||||
&& o.PublicKey == n.PublicKey
|
||||
&& o.ShortId == n.ShortId
|
||||
&& 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)
|
||||
{
|
||||
return string.Equals(a, b) || (string.IsNullOrEmpty(a) && string.IsNullOrEmpty(b));
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<int> RemoveProfileItem(Config config, string indexId)
|
||||
@@ -994,26 +1005,32 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static async Task<RetResult> AddCustomServer4Multiple(Config config, List<ProfileItem> selecteds, ECoreType coreType)
|
||||
public static async Task<RetResult> AddCustomServer4Multiple(Config config, List<ProfileItem> selecteds, ECoreType coreType, EMultipleLoad multipleLoad)
|
||||
{
|
||||
var indexId = Utils.GetMd5(Global.CoreMultipleLoadConfigFileName);
|
||||
var configPath = Utils.GetConfigPath(Global.CoreMultipleLoadConfigFileName);
|
||||
|
||||
var result = await CoreConfigHandler.GenerateClientMultipleLoadConfig(config, configPath, selecteds, coreType);
|
||||
var result = await CoreConfigHandler.GenerateClientMultipleLoadConfig(config, configPath, selecteds, coreType, multipleLoad);
|
||||
if (result.Success != true)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var fileName = configPath;
|
||||
if (!File.Exists(fileName))
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var profileItem = await AppHandler.Instance.GetProfileItem(indexId) ?? new();
|
||||
profileItem.IndexId = indexId;
|
||||
profileItem.Remarks = coreType == ECoreType.sing_box ? ResUI.menuSetDefaultMultipleServer : ResUI.menuSetDefaultLoadBalanceServer;
|
||||
profileItem.Remarks = multipleLoad switch
|
||||
{
|
||||
EMultipleLoad.Random => ResUI.menuSetDefaultMultipleServerXrayRandom,
|
||||
EMultipleLoad.RoundRobin => ResUI.menuSetDefaultMultipleServerXrayRoundRobin,
|
||||
EMultipleLoad.LeastPing => ResUI.menuSetDefaultMultipleServerXrayLeastPing,
|
||||
EMultipleLoad.LeastLoad => ResUI.menuSetDefaultMultipleServerXrayLeastLoad,
|
||||
_ => ResUI.menuSetDefaultMultipleServerXrayRoundRobin,
|
||||
};
|
||||
profileItem.Address = Global.CoreMultipleLoadConfigFileName;
|
||||
profileItem.ConfigType = EConfigType.Custom;
|
||||
profileItem.CoreType = coreType;
|
||||
@@ -1084,14 +1101,14 @@ namespace ServiceLib.Handler
|
||||
/// <returns>成功导入的数量</returns>
|
||||
private static async Task<int> AddBatchServersCommon(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
if (strData.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var subFilter = string.Empty;
|
||||
//remove sub items
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
{
|
||||
await RemoveServersViaSubid(config, subid, isSub);
|
||||
subFilter = (await AppHandler.Instance.GetSubItem(subid))?.Filter ?? "";
|
||||
@@ -1122,7 +1139,7 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
//exist sub items //filter
|
||||
if (isSub && Utils.IsNotEmpty(subid) && Utils.IsNotEmpty(subFilter))
|
||||
if (isSub && subid.IsNotEmpty() && subFilter.IsNotEmpty())
|
||||
{
|
||||
if (!Regex.IsMatch(profileItem.Remarks, subFilter))
|
||||
{
|
||||
@@ -1163,7 +1180,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
private static async Task<int> AddBatchServers4Custom(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
if (strData.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -1185,7 +1202,7 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
if (lstProfiles != null && lstProfiles.Count > 0)
|
||||
{
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
{
|
||||
await RemoveServersViaSubid(config, subid, isSub);
|
||||
}
|
||||
@@ -1236,12 +1253,12 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
profileItem = NaiveproxyFmt.ResolveFull(strData, subRemarks);
|
||||
}
|
||||
if (profileItem is null || Utils.IsNullOrEmpty(profileItem.Address))
|
||||
if (profileItem is null || profileItem.Address.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
{
|
||||
await RemoveServersViaSubid(config, subid, isSub);
|
||||
}
|
||||
@@ -1261,12 +1278,12 @@ namespace ServiceLib.Handler
|
||||
|
||||
private static async Task<int> AddBatchServers4SsSIP008(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
if (strData.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
{
|
||||
await RemoveServersViaSubid(config, subid, isSub);
|
||||
}
|
||||
@@ -1293,13 +1310,13 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static async Task<int> AddBatchServers(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
if (strData.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
List<ProfileItem>? lstOriSub = null;
|
||||
ProfileItem? activeProfile = null;
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
{
|
||||
lstOriSub = await AppHandler.Instance.ProfileItems(subid);
|
||||
activeProfile = lstOriSub?.FirstOrDefault(t => t.IndexId == config.IndexId);
|
||||
@@ -1424,7 +1441,7 @@ namespace ServiceLib.Handler
|
||||
item.Memo = subItem.Memo;
|
||||
}
|
||||
|
||||
if (Utils.IsNullOrEmpty(item.Id))
|
||||
if (item.Id.IsNullOrEmpty())
|
||||
{
|
||||
item.Id = Utils.GetGuid(false);
|
||||
|
||||
@@ -1457,7 +1474,7 @@ namespace ServiceLib.Handler
|
||||
/// <returns></returns>
|
||||
public static async Task<int> RemoveServersViaSubid(Config config, string subid, bool isSub)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(subid))
|
||||
if (subid.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -1508,7 +1525,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static async Task<int> SaveRoutingItem(Config config, RoutingItem item)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(item.Id))
|
||||
if (item.Id.IsNullOrEmpty())
|
||||
{
|
||||
item.Id = Utils.GetGuid(false);
|
||||
}
|
||||
@@ -1531,7 +1548,7 @@ namespace ServiceLib.Handler
|
||||
/// <returns></returns>
|
||||
public static async Task<int> AddBatchRoutingRules(RoutingItem routingItem, string strData)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
if (strData.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -1549,7 +1566,7 @@ namespace ServiceLib.Handler
|
||||
routingItem.RuleNum = lstRules.Count;
|
||||
routingItem.RuleSet = JsonUtils.Serialize(lstRules, false);
|
||||
|
||||
if (Utils.IsNullOrEmpty(routingItem.Id))
|
||||
if (routingItem.Id.IsNullOrEmpty())
|
||||
{
|
||||
routingItem.Id = Utils.GetGuid(false);
|
||||
}
|
||||
@@ -1668,7 +1685,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static async Task<int> InitRouting(Config config, bool blImportAdvancedRules = false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(config.ConstItem.RouteRulesTemplateSourceUrl))
|
||||
if (config.ConstItem.RouteRulesTemplateSourceUrl.IsNullOrEmpty())
|
||||
{
|
||||
await InitBuiltinRouting(config, blImportAdvancedRules);
|
||||
}
|
||||
@@ -1684,7 +1701,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
var downloadHandle = new DownloadService();
|
||||
var templateContent = await downloadHandle.TryDownloadString(config.ConstItem.RouteRulesTemplateSourceUrl, true, "");
|
||||
if (string.IsNullOrEmpty(templateContent))
|
||||
if (templateContent.IsNullOrEmpty())
|
||||
return await InitBuiltinRouting(config, blImportAdvancedRules); // fallback
|
||||
|
||||
var template = JsonUtils.Deserialize<RoutingTemplate>(templateContent);
|
||||
@@ -1701,14 +1718,14 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
var item = template.RoutingItems[i];
|
||||
|
||||
if (string.IsNullOrEmpty(item.Url) && string.IsNullOrEmpty(item.RuleSet))
|
||||
if (item.Url.IsNullOrEmpty() && item.RuleSet.IsNullOrEmpty())
|
||||
continue;
|
||||
|
||||
var ruleSetsString = !string.IsNullOrEmpty(item.RuleSet)
|
||||
var ruleSetsString = !item.RuleSet.IsNullOrEmpty()
|
||||
? item.RuleSet
|
||||
: await downloadHandle.TryDownloadString(item.Url, true, "");
|
||||
|
||||
if (string.IsNullOrEmpty(ruleSetsString))
|
||||
if (ruleSetsString.IsNullOrEmpty())
|
||||
continue;
|
||||
|
||||
item.Remarks = $"{template.Version}-{item.Remarks}";
|
||||
@@ -1820,7 +1837,7 @@ namespace ServiceLib.Handler
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (Utils.IsNullOrEmpty(item.Id))
|
||||
if (item.Id.IsNullOrEmpty())
|
||||
{
|
||||
item.Id = Utils.GetGuid(false);
|
||||
}
|
||||
@@ -1841,17 +1858,17 @@ namespace ServiceLib.Handler
|
||||
|
||||
var downloadHandle = new DownloadService();
|
||||
var templateContent = await downloadHandle.TryDownloadString(url, true, "");
|
||||
if (string.IsNullOrEmpty(templateContent))
|
||||
if (templateContent.IsNullOrEmpty())
|
||||
return currentItem;
|
||||
|
||||
var template = JsonUtils.Deserialize<DNSItem>(templateContent);
|
||||
if (template == null)
|
||||
return currentItem;
|
||||
|
||||
if (!string.IsNullOrEmpty(template.NormalDNS))
|
||||
if (!template.NormalDNS.IsNullOrEmpty())
|
||||
template.NormalDNS = await downloadHandle.TryDownloadString(template.NormalDNS, true, "");
|
||||
|
||||
if (!string.IsNullOrEmpty(template.TunDNS))
|
||||
if (!template.TunDNS.IsNullOrEmpty())
|
||||
template.TunDNS = await downloadHandle.TryDownloadString(template.TunDNS, true, "");
|
||||
|
||||
template.Id = currentItem.Id;
|
||||
@@ -1906,4 +1923,3 @@ namespace ServiceLib.Handler
|
||||
|
||||
#endregion Regional Presets
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
/// <summary>
|
||||
/// Core configuration file processing class
|
||||
/// </summary>
|
||||
@@ -33,7 +33,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (Utils.IsNotEmpty(fileName) && result.Data != null)
|
||||
if (fileName.IsNotEmpty() && result.Data != null)
|
||||
{
|
||||
await File.WriteAllTextAsync(fileName, result.Data.ToString());
|
||||
}
|
||||
@@ -133,16 +133,16 @@ namespace ServiceLib.Handler
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task<RetResult> GenerateClientMultipleLoadConfig(Config config, string fileName, List<ProfileItem> selecteds, ECoreType coreType)
|
||||
public static async Task<RetResult> GenerateClientMultipleLoadConfig(Config config, string fileName, List<ProfileItem> selecteds, ECoreType coreType, EMultipleLoad multipleLoad)
|
||||
{
|
||||
var result = new RetResult();
|
||||
if (coreType == ECoreType.sing_box)
|
||||
{
|
||||
result = await new CoreConfigSingboxService(config).GenerateClientMultipleLoadConfig(selecteds);
|
||||
}
|
||||
else if (coreType == ECoreType.Xray)
|
||||
else
|
||||
{
|
||||
result = await new CoreConfigV2rayService(config).GenerateClientMultipleLoadConfig(selecteds);
|
||||
result = await new CoreConfigV2rayService(config).GenerateClientMultipleLoadConfig(selecteds, multipleLoad);
|
||||
}
|
||||
|
||||
if (result.Success != true)
|
||||
@@ -153,4 +153,3 @@ namespace ServiceLib.Handler
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
/// <summary>
|
||||
/// Core process processing class
|
||||
/// </summary>
|
||||
@@ -24,6 +24,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
Environment.SetEnvironmentVariable(Global.V2RayLocalAsset, Utils.GetBinPath(""), EnvironmentVariableTarget.Process);
|
||||
Environment.SetEnvironmentVariable(Global.XrayLocalAsset, Utils.GetBinPath(""), EnvironmentVariableTarget.Process);
|
||||
Environment.SetEnvironmentVariable(Global.XrayLocalCert, Utils.GetBinPath(""), EnvironmentVariableTarget.Process);
|
||||
|
||||
//Copy the bin folder to the storage location (for init)
|
||||
if (Environment.GetEnvironmentVariable(Global.LocalAppData) == "1")
|
||||
@@ -240,7 +241,7 @@ namespace ServiceLib.Handler
|
||||
private async Task<Process?> RunProcess(CoreInfo? coreInfo, string configPath, bool displayLog, bool mayNeedSudo)
|
||||
{
|
||||
var fileName = CoreInfoHandler.Instance.GetCoreExecFile(coreInfo, out var msg);
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
if (fileName.IsNullOrEmpty())
|
||||
{
|
||||
UpdateFunc(false, msg);
|
||||
return null;
|
||||
@@ -274,13 +275,13 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
proc.OutputDataReceived += (sender, e) =>
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(e.Data))
|
||||
if (e.Data.IsNullOrEmpty())
|
||||
return;
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
};
|
||||
proc.ErrorDataReceived += (sender, e) =>
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(e.Data))
|
||||
if (e.Data.IsNullOrEmpty())
|
||||
return;
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
};
|
||||
@@ -406,4 +407,3 @@ namespace ServiceLib.Handler
|
||||
|
||||
#endregion Linux
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public sealed class CoreInfoHandler
|
||||
{
|
||||
private static readonly Lazy<CoreInfoHandler> _instance = new(() => new());
|
||||
@@ -215,4 +215,3 @@ namespace ServiceLib.Handler
|
||||
return $"{Global.GithubUrl}/{Global.CoreUrls[eCoreType]}/releases";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class BaseFmt
|
||||
{
|
||||
protected static string GetIpv6(string address)
|
||||
@@ -16,12 +16,12 @@ namespace ServiceLib.Handler.Fmt
|
||||
|
||||
protected static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
|
||||
{
|
||||
if (Utils.IsNotEmpty(item.Flow))
|
||||
if (item.Flow.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("flow", item.Flow);
|
||||
}
|
||||
|
||||
if (Utils.IsNotEmpty(item.StreamSecurity))
|
||||
if (item.StreamSecurity.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("security", item.StreamSecurity);
|
||||
}
|
||||
@@ -32,27 +32,27 @@ namespace ServiceLib.Handler.Fmt
|
||||
dicQuery.Add("security", securityDef);
|
||||
}
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Sni))
|
||||
if (item.Sni.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("sni", item.Sni);
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Alpn))
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Fingerprint))
|
||||
if (item.Fingerprint.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("fp", Utils.UrlEncode(item.Fingerprint));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.PublicKey))
|
||||
if (item.PublicKey.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("pbk", Utils.UrlEncode(item.PublicKey));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.ShortId))
|
||||
if (item.ShortId.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("sid", Utils.UrlEncode(item.ShortId));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.SpiderX))
|
||||
if (item.SpiderX.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("spx", Utils.UrlEncode(item.SpiderX));
|
||||
}
|
||||
@@ -61,21 +61,21 @@ namespace ServiceLib.Handler.Fmt
|
||||
dicQuery.Add("allowInsecure", "1");
|
||||
}
|
||||
|
||||
dicQuery.Add("type", Utils.IsNotEmpty(item.Network) ? item.Network : nameof(ETransport.tcp));
|
||||
dicQuery.Add("type", item.Network.IsNotEmpty() ? item.Network : nameof(ETransport.tcp));
|
||||
|
||||
switch (item.Network)
|
||||
{
|
||||
case nameof(ETransport.tcp):
|
||||
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(ETransport.kcp):
|
||||
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
|
||||
if (item.Path.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("seed", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
@@ -83,30 +83,30 @@ namespace ServiceLib.Handler.Fmt
|
||||
|
||||
case nameof(ETransport.ws):
|
||||
case nameof(ETransport.httpupgrade):
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
if (item.Path.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(ETransport.xhttp):
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
if (item.Path.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.HeaderType) && Global.XhttpMode.Contains(item.HeaderType))
|
||||
if (item.HeaderType.IsNotEmpty() && Global.XhttpMode.Contains(item.HeaderType))
|
||||
{
|
||||
dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Extra))
|
||||
if (item.Extra.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("extra", Utils.UrlEncode(item.Extra));
|
||||
}
|
||||
@@ -115,24 +115,24 @@ namespace ServiceLib.Handler.Fmt
|
||||
case nameof(ETransport.http):
|
||||
case nameof(ETransport.h2):
|
||||
dicQuery["type"] = nameof(ETransport.http);
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
if (item.Path.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(ETransport.quic):
|
||||
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
|
||||
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
|
||||
dicQuery.Add("quicSecurity", Utils.UrlEncode(item.RequestHost));
|
||||
dicQuery.Add("key", Utils.UrlEncode(item.Path));
|
||||
break;
|
||||
|
||||
case nameof(ETransport.grpc):
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
if (item.Path.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("authority", Utils.UrlEncode(item.RequestHost));
|
||||
dicQuery.Add("serviceName", Utils.UrlEncode(item.Path));
|
||||
@@ -215,8 +215,10 @@ namespace ServiceLib.Handler.Fmt
|
||||
foreach (var item in s)
|
||||
{
|
||||
if (str.Contains(item, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -237,4 +239,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return $"{Global.ProtocolShares[eConfigType]}{url}{query}{remark}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class ClashFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
||||
@@ -20,4 +20,3 @@
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class FmtHandler
|
||||
{
|
||||
private static readonly string _tag = "FmtHandler";
|
||||
@@ -37,7 +37,7 @@
|
||||
try
|
||||
{
|
||||
string str = config.TrimEx();
|
||||
if (Utils.IsNullOrEmpty(str))
|
||||
if (str.IsNullOrEmpty())
|
||||
{
|
||||
msg = ResUI.FailedReadConfiguration;
|
||||
return null;
|
||||
@@ -89,4 +89,3 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class Hysteria2Fmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? Resolve(string str, out string msg)
|
||||
@@ -36,26 +36,26 @@ namespace ServiceLib.Handler.Fmt
|
||||
string url = string.Empty;
|
||||
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (Utils.IsNotEmpty(item.Sni))
|
||||
if (item.Sni.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("sni", item.Sni);
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Alpn))
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
if (item.Path.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("obfs", "salamander");
|
||||
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0");
|
||||
if (Utils.IsNotEmpty(item.Ports))
|
||||
if (item.Ports.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("mport", Utils.UrlEncode(item.Ports.Replace(':', '-')));
|
||||
}
|
||||
@@ -99,4 +99,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class NaiveproxyFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
||||
@@ -20,4 +20,3 @@
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class ShadowsocksFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? Resolve(string str, out string msg)
|
||||
@@ -27,11 +27,11 @@ namespace ServiceLib.Handler.Fmt
|
||||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
string url = string.Empty;
|
||||
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
}
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
@@ -53,12 +53,14 @@ namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
var match = UrlFinder.Match(result);
|
||||
if (!match.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ProfileItem item = new();
|
||||
var base64 = match.Groups["base64"].Value.TrimEnd('/');
|
||||
var tag = match.Groups["tag"].Value;
|
||||
if (Utils.IsNotEmpty(tag))
|
||||
if (tag.IsNotEmpty())
|
||||
{
|
||||
item.Remarks = Utils.UrlDecode(tag);
|
||||
}
|
||||
@@ -72,11 +74,13 @@ namespace ServiceLib.Handler.Fmt
|
||||
return null;
|
||||
}
|
||||
if (!details.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
item.Security = details.Groups["method"].Value;
|
||||
item.Id = details.Groups["password"].Value;
|
||||
item.Address = details.Groups["hostname"].Value;
|
||||
item.Port = Utils.ToInt(details.Groups["port"].Value);
|
||||
item.Port = details.Groups["port"].Value.ToInt();
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -84,7 +88,9 @@ namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
var parsedUrl = Utils.TryUri(result);
|
||||
if (parsedUrl == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ProfileItem item = new()
|
||||
{
|
||||
@@ -96,7 +102,7 @@ namespace ServiceLib.Handler.Fmt
|
||||
//2022-blake3
|
||||
if (rawUserInfo.Contains(':'))
|
||||
{
|
||||
string[] userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
||||
var userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
||||
if (userInfoParts.Length != 2)
|
||||
{
|
||||
return null;
|
||||
@@ -107,8 +113,8 @@ namespace ServiceLib.Handler.Fmt
|
||||
else
|
||||
{
|
||||
// parse base64 UserInfo
|
||||
string userInfo = Utils.Base64Decode(rawUserInfo);
|
||||
string[] userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
||||
var userInfo = Utils.Base64Decode(rawUserInfo);
|
||||
var userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
||||
if (userInfoParts.Length != 2)
|
||||
{
|
||||
return null;
|
||||
@@ -122,7 +128,7 @@ namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
//obfs-host exists
|
||||
var obfsHost = queryParameters["plugin"]?.Split(';').FirstOrDefault(t => t.Contains("obfs-host"));
|
||||
if (queryParameters["plugin"].Contains("obfs=http") && Utils.IsNotEmpty(obfsHost))
|
||||
if (queryParameters["plugin"].Contains("obfs=http") && obfsHost.IsNotEmpty())
|
||||
{
|
||||
obfsHost = obfsHost?.Replace("obfs-host=", "");
|
||||
item.Network = Global.DefaultNetwork;
|
||||
@@ -162,7 +168,7 @@ namespace ServiceLib.Handler.Fmt
|
||||
Security = it.method,
|
||||
Id = it.password,
|
||||
Address = it.server,
|
||||
Port = Utils.ToInt(it.server_port)
|
||||
Port = it.server_port.ToInt()
|
||||
};
|
||||
lst.Add(ssItem);
|
||||
}
|
||||
@@ -171,4 +177,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,39 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class SingboxFmt : BaseFmt
|
||||
{
|
||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||
{
|
||||
var configObjects = JsonUtils.Deserialize<Object[]>(strData);
|
||||
if (configObjects != null && configObjects.Length > 0)
|
||||
var configObjects = JsonUtils.Deserialize<object[]>(strData);
|
||||
if (configObjects is not { Length: > 0 })
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ProfileItem> lstResult = [];
|
||||
foreach (var configObject in configObjects)
|
||||
{
|
||||
var objectString = JsonUtils.Serialize(configObject);
|
||||
var singboxCon = JsonUtils.Deserialize<SingboxConfig>(objectString);
|
||||
if (singboxCon?.inbounds?.Count > 0
|
||||
&& singboxCon.outbounds?.Count > 0
|
||||
&& singboxCon.route != null)
|
||||
var profileIt = ResolveFull(objectString, subRemarks);
|
||||
if (profileIt != null)
|
||||
{
|
||||
var fileName = WriteAllText(objectString);
|
||||
|
||||
var profileIt = new ProfileItem
|
||||
{
|
||||
CoreType = ECoreType.sing_box,
|
||||
Address = fileName,
|
||||
Remarks = subRemarks ?? "singbox_custom",
|
||||
};
|
||||
lstResult.Add(profileIt);
|
||||
}
|
||||
}
|
||||
return lstResult;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
||||
{
|
||||
var singboxConfig = JsonUtils.Deserialize<SingboxConfig>(strData);
|
||||
if (singboxConfig?.inbounds?.Count > 0
|
||||
&& singboxConfig.outbounds?.Count > 0
|
||||
&& singboxConfig.route != null)
|
||||
var config = JsonUtils.ParseJson(strData);
|
||||
if (config?["inbounds"] == null
|
||||
|| config["outbounds"] == null
|
||||
|| config["route"] == null
|
||||
|| config["dns"] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var fileName = WriteAllText(strData);
|
||||
var profileItem = new ProfileItem
|
||||
{
|
||||
@@ -49,7 +44,4 @@
|
||||
|
||||
return profileItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class SocksFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? Resolve(string str, out string msg)
|
||||
@@ -24,11 +24,11 @@ namespace ServiceLib.Handler.Fmt
|
||||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
var url = string.Empty;
|
||||
|
||||
}
|
||||
var remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace ServiceLib.Handler.Fmt
|
||||
return null;
|
||||
}
|
||||
item.Address = arr1[1][..indexPort];
|
||||
item.Port = Utils.ToInt(arr1[1][(indexPort + 1)..]);
|
||||
item.Port = arr1[1][(indexPort + 1)..].ToInt();
|
||||
item.Security = arr21.First();
|
||||
item.Id = arr21[1];
|
||||
|
||||
@@ -88,7 +88,9 @@ namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
var parsedUrl = Utils.TryUri(result);
|
||||
if (parsedUrl == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ProfileItem item = new()
|
||||
{
|
||||
@@ -110,4 +112,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class TrojanFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? Resolve(string str, out string msg)
|
||||
@@ -13,7 +13,9 @@ namespace ServiceLib.Handler.Fmt
|
||||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
@@ -21,7 +23,7 @@ namespace ServiceLib.Handler.Fmt
|
||||
item.Id = Utils.UrlDecode(url.UserInfo);
|
||||
|
||||
var query = Utils.ParseQueryString(url.Query);
|
||||
ResolveStdTransport(query, ref item);
|
||||
_ = ResolveStdTransport(query, ref item);
|
||||
|
||||
return item;
|
||||
}
|
||||
@@ -29,18 +31,17 @@ namespace ServiceLib.Handler.Fmt
|
||||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
string url = string.Empty;
|
||||
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
}
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
GetStdTransport(item, null, ref dicQuery);
|
||||
_ = GetStdTransport(item, null, ref dicQuery);
|
||||
|
||||
return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class TuicFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? Resolve(string str, out string msg)
|
||||
@@ -13,7 +13,9 @@ namespace ServiceLib.Handler.Fmt
|
||||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
@@ -36,20 +38,21 @@ namespace ServiceLib.Handler.Fmt
|
||||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
string url = string.Empty;
|
||||
}
|
||||
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (Utils.IsNotEmpty(item.Sni))
|
||||
if (item.Sni.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("sni", item.Sni);
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Alpn))
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
@@ -58,4 +61,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return ToUri(EConfigType.TUIC, item.Address, item.Port, $"{item.Id}:{item.Security}", dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,48 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class V2rayFmt : BaseFmt
|
||||
{
|
||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||
{
|
||||
var configObjects = JsonUtils.Deserialize<Object[]>(strData);
|
||||
if (configObjects != null && configObjects.Length > 0)
|
||||
var configObjects = JsonUtils.Deserialize<object[]>(strData);
|
||||
if (configObjects is not { Length: > 0 })
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ProfileItem> lstResult = [];
|
||||
foreach (var configObject in configObjects)
|
||||
{
|
||||
var objectString = JsonUtils.Serialize(configObject);
|
||||
var v2rayCon = JsonUtils.Deserialize<V2rayConfig>(objectString);
|
||||
if (v2rayCon?.inbounds?.Count > 0
|
||||
&& v2rayCon.outbounds?.Count > 0
|
||||
&& v2rayCon.routing != null)
|
||||
var profileIt = ResolveFull(objectString, subRemarks);
|
||||
if (profileIt != null)
|
||||
{
|
||||
var fileName = WriteAllText(objectString);
|
||||
|
||||
var profileIt = new ProfileItem
|
||||
{
|
||||
CoreType = ECoreType.Xray,
|
||||
Address = fileName,
|
||||
Remarks = v2rayCon.remarks ?? subRemarks ?? "v2ray_custom",
|
||||
};
|
||||
lstResult.Add(profileIt);
|
||||
}
|
||||
}
|
||||
|
||||
return lstResult;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
||||
{
|
||||
var v2rayConfig = JsonUtils.Deserialize<V2rayConfig>(strData);
|
||||
if (v2rayConfig?.inbounds?.Count > 0
|
||||
&& v2rayConfig.outbounds?.Count > 0
|
||||
&& v2rayConfig.routing != null)
|
||||
var config = JsonUtils.ParseJson(strData);
|
||||
if (config?["inbounds"] == null
|
||||
|| config["outbounds"] == null
|
||||
|| config["routing"] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var fileName = WriteAllText(strData);
|
||||
|
||||
var profileItem = new ProfileItem
|
||||
{
|
||||
CoreType = ECoreType.Xray,
|
||||
Address = fileName,
|
||||
Remarks = v2rayConfig.remarks ?? subRemarks ?? "v2ray_custom"
|
||||
Remarks = config?["remarks"]?.ToString() ?? subRemarks ?? "v2ray_custom"
|
||||
};
|
||||
|
||||
return profileItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class VLESSFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? Resolve(string str, out string msg)
|
||||
@@ -14,7 +14,9 @@ namespace ServiceLib.Handler.Fmt
|
||||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
@@ -24,7 +26,7 @@ namespace ServiceLib.Handler.Fmt
|
||||
var query = Utils.ParseQueryString(url.Query);
|
||||
item.Security = query["encryption"] ?? Global.None;
|
||||
item.StreamSecurity = query["security"] ?? "";
|
||||
ResolveStdTransport(query, ref item);
|
||||
_ = ResolveStdTransport(query, ref item);
|
||||
|
||||
return item;
|
||||
}
|
||||
@@ -32,16 +34,17 @@ namespace ServiceLib.Handler.Fmt
|
||||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
string url = string.Empty;
|
||||
}
|
||||
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (Utils.IsNotEmpty(item.Security))
|
||||
if (item.Security.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("encryption", item.Security);
|
||||
}
|
||||
@@ -49,9 +52,8 @@ namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
dicQuery.Add("encryption", Global.None);
|
||||
}
|
||||
GetStdTransport(item, Global.None, ref dicQuery);
|
||||
_ = GetStdTransport(item, Global.None, ref dicQuery);
|
||||
|
||||
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class VmessFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? Resolve(string str, out string msg)
|
||||
@@ -20,10 +20,10 @@ namespace ServiceLib.Handler.Fmt
|
||||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
string url = string.Empty;
|
||||
|
||||
VmessQRCode vmessQRCode = new()
|
||||
}
|
||||
var vmessQRCode = new VmessQRCode
|
||||
{
|
||||
v = item.ConfigVersion,
|
||||
ps = item.Remarks.TrimEx(),
|
||||
@@ -42,7 +42,7 @@ namespace ServiceLib.Handler.Fmt
|
||||
fp = item.Fingerprint
|
||||
};
|
||||
|
||||
url = JsonUtils.Serialize(vmessQRCode);
|
||||
var url = JsonUtils.Serialize(vmessQRCode);
|
||||
url = Utils.Base64Encode(url);
|
||||
url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}";
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace ServiceLib.Handler.Fmt
|
||||
result = result[Global.ProtocolShares[EConfigType.VMess].Length..];
|
||||
result = Utils.Base64Decode(result);
|
||||
|
||||
VmessQRCode? vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
|
||||
var vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
|
||||
if (vmessQRCode == null)
|
||||
{
|
||||
msg = ResUI.FailedConversionConfiguration;
|
||||
@@ -78,12 +78,12 @@ namespace ServiceLib.Handler.Fmt
|
||||
item.AlterId = vmessQRCode.aid;
|
||||
item.Security = Utils.ToString(vmessQRCode.scy);
|
||||
|
||||
item.Security = Utils.IsNotEmpty(vmessQRCode.scy) ? vmessQRCode.scy : Global.DefaultSecurity;
|
||||
if (Utils.IsNotEmpty(vmessQRCode.net))
|
||||
item.Security = vmessQRCode.scy.IsNotEmpty() ? vmessQRCode.scy : Global.DefaultSecurity;
|
||||
if (vmessQRCode.net.IsNotEmpty())
|
||||
{
|
||||
item.Network = vmessQRCode.net;
|
||||
}
|
||||
if (Utils.IsNotEmpty(vmessQRCode.type))
|
||||
if (vmessQRCode.type.IsNotEmpty())
|
||||
{
|
||||
item.HeaderType = vmessQRCode.type;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ namespace ServiceLib.Handler.Fmt
|
||||
|
||||
public static ProfileItem? ResolveStdVmess(string str)
|
||||
{
|
||||
ProfileItem item = new()
|
||||
var item = new ProfileItem
|
||||
{
|
||||
ConfigType = EConfigType.VMess,
|
||||
Security = "auto"
|
||||
@@ -108,7 +108,9 @@ namespace ServiceLib.Handler.Fmt
|
||||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
@@ -121,4 +123,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class WireguardFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? Resolve(string str, out string msg)
|
||||
@@ -13,7 +13,9 @@ namespace ServiceLib.Handler.Fmt
|
||||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
@@ -33,33 +35,33 @@ namespace ServiceLib.Handler.Fmt
|
||||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
string url = string.Empty;
|
||||
}
|
||||
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (Utils.IsNotEmpty(item.PublicKey))
|
||||
if (item.PublicKey.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("publickey", Utils.UrlEncode(item.PublicKey));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
if (item.Path.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("reserved", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("address", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
if (Utils.IsNotEmpty(item.ShortId))
|
||||
if (item.ShortId.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("mtu", Utils.UrlEncode(item.ShortId));
|
||||
}
|
||||
return ToUri(EConfigType.WireGuard, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using ReactiveUI;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
public class NoticeHandler
|
||||
{
|
||||
private static readonly Lazy<NoticeHandler> _instance = new(() => new());
|
||||
@@ -41,4 +41,3 @@ namespace ServiceLib.Handler
|
||||
SendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public class PacHandler
|
||||
{
|
||||
private static string _configPath;
|
||||
@@ -15,7 +15,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static async Task Start(string configPath, int httpPort, int pacPort)
|
||||
{
|
||||
_needRestart = (configPath != _configPath || httpPort != _httpPort || pacPort != _pacPort || !_isRunning);
|
||||
_needRestart = configPath != _configPath || httpPort != _httpPort || pacPort != _pacPort || !_isRunning;
|
||||
|
||||
_configPath = configPath;
|
||||
_httpPort = httpPort;
|
||||
@@ -33,6 +33,13 @@ namespace ServiceLib.Handler
|
||||
private static async Task InitText()
|
||||
{
|
||||
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))
|
||||
{
|
||||
var pac = EmbedUtils.GetEmbedText(Global.PacFileName);
|
||||
@@ -70,7 +77,7 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
var client = await _tcpListener.AcceptTcpClientAsync();
|
||||
await Task.Run(() => { WriteContent(client); });
|
||||
await Task.Run(() => WriteContent(client));
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -90,7 +97,9 @@ namespace ServiceLib.Handler
|
||||
public static void Stop()
|
||||
{
|
||||
if (_tcpListener == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_isRunning = false;
|
||||
@@ -103,4 +112,3 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ using System.Collections.Concurrent;
|
||||
|
||||
//using System.Reactive.Linq;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public class ProfileExHandler
|
||||
{
|
||||
private static readonly Lazy<ProfileExHandler> _instance = new(() => new());
|
||||
@@ -36,7 +36,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
private void IndexIdEnqueue(string indexId)
|
||||
{
|
||||
if (Utils.IsNotEmpty(indexId) && !_queIndexIds.Contains(indexId))
|
||||
if (indexId.IsNotEmpty() && !_queIndexIds.Contains(indexId))
|
||||
{
|
||||
_queIndexIds.Enqueue(indexId);
|
||||
}
|
||||
@@ -179,4 +179,3 @@ namespace ServiceLib.Handler
|
||||
return _lstProfileEx.Max(t => t == null ? 0 : t.Sort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public class StatisticsHandler
|
||||
{
|
||||
private static readonly Lazy<StatisticsHandler> instance = new(() => new());
|
||||
@@ -161,4 +161,3 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.SysProxy
|
||||
{
|
||||
namespace ServiceLib.Handler.SysProxy;
|
||||
|
||||
public class ProxySettingLinux
|
||||
{
|
||||
private static readonly string _proxySetFileName = $"{Global.ProxySetLinuxShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
||||
@@ -30,4 +30,3 @@ namespace ServiceLib.Handler.SysProxy
|
||||
await Utils.GetCliWrapOutput(fileName, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.SysProxy
|
||||
{
|
||||
namespace ServiceLib.Handler.SysProxy;
|
||||
|
||||
public class ProxySettingOSX
|
||||
{
|
||||
private static readonly string _proxySetFileName = $"{Global.ProxySetOSXShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
||||
@@ -35,4 +35,3 @@ namespace ServiceLib.Handler.SysProxy
|
||||
await Utils.GetCliWrapOutput(fileName, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using static ServiceLib.Handler.SysProxy.ProxySettingWindows.InternetConnectionOption;
|
||||
|
||||
namespace ServiceLib.Handler.SysProxy
|
||||
{
|
||||
namespace ServiceLib.Handler.SysProxy;
|
||||
|
||||
public class ProxySettingWindows
|
||||
{
|
||||
private const string _regPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
|
||||
@@ -60,7 +60,7 @@ namespace ServiceLib.Handler.SysProxy
|
||||
try
|
||||
{
|
||||
// set proxy for LAN
|
||||
bool result = SetConnectionProxy(null, strProxy, exceptions, type);
|
||||
var result = SetConnectionProxy(null, strProxy, exceptions, type);
|
||||
// set proxy for dial up connections
|
||||
var connections = EnumerateRasEntries();
|
||||
foreach (var connection in connections)
|
||||
@@ -71,27 +71,27 @@ namespace ServiceLib.Handler.SysProxy
|
||||
}
|
||||
catch
|
||||
{
|
||||
SetProxyFallback(strProxy, exceptions, type);
|
||||
_ = SetProxyFallback(strProxy, exceptions, type);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool SetConnectionProxy(string? connectionName, string? strProxy, string? exceptions, int type)
|
||||
{
|
||||
InternetPerConnOptionList list = new();
|
||||
var list = new InternetPerConnOptionList();
|
||||
|
||||
int optionCount = 1;
|
||||
var optionCount = 1;
|
||||
if (type == 1) // No proxy
|
||||
{
|
||||
optionCount = 1;
|
||||
}
|
||||
else if (type is 2 or 4) // named proxy or autoproxy script URL
|
||||
{
|
||||
optionCount = string.IsNullOrEmpty(exceptions) ? 2 : 3;
|
||||
optionCount = exceptions.IsNullOrEmpty() ? 2 : 3;
|
||||
}
|
||||
|
||||
int m_Int = (int)PerConnFlags.PROXY_TYPE_DIRECT;
|
||||
PerConnOption m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
||||
var m_Int = (int)PerConnFlags.PROXY_TYPE_DIRECT;
|
||||
var m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
||||
if (type == 2) // named proxy
|
||||
{
|
||||
m_Int = (int)(PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY);
|
||||
@@ -103,11 +103,9 @@ namespace ServiceLib.Handler.SysProxy
|
||||
m_Option = PerConnOption.INTERNET_PER_CONN_AUTOCONFIG_URL;
|
||||
}
|
||||
|
||||
//int optionCount = Utile.IsNullOrEmpty(strProxy) ? 1 : (Utile.IsNullOrEmpty(exceptions) ? 2 : 3);
|
||||
InternetConnectionOption[] options = new InternetConnectionOption[optionCount];
|
||||
var options = new InternetConnectionOption[optionCount];
|
||||
// USE a proxy server ...
|
||||
options[0].m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
||||
//options[0].m_Value.m_Int = (int)((optionCount < 2) ? PerConnFlags.PROXY_TYPE_DIRECT : (PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY));
|
||||
options[0].m_Value.m_Int = m_Int;
|
||||
// use THIS proxy server
|
||||
if (optionCount > 1)
|
||||
@@ -135,20 +133,20 @@ namespace ServiceLib.Handler.SysProxy
|
||||
list.dwOptionCount = options.Length;
|
||||
list.dwOptionError = 0;
|
||||
|
||||
int optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
|
||||
var optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
|
||||
// make a pointer out of all that ...
|
||||
nint optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length); // !! remember to deallocate memory 4
|
||||
var optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length); // !! remember to deallocate memory 4
|
||||
// copy the array over into that spot in memory ...
|
||||
for (int i = 0; i < options.Length; ++i)
|
||||
for (var i = 0; i < options.Length; ++i)
|
||||
{
|
||||
if (Environment.Is64BitOperatingSystem)
|
||||
{
|
||||
nint opt = new(optionsPtr.ToInt64() + (i * optSize));
|
||||
var opt = new nint(optionsPtr.ToInt64() + (i * optSize));
|
||||
Marshal.StructureToPtr(options[i], opt, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
nint opt = new(optionsPtr.ToInt32() + (i * optSize));
|
||||
var opt = new nint(optionsPtr.ToInt32() + (i * optSize));
|
||||
Marshal.StructureToPtr(options[i], opt, false);
|
||||
}
|
||||
}
|
||||
@@ -156,14 +154,14 @@ namespace ServiceLib.Handler.SysProxy
|
||||
list.options = optionsPtr;
|
||||
|
||||
// and then make a pointer out of the whole list
|
||||
nint ipcoListPtr = Marshal.AllocCoTaskMem(list.dwSize); // !! remember to deallocate memory 5
|
||||
var ipcoListPtr = Marshal.AllocCoTaskMem(list.dwSize); // !! remember to deallocate memory 5
|
||||
Marshal.StructureToPtr(list, ipcoListPtr, false);
|
||||
|
||||
// and finally, call the API method!
|
||||
bool isSuccess = NativeMethods.InternetSetOption(nint.Zero,
|
||||
var isSuccess = NativeMethods.InternetSetOption(nint.Zero,
|
||||
InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,
|
||||
ipcoListPtr, list.dwSize);
|
||||
int returnvalue = 0; // ERROR_SUCCESS
|
||||
var returnvalue = 0; // ERROR_SUCCESS
|
||||
if (!isSuccess)
|
||||
{ // get the error codes, they might be helpful
|
||||
returnvalue = Marshal.GetLastPInvokeError();
|
||||
@@ -171,13 +169,15 @@ namespace ServiceLib.Handler.SysProxy
|
||||
else
|
||||
{
|
||||
// Notify the system that the registry settings have been changed and cause them to be refreshed
|
||||
NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_SETTINGS_CHANGED, nint.Zero, 0);
|
||||
NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_REFRESH, nint.Zero, 0);
|
||||
_ = NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_SETTINGS_CHANGED, nint.Zero, 0);
|
||||
_ = NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_REFRESH, nint.Zero, 0);
|
||||
}
|
||||
|
||||
// FREE the data ASAP
|
||||
if (list.szConnection != nint.Zero)
|
||||
{
|
||||
Marshal.FreeHGlobal(list.szConnection); // release mem 3
|
||||
}
|
||||
if (optionCount > 1)
|
||||
{
|
||||
Marshal.FreeHGlobal(options[1].m_Value.m_StringPtr); // release mem 1
|
||||
@@ -204,18 +204,18 @@ namespace ServiceLib.Handler.SysProxy
|
||||
/// <exception cref="ApplicationException">Error message with win32 error code</exception>
|
||||
private static IEnumerable<string> EnumerateRasEntries()
|
||||
{
|
||||
int entries = 0;
|
||||
var entries = 0;
|
||||
// attempt to query with 1 entry buffer
|
||||
RASENTRYNAME[] rasEntryNames = new RASENTRYNAME[1];
|
||||
int bufferSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||
var rasEntryNames = new RASENTRYNAME[1];
|
||||
var bufferSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||
rasEntryNames[0].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||
|
||||
uint result = NativeMethods.RasEnumEntries(null, null, rasEntryNames, ref bufferSize, ref entries);
|
||||
var result = NativeMethods.RasEnumEntries(null, null, rasEntryNames, ref bufferSize, ref entries);
|
||||
// increase buffer if the buffer is not large enough
|
||||
if (result == (uint)ErrorCode.ERROR_BUFFER_TOO_SMALL)
|
||||
{
|
||||
rasEntryNames = new RASENTRYNAME[bufferSize / Marshal.SizeOf(typeof(RASENTRYNAME))];
|
||||
for (int i = 0; i < rasEntryNames.Length; i++)
|
||||
for (var i = 0; i < rasEntryNames.Length; i++)
|
||||
{
|
||||
rasEntryNames[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||
}
|
||||
@@ -225,7 +225,7 @@ namespace ServiceLib.Handler.SysProxy
|
||||
if (result == 0)
|
||||
{
|
||||
var entryNames = new List<string>();
|
||||
for (int i = 0; i < entries; i++)
|
||||
for (var i = 0; i < entries; i++)
|
||||
{
|
||||
entryNames.Add(rasEntryNames[i].szEntryName);
|
||||
}
|
||||
@@ -357,4 +357,3 @@ namespace ServiceLib.Handler.SysProxy
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.SysProxy
|
||||
{
|
||||
namespace ServiceLib.Handler.SysProxy;
|
||||
|
||||
public static class SysProxyHandler
|
||||
{
|
||||
private static readonly string _tag = "SysProxyHandler";
|
||||
@@ -75,7 +75,7 @@
|
||||
}
|
||||
|
||||
strProxy = string.Empty;
|
||||
if (Utils.IsNullOrEmpty(config.SystemProxyItem.SystemProxyAdvancedProtocol))
|
||||
if (config.SystemProxyItem.SystemProxyAdvancedProtocol.IsNullOrEmpty())
|
||||
{
|
||||
strProxy = $"{Global.Loopback}:{port}";
|
||||
}
|
||||
@@ -96,4 +96,3 @@
|
||||
ProxySettingWindows.SetProxy(strProxy, "", 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public class TaskHandler
|
||||
{
|
||||
private static readonly Lazy<TaskHandler> _instance = new(() => new());
|
||||
@@ -95,4 +95,3 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using System.Net;
|
||||
using WebDav;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public sealed class WebDavHandler
|
||||
{
|
||||
private static readonly Lazy<WebDavHandler> _instance = new(() => new());
|
||||
public static WebDavHandler Instance => _instance.Value;
|
||||
|
||||
private Config? _config;
|
||||
private readonly Config? _config;
|
||||
private WebDavClient? _client;
|
||||
private string? _lastDescription;
|
||||
private string _webDir = Global.AppName + "_backup";
|
||||
@@ -62,7 +62,9 @@ namespace ServiceLib.Handler
|
||||
private async Task<bool> TryCreateDir()
|
||||
{
|
||||
if (_client is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
var result2 = await _client.Mkcol(_webDir);
|
||||
@@ -177,4 +179,3 @@ namespace ServiceLib.Handler
|
||||
|
||||
public string GetLastError() => _lastDescription ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
public class CheckUpdateModel
|
||||
{
|
||||
public bool? IsSelected { get; set; }
|
||||
@@ -8,4 +8,3 @@
|
||||
public string? FileName { get; set; }
|
||||
public bool? IsFinished { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
public class ClashConnectionModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
@@ -14,4 +14,3 @@
|
||||
public string? Elapsed { get; set; }
|
||||
public string? Chain { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
public class ClashConnections
|
||||
{
|
||||
public ulong downloadTotal { get; set; }
|
||||
@@ -34,4 +34,3 @@
|
||||
public string? processPath { get; set; }
|
||||
public string? remoteDestination { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using static ServiceLib.Models.ClashProxies;
|
||||
using static ServiceLib.Models.ClashProxies;
|
||||
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
public class ClashProviders
|
||||
{
|
||||
public Dictionary<string, ProvidersItem>? providers { get; set; }
|
||||
@@ -14,4 +14,3 @@ namespace ServiceLib.Models
|
||||
public string? vehicleType { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
public class ClashProxies
|
||||
{
|
||||
public Dictionary<string, ProxiesItem>? proxies { get; set; }
|
||||
@@ -21,4 +21,3 @@
|
||||
public int delay { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ClashProxyModel
|
||||
{
|
||||
@@ -15,4 +15,3 @@
|
||||
|
||||
public bool IsActive { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
public class CmdItem
|
||||
{
|
||||
public string? Cmd { get; set; }
|
||||
public List<string>? Arguments { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
public class ComboItem
|
||||
{
|
||||
public string? ID
|
||||
@@ -12,4 +12,3 @@
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 本软件配置文件实体类
|
||||
/// </summary>
|
||||
@@ -54,4 +54,3 @@
|
||||
|
||||
#endregion other entities
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class CoreBasicItem
|
||||
{
|
||||
@@ -245,4 +245,3 @@ namespace ServiceLib.Models
|
||||
public string? Length { get; set; }
|
||||
public string? Interval { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class CoreInfo
|
||||
{
|
||||
@@ -18,4 +18,3 @@ namespace ServiceLib.Models
|
||||
public string? VersionArg { get; set; }
|
||||
public bool AbsolutePath { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using SQLite;
|
||||
using SQLite;
|
||||
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
[Serializable]
|
||||
public class DNSItem
|
||||
{
|
||||
@@ -17,4 +17,3 @@ namespace ServiceLib.Models
|
||||
public string? DomainStrategy4Freedom { get; set; }
|
||||
public string? DomainDNSAddress { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
public class GitHubReleaseAsset
|
||||
{
|
||||
[JsonPropertyName("url")] public string? Url { get; set; }
|
||||
@@ -65,4 +65,3 @@ namespace ServiceLib.Models
|
||||
|
||||
[JsonPropertyName("body")] public string? Body { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
internal class IPAPIInfo
|
||||
{
|
||||
public string? ip { get; set; }
|
||||
@@ -10,4 +10,3 @@
|
||||
public string? country_name { get; set; }
|
||||
public string? country_code { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using SQLite;
|
||||
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ProfileExItem
|
||||
{
|
||||
@@ -13,4 +13,3 @@ namespace ServiceLib.Models
|
||||
public int Sort { get; set; }
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using SQLite;
|
||||
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ProfileItem
|
||||
{
|
||||
@@ -48,12 +48,12 @@ namespace ServiceLib.Models
|
||||
|
||||
public List<string>? GetAlpn()
|
||||
{
|
||||
return Utils.IsNullOrEmpty(Alpn) ? null : Utils.String2List(Alpn);
|
||||
return Alpn.IsNullOrEmpty() ? null : Utils.String2List(Alpn);
|
||||
}
|
||||
|
||||
public string GetNetwork()
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(Network) || !Global.Networks.Contains(Network))
|
||||
if (Network.IsNullOrEmpty() || !Global.Networks.Contains(Network))
|
||||
{
|
||||
return Global.DefaultNetwork;
|
||||
}
|
||||
@@ -64,6 +64,7 @@ namespace ServiceLib.Models
|
||||
|
||||
[PrimaryKey]
|
||||
public string IndexId { get; set; }
|
||||
|
||||
public EConfigType ConfigType { get; set; }
|
||||
public int ConfigVersion { get; set; }
|
||||
public string Address { get; set; }
|
||||
@@ -93,4 +94,3 @@ namespace ServiceLib.Models
|
||||
public string SpiderX { get; set; }
|
||||
public string Extra { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ProfileItemModel : ProfileItem
|
||||
{
|
||||
@@ -15,4 +15,3 @@
|
||||
public string TotalUp { get; set; }
|
||||
public string TotalDown { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
public class RetResult
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
@@ -24,4 +24,3 @@
|
||||
Data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using SQLite;
|
||||
using SQLite;
|
||||
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
[Serializable]
|
||||
public class RoutingItem
|
||||
{
|
||||
@@ -20,4 +20,3 @@ namespace ServiceLib.Models
|
||||
public string DomainStrategy4Singbox { get; set; }
|
||||
public int Sort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class RoutingItemModel : RoutingItem
|
||||
{
|
||||
public bool IsActive { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class RoutingTemplate
|
||||
{
|
||||
public string Version { get; set; }
|
||||
public RoutingItem[] RoutingItems { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class RulesItem
|
||||
{
|
||||
@@ -16,4 +16,3 @@
|
||||
public bool Enabled { get; set; } = true;
|
||||
public string? Remarks { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class RulesItemModel : RulesItem
|
||||
{
|
||||
@@ -8,4 +8,3 @@
|
||||
public string Domains { get; set; }
|
||||
public string Protocols { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ServerSpeedItem : ServerStatItem
|
||||
{
|
||||
@@ -19,4 +19,3 @@
|
||||
|
||||
public ulong Down { get; set; }
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user