Compare commits
71 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
331e8ce960 | ||
|
|
a2cfe6fa51 | ||
|
|
8381fefb78 | ||
|
|
d3b95d781a | ||
|
|
3a4a96f87a | ||
|
|
3d462c4be3 | ||
|
|
82b366cd9b | ||
|
|
897a4e5635 | ||
|
|
8ea76fd318 | ||
|
|
693a96fff2 | ||
|
|
8b4e2f8f23 | ||
|
|
13b164acac | ||
|
|
e590547b30 | ||
|
|
5a0fdd971a | ||
|
|
514dce960a | ||
|
|
6ee6fb1706 | ||
|
|
6985328653 | ||
|
|
41c406b84d | ||
|
|
30f7f2c563 | ||
|
|
be3dbfb8e3 | ||
|
|
9b92259e80 | ||
|
|
1c04144573 | ||
|
|
adf3b955d6 | ||
|
|
0032a3d27a | ||
|
|
c6d347d49a | ||
|
|
ea42246d1b | ||
|
|
3f19958c75 | ||
|
|
35788158bc | ||
|
|
4fd494ded4 | ||
|
|
23eeb8ff55 | ||
|
|
456ffb200a | ||
|
|
18e0bb194e | ||
|
|
392f6111dd | ||
|
|
ce6572af3d | ||
|
|
cf59137481 | ||
|
|
519e588124 | ||
|
|
666c874998 | ||
|
|
5f9f677467 | ||
|
|
b06b5779dd | ||
|
|
e3a3b9c201 | ||
|
|
321ec30f39 | ||
|
|
5adae2dd2a | ||
|
|
be5e15dfb6 | ||
|
|
15d3418c79 | ||
|
|
0efb0228c6 | ||
|
|
75b399b48b | ||
|
|
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 |
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,26 +1,87 @@
|
||||
namespace AmazTool
|
||||
{
|
||||
namespace AmazTool;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
// If no arguments are provided, display usage guidelines and exit
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.WriteLine(Resx.Resource.Guidelines);
|
||||
Thread.Sleep(5000);
|
||||
ShowHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
var argData = Uri.UnescapeDataString(string.Join(" ", args));
|
||||
if (argData.Equals("rebootas"))
|
||||
// Log all arguments for debugging purposes
|
||||
foreach (var arg in args)
|
||||
{
|
||||
Console.WriteLine(arg);
|
||||
}
|
||||
|
||||
// Parse command based on first argument
|
||||
switch (args[0].ToLowerInvariant())
|
||||
{
|
||||
case "rebootas":
|
||||
// Handle application restart
|
||||
HandleRebootAsync();
|
||||
break;
|
||||
|
||||
case "help":
|
||||
case "--help":
|
||||
case "-h":
|
||||
case "/?":
|
||||
// Display help information
|
||||
ShowHelp();
|
||||
break;
|
||||
|
||||
default:
|
||||
// Default behavior: handle as upgrade data
|
||||
// Maintain backward compatibility with existing usage pattern
|
||||
var argData = Uri.UnescapeDataString(string.Join(" ", args));
|
||||
HandleUpgrade(argData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Global exception handling
|
||||
Console.WriteLine($"An error occurred: {ex.Message}");
|
||||
Console.WriteLine("Press any key to exit...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display help information and usage guidelines
|
||||
/// </summary>
|
||||
private static void ShowHelp()
|
||||
{
|
||||
Console.WriteLine(Resx.Resource.Guidelines);
|
||||
Console.WriteLine("Available commands:");
|
||||
Console.WriteLine(" rebootas - Restart the application");
|
||||
Console.WriteLine(" help - Display this help information");
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle application restart
|
||||
/// </summary>
|
||||
private static void HandleRebootAsync()
|
||||
{
|
||||
Console.WriteLine("Restarting application...");
|
||||
Thread.Sleep(1000);
|
||||
Utils.StartV2RayN();
|
||||
return;
|
||||
}
|
||||
|
||||
UpgradeApp.Upgrade(argData);
|
||||
}
|
||||
/// <summary>
|
||||
/// Handle application upgrade with the provided data
|
||||
/// </summary>
|
||||
/// <param name="upgradeData">Data for the upgrade process</param>
|
||||
private static void HandleUpgrade(string upgradeData)
|
||||
{
|
||||
Console.WriteLine("Upgrading application...");
|
||||
UpgradeApp.Upgrade(upgradeData);
|
||||
}
|
||||
}
|
||||
|
||||
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.5</Version>
|
||||
<Version>7.12.3</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="Avalonia.Controls.DataGrid" Version="11.3.0" />
|
||||
<PackageVersion Include="Avalonia.Desktop" Version="11.3.0" />
|
||||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.3.0" />
|
||||
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.3.0" />
|
||||
<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.7" />
|
||||
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.7" />
|
||||
<PackageVersion Include="Splat.NLog" Version="15.3.1" />
|
||||
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
<PackageVersion Include="TaskScheduler" Version="2.12.1" />
|
||||
<PackageVersion Include="WebDav.Client" Version="2.8.0" />
|
||||
<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>
|
||||
|
||||
@@ -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,14 +1,14 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class AesUtils
|
||||
{
|
||||
private const int KeySize = 256; // AES-256
|
||||
private const int IvSize = 16; // AES block size
|
||||
private const int Iterations = 10000;
|
||||
private static readonly byte[] Salt = Encoding.ASCII.GetBytes("saltysalt".PadRight(16, ' ')); // google浏览器默认盐值
|
||||
private static readonly byte[] Salt = Encoding.ASCII.GetBytes("saltysalt".PadRight(16, ' '));
|
||||
private static readonly string DefaultPassword = Utils.GetMd5(Utils.GetHomePath() + "AesUtils");
|
||||
|
||||
/// <summary>
|
||||
@@ -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());
|
||||
@@ -178,4 +178,3 @@ namespace ServiceLib.Common
|
||||
downloadOpt = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ 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";
|
||||
@@ -224,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
|
||||
@@ -203,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
|
||||
@@ -178,4 +177,4 @@ namespace ServiceLib.Common
|
||||
}
|
||||
|
||||
#endregion Helper classes
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Encodings.Web;
|
||||
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";
|
||||
@@ -86,7 +87,8 @@ namespace ServiceLib.Common
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = indented,
|
||||
DefaultIgnoreCondition = nullValue ? JsonIgnoreCondition.Never : JsonIgnoreCondition.WhenWritingNull
|
||||
DefaultIgnoreCondition = nullValue ? JsonIgnoreCondition.Never : JsonIgnoreCondition.WhenWritingNull,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
};
|
||||
result = JsonSerializer.Serialize(obj, options);
|
||||
}
|
||||
@@ -128,4 +130,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();
|
||||
@@ -32,7 +35,7 @@ namespace ServiceLib.Common
|
||||
return;
|
||||
}
|
||||
|
||||
LogManager.GetLogger("Log1").Info(strContent);
|
||||
_logger1.Info(strContent);
|
||||
}
|
||||
|
||||
public static void SaveLog(string strTitle, Exception ex)
|
||||
@@ -42,13 +45,11 @@ namespace ServiceLib.Common
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -87,4 +87,3 @@ namespace ServiceLib.Common
|
||||
return flipped;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public class SemanticVersion
|
||||
{
|
||||
private readonly int major;
|
||||
@@ -184,4 +184,3 @@ namespace ServiceLib.Common
|
||||
|
||||
#endregion Private
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Collections;
|
||||
using SQLite;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public sealed class SQLiteHelper
|
||||
{
|
||||
private static readonly Lazy<SQLiteHelper> _instance = new(() => new());
|
||||
@@ -88,4 +88,3 @@ namespace ServiceLib.Common
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
namespace ServiceLib.Common;
|
||||
|
||||
public static class StringEx
|
||||
{
|
||||
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? value)
|
||||
@@ -80,4 +80,3 @@ namespace ServiceLib.Common
|
||||
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";
|
||||
@@ -863,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";
|
||||
@@ -71,4 +71,3 @@ namespace ServiceLib.Common
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ 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";
|
||||
@@ -11,7 +11,7 @@ namespace ServiceLib.Common
|
||||
#region YAML
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化成对象
|
||||
/// Deserialize
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="str"></param>
|
||||
@@ -34,7 +34,7 @@ namespace ServiceLib.Common
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 序列化
|
||||
/// Serialize
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
@@ -77,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,
|
||||
@@ -20,6 +20,7 @@
|
||||
BrowseServer,
|
||||
ImportRulesFromFile,
|
||||
InitSettingFont,
|
||||
PasswordInput,
|
||||
SubEditWindow,
|
||||
RoutingRuleSettingWindow,
|
||||
RoutingRuleDetailsWindow,
|
||||
@@ -43,4 +44,3 @@
|
||||
DispatcherCheckUpdateFinished,
|
||||
DispatcherShowMsg,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib
|
||||
{
|
||||
namespace ServiceLib;
|
||||
|
||||
public class Global
|
||||
{
|
||||
#region const
|
||||
@@ -8,9 +8,7 @@ namespace ServiceLib
|
||||
public const string GithubUrl = "https://github.com";
|
||||
public const string GithubApiUrl = "https://api.github.com/repos";
|
||||
public const string GeoUrl = "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/{0}.dat";
|
||||
public const string SpeedPingTestUrl = @"https://www.google.com/generate_204";
|
||||
public const string SingboxRulesetUrl = @"https://raw.githubusercontent.com/2dust/sing-box-rules/rule-set-{0}/{1}.srs";
|
||||
public const string IPAPIUrl = "https://api.ip.sb/geoip";
|
||||
|
||||
public const string PromotionUrl = @"aHR0cHM6Ly85LjIzNDQ1Ni54eXovYWJjLmh0bWw=";
|
||||
public const string ConfigFileName = "guiNConfig.json";
|
||||
@@ -72,6 +70,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";
|
||||
|
||||
@@ -124,7 +123,7 @@ namespace ServiceLib
|
||||
[
|
||||
"",
|
||||
@"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/{0}.dat",
|
||||
@"https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/{0}.dat"
|
||||
@"https://github.com/Chocolate4U/Iran-v2ray-rules/releases/latest/download/{0}.dat"
|
||||
];
|
||||
|
||||
public static readonly List<string> SingboxRulesetSources =
|
||||
@@ -518,6 +517,15 @@ namespace ServiceLib
|
||||
@"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb"
|
||||
];
|
||||
|
||||
public static readonly List<string> IPAPIUrls =
|
||||
[
|
||||
@"https://speed.cloudflare.com/meta",
|
||||
@"https://api.ip.sb/geoip",
|
||||
@"https://api-ipv4.ip.sb/geoip",
|
||||
@"https://api-ipv6.ip.sb/geoip",
|
||||
@"https://api.ipapi.is",
|
||||
@""
|
||||
];
|
||||
|
||||
#endregion const
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public sealed class AppHandler
|
||||
{
|
||||
#region Property
|
||||
@@ -9,7 +9,6 @@ namespace ServiceLib.Handler
|
||||
private int? _statePort;
|
||||
private int? _statePort2;
|
||||
private Job? _processJob;
|
||||
private bool? _isAdministrator;
|
||||
public static AppHandler Instance => _instance.Value;
|
||||
public Config Config => _config;
|
||||
|
||||
@@ -31,14 +30,7 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAdministrator
|
||||
{
|
||||
get
|
||||
{
|
||||
_isAdministrator ??= Utils.IsAdministrator();
|
||||
return _isAdministrator.Value;
|
||||
}
|
||||
}
|
||||
public string LinuxSudoPwd { get; set; }
|
||||
|
||||
#endregion Property
|
||||
|
||||
@@ -80,6 +72,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;
|
||||
}
|
||||
|
||||
@@ -241,4 +237,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";
|
||||
@@ -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());
|
||||
@@ -185,4 +185,3 @@ namespace ServiceLib.Handler
|
||||
return $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort2}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using System.Data;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
/// <summary>
|
||||
/// 本软件配置文件处理类
|
||||
/// </summary>
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public class ConfigHandler
|
||||
{
|
||||
private static readonly string _configRes = Global.ConfigFileName;
|
||||
@@ -14,10 +11,12 @@ namespace ServiceLib.Handler
|
||||
#region ConfigHandler
|
||||
|
||||
/// <summary>
|
||||
/// 载入配置文件
|
||||
/// Load the application configuration file
|
||||
/// If the file exists, deserialize it from JSON
|
||||
/// If not found, create a new Config object with default settings
|
||||
/// Initialize default values for missing configuration sections
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns>Config object containing application settings or null if there's an error</returns>
|
||||
public static Config? LoadConfig()
|
||||
{
|
||||
Config? config = null;
|
||||
@@ -123,7 +122,7 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
if (config.SpeedTestItem.SpeedPingTestUrl.IsNullOrEmpty())
|
||||
{
|
||||
config.SpeedTestItem.SpeedPingTestUrl = Global.SpeedPingTestUrl;
|
||||
config.SpeedTestItem.SpeedPingTestUrl = Global.SpeedPingTestUrls.First();
|
||||
}
|
||||
if (config.SpeedTestItem.MixedConcurrencyCount < 1)
|
||||
{
|
||||
@@ -169,10 +168,11 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保参数
|
||||
/// Save the configuration to a file
|
||||
/// First writes to a temporary file, then replaces the original file
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Configuration object to be saved</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> SaveConfig(Config config)
|
||||
{
|
||||
try
|
||||
@@ -204,6 +204,13 @@ namespace ServiceLib.Handler
|
||||
|
||||
#region Server
|
||||
|
||||
/// <summary>
|
||||
/// Add a server profile to the configuration
|
||||
/// Dispatches the request to the appropriate method based on the config type
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">Server profile to add</param>
|
||||
/// <returns>Result of the operation (0 if successful, -1 if failed)</returns>
|
||||
public static async Task<int> AddServer(Config config, ProfileItem profileItem)
|
||||
{
|
||||
var item = await AppHandler.Instance.GetProfileItem(profileItem.IndexId);
|
||||
@@ -258,11 +265,13 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Add or edit a VMess server
|
||||
/// Validates and processes VMess-specific settings
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">VMess profile to add</param>
|
||||
/// <param name="toFile">Whether to save to file</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddVMessServer(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigType = EConfigType.VMess;
|
||||
@@ -291,11 +300,11 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除服务器
|
||||
/// Remove multiple servers from the configuration
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="indexes"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="indexes">List of server profiles to remove</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> RemoveServers(Config config, List<ProfileItem> indexes)
|
||||
{
|
||||
var subid = "TempRemoveSubId";
|
||||
@@ -311,11 +320,12 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 克隆服务器
|
||||
/// Clone server profiles
|
||||
/// Creates copies of the specified server profiles with "-clone" appended to the remarks
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="indexes">List of server profiles to clone</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> CopyServer(Config config, List<ProfileItem> indexes)
|
||||
{
|
||||
foreach (var it in indexes)
|
||||
@@ -347,11 +357,12 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置活动服务器
|
||||
/// Set the default server by its index ID
|
||||
/// Updates the configuration to use the specified server as default
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="indexId">Index ID of the server to set as default</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> SetDefaultServerIndex(Config config, string? indexId)
|
||||
{
|
||||
if (indexId.IsNullOrEmpty())
|
||||
@@ -366,6 +377,13 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a default server from the provided list of profiles
|
||||
/// Ensures there's always a valid default server selected
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="lstProfile">List of profile models to choose from</param>
|
||||
/// <returns>Result of SetDefaultServerIndex operation</returns>
|
||||
public static async Task<int> SetDefaultServer(Config config, List<ProfileItemModel> lstProfile)
|
||||
{
|
||||
if (lstProfile.Exists(t => t.IndexId == config.IndexId))
|
||||
@@ -386,6 +404,12 @@ namespace ServiceLib.Handler
|
||||
return await SetDefaultServerIndex(config, item?.IndexId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current default server profile
|
||||
/// If the current default is invalid, selects a new default
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <returns>The default profile item or null if none exists</returns>
|
||||
public static async Task<ProfileItem?> GetDefaultServer(Config config)
|
||||
{
|
||||
var item = await AppHandler.Instance.GetProfileItem(config.IndexId);
|
||||
@@ -400,13 +424,15 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移动服务器
|
||||
/// Move a server in the list to a different position
|
||||
/// Supports moving to top, up, down, bottom or specific position
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="lstProfile"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="eMove"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="lstProfile">List of server profiles</param>
|
||||
/// <param name="index">Index of the server to move</param>
|
||||
/// <param name="eMove">Direction to move the server</param>
|
||||
/// <param name="pos">Target position when using EMove.Position</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> MoveServer(Config config, List<ProfileItem> lstProfile, int index, EMove eMove, int pos = -1)
|
||||
{
|
||||
int count = lstProfile.Count;
|
||||
@@ -474,11 +500,13 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加自定义服务器
|
||||
/// Add a custom server configuration from a file
|
||||
/// Copies the configuration file to the app's config directory
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">Profile item with the file path in Address</param>
|
||||
/// <param name="blDelete">Whether to delete the source file after copying</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddCustomServer(Config config, ProfileItem profileItem, bool blDelete)
|
||||
{
|
||||
var fileName = profileItem.Address;
|
||||
@@ -517,11 +545,12 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Edit an existing custom server configuration
|
||||
/// Updates the server's properties without changing the file
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">Profile item with updated properties</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> EditCustomServer(Config config, ProfileItem profileItem)
|
||||
{
|
||||
var item = await AppHandler.Instance.GetProfileItem(profileItem.IndexId);
|
||||
@@ -551,11 +580,13 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Add or edit a Shadowsocks server
|
||||
/// Validates and processes Shadowsocks-specific settings
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">Shadowsocks profile to add</param>
|
||||
/// <param name="toFile">Whether to save to file</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddShadowsocksServer(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigType = EConfigType.Shadowsocks;
|
||||
@@ -579,11 +610,13 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Add or edit a SOCKS server
|
||||
/// Processes SOCKS-specific settings
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">SOCKS profile to add</param>
|
||||
/// <param name="toFile">Whether to save to file</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddSocksServer(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigType = EConfigType.SOCKS;
|
||||
@@ -596,11 +629,13 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Add or edit an HTTP server
|
||||
/// Processes HTTP-specific settings
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">HTTP profile to add</param>
|
||||
/// <param name="toFile">Whether to save to file</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddHttpServer(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigType = EConfigType.HTTP;
|
||||
@@ -613,11 +648,13 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Add or edit a Trojan server
|
||||
/// Validates and processes Trojan-specific settings
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">Trojan profile to add</param>
|
||||
/// <param name="toFile">Whether to save to file</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddTrojanServer(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigType = EConfigType.Trojan;
|
||||
@@ -639,11 +676,14 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Add or edit a Hysteria2 server
|
||||
/// Validates and processes Hysteria2-specific settings
|
||||
/// Sets the core type to sing_box as required by Hysteria2
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">Hysteria2 profile to add</param>
|
||||
/// <param name="toFile">Whether to save to file</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddHysteria2Server(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigType = EConfigType.Hysteria2;
|
||||
@@ -669,11 +709,14 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Add or edit a TUIC server
|
||||
/// Validates and processes TUIC-specific settings
|
||||
/// Sets the core type to sing_box as required by TUIC
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">TUIC profile to add</param>
|
||||
/// <param name="toFile">Whether to save to file</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddTuicServer(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigType = EConfigType.TUIC;
|
||||
@@ -708,15 +751,16 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Add or edit a WireGuard server
|
||||
/// Validates and processes WireGuard-specific settings
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">WireGuard profile to add</param>
|
||||
/// <param name="toFile">Whether to save to file</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddWireguardServer(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigType = EConfigType.WireGuard;
|
||||
profileItem.CoreType = ECoreType.sing_box;
|
||||
|
||||
profileItem.Address = profileItem.Address.TrimEx();
|
||||
profileItem.Id = profileItem.Id.TrimEx();
|
||||
@@ -739,6 +783,15 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sort the server list by the specified column
|
||||
/// Updates the sort order in the profile extension data
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="subId">Subscription ID to filter servers</param>
|
||||
/// <param name="colName">Column name to sort by</param>
|
||||
/// <param name="asc">Sort in ascending order if true, descending if false</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> SortServers(Config config, string subId, string colName, bool asc)
|
||||
{
|
||||
var lstModel = await AppHandler.Instance.ProfileItems(subId, "");
|
||||
@@ -746,8 +799,11 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var lstServerStat = (config.GuiItem.EnableStatistics ? StatisticsHandler.Instance.ServerStat : null) ?? [];
|
||||
var lstProfileExs = await ProfileExHandler.Instance.GetProfileExs();
|
||||
var lstProfile = (from t in lstModel
|
||||
join t2 in lstServerStat on t.IndexId equals t2.IndexId into t2b
|
||||
from t22 in t2b.DefaultIfEmpty()
|
||||
join t3 in lstProfileExs on t.IndexId equals t3.IndexId into t3b
|
||||
from t33 in t3b.DefaultIfEmpty()
|
||||
select new ProfileItemModel
|
||||
@@ -762,7 +818,11 @@ namespace ServiceLib.Handler
|
||||
StreamSecurity = t.StreamSecurity,
|
||||
Delay = t33?.Delay ?? 0,
|
||||
Speed = t33?.Speed ?? 0,
|
||||
Sort = t33?.Sort ?? 0
|
||||
Sort = t33?.Sort ?? 0,
|
||||
TodayDown = (t22?.TodayDown ?? 0).ToString("D16"),
|
||||
TodayUp = (t22?.TodayUp ?? 0).ToString("D16"),
|
||||
TotalDown = (t22?.TotalDown ?? 0).ToString("D16"),
|
||||
TotalUp = (t22?.TotalUp ?? 0).ToString("D16"),
|
||||
}).ToList();
|
||||
|
||||
Enum.TryParse(colName, true, out EServerColName name);
|
||||
@@ -780,6 +840,10 @@ namespace ServiceLib.Handler
|
||||
EServerColName.DelayVal => lstProfile.OrderBy(t => t.Delay).ToList(),
|
||||
EServerColName.SpeedVal => lstProfile.OrderBy(t => t.Speed).ToList(),
|
||||
EServerColName.SubRemarks => lstProfile.OrderBy(t => t.Subid).ToList(),
|
||||
EServerColName.TodayDown => lstProfile.OrderBy(t => t.TodayDown).ToList(),
|
||||
EServerColName.TodayUp => lstProfile.OrderBy(t => t.TodayUp).ToList(),
|
||||
EServerColName.TotalDown => lstProfile.OrderBy(t => t.TotalDown).ToList(),
|
||||
EServerColName.TotalUp => lstProfile.OrderBy(t => t.TotalUp).ToList(),
|
||||
_ => lstProfile
|
||||
};
|
||||
}
|
||||
@@ -796,6 +860,10 @@ namespace ServiceLib.Handler
|
||||
EServerColName.DelayVal => lstProfile.OrderByDescending(t => t.Delay).ToList(),
|
||||
EServerColName.SpeedVal => lstProfile.OrderByDescending(t => t.Speed).ToList(),
|
||||
EServerColName.SubRemarks => lstProfile.OrderByDescending(t => t.Subid).ToList(),
|
||||
EServerColName.TodayDown => lstProfile.OrderByDescending(t => t.TodayDown).ToList(),
|
||||
EServerColName.TodayUp => lstProfile.OrderByDescending(t => t.TodayUp).ToList(),
|
||||
EServerColName.TotalDown => lstProfile.OrderByDescending(t => t.TotalDown).ToList(),
|
||||
EServerColName.TotalUp => lstProfile.OrderByDescending(t => t.TotalUp).ToList(),
|
||||
_ => lstProfile
|
||||
};
|
||||
}
|
||||
@@ -832,11 +900,13 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or edit server
|
||||
/// Add or edit a VLESS server
|
||||
/// Validates and processes VLESS-specific settings
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="profileItem"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">VLESS profile to add</param>
|
||||
/// <param name="toFile">Whether to save to file</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddVlessServer(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigType = EConfigType.VLESS;
|
||||
@@ -868,6 +938,13 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove duplicate servers from a subscription
|
||||
/// Compares servers based on their properties rather than just names
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="subId">Subscription ID to deduplicate</param>
|
||||
/// <returns>Tuple with total count and remaining count after deduplication</returns>
|
||||
public static async Task<Tuple<int, int>> DedupServerList(Config config, string subId)
|
||||
{
|
||||
var lstProfile = await AppHandler.Instance.ProfileItems(subId);
|
||||
@@ -899,6 +976,14 @@ namespace ServiceLib.Handler
|
||||
return new Tuple<int, int>(lstProfile.Count, lstKeep.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Common server addition logic used by all server types
|
||||
/// Sets common properties and handles sorting and persistence
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="profileItem">Profile item to add</param>
|
||||
/// <param name="toFile">Whether to save to database</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> AddServerCommon(Config config, ProfileItem profileItem, bool toFile = true)
|
||||
{
|
||||
profileItem.ConfigVersion = 2;
|
||||
@@ -950,6 +1035,14 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compare two profile items to determine if they represent the same server
|
||||
/// Used for deduplication and server matching
|
||||
/// </summary>
|
||||
/// <param name="o">First profile item</param>
|
||||
/// <param name="n">Second profile item</param>
|
||||
/// <param name="remarks">Whether to compare remarks</param>
|
||||
/// <returns>True if the profiles match, false otherwise</returns>
|
||||
private static bool CompareProfileItem(ProfileItem? o, ProfileItem? n, bool remarks)
|
||||
{
|
||||
if (o == null || n == null)
|
||||
@@ -981,6 +1074,13 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a single server profile by its index ID
|
||||
/// Deletes the configuration file if it's a custom config
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="indexId">Index ID of the profile to remove</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
private static async Task<int> RemoveProfileItem(Config config, string indexId)
|
||||
{
|
||||
try
|
||||
@@ -1005,12 +1105,21 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static async Task<RetResult> AddCustomServer4Multiple(Config config, List<ProfileItem> selecteds, ECoreType coreType)
|
||||
/// <summary>
|
||||
/// Create a custom server that combines multiple servers for load balancing
|
||||
/// Generates a configuration file that references multiple servers
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="selecteds">Selected servers to combine</param>
|
||||
/// <param name="coreType">Core type to use (Xray or sing_box)</param>
|
||||
/// <param name="multipleLoad">Load balancing algorithm</param>
|
||||
/// <returns>Result object with success state and data</returns>
|
||||
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;
|
||||
@@ -1023,7 +1132,21 @@ namespace ServiceLib.Handler
|
||||
|
||||
var profileItem = await AppHandler.Instance.GetProfileItem(indexId) ?? new();
|
||||
profileItem.IndexId = indexId;
|
||||
profileItem.Remarks = coreType == ECoreType.sing_box ? ResUI.menuSetDefaultMultipleServer : ResUI.menuSetDefaultLoadBalanceServer;
|
||||
if (coreType == ECoreType.Xray)
|
||||
{
|
||||
profileItem.Remarks = multipleLoad switch
|
||||
{
|
||||
EMultipleLoad.Random => ResUI.menuSetDefaultMultipleServerXrayRandom,
|
||||
EMultipleLoad.RoundRobin => ResUI.menuSetDefaultMultipleServerXrayRoundRobin,
|
||||
EMultipleLoad.LeastPing => ResUI.menuSetDefaultMultipleServerXrayLeastPing,
|
||||
EMultipleLoad.LeastLoad => ResUI.menuSetDefaultMultipleServerXrayLeastLoad,
|
||||
_ => ResUI.menuSetDefaultMultipleServerXrayRoundRobin,
|
||||
};
|
||||
}
|
||||
else if (coreType == ECoreType.sing_box)
|
||||
{
|
||||
profileItem.Remarks = ResUI.menuSetDefaultMultipleServerSingBoxLeastPing;
|
||||
}
|
||||
profileItem.Address = Global.CoreMultipleLoadConfigFileName;
|
||||
profileItem.ConfigType = EConfigType.Custom;
|
||||
profileItem.CoreType = coreType;
|
||||
@@ -1034,6 +1157,14 @@ namespace ServiceLib.Handler
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a SOCKS server profile for pre-SOCKS functionality
|
||||
/// Used when TUN mode is enabled or when a custom config has a pre-SOCKS port
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="node">Server node that might need pre-SOCKS</param>
|
||||
/// <param name="coreType">Core type being used</param>
|
||||
/// <returns>A SOCKS profile item or null if not needed</returns>
|
||||
public static async Task<ProfileItem?> GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType)
|
||||
{
|
||||
ProfileItem? itemSocks = null;
|
||||
@@ -1063,6 +1194,13 @@ namespace ServiceLib.Handler
|
||||
return itemSocks;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove servers with invalid test results (timeout)
|
||||
/// Useful for cleaning up subscription lists
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="subid">Subscription ID to filter servers</param>
|
||||
/// <returns>Number of removed servers or -1 if failed</returns>
|
||||
public static async Task<int> RemoveInvalidServerResult(Config config, string subid)
|
||||
{
|
||||
var lstModel = await AppHandler.Instance.ProfileItems(subid, "");
|
||||
@@ -1086,12 +1224,14 @@ namespace ServiceLib.Handler
|
||||
#region Batch add servers
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加服务器
|
||||
/// Add multiple servers from string data (common protocols)
|
||||
/// Parses the string data into server profiles
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="strData"></param>
|
||||
/// <param name="subid"></param>
|
||||
/// <returns>成功导入的数量</returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="strData">String data containing server information</param>
|
||||
/// <param name="subid">Subscription ID to associate with the servers</param>
|
||||
/// <param name="isSub">Whether this is from a subscription</param>
|
||||
/// <returns>Number of successfully imported servers or -1 if failed</returns>
|
||||
private static async Task<int> AddBatchServersCommon(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
@@ -1171,6 +1311,15 @@ namespace ServiceLib.Handler
|
||||
return countServers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add servers from custom configuration formats (sing-box, v2ray, etc.)
|
||||
/// Handles various configuration formats and imports them as custom configs
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="strData">String data containing server information</param>
|
||||
/// <param name="subid">Subscription ID to associate with the servers</param>
|
||||
/// <param name="isSub">Whether this is from a subscription</param>
|
||||
/// <returns>Number of successfully imported servers or -1 if failed</returns>
|
||||
private static async Task<int> AddBatchServers4Custom(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
@@ -1269,6 +1418,15 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Shadowsocks servers from SIP008 format
|
||||
/// SIP008 is a JSON-based format for Shadowsocks servers
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="strData">String data in SIP008 format</param>
|
||||
/// <param name="subid">Subscription ID to associate with the servers</param>
|
||||
/// <param name="isSub">Whether this is from a subscription</param>
|
||||
/// <returns>Number of successfully imported servers or -1 if failed</returns>
|
||||
private static async Task<int> AddBatchServers4SsSIP008(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
@@ -1301,6 +1459,15 @@ namespace ServiceLib.Handler
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main entry point for adding batch servers from various formats
|
||||
/// Tries different parsing methods to import as many servers as possible
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="strData">String data containing server information</param>
|
||||
/// <param name="subid">Subscription ID to associate with the servers</param>
|
||||
/// <param name="isSub">Whether this is from a subscription</param>
|
||||
/// <returns>Number of successfully imported servers or -1 if failed</returns>
|
||||
public static async Task<int> AddBatchServers(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
@@ -1373,11 +1540,12 @@ namespace ServiceLib.Handler
|
||||
#region Sub & Group
|
||||
|
||||
/// <summary>
|
||||
/// add sub
|
||||
/// Add a subscription item from URL
|
||||
/// Creates a new subscription with default settings
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="url">Subscription URL</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddSubItem(Config config, string url)
|
||||
{
|
||||
//already exists
|
||||
@@ -1409,6 +1577,12 @@ namespace ServiceLib.Handler
|
||||
return await AddSubItem(config, subItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or update a subscription item
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="subItem">Subscription item to add or update</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddSubItem(Config config, SubItem subItem)
|
||||
{
|
||||
var item = await AppHandler.Instance.GetSubItem(subItem.Id);
|
||||
@@ -1460,11 +1634,12 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除服务器
|
||||
/// Remove servers associated with a subscription ID
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="subid"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="subid">Subscription ID</param>
|
||||
/// <param name="isSub">Whether to only remove servers marked as subscription items</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> RemoveServersViaSubid(Config config, string subid, bool isSub)
|
||||
{
|
||||
if (subid.IsNullOrEmpty())
|
||||
@@ -1488,6 +1663,12 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a subscription item and all its associated servers
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="id">Subscription ID to delete</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> DeleteSubItem(Config config, string id)
|
||||
{
|
||||
var item = await AppHandler.Instance.GetSubItem(id);
|
||||
@@ -1501,6 +1682,13 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move servers to a different group (subscription)
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="lstProfile">List of profiles to move</param>
|
||||
/// <param name="subid">Target subscription ID</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> MoveToGroup(Config config, List<ProfileItem> lstProfile, string subid)
|
||||
{
|
||||
foreach (var item in lstProfile)
|
||||
@@ -1516,6 +1704,12 @@ namespace ServiceLib.Handler
|
||||
|
||||
#region Routing
|
||||
|
||||
/// <summary>
|
||||
/// Save a routing item to the database
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="item">Routing item to save</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> SaveRoutingItem(Config config, RoutingItem item)
|
||||
{
|
||||
if (item.Id.IsNullOrEmpty())
|
||||
@@ -1534,11 +1728,11 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddBatchRoutingRules
|
||||
/// Add multiple routing rules to a routing item
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="strData"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="routingItem">Routing item to add rules to</param>
|
||||
/// <param name="strData">JSON string containing rules data</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> AddBatchRoutingRules(RoutingItem routingItem, string strData)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
@@ -1575,12 +1769,14 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MoveRoutingRule
|
||||
/// Move a routing rule within a rules list
|
||||
/// Supports moving to top, up, down, bottom or specific position
|
||||
/// </summary>
|
||||
/// <param name="routingItem"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="eMove"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="rules">List of routing rules</param>
|
||||
/// <param name="index">Index of the rule to move</param>
|
||||
/// <param name="eMove">Direction to move the rule</param>
|
||||
/// <param name="pos">Target position when using EMove.Position</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> MoveRoutingRule(List<RulesItem> rules, int index, EMove eMove, int pos = -1)
|
||||
{
|
||||
int count = rules.Count;
|
||||
@@ -1651,6 +1847,12 @@ namespace ServiceLib.Handler
|
||||
return await Task.FromResult(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the default routing configuration
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="routingItem">Routing item to set as default</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> SetDefaultRouting(Config config, RoutingItem routingItem)
|
||||
{
|
||||
if (await SQLiteHelper.Instance.TableAsync<RoutingItem>().Where(t => t.Id == routingItem.Id).CountAsync() > 0)
|
||||
@@ -1663,6 +1865,12 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current default routing configuration
|
||||
/// If no default is set, selects the first available routing item
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <returns>The default routing item</returns>
|
||||
public static async Task<RoutingItem> GetDefaultRouting(Config config)
|
||||
{
|
||||
var item = await AppHandler.Instance.GetRoutingItem(config.RoutingBasicItem.RoutingIndexId);
|
||||
@@ -1676,6 +1884,12 @@ namespace ServiceLib.Handler
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize routing rules from built-in or external templates
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="blImportAdvancedRules">Whether to import advanced rules</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> InitRouting(Config config, bool blImportAdvancedRules = false)
|
||||
{
|
||||
if (config.ConstItem.RouteRulesTemplateSourceUrl.IsNullOrEmpty())
|
||||
@@ -1690,6 +1904,13 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize routing rules from external templates
|
||||
/// Downloads and processes routing templates from a URL
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="blImportAdvancedRules">Whether to import advanced rules</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> InitExternalRouting(Config config, bool blImportAdvancedRules = false)
|
||||
{
|
||||
var downloadHandle = new DownloadService();
|
||||
@@ -1738,6 +1959,13 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize built-in routing rules
|
||||
/// Creates default routing configurations (whitelist, blacklist, global)
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="blImportAdvancedRules">Whether to import advanced rules</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> InitBuiltinRouting(Config config, bool blImportAdvancedRules = false)
|
||||
{
|
||||
var ver = "V3-";
|
||||
@@ -1791,6 +2019,10 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a routing item from the database
|
||||
/// </summary>
|
||||
/// <param name="routingItem">Routing item to remove</param>
|
||||
public static async Task RemoveRoutingItem(RoutingItem routingItem)
|
||||
{
|
||||
await SQLiteHelper.Instance.DeleteAsync(routingItem);
|
||||
@@ -1800,6 +2032,12 @@ namespace ServiceLib.Handler
|
||||
|
||||
#region DNS
|
||||
|
||||
/// <summary>
|
||||
/// Initialize built-in DNS configurations
|
||||
/// Creates default DNS items for V2Ray and sing-box
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <returns>0 if successful</returns>
|
||||
public static async Task<int> InitBuiltinDNS(Config config)
|
||||
{
|
||||
var items = await AppHandler.Instance.DNSItems();
|
||||
@@ -1823,6 +2061,12 @@ namespace ServiceLib.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save a DNS item to the database
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="item">DNS item to save</param>
|
||||
/// <returns>0 if successful, -1 if failed</returns>
|
||||
public static async Task<int> SaveDNSItems(Config config, DNSItem item)
|
||||
{
|
||||
if (item == null)
|
||||
@@ -1845,6 +2089,13 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an external DNS configuration from URL
|
||||
/// Downloads and processes DNS templates
|
||||
/// </summary>
|
||||
/// <param name="type">Core type (Xray or sing-box)</param>
|
||||
/// <param name="url">URL of the DNS template</param>
|
||||
/// <returns>DNS item with configuration from the URL</returns>
|
||||
public static async Task<DNSItem> GetExternalDNSItem(ECoreType type, string url)
|
||||
{
|
||||
var currentItem = await AppHandler.Instance.GetDNSItem(type);
|
||||
@@ -1876,6 +2127,13 @@ namespace ServiceLib.Handler
|
||||
|
||||
#region Regional Presets
|
||||
|
||||
/// <summary>
|
||||
/// Apply regional presets for geo-specific configurations
|
||||
/// Sets up geo files, routing rules, and DNS for specific regions
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
/// <param name="type">Type of preset (Default, Russia, Iran)</param>
|
||||
/// <returns>True if successful</returns>
|
||||
public static async Task<bool> ApplyRegionalPreset(Config config, EPresetType type)
|
||||
{
|
||||
switch (type)
|
||||
@@ -1916,4 +2174,3 @@ namespace ServiceLib.Handler
|
||||
|
||||
#endregion Regional Presets
|
||||
}
|
||||
}
|
||||
|
||||
42
v2rayN/ServiceLib/Handler/ConnectionHandler.cs
Normal file
42
v2rayN/ServiceLib/Handler/ConnectionHandler.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public class ConnectionHandler
|
||||
{
|
||||
private static readonly Lazy<ConnectionHandler> _instance = new(() => new());
|
||||
public static ConnectionHandler Instance => _instance.Value;
|
||||
|
||||
public async Task<string> RunAvailabilityCheck()
|
||||
{
|
||||
var downloadHandle = new DownloadService();
|
||||
var time = await downloadHandle.RunAvailabilityCheck(null);
|
||||
var ip = time > 0 ? await GetIPInfo(downloadHandle) ?? Global.None : Global.None;
|
||||
|
||||
return string.Format(ResUI.TestMeOutput, time, ip);
|
||||
}
|
||||
|
||||
private async Task<string?> GetIPInfo(DownloadService downloadHandle)
|
||||
{
|
||||
var url = AppHandler.Instance.Config.SpeedTestItem.IPAPIUrl;
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var result = await downloadHandle.TryDownloadString(url, true, "");
|
||||
if (result == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var ipInfo = JsonUtils.Deserialize<IPAPIInfo>(result);
|
||||
if (ipInfo == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var ip = ipInfo.ip ?? ipInfo.clientIp ?? ipInfo.ip_addr ?? ipInfo.query;
|
||||
var country = ipInfo.country_code ?? ipInfo.country ?? ipInfo.countryCode ?? ipInfo.location?.country_code;
|
||||
|
||||
return $"({country ?? "unknown"}) {ip}";
|
||||
}
|
||||
}
|
||||
126
v2rayN/ServiceLib/Handler/CoreAdminHandler.cs
Normal file
126
v2rayN/ServiceLib/Handler/CoreAdminHandler.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using CliWrap;
|
||||
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public class CoreAdminHandler
|
||||
{
|
||||
private static readonly Lazy<CoreAdminHandler> _instance = new(() => new());
|
||||
public static CoreAdminHandler Instance => _instance.Value;
|
||||
private Config _config;
|
||||
private Action<bool, string>? _updateFunc;
|
||||
private int _linuxSudoPid = -1;
|
||||
|
||||
public async Task Init(Config config, Action<bool, string> updateFunc)
|
||||
{
|
||||
if (_config != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_config = config;
|
||||
_updateFunc = updateFunc;
|
||||
}
|
||||
|
||||
private void UpdateFunc(bool notify, string msg)
|
||||
{
|
||||
_updateFunc?.Invoke(notify, msg);
|
||||
}
|
||||
|
||||
public async Task<Process?> RunProcessAsLinuxSudo(string fileName, CoreInfo coreInfo, string configPath)
|
||||
{
|
||||
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath).AppendQuotes())}";
|
||||
var shFilePath = await CreateLinuxShellFile(cmdLine, "run_as_sudo.sh");
|
||||
|
||||
Process proc = new()
|
||||
{
|
||||
StartInfo = new()
|
||||
{
|
||||
FileName = shFilePath,
|
||||
Arguments = "",
|
||||
WorkingDirectory = Utils.GetBinConfigPath(),
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true,
|
||||
StandardInputEncoding = Encoding.UTF8,
|
||||
StandardOutputEncoding = Encoding.UTF8,
|
||||
StandardErrorEncoding = Encoding.UTF8,
|
||||
}
|
||||
};
|
||||
|
||||
proc.OutputDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data.IsNotEmpty())
|
||||
{
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
}
|
||||
};
|
||||
proc.ErrorDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data.IsNotEmpty())
|
||||
{
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
}
|
||||
};
|
||||
|
||||
proc.Start();
|
||||
proc.BeginOutputReadLine();
|
||||
proc.BeginErrorReadLine();
|
||||
|
||||
await Task.Delay(10);
|
||||
await proc.StandardInput.WriteLineAsync();
|
||||
await Task.Delay(10);
|
||||
await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd);
|
||||
|
||||
await Task.Delay(100);
|
||||
if (proc is null or { HasExited: true })
|
||||
{
|
||||
throw new Exception(ResUI.FailedToRunCore);
|
||||
}
|
||||
|
||||
_linuxSudoPid = proc.Id;
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
public async Task KillProcessAsLinuxSudo()
|
||||
{
|
||||
if (_linuxSudoPid < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var cmdLine = $"pkill -P {_linuxSudoPid} ; kill {_linuxSudoPid}";
|
||||
var shFilePath = await CreateLinuxShellFile(cmdLine, "kill_as_sudo.sh");
|
||||
|
||||
await Cli.Wrap(shFilePath)
|
||||
.WithStandardInputPipe(PipeSource.FromString(AppHandler.Instance.LinuxSudoPwd))
|
||||
.ExecuteAsync();
|
||||
|
||||
_linuxSudoPid = -1;
|
||||
}
|
||||
|
||||
private async Task<string> CreateLinuxShellFile(string cmdLine, string fileName)
|
||||
{
|
||||
var shFilePath = Utils.GetBinConfigPath(fileName);
|
||||
File.Delete(shFilePath);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("#!/bin/sh");
|
||||
if (Utils.IsAdministrator())
|
||||
{
|
||||
sb.AppendLine($"{cmdLine}");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($"sudo -S {cmdLine}");
|
||||
}
|
||||
|
||||
await File.WriteAllTextAsync(shFilePath, sb.ToString());
|
||||
await Utils.SetLinuxChmod(shFilePath);
|
||||
|
||||
return shFilePath;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
/// <summary>
|
||||
/// Core configuration file processing class
|
||||
/// </summary>
|
||||
@@ -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>
|
||||
@@ -13,7 +13,7 @@ namespace ServiceLib.Handler
|
||||
private Config _config;
|
||||
private Process? _process;
|
||||
private Process? _processPre;
|
||||
private int _linuxSudoPid = -1;
|
||||
private bool _linuxSudo = false;
|
||||
private Action<bool, string>? _updateFunc;
|
||||
private const string _tag = "CoreHandler";
|
||||
|
||||
@@ -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")
|
||||
@@ -100,7 +101,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public async Task<int> LoadCoreConfigSpeedtest(List<ServerTestItem> selecteds)
|
||||
{
|
||||
var coreType = selecteds.Exists(t => t.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.WireGuard) ? ECoreType.sing_box : ECoreType.Xray;
|
||||
var coreType = selecteds.Exists(t => t.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC) ? ECoreType.sing_box : ECoreType.Xray;
|
||||
var fileName = string.Format(Global.CoreSpeedtestConfigFileName, Utils.GetGuid(false));
|
||||
var configPath = Utils.GetBinConfigPath(fileName);
|
||||
var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType);
|
||||
@@ -154,23 +155,23 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_linuxSudo)
|
||||
{
|
||||
await CoreAdminHandler.Instance.KillProcessAsLinuxSudo();
|
||||
_linuxSudo = false;
|
||||
}
|
||||
|
||||
if (_process != null)
|
||||
{
|
||||
await ProcUtils.ProcessKill(_process, true);
|
||||
await ProcUtils.ProcessKill(_process, Utils.IsWindows());
|
||||
_process = null;
|
||||
}
|
||||
|
||||
if (_processPre != null)
|
||||
{
|
||||
await ProcUtils.ProcessKill(_processPre, true);
|
||||
await ProcUtils.ProcessKill(_processPre, Utils.IsWindows());
|
||||
_processPre = null;
|
||||
}
|
||||
|
||||
if (_linuxSudoPid > 0)
|
||||
{
|
||||
await KillProcessAsLinuxSudo();
|
||||
}
|
||||
_linuxSudoPid = -1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -224,15 +225,6 @@ namespace ServiceLib.Handler
|
||||
_updateFunc?.Invoke(notify, msg);
|
||||
}
|
||||
|
||||
private bool IsNeedSudo(ECoreType eCoreType)
|
||||
{
|
||||
return _config.TunModeItem.EnableTun
|
||||
&& eCoreType == ECoreType.sing_box
|
||||
&& (Utils.IsNonWindows())
|
||||
//&& _config.TunModeItem.LinuxSudoPwd.IsNotEmpty()
|
||||
;
|
||||
}
|
||||
|
||||
#endregion Private
|
||||
|
||||
#region Process
|
||||
@@ -247,6 +239,28 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (mayNeedSudo
|
||||
&& _config.TunModeItem.EnableTun
|
||||
&& coreInfo.CoreType == ECoreType.sing_box
|
||||
&& Utils.IsNonWindows())
|
||||
{
|
||||
_linuxSudo = true;
|
||||
await CoreAdminHandler.Instance.Init(_config, _updateFunc);
|
||||
return await CoreAdminHandler.Instance.RunProcessAsLinuxSudo(fileName, coreInfo, configPath);
|
||||
}
|
||||
|
||||
return await RunProcessNormal(fileName, coreInfo, configPath, displayLog);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
UpdateFunc(mayNeedSudo, ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Process?> RunProcessNormal(string fileName, CoreInfo? coreInfo, string configPath, bool displayLog)
|
||||
{
|
||||
Process proc = new()
|
||||
{
|
||||
@@ -264,47 +278,32 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
};
|
||||
|
||||
var isNeedSudo = mayNeedSudo && IsNeedSudo(coreInfo.CoreType);
|
||||
if (isNeedSudo)
|
||||
{
|
||||
await RunProcessAsLinuxSudo(proc, fileName, coreInfo, configPath);
|
||||
}
|
||||
|
||||
if (displayLog)
|
||||
{
|
||||
proc.OutputDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data.IsNullOrEmpty())
|
||||
return;
|
||||
if (e.Data.IsNotEmpty())
|
||||
{
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
}
|
||||
};
|
||||
proc.ErrorDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data.IsNullOrEmpty())
|
||||
return;
|
||||
if (e.Data.IsNotEmpty())
|
||||
{
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
}
|
||||
};
|
||||
}
|
||||
proc.Start();
|
||||
|
||||
if (isNeedSudo && _config.TunModeItem.LinuxSudoPwd.IsNotEmpty())
|
||||
{
|
||||
var pwd = DesUtils.Decrypt(_config.TunModeItem.LinuxSudoPwd);
|
||||
await Task.Delay(10);
|
||||
await proc.StandardInput.WriteLineAsync(pwd);
|
||||
await Task.Delay(10);
|
||||
await proc.StandardInput.WriteLineAsync(pwd);
|
||||
}
|
||||
if (isNeedSudo)
|
||||
_linuxSudoPid = proc.Id;
|
||||
|
||||
if (displayLog)
|
||||
{
|
||||
proc.BeginOutputReadLine();
|
||||
proc.BeginErrorReadLine();
|
||||
}
|
||||
|
||||
await Task.Delay(500);
|
||||
await Task.Delay(100);
|
||||
AppHandler.Instance.AddProcess(proc.Handle);
|
||||
if (proc is null or { HasExited: true })
|
||||
{
|
||||
@@ -312,98 +311,6 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
return proc;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
UpdateFunc(mayNeedSudo, ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Process
|
||||
|
||||
#region Linux
|
||||
|
||||
private async Task RunProcessAsLinuxSudo(Process proc, string fileName, CoreInfo coreInfo, string configPath)
|
||||
{
|
||||
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath).AppendQuotes())}";
|
||||
|
||||
var shFilePath = await CreateLinuxShellFile(cmdLine, "run_as_sudo.sh");
|
||||
proc.StartInfo.FileName = shFilePath;
|
||||
proc.StartInfo.Arguments = "";
|
||||
proc.StartInfo.WorkingDirectory = "";
|
||||
if (_config.TunModeItem.LinuxSudoPwd.IsNotEmpty())
|
||||
{
|
||||
proc.StartInfo.StandardInputEncoding = Encoding.UTF8;
|
||||
proc.StartInfo.RedirectStandardInput = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task KillProcessAsLinuxSudo()
|
||||
{
|
||||
var cmdLine = $"kill {_linuxSudoPid}";
|
||||
var shFilePath = await CreateLinuxShellFile(cmdLine, "kill_as_sudo.sh");
|
||||
Process proc = new()
|
||||
{
|
||||
StartInfo = new()
|
||||
{
|
||||
FileName = shFilePath,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
StandardInputEncoding = Encoding.UTF8,
|
||||
RedirectStandardInput = true
|
||||
}
|
||||
};
|
||||
proc.Start();
|
||||
|
||||
if (_config.TunModeItem.LinuxSudoPwd.IsNotEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
var pwd = DesUtils.Decrypt(_config.TunModeItem.LinuxSudoPwd);
|
||||
await Task.Delay(10);
|
||||
await proc.StandardInput.WriteLineAsync(pwd);
|
||||
await Task.Delay(10);
|
||||
await proc.StandardInput.WriteLineAsync(pwd);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(10));
|
||||
await proc.WaitForExitAsync(timeout.Token);
|
||||
await Task.Delay(3000);
|
||||
}
|
||||
|
||||
private async Task<string> CreateLinuxShellFile(string cmdLine, string fileName)
|
||||
{
|
||||
//Shell scripts
|
||||
var shFilePath = Utils.GetBinConfigPath(AppHandler.Instance.IsAdministrator ? "root_" + fileName : fileName);
|
||||
File.Delete(shFilePath);
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("#!/bin/sh");
|
||||
if (AppHandler.Instance.IsAdministrator)
|
||||
{
|
||||
sb.AppendLine($"{cmdLine}");
|
||||
}
|
||||
else if (_config.TunModeItem.LinuxSudoPwd.IsNullOrEmpty())
|
||||
{
|
||||
sb.AppendLine($"pkexec {cmdLine}");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($"sudo -S {cmdLine}");
|
||||
}
|
||||
|
||||
await File.WriteAllTextAsync(shFilePath, sb.ToString());
|
||||
await Utils.SetLinuxChmod(shFilePath);
|
||||
Logging.SaveLog(shFilePath);
|
||||
|
||||
return shFilePath;
|
||||
}
|
||||
|
||||
#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,17 +1,20 @@
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class BaseFmt
|
||||
{
|
||||
protected static string GetIpv6(string address)
|
||||
{
|
||||
if (Utils.IsIpv6(address))
|
||||
{
|
||||
// 检查地址是否已经被方括号包围,如果没有,则添加方括号
|
||||
// Check if the address is already surrounded by square brackets, if not, add square brackets
|
||||
return address.StartsWith('[') && address.EndsWith(']') ? address : $"[{address}]";
|
||||
}
|
||||
return address; // 如果不是IPv6地址,直接返回原地址
|
||||
else
|
||||
{
|
||||
return address;
|
||||
}
|
||||
}
|
||||
|
||||
protected static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
|
||||
@@ -239,4 +242,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";
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -177,4 +177,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class SingboxFmt : BaseFmt
|
||||
{
|
||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||
@@ -45,4 +45,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return profileItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -112,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)
|
||||
@@ -45,4 +45,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
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)
|
||||
@@ -61,4 +61,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return ToUri(EConfigType.TUIC, item.Address, item.Port, $"{item.Id}:{item.Security}", dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class V2rayFmt : BaseFmt
|
||||
{
|
||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||
@@ -46,4 +46,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return profileItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -57,4 +57,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
namespace ServiceLib.Handler.Fmt;
|
||||
|
||||
public class VmessFmt : BaseFmt
|
||||
{
|
||||
public static ProfileItem? Resolve(string str, out string msg)
|
||||
{
|
||||
msg = ResUI.ConfigurationFormatIncorrect;
|
||||
ProfileItem? item;
|
||||
if (str.IndexOf('?') > 0 && str.IndexOf('&') > 0)
|
||||
if (str.IndexOf('@') > 0)
|
||||
{
|
||||
item = ResolveStdVmess(str);
|
||||
item = ResolveStdVmess(str) ?? ResolveVmess(str, out msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -123,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)
|
||||
@@ -65,4 +65,3 @@ namespace ServiceLib.Handler.Fmt
|
||||
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;
|
||||
@@ -112,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());
|
||||
@@ -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";
|
||||
@@ -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";
|
||||
@@ -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,8 +1,8 @@
|
||||
using System.Net;
|
||||
using WebDav;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public sealed class WebDavHandler
|
||||
{
|
||||
private static readonly Lazy<WebDavHandler> _instance = new(() => new());
|
||||
@@ -179,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,8 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 本软件配置文件实体类
|
||||
/// </summary>
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class Config
|
||||
{
|
||||
@@ -54,4 +51,3 @@
|
||||
|
||||
#endregion other entities
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
[Serializable]
|
||||
public class CoreBasicItem
|
||||
{
|
||||
@@ -147,7 +147,6 @@ namespace ServiceLib.Models
|
||||
public int Mtu { get; set; }
|
||||
public bool EnableExInbound { get; set; }
|
||||
public bool EnableIPv6Address { get; set; }
|
||||
public string? LinuxSudoPwd { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -157,6 +156,7 @@ namespace ServiceLib.Models
|
||||
public string SpeedTestUrl { get; set; }
|
||||
public string SpeedPingTestUrl { get; set; }
|
||||
public int MixedConcurrencyCount { get; set; }
|
||||
public string IPAPIUrl { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -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,13 +1,19 @@
|
||||
namespace ServiceLib.Models
|
||||
{
|
||||
namespace ServiceLib.Models;
|
||||
|
||||
internal class IPAPIInfo
|
||||
{
|
||||
public string? ip { get; set; }
|
||||
public string? city { get; set; }
|
||||
public string? region { get; set; }
|
||||
public string? region_code { get; set; }
|
||||
public string? clientIp { get; set; }
|
||||
public string? ip_addr { get; set; }
|
||||
public string? query { get; set; }
|
||||
public string? country { get; set; }
|
||||
public string? country_name { get; set; }
|
||||
public string? country_code { get; set; }
|
||||
public string? countryCode { get; set; }
|
||||
public LocationInfo? location { get; set; }
|
||||
}
|
||||
|
||||
public class LocationInfo
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -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