Compare commits
128 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1e6898290 | ||
|
|
8597332b21 | ||
|
|
7cc42ae249 | ||
|
|
e054d4487d | ||
|
|
6ef36f521d | ||
|
|
a02a122dd1 | ||
|
|
701138617c | ||
|
|
d0e2cc9442 | ||
|
|
d561f10edc | ||
|
|
2df412476a | ||
|
|
e6011cfede | ||
|
|
bcf43e2928 | ||
|
|
3f0f895424 | ||
|
|
07a3bdc618 | ||
|
|
7e348c196e | ||
|
|
51e5885e76 | ||
|
|
50d7912f62 | ||
|
|
3869148fc8 | ||
|
|
a0af4fb30c | ||
|
|
c374b8565b | ||
|
|
7e8b405555 | ||
|
|
c3439c5abe | ||
|
|
d4a8787356 | ||
|
|
23b27575a0 | ||
|
|
8d8a887c42 | ||
|
|
1229c967ba | ||
|
|
d35f65f86d | ||
|
|
0a8ce0f961 | ||
|
|
8092481d26 | ||
|
|
764014e49a | ||
|
|
71cc6d7a88 | ||
|
|
f3af831cf2 | ||
|
|
78fde575d7 | ||
|
|
6e5af34877 | ||
|
|
8d1853e991 | ||
|
|
859299c712 | ||
|
|
7fbb0013b0 | ||
|
|
837cfbd03b | ||
|
|
cdc5d72cfa | ||
|
|
8dcf5c5b90 | ||
|
|
67fe6ac3d8 | ||
|
|
438eaba4d5 | ||
|
|
3c8baa99d5 | ||
|
|
e70658f311 | ||
|
|
2dd10cf5a1 | ||
|
|
96781a784b | ||
|
|
9748fbb076 | ||
|
|
aa5e4378ab | ||
|
|
a7de149fd7 | ||
|
|
ae38be36f5 | ||
|
|
a20e989211 | ||
|
|
579f47ba0d | ||
|
|
24cad87954 | ||
|
|
84d72cd110 | ||
|
|
c0cd46a5aa | ||
|
|
98613c43ca | ||
|
|
555960e210 | ||
|
|
a18ae5582b | ||
|
|
6d6894591c | ||
|
|
984b97fc14 | ||
|
|
a7f35d4495 | ||
|
|
add92cfa7c | ||
|
|
6079e76be5 | ||
|
|
166c7cb2f5 | ||
|
|
dbd3ca44c2 | ||
|
|
ae495dde54 | ||
|
|
4ae25b2f34 | ||
|
|
cdfb621c59 | ||
|
|
29e8df7d2e | ||
|
|
72ff947d95 | ||
|
|
3edaac5739 | ||
|
|
5777a97119 | ||
|
|
aeddbc1dcc | ||
|
|
2f3e409487 | ||
|
|
aa133bb50b | ||
|
|
3bc79a4ba1 | ||
|
|
064a04fbad | ||
|
|
39ed13cf8a | ||
|
|
a1edacb196 | ||
|
|
c9f79e4b47 | ||
|
|
40c1498226 | ||
|
|
390061f9bd | ||
|
|
42324a2c9e | ||
|
|
b9b4ca6360 | ||
|
|
565697bc0b | ||
|
|
2e6c82c851 | ||
|
|
ee75dd37af | ||
|
|
4859dcda08 | ||
|
|
2e962e555d | ||
|
|
ab73e5acb2 | ||
|
|
4e3e5ce130 | ||
|
|
bb8eef3bf5 | ||
|
|
eee87ded29 | ||
|
|
e0f005bd96 | ||
|
|
2cacc372ad | ||
|
|
0b1b681655 | ||
|
|
deafd73306 | ||
|
|
317a5da120 | ||
|
|
071cefc511 | ||
|
|
32a5cc8aa3 | ||
|
|
c41378a085 | ||
|
|
6910e03ef4 | ||
|
|
5060a358db | ||
|
|
b3e9a957c4 | ||
|
|
f6dbfc2dac | ||
|
|
2966a34e63 | ||
|
|
50959951ae | ||
|
|
c2e1cf7bdb | ||
|
|
51ac7cc8be | ||
|
|
3144f1d1c2 | ||
|
|
a176e7b912 | ||
|
|
1198ec0f74 | ||
|
|
4104964e38 | ||
|
|
3bbd1edf06 | ||
|
|
41cc260b5c | ||
|
|
6cd5063c9b | ||
|
|
e544df6d01 | ||
|
|
f952d2383c | ||
|
|
8a29e147d3 | ||
|
|
8a19128e7f | ||
|
|
7dc9fbd8ff | ||
|
|
31a179e647 | ||
|
|
c3fdfcc4bd | ||
|
|
7ea8fae2da | ||
|
|
67ffa810d3 | ||
|
|
ba2a636dd2 | ||
|
|
d471336994 | ||
|
|
7e6482fdff |
7
.github/ISSUE_TEMPLATE/01_bug_report.yml
vendored
7
.github/ISSUE_TEMPLATE/01_bug_report.yml
vendored
@@ -3,6 +3,13 @@ description: 在提出问题前请先自行排除服务器端问题和升级到
|
|||||||
title: "[Bug]: "
|
title: "[Bug]: "
|
||||||
labels: ["bug"]
|
labels: ["bug"]
|
||||||
body:
|
body:
|
||||||
|
- type: input
|
||||||
|
id: "os-version"
|
||||||
|
attributes:
|
||||||
|
label: "操作系统和版本"
|
||||||
|
description: "操作系统和版本"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
- type: input
|
- type: input
|
||||||
id: "expectation"
|
id: "expectation"
|
||||||
attributes:
|
attributes:
|
||||||
|
|||||||
69
.github/workflows/build-all.yml
vendored
Normal file
69
.github/workflows/build-all.yml
vendored
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
name: release all platforms
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
release_tag:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Trigger build windows
|
||||||
|
if: github.event.inputs.release_tag != ''
|
||||||
|
run: |
|
||||||
|
curl -X POST \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-windows.yml/dispatches \
|
||||||
|
-d "{
|
||||||
|
\"ref\": \"master\",
|
||||||
|
\"inputs\": {
|
||||||
|
\"release_tag\": \"${{ github.event.inputs.release_tag }}\"
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
|
||||||
|
- name: Trigger build linux
|
||||||
|
if: github.event.inputs.release_tag != ''
|
||||||
|
run: |
|
||||||
|
curl -X POST \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-linux.yml/dispatches \
|
||||||
|
-d "{
|
||||||
|
\"ref\": \"master\",
|
||||||
|
\"inputs\": {
|
||||||
|
\"release_tag\": \"${{ github.event.inputs.release_tag }}\"
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
|
||||||
|
- name: Trigger build osx
|
||||||
|
if: github.event.inputs.release_tag != ''
|
||||||
|
run: |
|
||||||
|
curl -X POST \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-osx.yml/dispatches \
|
||||||
|
-d "{
|
||||||
|
\"ref\": \"master\",
|
||||||
|
\"inputs\": {
|
||||||
|
\"release_tag\": \"${{ github.event.inputs.release_tag }}\"
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
|
||||||
|
- name: Trigger build windows desktop
|
||||||
|
if: github.event.inputs.release_tag != ''
|
||||||
|
run: |
|
||||||
|
curl -X POST \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-windows-desktop.yml/dispatches \
|
||||||
|
-d "{
|
||||||
|
\"ref\": \"master\",
|
||||||
|
\"inputs\": {
|
||||||
|
\"release_tag\": \"${{ github.event.inputs.release_tag }}\"
|
||||||
|
}
|
||||||
|
}"
|
||||||
18
.github/workflows/build-linux.yml
vendored
18
.github/workflows/build-linux.yml
vendored
@@ -27,6 +27,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4.2.2
|
uses: actions/checkout@v4.2.2
|
||||||
|
with:
|
||||||
|
submodules: 'recursive'
|
||||||
|
fetch-depth: '0'
|
||||||
|
|
||||||
- name: Setup
|
- name: Setup
|
||||||
uses: actions/setup-dotnet@v4.3.0
|
uses: actions/setup-dotnet@v4.3.0
|
||||||
@@ -36,13 +39,13 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
cd v2rayN
|
cd v2rayN
|
||||||
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r linux-x64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -o $OutputPath64
|
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r linux-x64 --self-contained=true -o $OutputPath64
|
||||||
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r linux-arm64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -o $OutputPathArm64
|
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r linux-arm64 --self-contained=true -o $OutputPathArm64
|
||||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r linux-x64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=true -o $OutputPath64
|
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r linux-x64 --self-contained=true -p:PublishTrimmed=true -o $OutputPath64
|
||||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r linux-arm64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=true -o $OutputPathArm64
|
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r linux-arm64 --self-contained=true -p:PublishTrimmed=true -o $OutputPathArm64
|
||||||
|
|
||||||
- name: Upload build artifacts
|
- name: Upload build artifacts
|
||||||
uses: actions/upload-artifact@v4.6.0
|
uses: actions/upload-artifact@v4.6.1
|
||||||
with:
|
with:
|
||||||
name: v2rayN-linux
|
name: v2rayN-linux
|
||||||
path: |
|
path: |
|
||||||
@@ -68,9 +71,8 @@ jobs:
|
|||||||
- name: Package AppImage
|
- name: Package AppImage
|
||||||
if: github.event.inputs.release_tag != ''
|
if: github.event.inputs.release_tag != ''
|
||||||
run: |
|
run: |
|
||||||
chmod 755 package-appimage.sh
|
chmod a+x package-appimage.sh
|
||||||
./package-appimage.sh $OutputArch $OutputPath64 ${{ github.event.inputs.release_tag }}
|
./package-appimage.sh
|
||||||
./package-appimage.sh $OutputArchArm $OutputPathArm64 ${{ github.event.inputs.release_tag }}
|
|
||||||
|
|
||||||
- name: Upload AppImage to release
|
- name: Upload AppImage to release
|
||||||
uses: svenstaro/upload-release-action@v2
|
uses: svenstaro/upload-release-action@v2
|
||||||
|
|||||||
13
.github/workflows/build-osx.yml
vendored
13
.github/workflows/build-osx.yml
vendored
@@ -27,6 +27,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4.2.2
|
uses: actions/checkout@v4.2.2
|
||||||
|
with:
|
||||||
|
submodules: 'recursive'
|
||||||
|
fetch-depth: '0'
|
||||||
|
|
||||||
- name: Setup
|
- name: Setup
|
||||||
uses: actions/setup-dotnet@v4.3.0
|
uses: actions/setup-dotnet@v4.3.0
|
||||||
@@ -36,13 +39,13 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
cd v2rayN
|
cd v2rayN
|
||||||
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r osx-x64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -o $OutputPath64
|
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r osx-x64 --self-contained=true -o $OutputPath64
|
||||||
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r osx-arm64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -o $OutputPathArm64
|
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r osx-arm64 --self-contained=true -o $OutputPathArm64
|
||||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r osx-x64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=true -o $OutputPath64
|
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r osx-x64 --self-contained=true -p:PublishTrimmed=true -o $OutputPath64
|
||||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r osx-arm64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=true -o $OutputPathArm64
|
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r osx-arm64 --self-contained=true -p:PublishTrimmed=true -o $OutputPathArm64
|
||||||
|
|
||||||
- name: Upload build artifacts
|
- name: Upload build artifacts
|
||||||
uses: actions/upload-artifact@v4.6.0
|
uses: actions/upload-artifact@v4.6.1
|
||||||
with:
|
with:
|
||||||
name: v2rayN-macos
|
name: v2rayN-macos
|
||||||
path: |
|
path: |
|
||||||
|
|||||||
33
.github/workflows/build-windows-desktop.yml
vendored
33
.github/workflows/build-windows-desktop.yml
vendored
@@ -27,6 +27,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4.2.2
|
uses: actions/checkout@v4.2.2
|
||||||
|
with:
|
||||||
|
submodules: 'recursive'
|
||||||
|
fetch-depth: '0'
|
||||||
|
|
||||||
- name: Setup
|
- name: Setup
|
||||||
uses: actions/setup-dotnet@v4.3.0
|
uses: actions/setup-dotnet@v4.3.0
|
||||||
@@ -36,15 +39,33 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
cd v2rayN
|
cd v2rayN
|
||||||
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r win-x64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:EnableWindowsTargeting=true -o $OutputPath64
|
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r win-x64 --self-contained=true -p:EnableWindowsTargeting=true -o $OutputPath64
|
||||||
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r win-arm64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:EnableWindowsTargeting=true -o $OutputPathArm64
|
dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r win-arm64 --self-contained=true -p:EnableWindowsTargeting=true -o $OutputPathArm64
|
||||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-x64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=true -p:EnableWindowsTargeting=true -o $OutputPath64
|
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-x64 --self-contained=true -p:EnableWindowsTargeting=true -p:PublishTrimmed=true -o $OutputPath64
|
||||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-arm64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=true -p:EnableWindowsTargeting=true -o $OutputPathArm64
|
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
|
- name: Upload build artifacts
|
||||||
uses: actions/upload-artifact@v4.6.0
|
uses: actions/upload-artifact@v4.6.1
|
||||||
with:
|
with:
|
||||||
name: v2rayN-windows-desktop
|
name: v2rayN-windows-desktop
|
||||||
path: |
|
path: |
|
||||||
${{ github.workspace }}/v2rayN/Release/windows*
|
${{ github.workspace }}/v2rayN/Release/windows*
|
||||||
|
|
||||||
|
# release zip archive
|
||||||
|
- name: Package release zip archive
|
||||||
|
if: github.event.inputs.release_tag != ''
|
||||||
|
run: |
|
||||||
|
chmod 755 package-release-zip.sh
|
||||||
|
./package-release-zip.sh $OutputArch $OutputPath64
|
||||||
|
mv "v2rayN-${OutputArch}.zip" "v2rayN-${OutputArch}-desktop.zip"
|
||||||
|
./package-release-zip.sh $OutputArchArm $OutputPathArm64
|
||||||
|
mv "v2rayN-${OutputArchArm}.zip" "v2rayN-${OutputArchArm}-desktop.zip"
|
||||||
|
|
||||||
|
- name: Upload zip archive to release
|
||||||
|
uses: svenstaro/upload-release-action@v2
|
||||||
|
if: github.event.inputs.release_tag != ''
|
||||||
|
with:
|
||||||
|
file: ${{ github.workspace }}/v2rayN*.zip
|
||||||
|
tag: ${{ github.event.inputs.release_tag }}
|
||||||
|
file_glob: true
|
||||||
|
prerelease: true
|
||||||
|
|||||||
14
.github/workflows/build-windows.yml
vendored
14
.github/workflows/build-windows.yml
vendored
@@ -37,16 +37,16 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
cd v2rayN
|
cd v2rayN
|
||||||
dotnet publish ./v2rayN/v2rayN.csproj -c Release -r win-x64 --self-contained=false -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:EnableWindowsTargeting=true -o $OutputPath64
|
dotnet publish ./v2rayN/v2rayN.csproj -c Release -r win-x64 --self-contained=false -p:EnableWindowsTargeting=true -o $OutputPath64
|
||||||
dotnet publish ./v2rayN/v2rayN.csproj -c Release -r win-arm64 --self-contained=false -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:EnableWindowsTargeting=true -o $OutputPathArm64
|
dotnet publish ./v2rayN/v2rayN.csproj -c Release -r win-arm64 --self-contained=false -p:EnableWindowsTargeting=true -o $OutputPathArm64
|
||||||
dotnet publish ./v2rayN/v2rayN.csproj -c Release -r win-x64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:EnableWindowsTargeting=true -o $OutputPath64Sc
|
dotnet publish ./v2rayN/v2rayN.csproj -c Release -r win-x64 --self-contained=true -p:EnableWindowsTargeting=true -o $OutputPath64Sc
|
||||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-x64 --self-contained=false -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:EnableWindowsTargeting=true -o $OutputPath64
|
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-x64 --self-contained=false -p:EnableWindowsTargeting=true -o $OutputPath64
|
||||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-arm64 --self-contained=false -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:EnableWindowsTargeting=true -o $OutputPathArm64
|
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-arm64 --self-contained=false -p:EnableWindowsTargeting=true -o $OutputPathArm64
|
||||||
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-x64 --self-contained=true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=true -p:EnableWindowsTargeting=true -o $OutputPath64Sc
|
dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-x64 --self-contained=true -p:EnableWindowsTargeting=true -p:PublishTrimmed=true -o $OutputPath64Sc
|
||||||
|
|
||||||
|
|
||||||
- name: Upload build artifacts
|
- name: Upload build artifacts
|
||||||
uses: actions/upload-artifact@v4.6.0
|
uses: actions/upload-artifact@v4.6.1
|
||||||
with:
|
with:
|
||||||
name: v2rayN-windows
|
name: v2rayN-windows
|
||||||
path: |
|
path: |
|
||||||
|
|||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "v2rayN/GlobalHotKeys"]
|
||||||
|
path = v2rayN/GlobalHotKeys
|
||||||
|
url = https://github.com/2dust/GlobalHotKeys
|
||||||
@@ -1,71 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
Arch="$1"
|
sudo apt update -y
|
||||||
OutputPath="$2"
|
|
||||||
Version="$3"
|
|
||||||
|
|
||||||
FileName="v2rayN-${Arch}.zip"
|
|
||||||
wget -nv -O $FileName "https://github.com/2dust/v2rayN-core-bin/raw/refs/heads/master/$FileName"
|
|
||||||
7z x $FileName -aoa
|
|
||||||
cp -rf v2rayN-${Arch}/* $OutputPath
|
|
||||||
|
|
||||||
PackagePath="v2rayN-Package-${Arch}"
|
|
||||||
mkdir -p "${PackagePath}/AppDir/opt"
|
|
||||||
cp -rf $OutputPath "${PackagePath}/AppDir/opt/v2rayN"
|
|
||||||
echo "When this file exists, app will not store configs under this folder" >"${PackagePath}/AppDir/opt/v2rayN/NotStoreConfigHere.txt"
|
|
||||||
|
|
||||||
if [ $Arch = "linux-64" ]; then
|
|
||||||
Arch2="x86_64"
|
|
||||||
Arch3="amd64"
|
|
||||||
else
|
|
||||||
Arch2="aarch64"
|
|
||||||
Arch3="arm64"
|
|
||||||
fi
|
|
||||||
echo $Arch2
|
|
||||||
|
|
||||||
# basic
|
|
||||||
cat >"${PackagePath}/AppDir/AppRun" <<-EOF
|
|
||||||
#!/bin/sh
|
|
||||||
HERE="\$(dirname "\$(readlink -f "\${0}")")"
|
|
||||||
export PATH="\${HERE}"/opt/v2rayN/:"\${PATH}"
|
|
||||||
export LD_LIBRARY_PATH="\${HERE}"/opt/v2rayN/:"\${LD_LIBRARY_PATH}"
|
|
||||||
exec "\${HERE}/opt/v2rayN/v2rayN" \$@
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cat >"${PackagePath}/AppDir/v2rayN.desktop" <<-EOF
|
|
||||||
[Desktop Entry]
|
|
||||||
Name=v2rayN
|
|
||||||
Comment=A GUI client for Windows and Linux, support Xray core and sing-box-core and others
|
|
||||||
Exec=v2rayN
|
|
||||||
Icon=v2rayN
|
|
||||||
Terminal=false
|
|
||||||
Type=Application
|
|
||||||
Categories=Network;
|
|
||||||
EOF
|
|
||||||
|
|
||||||
sudo cp "${PackagePath}/AppDir/opt/v2rayN/v2rayN.png" "${PackagePath}/AppDir/v2rayN.png"
|
|
||||||
sudo dpkg --add-architecture ${Arch3}
|
|
||||||
mkdir deb_folder
|
|
||||||
cd deb_folder
|
|
||||||
apt download libicu74:${Arch3}
|
|
||||||
apt download libfontconfig1:${Arch3} || true
|
|
||||||
apt download libfontconfig:${Arch3} || true
|
|
||||||
mkdir ../output_folder
|
|
||||||
for deb in *.deb; do
|
|
||||||
dpkg-deb -x "$deb" ../output_folder/
|
|
||||||
done
|
|
||||||
cd ..
|
|
||||||
find output_folder -type f -name "*.so*" -exec cp {} ${PackagePath}/AppDir/opt/v2rayN/ \;
|
|
||||||
find output_folder -type l -name "*.so*" -exec cp {} ${PackagePath}/AppDir/opt/v2rayN/ \;
|
|
||||||
rm -rf deb_folder output_folder
|
|
||||||
|
|
||||||
sudo chmod 0755 "${PackagePath}/AppDir/opt/v2rayN/v2rayN"
|
|
||||||
sudo chmod 0755 "${PackagePath}/AppDir/AppRun"
|
|
||||||
|
|
||||||
# desktop && PATH
|
|
||||||
|
|
||||||
wget "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage"
|
|
||||||
chmod a+x appimagetool-x86_64.AppImage
|
|
||||||
sudo apt install -y libfuse2
|
sudo apt install -y libfuse2
|
||||||
sudo ./appimagetool-x86_64.AppImage "${PackagePath}/AppDir"
|
wget -O pkg2appimage https://github.com/AppImageCommunity/pkg2appimage/releases/download/continuous/pkg2appimage-1eceb30-x86_64.AppImage
|
||||||
sudo mv "v2rayN-${Arch2}.AppImage" "v2rayN-${Arch}.AppImage"
|
chmod a+x pkg2appimage
|
||||||
|
export AppImageOutputArch=$OutputArch
|
||||||
|
export OutputPath=$OutputPath64
|
||||||
|
./pkg2appimage ./pkg2appimage.yml
|
||||||
|
mv out/*.AppImage v2rayN-${AppImageOutputArch}.AppImage
|
||||||
|
export AppImageOutputArch=$OutputArchArm
|
||||||
|
export OutputPath=$OutputPathArm64
|
||||||
|
./pkg2appimage ./pkg2appimage.yml
|
||||||
|
mv out/*.AppImage v2rayN-${AppImageOutputArch}.AppImage
|
||||||
|
|||||||
37
pkg2appimage.yml
Normal file
37
pkg2appimage.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
app: v2rayN
|
||||||
|
binpatch: true
|
||||||
|
|
||||||
|
ingredients:
|
||||||
|
script:
|
||||||
|
- export FileName="v2rayN-${AppImageOutputArch}.zip"
|
||||||
|
- wget -nv -O $FileName "https://github.com/2dust/v2rayN-core-bin/raw/refs/heads/master/${FileName}"
|
||||||
|
- 7z x $FileName -aoa
|
||||||
|
- cp -rf v2rayN-${AppImageOutputArch}/* $OutputPath
|
||||||
|
|
||||||
|
script:
|
||||||
|
- mkdir -p usr/bin usr/lib
|
||||||
|
- cp -rf $OutputPath usr/lib/v2rayN
|
||||||
|
- echo "When this file exists, app will not store configs under this folder" > usr/lib/v2rayN/NotStoreConfigHere.txt
|
||||||
|
- ln -sf usr/lib/v2rayN/v2rayN usr/bin/v2rayN
|
||||||
|
- chmod a+x usr/lib/v2rayN/v2rayN
|
||||||
|
- find usr -type f -exec sh -c 'file "{}" | grep -qi "executable" && chmod +x "{}"' \;
|
||||||
|
- install -Dm644 usr/lib/v2rayN/v2rayN.png v2rayN.png
|
||||||
|
- install -Dm644 usr/lib/v2rayN/v2rayN.png usr/share/pixmaps/v2rayN.png
|
||||||
|
- cat > v2rayN.desktop <<EOF
|
||||||
|
- [Desktop Entry]
|
||||||
|
- Name=v2rayN
|
||||||
|
- Comment=A GUI client for Windows and Linux, support Xray core and sing-box-core and others
|
||||||
|
- Exec=v2rayN
|
||||||
|
- Icon=v2rayN
|
||||||
|
- Terminal=false
|
||||||
|
- Type=Application
|
||||||
|
- Categories=Network;
|
||||||
|
- EOF
|
||||||
|
- install -Dm644 v2rayN.desktop usr/share/applications/v2rayN.desktop
|
||||||
|
- cat > AppRun <<\EOF
|
||||||
|
- #!/bin/sh
|
||||||
|
- HERE="$(dirname "$(readlink -f "${0}")")"
|
||||||
|
- cd ${HERE}/usr/lib/v2rayN
|
||||||
|
- exec ${HERE}/usr/lib/v2rayN/v2rayN $@
|
||||||
|
- EOF
|
||||||
|
- chmod a+x AppRun
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
namespace AmazTool
|
namespace AmazTool
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 应用程序的主入口点。
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@@ -26,4 +23,4 @@
|
|||||||
UpgradeApp.Upgrade(argData);
|
UpgradeApp.Upgrade(argData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,10 @@ namespace AmazTool
|
|||||||
|
|
||||||
var lst = entry.FullName.Split(splitKey);
|
var lst = entry.FullName.Split(splitKey);
|
||||||
if (lst.Length == 1)
|
if (lst.Length == 1)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var fullName = string.Join(splitKey, lst[1..lst.Length]);
|
var fullName = string.Join(splitKey, lst[1..lst.Length]);
|
||||||
|
|
||||||
if (string.Equals(Utils.GetExePath(), Utils.GetPath(fullName), StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(Utils.GetExePath(), Utils.GetPath(fullName), StringComparison.OrdinalIgnoreCase))
|
||||||
@@ -75,7 +78,16 @@ namespace AmazTool
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
entry.ExtractToFile(entryOutputPath, true);
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
entry.ExtractToFile(entryOutputPath, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
entry.ExtractToFile(entryOutputPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine(entryOutputPath);
|
Console.WriteLine(entryOutputPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace AmazTool
|
namespace AmazTool
|
||||||
{
|
{
|
||||||
@@ -16,7 +16,7 @@ namespace AmazTool
|
|||||||
|
|
||||||
public static string GetPath(string fileName)
|
public static string GetPath(string fileName)
|
||||||
{
|
{
|
||||||
string startupPath = StartupPath();
|
var startupPath = StartupPath();
|
||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
return startupPath;
|
return startupPath;
|
||||||
@@ -49,4 +49,4 @@ namespace AmazTool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project>
|
<Project>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>7.8.0</Version>
|
<Version>7.10.5</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
@@ -28,6 +28,6 @@
|
|||||||
|
|
||||||
<UseSystemResourceKeys>true</UseSystemResourceKeys>
|
<UseSystemResourceKeys>true</UseSystemResourceKeys>
|
||||||
<PublishSingleFile>true</PublishSingleFile>
|
<PublishSingleFile>true</PublishSingleFile>
|
||||||
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
|
<PublishReadyToRun>false</PublishReadyToRun>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -5,24 +5,24 @@
|
|||||||
<CentralPackageVersionOverrideEnabled>false</CentralPackageVersionOverrideEnabled>
|
<CentralPackageVersionOverrideEnabled>false</CentralPackageVersionOverrideEnabled>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.2.3" />
|
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.2.5" />
|
||||||
<PackageVersion Include="Avalonia.Desktop" Version="11.2.3" />
|
<PackageVersion Include="Avalonia.Desktop" Version="11.2.5" />
|
||||||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.2.3" />
|
<PackageVersion Include="Avalonia.Diagnostics" Version="11.2.5" />
|
||||||
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.2.3" />
|
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.2.5" />
|
||||||
<PackageVersion Include="CliWrap" Version="3.7.1" />
|
<PackageVersion Include="CliWrap" Version="3.8.2" />
|
||||||
<PackageVersion Include="Downloader" Version="3.3.3" />
|
<PackageVersion Include="Downloader" Version="3.3.4" />
|
||||||
<PackageVersion Include="H.NotifyIcon.Wpf" Version="2.2.0" />
|
<PackageVersion Include="H.NotifyIcon.Wpf" Version="2.3.0" />
|
||||||
<PackageVersion Include="MaterialDesignThemes" Version="5.2.1" />
|
<PackageVersion Include="MaterialDesignThemes" Version="5.2.1" />
|
||||||
<PackageVersion Include="MessageBox.Avalonia" Version="3.2.0" />
|
<PackageVersion Include="MessageBox.Avalonia" Version="3.2.0" />
|
||||||
<PackageVersion Include="QRCoder" Version="1.6.0" />
|
<PackageVersion Include="QRCoder" Version="1.6.0" />
|
||||||
<PackageVersion Include="ReactiveUI" Version="20.1.63" />
|
<PackageVersion Include="ReactiveUI" Version="20.1.63" />
|
||||||
<PackageVersion Include="ReactiveUI.Fody" Version="19.5.41" />
|
<PackageVersion Include="ReactiveUI.Fody" Version="19.5.41" />
|
||||||
<PackageVersion Include="ReactiveUI.WPF" Version="20.1.63" />
|
<PackageVersion Include="ReactiveUI.WPF" Version="20.1.63" />
|
||||||
<PackageVersion Include="Semi.Avalonia" Version="11.2.1.4" />
|
<PackageVersion Include="Semi.Avalonia" Version="11.2.1.5" />
|
||||||
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.4" />
|
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.5" />
|
||||||
<PackageVersion Include="Splat.NLog" Version="15.3.1" />
|
<PackageVersion Include="Splat.NLog" Version="15.3.1" />
|
||||||
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
||||||
<PackageVersion Include="TaskScheduler" Version="2.11.0" />
|
<PackageVersion Include="TaskScheduler" Version="2.12.1" />
|
||||||
<PackageVersion Include="WebDav.Client" Version="2.8.0" />
|
<PackageVersion Include="WebDav.Client" Version="2.8.0" />
|
||||||
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
|
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
|
||||||
<PackageVersion Include="ZXing.Net.Bindings.SkiaSharp" Version="0.16.14" />
|
<PackageVersion Include="ZXing.Net.Bindings.SkiaSharp" Version="0.16.14" />
|
||||||
|
|||||||
1
v2rayN/GlobalHotKeys
Submodule
1
v2rayN/GlobalHotKeys
Submodule
Submodule v2rayN/GlobalHotKeys added at ef73fa22c4
@@ -10,7 +10,7 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
public async Task<string?> DownloadStringAsync(IWebProxy? webProxy, string url, string? userAgent, int timeout)
|
public async Task<string?> DownloadStringAsync(IWebProxy? webProxy, string url, string? userAgent, int timeout)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace ServiceLib.Common
|
|||||||
Uri uri = new(url);
|
Uri uri = new(url);
|
||||||
//Authorization Header
|
//Authorization Header
|
||||||
var headers = new WebHeaderCollection();
|
var headers = new WebHeaderCollection();
|
||||||
if (Utils.IsNotEmpty(uri.UserInfo))
|
if (uri.UserInfo.IsNotEmpty())
|
||||||
{
|
{
|
||||||
headers.Add(HttpRequestHeader.Authorization, "Basic " + Utils.Base64Encode(uri.UserInfo));
|
headers.Add(HttpRequestHeader.Authorization, "Basic " + Utils.Base64Encode(uri.UserInfo));
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
public async Task DownloadDataAsync4Speed(IWebProxy webProxy, string url, IProgress<string> progress, int timeout)
|
public async Task DownloadDataAsync4Speed(IWebProxy webProxy, string url, IProgress<string> progress, int timeout)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(url));
|
throw new ArgumentNullException(nameof(url));
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ namespace ServiceLib.Common
|
|||||||
//};
|
//};
|
||||||
downloader.DownloadProgressChanged += (sender, value) =>
|
downloader.DownloadProgressChanged += (sender, value) =>
|
||||||
{
|
{
|
||||||
var ts = (DateTime.Now - totalDatetime);
|
var ts = DateTime.Now - totalDatetime;
|
||||||
if (progress != null && ts.Seconds > totalSecond)
|
if (progress != null && ts.Seconds > totalSecond)
|
||||||
{
|
{
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
@@ -119,11 +119,11 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
public async Task DownloadFileAsync(IWebProxy? webProxy, string url, string fileName, IProgress<double> progress, int timeout)
|
public async Task DownloadFileAsync(IWebProxy? webProxy, string url, string fileName, IProgress<double> progress, int timeout)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(url));
|
throw new ArgumentNullException(nameof(url));
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(fileName));
|
throw new ArgumentNullException(nameof(fileName));
|
||||||
}
|
}
|
||||||
@@ -146,10 +146,7 @@ namespace ServiceLib.Common
|
|||||||
var progressPercentage = 0;
|
var progressPercentage = 0;
|
||||||
var hasValue = false;
|
var hasValue = false;
|
||||||
await using var downloader = new Downloader.DownloadService(downloadOpt);
|
await using var downloader = new Downloader.DownloadService(downloadOpt);
|
||||||
downloader.DownloadStarted += (sender, value) =>
|
downloader.DownloadStarted += (sender, value) => progress?.Report(0);
|
||||||
{
|
|
||||||
progress?.Report(0);
|
|
||||||
};
|
|
||||||
downloader.DownloadProgressChanged += (sender, value) =>
|
downloader.DownloadProgressChanged += (sender, value) =>
|
||||||
{
|
{
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Formats.Tar;
|
using System.Formats.Tar;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ namespace ServiceLib.Common
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(ignoredName) && entry.Name.Contains(ignoredName))
|
if (ignoredName.IsNotEmpty() && entry.Name.Contains(ignoredName))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -163,18 +163,20 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
// Check if the source directory exists
|
// Check if the source directory exists
|
||||||
if (!dir.Exists)
|
if (!dir.Exists)
|
||||||
|
{
|
||||||
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
|
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
|
||||||
|
}
|
||||||
|
|
||||||
// Cache directories before we start copying
|
// Cache directories before we start copying
|
||||||
var dirs = dir.GetDirectories();
|
var dirs = dir.GetDirectories();
|
||||||
|
|
||||||
// Create the destination directory
|
// Create the destination directory
|
||||||
Directory.CreateDirectory(destinationDir);
|
_ = Directory.CreateDirectory(destinationDir);
|
||||||
|
|
||||||
// Get the files in the source directory and copy to the destination directory
|
// Get the files in the source directory and copy to the destination directory
|
||||||
foreach (var file in dir.GetFiles())
|
foreach (var file in dir.GetFiles())
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(ignoredName) && file.Name.Contains(ignoredName))
|
if (ignoredName.IsNotEmpty() && file.Name.Contains(ignoredName))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -187,7 +189,7 @@ namespace ServiceLib.Common
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
file.CopyTo(targetFilePath, overwrite);
|
_ = file.CopyTo(targetFilePath, overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If recursive and copying subdirectories, recursively call this method
|
// If recursive and copying subdirectories, recursively call this method
|
||||||
@@ -222,4 +224,4 @@ namespace ServiceLib.Common
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,17 @@ namespace ServiceLib.Common
|
|||||||
public static HttpClientHelper Instance => _instance.Value;
|
public static HttpClientHelper Instance => _instance.Value;
|
||||||
private readonly HttpClient httpClient;
|
private readonly HttpClient httpClient;
|
||||||
|
|
||||||
private HttpClientHelper(HttpClient httpClient) => this.httpClient = httpClient;
|
private HttpClientHelper(HttpClient httpClient)
|
||||||
|
{
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<string?> TryGetAsync(string url)
|
public async Task<string?> TryGetAsync(string url)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -38,15 +43,19 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
public async Task<string?> GetAsync(string url)
|
public async Task<string?> GetAsync(string url)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
return await httpClient.GetStringAsync(url);
|
return await httpClient.GetStringAsync(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string?> GetAsync(HttpClient client, string url, CancellationToken token = default)
|
public async Task<string?> GetAsync(HttpClient client, string url, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
return await client.GetStringAsync(url, token);
|
return await client.GetStringAsync(url, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,13 +64,13 @@ namespace ServiceLib.Common
|
|||||||
var jsonContent = JsonUtils.Serialize(headers);
|
var jsonContent = JsonUtils.Serialize(headers);
|
||||||
var content = new StringContent(jsonContent, Encoding.UTF8, MediaTypeNames.Application.Json);
|
var content = new StringContent(jsonContent, Encoding.UTF8, MediaTypeNames.Application.Json);
|
||||||
|
|
||||||
var result = await httpClient.PutAsync(url, content);
|
await httpClient.PutAsync(url, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PatchAsync(string url, Dictionary<string, string> headers)
|
public async Task PatchAsync(string url, Dictionary<string, string> headers)
|
||||||
{
|
{
|
||||||
var myContent = JsonUtils.Serialize(headers);
|
var myContent = JsonUtils.Serialize(headers);
|
||||||
var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);
|
var buffer = Encoding.UTF8.GetBytes(myContent);
|
||||||
var byteContent = new ByteArrayContent(buffer);
|
var byteContent = new ByteArrayContent(buffer);
|
||||||
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||||
|
|
||||||
@@ -78,12 +87,16 @@ namespace ServiceLib.Common
|
|||||||
ArgumentNullException.ThrowIfNull(url);
|
ArgumentNullException.ThrowIfNull(url);
|
||||||
ArgumentNullException.ThrowIfNull(fileName);
|
ArgumentNullException.ThrowIfNull(fileName);
|
||||||
if (File.Exists(fileName))
|
if (File.Exists(fileName))
|
||||||
|
{
|
||||||
File.Delete(fileName);
|
File.Delete(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
|
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
throw new Exception(response.StatusCode.ToString());
|
throw new Exception(response.StatusCode.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
var total = response.Content.Headers.ContentLength ?? -1L;
|
var total = response.Content.Headers.ContentLength ?? -1L;
|
||||||
var canReportProgress = total != -1 && progress != null;
|
var canReportProgress = total != -1 && progress != null;
|
||||||
@@ -102,7 +115,9 @@ namespace ServiceLib.Common
|
|||||||
totalRead += read;
|
totalRead += read;
|
||||||
|
|
||||||
if (read == 0)
|
if (read == 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
await file.WriteAsync(buffer.AsMemory(0, read), token);
|
await file.WriteAsync(buffer.AsMemory(0, read), token);
|
||||||
|
|
||||||
if (canReportProgress)
|
if (canReportProgress)
|
||||||
@@ -123,7 +138,7 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
public async Task DownloadDataAsync4Speed(HttpClient client, string url, IProgress<string> progress, CancellationToken token = default)
|
public async Task DownloadDataAsync4Speed(HttpClient client, string url, IProgress<string> progress, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(url));
|
throw new ArgumentNullException(nameof(url));
|
||||||
}
|
}
|
||||||
@@ -173,7 +188,7 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
totalRead += read;
|
totalRead += read;
|
||||||
|
|
||||||
var ts = (DateTime.Now - totalDatetime);
|
var ts = DateTime.Now - totalDatetime;
|
||||||
if (progress != null && ts.Seconds > totalSecond)
|
if (progress != null && ts.Seconds > totalSecond)
|
||||||
{
|
{
|
||||||
totalSecond = ts.Seconds;
|
totalSecond = ts.Seconds;
|
||||||
|
|||||||
@@ -15,27 +15,29 @@ namespace ServiceLib.Common
|
|||||||
public Job()
|
public Job()
|
||||||
{
|
{
|
||||||
handle = CreateJobObject(IntPtr.Zero, null);
|
handle = CreateJobObject(IntPtr.Zero, null);
|
||||||
IntPtr extendedInfoPtr = IntPtr.Zero;
|
var extendedInfoPtr = IntPtr.Zero;
|
||||||
JOBOBJECT_BASIC_LIMIT_INFORMATION info = new()
|
var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION
|
||||||
{
|
{
|
||||||
LimitFlags = 0x2000
|
LimitFlags = 0x2000
|
||||||
};
|
};
|
||||||
|
|
||||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedInfo = new()
|
var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION
|
||||||
{
|
{
|
||||||
BasicLimitInformation = info
|
BasicLimitInformation = info
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
|
var length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
|
||||||
extendedInfoPtr = Marshal.AllocHGlobal(length);
|
extendedInfoPtr = Marshal.AllocHGlobal(length);
|
||||||
Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);
|
Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);
|
||||||
|
|
||||||
if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr,
|
if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr,
|
||||||
(uint)length))
|
(uint)length))
|
||||||
|
{
|
||||||
throw new Exception(string.Format("Unable to set information. Error: {0}",
|
throw new Exception(string.Format("Unable to set information. Error: {0}",
|
||||||
Marshal.GetLastWin32Error()));
|
Marshal.GetLastWin32Error()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -48,7 +50,7 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
public bool AddProcess(IntPtr processHandle)
|
public bool AddProcess(IntPtr processHandle)
|
||||||
{
|
{
|
||||||
bool succ = AssignProcessToJobObject(handle, processHandle);
|
var succ = AssignProcessToJobObject(handle, processHandle);
|
||||||
|
|
||||||
if (!succ)
|
if (!succ)
|
||||||
{
|
{
|
||||||
@@ -76,7 +78,9 @@ namespace ServiceLib.Common
|
|||||||
private void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposed)
|
if (disposed)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
disposed = true;
|
disposed = true;
|
||||||
|
|
||||||
if (disposing)
|
if (disposing)
|
||||||
@@ -104,7 +108,7 @@ namespace ServiceLib.Common
|
|||||||
private static extern IntPtr CreateJobObject(IntPtr a, string? lpName);
|
private static extern IntPtr CreateJobObject(IntPtr a, string? lpName);
|
||||||
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength);
|
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);
|
||||||
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
private static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
|
private static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
|
||||||
@@ -121,34 +125,34 @@ namespace ServiceLib.Common
|
|||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
internal struct IO_COUNTERS
|
internal struct IO_COUNTERS
|
||||||
{
|
{
|
||||||
public UInt64 ReadOperationCount;
|
public ulong ReadOperationCount;
|
||||||
public UInt64 WriteOperationCount;
|
public ulong WriteOperationCount;
|
||||||
public UInt64 OtherOperationCount;
|
public ulong OtherOperationCount;
|
||||||
public UInt64 ReadTransferCount;
|
public ulong ReadTransferCount;
|
||||||
public UInt64 WriteTransferCount;
|
public ulong WriteTransferCount;
|
||||||
public UInt64 OtherTransferCount;
|
public ulong OtherTransferCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
internal struct JOBOBJECT_BASIC_LIMIT_INFORMATION
|
internal struct JOBOBJECT_BASIC_LIMIT_INFORMATION
|
||||||
{
|
{
|
||||||
public Int64 PerProcessUserTimeLimit;
|
public long PerProcessUserTimeLimit;
|
||||||
public Int64 PerJobUserTimeLimit;
|
public long PerJobUserTimeLimit;
|
||||||
public UInt32 LimitFlags;
|
public uint LimitFlags;
|
||||||
public UIntPtr MinimumWorkingSetSize;
|
public UIntPtr MinimumWorkingSetSize;
|
||||||
public UIntPtr MaximumWorkingSetSize;
|
public UIntPtr MaximumWorkingSetSize;
|
||||||
public UInt32 ActiveProcessLimit;
|
public uint ActiveProcessLimit;
|
||||||
public UIntPtr Affinity;
|
public UIntPtr Affinity;
|
||||||
public UInt32 PriorityClass;
|
public uint PriorityClass;
|
||||||
public UInt32 SchedulingClass;
|
public uint SchedulingClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct SECURITY_ATTRIBUTES
|
public struct SECURITY_ATTRIBUTES
|
||||||
{
|
{
|
||||||
public UInt32 nLength;
|
public uint nLength;
|
||||||
public IntPtr lpSecurityDescriptor;
|
public IntPtr lpSecurityDescriptor;
|
||||||
public Int32 bInheritHandle;
|
public int bInheritHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ namespace ServiceLib.Common
|
|||||||
public static void SaveLog(string strContent)
|
public static void SaveLog(string strContent)
|
||||||
{
|
{
|
||||||
if (!LogManager.IsLoggingEnabled())
|
if (!LogManager.IsLoggingEnabled())
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LogManager.GetLogger("Log1").Info(strContent);
|
LogManager.GetLogger("Log1").Info(strContent);
|
||||||
}
|
}
|
||||||
@@ -36,7 +38,9 @@ namespace ServiceLib.Common
|
|||||||
public static void SaveLog(string strTitle, Exception ex)
|
public static void SaveLog(string strTitle, Exception ex)
|
||||||
{
|
{
|
||||||
if (!LogManager.IsLoggingEnabled())
|
if (!LogManager.IsLoggingEnabled())
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var logger = LogManager.GetLogger("Log2");
|
var logger = LogManager.GetLogger("Log2");
|
||||||
logger.Debug($"{strTitle},{ex.Message}");
|
logger.Debug($"{strTitle},{ex.Message}");
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public static class ProcUtils
|
|||||||
|
|
||||||
public static void ProcessStart(string? fileName, string arguments = "")
|
public static void ProcessStart(string? fileName, string arguments = "")
|
||||||
{
|
{
|
||||||
ProcessStart(fileName, arguments, null);
|
_ = ProcessStart(fileName, arguments, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int? ProcessStart(string? fileName, string arguments, string? dir)
|
public static int? ProcessStart(string? fileName, string arguments, string? dir)
|
||||||
@@ -20,9 +20,13 @@ public static class ProcUtils
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (fileName.Contains(' '))
|
if (fileName.Contains(' '))
|
||||||
|
{
|
||||||
fileName = fileName.AppendQuotes();
|
fileName = fileName.AppendQuotes();
|
||||||
|
}
|
||||||
if (arguments.Contains(' '))
|
if (arguments.Contains(' '))
|
||||||
|
{
|
||||||
arguments = arguments.AppendQuotes();
|
arguments = arguments.AppendQuotes();
|
||||||
|
}
|
||||||
|
|
||||||
Process proc = new()
|
Process proc = new()
|
||||||
{
|
{
|
||||||
@@ -34,7 +38,7 @@ public static class ProcUtils
|
|||||||
WorkingDirectory = dir ?? string.Empty
|
WorkingDirectory = dir ?? string.Empty
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
proc.Start();
|
_ = proc.Start();
|
||||||
return dir is null ? null : proc.Id;
|
return dir is null ? null : proc.Id;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -56,7 +60,7 @@ public static class ProcUtils
|
|||||||
FileName = Utils.GetExePath().AppendQuotes(),
|
FileName = Utils.GetExePath().AppendQuotes(),
|
||||||
Verb = blAdmin ? "runas" : null,
|
Verb = blAdmin ? "runas" : null,
|
||||||
};
|
};
|
||||||
Process.Start(startInfo);
|
_ = Process.Start(startInfo);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -86,17 +90,43 @@ public static class ProcUtils
|
|||||||
GetProcessKeyInfo(proc, review, out var procId, out var fileName, out var processName);
|
GetProcessKeyInfo(proc, review, out var procId, out var fileName, out var processName);
|
||||||
|
|
||||||
try
|
try
|
||||||
{ proc?.Kill(true); }
|
{
|
||||||
catch (Exception ex) { Logging.SaveLog(_tag, ex); }
|
if (Utils.IsNonWindows())
|
||||||
|
{
|
||||||
|
proc?.Kill(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{ proc?.Kill(); }
|
{
|
||||||
catch (Exception ex) { Logging.SaveLog(_tag, ex); }
|
proc?.Kill();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{ proc?.Close(); }
|
{
|
||||||
catch (Exception ex) { Logging.SaveLog(_tag, ex); }
|
proc?.Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{ proc?.Dispose(); }
|
{
|
||||||
catch (Exception ex) { Logging.SaveLog(_tag, ex); }
|
proc?.Dispose();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
|
||||||
await Task.Delay(300);
|
await Task.Delay(300);
|
||||||
await ProcessKillByKeyInfo(review, procId, fileName, processName);
|
await ProcessKillByKeyInfo(review, procId, fileName, processName);
|
||||||
@@ -108,7 +138,9 @@ public static class ProcUtils
|
|||||||
fileName = null;
|
fileName = null;
|
||||||
processName = null;
|
processName = null;
|
||||||
if (!review)
|
if (!review)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
procId = proc?.Id;
|
procId = proc?.Id;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace ServiceLib.Common
|
|||||||
var reader = new BarcodeReader();
|
var reader = new BarcodeReader();
|
||||||
var result = reader.Decode(bitmap);
|
var result = reader.Decode(bitmap);
|
||||||
|
|
||||||
if (result != null && Utils.IsNotEmpty(result.Text))
|
if (result != null && result.Text.IsNotEmpty())
|
||||||
{
|
{
|
||||||
return result.Text;
|
return result.Text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
namespace ServiceLib.Common
|
namespace ServiceLib.Common
|
||||||
{
|
{
|
||||||
public class SemanticVersion
|
public class SemanticVersion
|
||||||
{
|
{
|
||||||
private int major;
|
private readonly int major;
|
||||||
private int minor;
|
private readonly int minor;
|
||||||
private int patch;
|
private readonly int patch;
|
||||||
private string version;
|
private readonly string version;
|
||||||
|
|
||||||
public SemanticVersion(int major, int minor, int patch)
|
public SemanticVersion(int major, int minor, int patch)
|
||||||
{
|
{
|
||||||
this.major = major;
|
this.major = major;
|
||||||
this.minor = minor;
|
this.minor = minor;
|
||||||
this.patch = patch;
|
this.patch = patch;
|
||||||
this.version = $"{major}.{minor}.{patch}";
|
version = $"{major}.{minor}.{patch}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public SemanticVersion(string? version)
|
public SemanticVersion(string? version)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (version.IsNullOrEmpty())
|
if (string.IsNullOrEmpty(version))
|
||||||
{
|
{
|
||||||
this.major = 0;
|
major = 0;
|
||||||
this.minor = 0;
|
minor = 0;
|
||||||
this.patch = 0;
|
patch = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.version = version.RemovePrefix('v');
|
this.version = version.RemovePrefix('v');
|
||||||
@@ -31,15 +31,15 @@
|
|||||||
var parts = this.version.Split('.');
|
var parts = this.version.Split('.');
|
||||||
if (parts.Length == 2)
|
if (parts.Length == 2)
|
||||||
{
|
{
|
||||||
this.major = int.Parse(parts.First());
|
major = int.Parse(parts.First());
|
||||||
this.minor = int.Parse(parts.Last());
|
minor = int.Parse(parts.Last());
|
||||||
this.patch = 0;
|
patch = 0;
|
||||||
}
|
}
|
||||||
else if (parts.Length is 3 or 4)
|
else if (parts.Length is 3 or 4)
|
||||||
{
|
{
|
||||||
this.major = int.Parse(parts[0]);
|
major = int.Parse(parts[0]);
|
||||||
this.minor = int.Parse(parts[1]);
|
minor = int.Parse(parts[1]);
|
||||||
this.patch = int.Parse(parts[2]);
|
patch = int.Parse(parts[2]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -48,9 +48,9 @@
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
this.major = 0;
|
major = 0;
|
||||||
this.minor = 0;
|
minor = 0;
|
||||||
this.patch = 0;
|
patch = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
{
|
{
|
||||||
if (obj is SemanticVersion other)
|
if (obj is SemanticVersion other)
|
||||||
{
|
{
|
||||||
return this.major == other.major && this.minor == other.minor && this.patch == other.patch;
|
return major == other.major && minor == other.minor && patch == other.patch;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
return this.major.GetHashCode() ^ this.minor.GetHashCode() ^ this.patch.GetHashCode();
|
return major.GetHashCode() ^ minor.GetHashCode() ^ patch.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -77,18 +77,18 @@
|
|||||||
/// <returns>major.minor.patch</returns>
|
/// <returns>major.minor.patch</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return this.version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ToVersionString(string? prefix = null)
|
public string ToVersionString(string? prefix = null)
|
||||||
{
|
{
|
||||||
if (prefix == null)
|
if (prefix == null)
|
||||||
{
|
{
|
||||||
return this.version;
|
return version;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $"{prefix}{this.version}";
|
return $"{prefix}{version}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,31 +108,31 @@
|
|||||||
|
|
||||||
private bool GreaterEquals(SemanticVersion other)
|
private bool GreaterEquals(SemanticVersion other)
|
||||||
{
|
{
|
||||||
if (this.major < other.major)
|
if (major < other.major)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (this.major > other.major)
|
else if (major > other.major)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (this.minor < other.minor)
|
if (minor < other.minor)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (this.minor > other.minor)
|
else if (minor > other.minor)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (this.patch < other.patch)
|
if (patch < other.patch)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (this.patch > other.patch)
|
else if (patch > other.patch)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -146,31 +146,31 @@
|
|||||||
|
|
||||||
private bool LessEquals(SemanticVersion other)
|
private bool LessEquals(SemanticVersion other)
|
||||||
{
|
{
|
||||||
if (this.major < other.major)
|
if (major < other.major)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (this.major > other.major)
|
else if (major > other.major)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (this.minor < other.minor)
|
if (minor < other.minor)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (this.minor > other.minor)
|
else if (minor > other.minor)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (this.patch < other.patch)
|
if (patch < other.patch)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (this.patch > other.patch)
|
else if (patch > other.patch)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -184,4 +184,4 @@
|
|||||||
|
|
||||||
#endregion Private
|
#endregion Private
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace ServiceLib.Common
|
|||||||
{
|
{
|
||||||
private static readonly Lazy<SQLiteHelper> _instance = new(() => new());
|
private static readonly Lazy<SQLiteHelper> _instance = new(() => new());
|
||||||
public static SQLiteHelper Instance => _instance.Value;
|
public static SQLiteHelper Instance => _instance.Value;
|
||||||
private string _connstr;
|
private readonly string _connstr;
|
||||||
private SQLiteConnection _db;
|
private SQLiteConnection _db;
|
||||||
private SQLiteAsyncConnection _dbAsync;
|
private SQLiteAsyncConnection _dbAsync;
|
||||||
private readonly string _configDB = "guiNDB.db";
|
private readonly string _configDB = "guiNDB.db";
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace ServiceLib.Common
|
|||||||
{
|
{
|
||||||
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? value)
|
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? value)
|
||||||
{
|
{
|
||||||
return string.IsNullOrEmpty(value);
|
return string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value)
|
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value)
|
||||||
@@ -22,7 +22,9 @@ namespace ServiceLib.Common
|
|||||||
public static bool BeginWithAny(this string s, IEnumerable<char> chars)
|
public static bool BeginWithAny(this string s, IEnumerable<char> chars)
|
||||||
{
|
{
|
||||||
if (s.IsNullOrEmpty())
|
if (s.IsNullOrEmpty())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return chars.Contains(s.First());
|
return chars.Contains(s.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +38,9 @@ namespace ServiceLib.Common
|
|||||||
while (reader.ReadLine() is { } line)
|
while (reader.ReadLine() is { } line)
|
||||||
{
|
{
|
||||||
if (line.IsWhiteSpace())
|
if (line.IsWhiteSpace())
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
yield return line;
|
yield return line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,5 +74,10 @@ namespace ServiceLib.Common
|
|||||||
{
|
{
|
||||||
return string.IsNullOrEmpty(value) ? string.Empty : $"\"{value}\"";
|
return string.IsNullOrEmpty(value) ? string.Empty : $"\"{value}\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int ToInt(this string? value, int defaultValue = 0)
|
||||||
|
{
|
||||||
|
return int.TryParse(value, out var result) ? result : defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,85 +20,69 @@ namespace ServiceLib.Common
|
|||||||
#region 转换函数
|
#region 转换函数
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转逗号分隔的字符串
|
/// Convert to comma-separated string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="lst"></param>
|
/// <param name="lst"></param>
|
||||||
/// <param name="wrap"></param>
|
/// <param name="wrap"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string List2String(List<string>? lst, bool wrap = false)
|
public static string List2String(List<string>? lst, bool wrap = false)
|
||||||
{
|
{
|
||||||
|
if (lst == null || lst.Count == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var separator = wrap ? "," + Environment.NewLine : ",";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (lst == null)
|
return string.Join(separator, lst);
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
if (wrap)
|
|
||||||
{
|
|
||||||
return string.Join("," + Environment.NewLine, lst);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return string.Join(",", lst);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logging.SaveLog(_tag, ex);
|
Logging.SaveLog(_tag, ex);
|
||||||
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.Empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 逗号分隔的字符串
|
/// Comma-separated string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="str"></param>
|
/// <param name="str"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static List<string>? String2List(string? str)
|
public static List<string>? String2List(string? str)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(str))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (str == null)
|
str = str.Replace(Environment.NewLine, string.Empty);
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = str.Replace(Environment.NewLine, "");
|
|
||||||
return new List<string>(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
return new List<string>(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logging.SaveLog(_tag, ex);
|
Logging.SaveLog(_tag, ex);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 逗号分隔的字符串,先排序后转List
|
/// Comma-separated string, sorted and then converted to List
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="str"></param>
|
/// <param name="str"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static List<string>? String2ListSorted(string str)
|
public static List<string>? String2ListSorted(string str)
|
||||||
{
|
{
|
||||||
try
|
var lst = String2List(str);
|
||||||
{
|
lst?.Sort();
|
||||||
str = str.Replace(Environment.NewLine, "");
|
return lst;
|
||||||
List<string> list = new(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
|
||||||
list.Sort();
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logging.SaveLog(_tag, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base64编码
|
/// Base64 Encode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="plainText"></param>
|
/// <param name="plainText"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@@ -118,7 +102,7 @@ namespace ServiceLib.Common
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base64解码
|
/// Base64 Decode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="plainText"></param>
|
/// <param name="plainText"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@@ -127,7 +111,10 @@ namespace ServiceLib.Common
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (plainText.IsNullOrEmpty())
|
if (plainText.IsNullOrEmpty())
|
||||||
|
{
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
plainText = plainText.Trim()
|
plainText = plainText.Trim()
|
||||||
.Replace(Environment.NewLine, "")
|
.Replace(Environment.NewLine, "")
|
||||||
.Replace("\n", "")
|
.Replace("\n", "")
|
||||||
@@ -152,18 +139,6 @@ namespace ServiceLib.Common
|
|||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int ToInt(object? obj)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Convert.ToInt32(obj ?? string.Empty);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ToBool(object obj)
|
public static bool ToBool(object obj)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -188,55 +163,25 @@ namespace ServiceLib.Common
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ToHumanReadable(long amount, out double result, out string unit)
|
|
||||||
{
|
|
||||||
var factor = 1024u;
|
|
||||||
//long KBs = amount / factor;
|
|
||||||
var KBs = amount;
|
|
||||||
if (KBs > 0)
|
|
||||||
{
|
|
||||||
// multi KB
|
|
||||||
var MBs = KBs / factor;
|
|
||||||
if (MBs > 0)
|
|
||||||
{
|
|
||||||
// multi MB
|
|
||||||
var GBs = MBs / factor;
|
|
||||||
if (GBs > 0)
|
|
||||||
{
|
|
||||||
// multi GB
|
|
||||||
var TBs = GBs / factor;
|
|
||||||
if (TBs > 0)
|
|
||||||
{
|
|
||||||
result = TBs + ((GBs % factor) / (factor + 0.0));
|
|
||||||
unit = "TB";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = GBs + ((MBs % factor) / (factor + 0.0));
|
|
||||||
unit = "GB";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = MBs + ((KBs % factor) / (factor + 0.0));
|
|
||||||
unit = "MB";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = KBs + ((amount % factor) / (factor + 0.0));
|
|
||||||
unit = "KB";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = amount;
|
|
||||||
unit = "B";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string HumanFy(long amount)
|
public static string HumanFy(long amount)
|
||||||
{
|
{
|
||||||
ToHumanReadable(amount, out var result, out var unit);
|
if (amount <= 0)
|
||||||
return $"{result:f1} {unit}";
|
{
|
||||||
|
return $"{amount:f1} B";
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] units = ["KB", "MB", "GB", "TB", "PB"];
|
||||||
|
var unitIndex = 0;
|
||||||
|
double size = amount;
|
||||||
|
|
||||||
|
// Loop and divide by 1024 until a suitable unit is found
|
||||||
|
while (size >= 1024 && unitIndex < units.Length - 1)
|
||||||
|
{
|
||||||
|
size /= 1024;
|
||||||
|
unitIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"{size:f1} {units[unitIndex]}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string UrlEncode(string url)
|
public static string UrlEncode(string url)
|
||||||
@@ -252,7 +197,7 @@ namespace ServiceLib.Common
|
|||||||
public static NameValueCollection ParseQueryString(string query)
|
public static NameValueCollection ParseQueryString(string query)
|
||||||
{
|
{
|
||||||
var result = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
|
var result = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
|
||||||
if (IsNullOrEmpty(query))
|
if (query.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -280,15 +225,54 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
public static string GetMd5(string str)
|
public static string GetMd5(string str)
|
||||||
{
|
{
|
||||||
var byteOld = Encoding.UTF8.GetBytes(str);
|
if (string.IsNullOrEmpty(str))
|
||||||
var byteNew = MD5.HashData(byteOld);
|
|
||||||
StringBuilder sb = new(32);
|
|
||||||
foreach (var b in byteNew)
|
|
||||||
{
|
{
|
||||||
sb.Append(b.ToString("x2"));
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.ToString();
|
try
|
||||||
|
{
|
||||||
|
var byteOld = Encoding.UTF8.GetBytes(str);
|
||||||
|
var byteNew = MD5.HashData(byteOld);
|
||||||
|
StringBuilder sb = new(32);
|
||||||
|
foreach (var b in byteNew)
|
||||||
|
{
|
||||||
|
sb.Append(b.ToString("x2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetFileHash(string filePath)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(filePath))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var md5 = MD5.Create();
|
||||||
|
using var stream = File.OpenRead(filePath);
|
||||||
|
var hash = md5.ComputeHash(stream);
|
||||||
|
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -298,7 +282,7 @@ namespace ServiceLib.Common
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetPunycode(string url)
|
public static string GetPunycode(string url)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@@ -331,7 +315,7 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
public static string Convert2Comma(string text)
|
public static string Convert2Comma(string text)
|
||||||
{
|
{
|
||||||
if (IsNullOrEmpty(text))
|
if (text.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@@ -344,7 +328,7 @@ namespace ServiceLib.Common
|
|||||||
#region 数据检查
|
#region 数据检查
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 判断输入的是否是数字
|
/// Determine if the input is a number
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="oText"></param>
|
/// <param name="oText"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@@ -353,28 +337,13 @@ namespace ServiceLib.Common
|
|||||||
return oText.All(char.IsNumber);
|
return oText.All(char.IsNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsNullOrEmpty(string? text)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(text))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return text == "null";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsNotEmpty(string? text)
|
|
||||||
{
|
|
||||||
return !string.IsNullOrEmpty(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 验证Domain地址是否合法
|
/// Validate if the domain address is valid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="domain"></param>
|
/// <param name="domain"></param>
|
||||||
public static bool IsDomain(string? domain)
|
public static bool IsDomain(string? domain)
|
||||||
{
|
{
|
||||||
if (IsNullOrEmpty(domain))
|
if (domain.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -433,10 +402,22 @@ namespace ServiceLib.Common
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var ipProperties = IPGlobalProperties.GetIPGlobalProperties();
|
List<IPEndPoint> lstIpEndPoints = new();
|
||||||
var ipEndPoints = ipProperties.GetActiveTcpListeners();
|
List<TcpConnectionInformation> lstTcpConns = new();
|
||||||
//var lstIpEndPoints = new List<IPEndPoint>(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners());
|
|
||||||
return ipEndPoints.Any(endPoint => endPoint.Port == port);
|
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners());
|
||||||
|
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners());
|
||||||
|
lstTcpConns.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections());
|
||||||
|
|
||||||
|
if (lstIpEndPoints?.FindIndex(it => it.Port == port) >= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lstTcpConns?.FindIndex(it => it.LocalEndPoint.Port == port) >= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -479,7 +460,7 @@ namespace ServiceLib.Common
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 取得版本
|
/// Get version
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetVersion(bool blFull = true)
|
public static string GetVersion(bool blFull = true)
|
||||||
@@ -517,7 +498,7 @@ namespace ServiceLib.Common
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 取得GUID
|
/// GUID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetGuid(bool full = true)
|
public static string GetGuid(bool full = true)
|
||||||
@@ -622,13 +603,20 @@ namespace ServiceLib.Common
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var basePath = GetBaseDirectory();
|
||||||
//When this file exists, it is equivalent to having no permission to read and write
|
//When this file exists, it is equivalent to having no permission to read and write
|
||||||
if (File.Exists(Path.Combine(GetBaseDirectory(), "NotStoreConfigHere.txt")))
|
if (File.Exists(Path.Combine(basePath, "NotStoreConfigHere.txt")))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tempPath = Path.Combine(GetBaseDirectory(), "guiTemps");
|
//Check if it is installed by Windows WinGet
|
||||||
|
if (IsWindows() && basePath.Contains("Users") && basePath.Contains("WinGet"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tempPath = Path.Combine(basePath, "guiTemps");
|
||||||
if (!Directory.Exists(tempPath))
|
if (!Directory.Exists(tempPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(tempPath);
|
Directory.CreateDirectory(tempPath);
|
||||||
@@ -648,7 +636,7 @@ namespace ServiceLib.Common
|
|||||||
public static string GetPath(string fileName)
|
public static string GetPath(string fileName)
|
||||||
{
|
{
|
||||||
var startupPath = StartupPath();
|
var startupPath = StartupPath();
|
||||||
if (IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return startupPath;
|
return startupPath;
|
||||||
}
|
}
|
||||||
@@ -684,7 +672,7 @@ namespace ServiceLib.Common
|
|||||||
Directory.CreateDirectory(tempPath);
|
Directory.CreateDirectory(tempPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsNullOrEmpty(filename))
|
if (filename.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return tempPath;
|
return tempPath;
|
||||||
}
|
}
|
||||||
@@ -713,7 +701,7 @@ namespace ServiceLib.Common
|
|||||||
Directory.CreateDirectory(tempPath);
|
Directory.CreateDirectory(tempPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(filename))
|
if (filename.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return tempPath;
|
return tempPath;
|
||||||
}
|
}
|
||||||
@@ -740,7 +728,7 @@ namespace ServiceLib.Common
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsNullOrEmpty(filename))
|
if (filename.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return tempPath;
|
return tempPath;
|
||||||
}
|
}
|
||||||
@@ -758,7 +746,7 @@ namespace ServiceLib.Common
|
|||||||
Directory.CreateDirectory(tempPath);
|
Directory.CreateDirectory(tempPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(filename))
|
if (filename.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return tempPath;
|
return tempPath;
|
||||||
}
|
}
|
||||||
@@ -776,7 +764,25 @@ namespace ServiceLib.Common
|
|||||||
Directory.CreateDirectory(tempPath);
|
Directory.CreateDirectory(tempPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(filename))
|
if (filename.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return tempPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Path.Combine(tempPath, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetBinConfigPath(string filename = "")
|
||||||
|
{
|
||||||
|
var tempPath = Path.Combine(StartupPath(), "binConfigs");
|
||||||
|
if (!Directory.Exists(tempPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(tempPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filename.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return tempPath;
|
return tempPath;
|
||||||
}
|
}
|
||||||
@@ -827,7 +833,7 @@ namespace ServiceLib.Common
|
|||||||
private static async Task<string?> GetLinuxUserId()
|
private static async Task<string?> GetLinuxUserId()
|
||||||
{
|
{
|
||||||
var arg = new List<string>() { "-c", "id -u" };
|
var arg = new List<string>() { "-c", "id -u" };
|
||||||
return await GetCliWrapOutput("/bin/bash", arg);
|
return await GetCliWrapOutput(Global.LinuxBash, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string?> SetLinuxChmod(string? fileName)
|
public static async Task<string?> SetLinuxChmod(string? fileName)
|
||||||
@@ -838,14 +844,14 @@ namespace ServiceLib.Common
|
|||||||
fileName = fileName.AppendQuotes();
|
fileName = fileName.AppendQuotes();
|
||||||
//File.SetUnixFileMode(fileName, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);
|
//File.SetUnixFileMode(fileName, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);
|
||||||
var arg = new List<string>() { "-c", $"chmod +x {fileName}" };
|
var arg = new List<string>() { "-c", $"chmod +x {fileName}" };
|
||||||
return await GetCliWrapOutput("/bin/bash", arg);
|
return await GetCliWrapOutput(Global.LinuxBash, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string?> GetLinuxFontFamily(string lang)
|
public static async Task<string?> GetLinuxFontFamily(string lang)
|
||||||
{
|
{
|
||||||
// var arg = new List<string>() { "-c", $"fc-list :lang={lang} family" };
|
// var arg = new List<string>() { "-c", $"fc-list :lang={lang} family" };
|
||||||
var arg = new List<string>() { "-c", $"fc-list : family" };
|
var arg = new List<string>() { "-c", $"fc-list : family" };
|
||||||
return await GetCliWrapOutput("/bin/bash", arg);
|
return await GetCliWrapOutput(Global.LinuxBash, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string? GetHomePath()
|
public static string? GetHomePath()
|
||||||
@@ -855,12 +861,6 @@ namespace ServiceLib.Common
|
|||||||
: Environment.GetEnvironmentVariable("HOME");
|
: Environment.GetEnvironmentVariable("HOME");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string?> GetListNetworkServices()
|
|
||||||
{
|
|
||||||
var arg = new List<string>() { "-c", $"networksetup -listallnetworkservices" };
|
|
||||||
return await GetCliWrapOutput("/bin/bash", arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Platform
|
#endregion Platform
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace ServiceLib.Common
|
|||||||
{
|
{
|
||||||
regKey = Registry.CurrentUser.OpenSubKey(path, false);
|
regKey = Registry.CurrentUser.OpenSubKey(path, false);
|
||||||
var value = regKey?.GetValue(name) as string;
|
var value = regKey?.GetValue(name) as string;
|
||||||
return Utils.IsNullOrEmpty(value) ? def : value;
|
return value.IsNullOrEmpty() ? def : value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -34,7 +34,7 @@ namespace ServiceLib.Common
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
regKey = Registry.CurrentUser.CreateSubKey(path);
|
regKey = Registry.CurrentUser.CreateSubKey(path);
|
||||||
if (Utils.IsNullOrEmpty(value.ToString()))
|
if (value.ToString().IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
regKey?.DeleteValue(name, false);
|
regKey?.DeleteValue(name, false);
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ namespace ServiceLib.Common
|
|||||||
var arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" """;
|
var arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" """;
|
||||||
|
|
||||||
// Try to remove the device
|
// Try to remove the device
|
||||||
await Utils.GetCliWrapOutput(pnpUtilPath, arg);
|
_ = await Utils.GetCliWrapOutput(pnpUtilPath, arg);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using YamlDotNet.Core;
|
using YamlDotNet.Core;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
using YamlDotNet.Serialization.NamingConventions;
|
using YamlDotNet.Serialization.NamingConventions;
|
||||||
|
|
||||||
@@ -62,9 +62,6 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
public static string? PreprocessYaml(string str)
|
public static string? PreprocessYaml(string str)
|
||||||
{
|
{
|
||||||
var deserializer = new DeserializerBuilder()
|
|
||||||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
|
||||||
.Build();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var mergingParser = new MergingParser(new Parser(new StringReader(str)));
|
var mergingParser = new MergingParser(new Parser(new StringReader(str)));
|
||||||
@@ -80,4 +77,4 @@ namespace ServiceLib.Common
|
|||||||
|
|
||||||
#endregion YAML
|
#endregion YAML
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace ServiceLib.Enums
|
namespace ServiceLib.Enums
|
||||||
{
|
{
|
||||||
public enum EMsgCommand
|
public enum EMsgCommand
|
||||||
{
|
{
|
||||||
@@ -6,7 +6,6 @@
|
|||||||
SendMsgView,
|
SendMsgView,
|
||||||
SendSnackMsg,
|
SendSnackMsg,
|
||||||
RefreshProfiles,
|
RefreshProfiles,
|
||||||
StopSpeedtest,
|
|
||||||
AppExit
|
AppExit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace ServiceLib
|
|||||||
public const string ConfigFileName = "guiNConfig.json";
|
public const string ConfigFileName = "guiNConfig.json";
|
||||||
public const string CoreConfigFileName = "config.json";
|
public const string CoreConfigFileName = "config.json";
|
||||||
public const string CorePreConfigFileName = "configPre.json";
|
public const string CorePreConfigFileName = "configPre.json";
|
||||||
public const string CoreSpeedtestConfigFileName = "configSpeedtest.json";
|
public const string CoreSpeedtestConfigFileName = "configTest{0}.json";
|
||||||
public const string CoreMultipleLoadConfigFileName = "configMultipleLoad.json";
|
public const string CoreMultipleLoadConfigFileName = "configMultipleLoad.json";
|
||||||
public const string ClashMixinConfigFileName = "Mixin.yaml";
|
public const string ClashMixinConfigFileName = "Mixin.yaml";
|
||||||
|
|
||||||
@@ -38,6 +38,8 @@ namespace ServiceLib
|
|||||||
public const string ClashTunYaml = NamespaceSample + "clash_tun_yaml";
|
public const string ClashTunYaml = NamespaceSample + "clash_tun_yaml";
|
||||||
public const string LinuxAutostartConfig = NamespaceSample + "linux_autostart_config";
|
public const string LinuxAutostartConfig = NamespaceSample + "linux_autostart_config";
|
||||||
public const string PacFileName = NamespaceSample + "pac";
|
public const string PacFileName = NamespaceSample + "pac";
|
||||||
|
public const string ProxySetOSXShellFileName = NamespaceSample + "proxy_set_osx_sh";
|
||||||
|
public const string ProxySetLinuxShellFileName = NamespaceSample + "proxy_set_linux_sh";
|
||||||
|
|
||||||
public const string DefaultSecurity = "auto";
|
public const string DefaultSecurity = "auto";
|
||||||
public const string DefaultNetwork = "tcp";
|
public const string DefaultNetwork = "tcp";
|
||||||
@@ -64,14 +66,14 @@ namespace ServiceLib
|
|||||||
public const string GrpcGunMode = "gun";
|
public const string GrpcGunMode = "gun";
|
||||||
public const string GrpcMultiMode = "multi";
|
public const string GrpcMultiMode = "multi";
|
||||||
public const int MaxPort = 65536;
|
public const int MaxPort = 65536;
|
||||||
public const string DelayUnit = "";
|
|
||||||
public const string SpeedUnit = "";
|
|
||||||
public const int MinFontSize = 8;
|
public const int MinFontSize = 8;
|
||||||
public const string RebootAs = "rebootas";
|
public const string RebootAs = "rebootas";
|
||||||
public const string AvaAssets = "avares://v2rayN/Assets/";
|
public const string AvaAssets = "avares://v2rayN/Assets/";
|
||||||
public const string LocalAppData = "V2RAYN_LOCAL_APPLICATION_DATA";
|
public const string LocalAppData = "V2RAYN_LOCAL_APPLICATION_DATA_V2";
|
||||||
public const string V2RayLocalAsset = "V2RAY_LOCATION_ASSET";
|
public const string V2RayLocalAsset = "V2RAY_LOCATION_ASSET";
|
||||||
public const string XrayLocalAsset = "XRAY_LOCATION_ASSET";
|
public const string XrayLocalAsset = "XRAY_LOCATION_ASSET";
|
||||||
|
public const int SpeedTestPageSize = 1000;
|
||||||
|
public const string LinuxBash = "/bin/bash";
|
||||||
|
|
||||||
public static readonly List<string> IEProxyProtocols =
|
public static readonly List<string> IEProxyProtocols =
|
||||||
[
|
[
|
||||||
@@ -104,10 +106,10 @@ namespace ServiceLib
|
|||||||
|
|
||||||
public static readonly List<string> SpeedTestUrls =
|
public static readonly List<string> SpeedTestUrls =
|
||||||
[
|
[
|
||||||
@"https://speed.cloudflare.com/__down?bytes=100000000",
|
@"https://cachefly.cachefly.net/50mb.test",
|
||||||
@"https://speed.cloudflare.com/__down?bytes=50000000",
|
|
||||||
@"https://speed.cloudflare.com/__down?bytes=10000000",
|
@"https://speed.cloudflare.com/__down?bytes=10000000",
|
||||||
@"https://cachefly.cachefly.net/50mb.test"
|
@"https://speed.cloudflare.com/__down?bytes=50000000",
|
||||||
|
@"https://speed.cloudflare.com/__down?bytes=100000000",
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly List<string> SpeedPingTestUrls =
|
public static readonly List<string> SpeedPingTestUrls =
|
||||||
@@ -263,7 +265,8 @@ namespace ServiceLib
|
|||||||
"utp",
|
"utp",
|
||||||
"wechat-video",
|
"wechat-video",
|
||||||
"dtls",
|
"dtls",
|
||||||
"wireguard"
|
"wireguard",
|
||||||
|
"dns"
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly List<string> CoreTypes =
|
public static readonly List<string> CoreTypes =
|
||||||
@@ -427,12 +430,12 @@ namespace ServiceLib
|
|||||||
"fakedns+others"
|
"fakedns+others"
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly List<string> TunMtus =
|
public static readonly List<int> TunMtus =
|
||||||
[
|
[
|
||||||
"1280",
|
1280,
|
||||||
"1408",
|
1408,
|
||||||
"1500",
|
1500,
|
||||||
"9000"
|
9000
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly List<string> TunStacks =
|
public static readonly List<string> TunStacks =
|
||||||
@@ -508,6 +511,13 @@ namespace ServiceLib
|
|||||||
{ ECoreType.v2rayN, "2dust/v2rayN" },
|
{ ECoreType.v2rayN, "2dust/v2rayN" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static readonly List<string> OtherGeoUrls =
|
||||||
|
[
|
||||||
|
@"https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat",
|
||||||
|
@"https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb",
|
||||||
|
@"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb"
|
||||||
|
];
|
||||||
|
|
||||||
#endregion const
|
#endregion const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Handler
|
||||||
{
|
{
|
||||||
public sealed class AppHandler
|
public sealed class AppHandler
|
||||||
{
|
{
|
||||||
@@ -80,8 +80,6 @@
|
|||||||
Logging.SaveLog($"v2rayN start up | {Utils.GetRuntimeInfo()}");
|
Logging.SaveLog($"v2rayN start up | {Utils.GetRuntimeInfo()}");
|
||||||
Logging.LoggingEnabled(_config.GuiItem.EnableLog);
|
Logging.LoggingEnabled(_config.GuiItem.EnableLog);
|
||||||
|
|
||||||
ClearExpiredFiles();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,15 +90,6 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearExpiredFiles()
|
|
||||||
{
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
FileManager.DeleteExpiredFiles(Utils.GetLogPath(), DateTime.Now.AddMonths(-1));
|
|
||||||
FileManager.DeleteExpiredFiles(Utils.GetTempPath(), DateTime.Now.AddMonths(-1));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Init
|
#endregion Init
|
||||||
|
|
||||||
#region Config
|
#region Config
|
||||||
@@ -142,7 +131,7 @@
|
|||||||
|
|
||||||
public async Task<List<ProfileItem>?> ProfileItems(string subid)
|
public async Task<List<ProfileItem>?> ProfileItems(string subid)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(subid))
|
if (subid.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return await SQLiteHelper.Instance.TableAsync<ProfileItem>().ToListAsync();
|
return await SQLiteHelper.Instance.TableAsync<ProfileItem>().ToListAsync();
|
||||||
}
|
}
|
||||||
@@ -164,11 +153,11 @@
|
|||||||
from ProfileItem a
|
from ProfileItem a
|
||||||
left join SubItem b on a.subid = b.id
|
left join SubItem b on a.subid = b.id
|
||||||
where 1=1 ";
|
where 1=1 ";
|
||||||
if (Utils.IsNotEmpty(subid))
|
if (subid.IsNotEmpty())
|
||||||
{
|
{
|
||||||
sql += $" and a.subid = '{subid}'";
|
sql += $" and a.subid = '{subid}'";
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(filter))
|
if (filter.IsNotEmpty())
|
||||||
{
|
{
|
||||||
if (filter.Contains('\''))
|
if (filter.Contains('\''))
|
||||||
{
|
{
|
||||||
@@ -182,7 +171,7 @@
|
|||||||
|
|
||||||
public async Task<ProfileItem?> GetProfileItem(string indexId)
|
public async Task<ProfileItem?> GetProfileItem(string indexId)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(indexId))
|
if (indexId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -191,7 +180,7 @@
|
|||||||
|
|
||||||
public async Task<ProfileItem?> GetProfileItemViaRemarks(string? remarks)
|
public async Task<ProfileItem?> GetProfileItemViaRemarks(string? remarks)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(remarks))
|
if (remarks.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -252,4 +241,4 @@
|
|||||||
|
|
||||||
#endregion Core Type
|
#endregion Core Type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace ServiceLib.Handler
|
|||||||
/// <exception cref="ArgumentNullException"></exception>
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
public static void AutoStartTaskService(string taskName, string fileName, string description)
|
public static void AutoStartTaskService(string taskName, string fileName, string description)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(taskName))
|
if (taskName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ namespace ServiceLib.Handler
|
|||||||
var logonUser = WindowsIdentity.GetCurrent().Name;
|
var logonUser = WindowsIdentity.GetCurrent().Name;
|
||||||
using var taskService = new Microsoft.Win32.TaskScheduler.TaskService();
|
using var taskService = new Microsoft.Win32.TaskScheduler.TaskService();
|
||||||
var tasks = taskService.RootFolder.GetTasks(new Regex(taskName));
|
var tasks = taskService.RootFolder.GetTasks(new Regex(taskName));
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
foreach (var t in tasks)
|
foreach (var t in tasks)
|
||||||
{
|
{
|
||||||
@@ -109,7 +109,7 @@ namespace ServiceLib.Handler
|
|||||||
task.Settings.RunOnlyIfIdle = false;
|
task.Settings.RunOnlyIfIdle = false;
|
||||||
task.Settings.IdleSettings.StopOnIdleEnd = false;
|
task.Settings.IdleSettings.StopOnIdleEnd = false;
|
||||||
task.Settings.ExecutionTimeLimit = TimeSpan.Zero;
|
task.Settings.ExecutionTimeLimit = TimeSpan.Zero;
|
||||||
task.Triggers.Add(new Microsoft.Win32.TaskScheduler.LogonTrigger { UserId = logonUser, Delay = TimeSpan.FromSeconds(10) });
|
task.Triggers.Add(new Microsoft.Win32.TaskScheduler.LogonTrigger { UserId = logonUser, Delay = TimeSpan.FromSeconds(30) });
|
||||||
task.Principal.RunLevel = Microsoft.Win32.TaskScheduler.TaskRunLevel.Highest;
|
task.Principal.RunLevel = Microsoft.Win32.TaskScheduler.TaskRunLevel.Highest;
|
||||||
task.Actions.Add(new Microsoft.Win32.TaskScheduler.ExecAction(fileName.AppendQuotes(), null, Path.GetDirectoryName(fileName)));
|
task.Actions.Add(new Microsoft.Win32.TaskScheduler.ExecAction(fileName.AppendQuotes(), null, Path.GetDirectoryName(fileName)));
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ namespace ServiceLib.Handler
|
|||||||
if (File.Exists(launchAgentPath))
|
if (File.Exists(launchAgentPath))
|
||||||
{
|
{
|
||||||
var args = new[] { "-c", $"launchctl unload -w \"{launchAgentPath}\"" };
|
var args = new[] { "-c", $"launchctl unload -w \"{launchAgentPath}\"" };
|
||||||
await Utils.GetCliWrapOutput("/bin/bash", args);
|
await Utils.GetCliWrapOutput(Global.LinuxBash, args);
|
||||||
|
|
||||||
File.Delete(launchAgentPath);
|
File.Delete(launchAgentPath);
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ namespace ServiceLib.Handler
|
|||||||
await File.WriteAllTextAsync(launchAgentPath, plistContent);
|
await File.WriteAllTextAsync(launchAgentPath, plistContent);
|
||||||
|
|
||||||
var args = new[] { "-c", $"launchctl load -w \"{launchAgentPath}\"" };
|
var args = new[] { "-c", $"launchctl load -w \"{launchAgentPath}\"" };
|
||||||
await Utils.GetCliWrapOutput("/bin/bash", args);
|
await Utils.GetCliWrapOutput(Global.LinuxBash, args);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using static ServiceLib.Models.ClashProxies;
|
using static ServiceLib.Models.ClashProxies;
|
||||||
|
|
||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Handler
|
||||||
{
|
{
|
||||||
@@ -7,13 +7,13 @@ namespace ServiceLib.Handler
|
|||||||
private static readonly Lazy<ClashApiHandler> instance = new(() => new());
|
private static readonly Lazy<ClashApiHandler> instance = new(() => new());
|
||||||
public static ClashApiHandler Instance => instance.Value;
|
public static ClashApiHandler Instance => instance.Value;
|
||||||
|
|
||||||
|
private static readonly string _tag = "ClashApiHandler";
|
||||||
private Dictionary<string, ProxiesItem>? _proxies;
|
private Dictionary<string, ProxiesItem>? _proxies;
|
||||||
public Dictionary<string, object> ProfileContent { get; set; }
|
public Dictionary<string, object> ProfileContent { get; set; }
|
||||||
private static readonly string _tag = "ClashApiHandler";
|
|
||||||
|
|
||||||
public async Task<Tuple<ClashProxies, ClashProviders>?> GetClashProxiesAsync(Config config)
|
public async Task<Tuple<ClashProxies, ClashProviders>?> GetClashProxiesAsync()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < 5; i++)
|
for (var i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
var url = $"{GetApiUrl()}/proxies";
|
var url = $"{GetApiUrl()}/proxies";
|
||||||
var result = await HttpClientHelper.Instance.TryGetAsync(url);
|
var result = await HttpClientHelper.Instance.TryGetAsync(url);
|
||||||
@@ -37,64 +37,55 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
public void ClashProxiesDelayTest(bool blAll, List<ClashProxyModel> lstProxy, Action<ClashProxyModel?, string> updateFunc)
|
public void ClashProxiesDelayTest(bool blAll, List<ClashProxyModel> lstProxy, Action<ClashProxyModel?, string> updateFunc)
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
Task.Run(async () =>
|
||||||
{
|
|
||||||
if (blAll)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 5; i++)
|
if (blAll)
|
||||||
{
|
{
|
||||||
if (_proxies != null)
|
if (_proxies == null)
|
||||||
{
|
{
|
||||||
break;
|
await GetClashProxiesAsync();
|
||||||
|
}
|
||||||
|
lstProxy = new List<ClashProxyModel>();
|
||||||
|
foreach (var kv in _proxies ?? [])
|
||||||
|
{
|
||||||
|
if (Global.notAllowTestType.Contains(kv.Value.type?.ToLower()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lstProxy.Add(new ClashProxyModel()
|
||||||
|
{
|
||||||
|
Name = kv.Value.name,
|
||||||
|
Type = kv.Value.type?.ToLower(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Task.Delay(5000).Wait();
|
|
||||||
}
|
}
|
||||||
if (_proxies == null)
|
|
||||||
|
if (lstProxy is not { Count: > 0 })
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lstProxy = new List<ClashProxyModel>();
|
var urlBase = $"{GetApiUrl()}/proxies";
|
||||||
foreach (KeyValuePair<string, ProxiesItem> kv in _proxies)
|
urlBase += @"/{0}/delay?timeout=10000&url=" + AppHandler.Instance.Config.SpeedTestItem.SpeedPingTestUrl;
|
||||||
|
|
||||||
|
var tasks = new List<Task>();
|
||||||
|
foreach (var it in lstProxy)
|
||||||
{
|
{
|
||||||
if (Global.notAllowTestType.Contains(kv.Value.type.ToLower()))
|
if (Global.notAllowTestType.Contains(it.Type.ToLower()))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lstProxy.Add(new ClashProxyModel()
|
var name = it.Name;
|
||||||
|
var url = string.Format(urlBase, name);
|
||||||
|
tasks.Add(Task.Run(async () =>
|
||||||
{
|
{
|
||||||
Name = kv.Value.name,
|
var result = await HttpClientHelper.Instance.TryGetAsync(url);
|
||||||
Type = kv.Value.type.ToLower(),
|
updateFunc?.Invoke(it, result);
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
}
|
await Task.WhenAll(tasks);
|
||||||
|
await Task.Delay(1000);
|
||||||
if (lstProxy == null)
|
updateFunc?.Invoke(null, "");
|
||||||
{
|
});
|
||||||
return;
|
|
||||||
}
|
|
||||||
var urlBase = $"{GetApiUrl()}/proxies";
|
|
||||||
urlBase += @"/{0}/delay?timeout=10000&url=" + AppHandler.Instance.Config.SpeedTestItem.SpeedPingTestUrl;
|
|
||||||
|
|
||||||
List<Task> tasks = new List<Task>();
|
|
||||||
foreach (var it in lstProxy)
|
|
||||||
{
|
|
||||||
if (Global.notAllowTestType.Contains(it.Type.ToLower()))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var name = it.Name;
|
|
||||||
var url = string.Format(urlBase, name);
|
|
||||||
tasks.Add(Task.Run(async () =>
|
|
||||||
{
|
|
||||||
var result = await HttpClientHelper.Instance.TryGetAsync(url);
|
|
||||||
updateFunc?.Invoke(it, result);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
Task.WaitAll(tasks.ToArray());
|
|
||||||
|
|
||||||
Task.Delay(1000).Wait();
|
|
||||||
updateFunc?.Invoke(null, "");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProxiesItem>? GetClashProxyGroups()
|
public List<ProxiesItem>? GetClashProxyGroups()
|
||||||
@@ -120,7 +111,7 @@ namespace ServiceLib.Handler
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var url = $"{GetApiUrl()}/proxies/{name}";
|
var url = $"{GetApiUrl()}/proxies/{name}";
|
||||||
Dictionary<string, string> headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>();
|
||||||
headers.Add("name", nameNode);
|
headers.Add("name", nameNode);
|
||||||
await HttpClientHelper.Instance.PutAsync(url, headers);
|
await HttpClientHelper.Instance.PutAsync(url, headers);
|
||||||
}
|
}
|
||||||
@@ -148,7 +139,7 @@ namespace ServiceLib.Handler
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var url = $"{GetApiUrl()}/configs?force=true";
|
var url = $"{GetApiUrl()}/configs?force=true";
|
||||||
Dictionary<string, string> headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>();
|
||||||
headers.Add("path", filePath);
|
headers.Add("path", filePath);
|
||||||
await HttpClientHelper.Instance.PutAsync(url, headers);
|
await HttpClientHelper.Instance.PutAsync(url, headers);
|
||||||
}
|
}
|
||||||
@@ -158,7 +149,7 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ClashConnections?> GetClashConnectionsAsync(Config config)
|
public async Task<ClashConnections?> GetClashConnectionsAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -194,4 +185,4 @@ namespace ServiceLib.Handler
|
|||||||
return $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort2}";
|
return $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort2}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
Config? config = null;
|
Config? config = null;
|
||||||
var result = EmbedUtils.LoadResource(Utils.GetConfigPath(_configRes));
|
var result = EmbedUtils.LoadResource(Utils.GetConfigPath(_configRes));
|
||||||
if (Utils.IsNotEmpty(result))
|
if (result.IsNotEmpty())
|
||||||
{
|
{
|
||||||
config = JsonUtils.Deserialize<Config>(result);
|
config = JsonUtils.Deserialize<Config>(result);
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
config.RoutingBasicItem ??= new();
|
config.RoutingBasicItem ??= new();
|
||||||
if (Utils.IsNullOrEmpty(config.RoutingBasicItem.DomainStrategy))
|
if (config.RoutingBasicItem.DomainStrategy.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies.First();
|
config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies.First();
|
||||||
}
|
}
|
||||||
@@ -103,16 +103,11 @@ namespace ServiceLib.Handler
|
|||||||
};
|
};
|
||||||
config.UiItem.MainColumnItem ??= new();
|
config.UiItem.MainColumnItem ??= new();
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(config.UiItem.CurrentLanguage))
|
if (config.UiItem.CurrentLanguage.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
if (Thread.CurrentThread.CurrentCulture.Name.Equals("zh-cn", StringComparison.CurrentCultureIgnoreCase))
|
config.UiItem.CurrentLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Equals("zh", StringComparison.CurrentCultureIgnoreCase)
|
||||||
{
|
? Global.Languages.First()
|
||||||
config.UiItem.CurrentLanguage = Global.Languages.First();
|
: Global.Languages[2];
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
config.UiItem.CurrentLanguage = Global.Languages[2];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config.ConstItem ??= new ConstItem();
|
config.ConstItem ??= new ConstItem();
|
||||||
@@ -122,14 +117,18 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
config.SpeedTestItem.SpeedTestTimeout = 10;
|
config.SpeedTestItem.SpeedTestTimeout = 10;
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedTestUrl))
|
if (config.SpeedTestItem.SpeedTestUrl.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls.First();
|
config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls.First();
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedPingTestUrl))
|
if (config.SpeedTestItem.SpeedPingTestUrl.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
config.SpeedTestItem.SpeedPingTestUrl = Global.SpeedPingTestUrl;
|
config.SpeedTestItem.SpeedPingTestUrl = Global.SpeedPingTestUrl;
|
||||||
}
|
}
|
||||||
|
if (config.SpeedTestItem.MixedConcurrencyCount < 1)
|
||||||
|
{
|
||||||
|
config.SpeedTestItem.MixedConcurrencyCount = 5;
|
||||||
|
}
|
||||||
|
|
||||||
config.Mux4RayItem ??= new()
|
config.Mux4RayItem ??= new()
|
||||||
{
|
{
|
||||||
@@ -159,6 +158,7 @@ namespace ServiceLib.Handler
|
|||||||
Length = "100-200",
|
Length = "100-200",
|
||||||
Interval = "10-20"
|
Interval = "10-20"
|
||||||
};
|
};
|
||||||
|
config.GlobalHotkeys ??= new();
|
||||||
|
|
||||||
if (config.SystemProxyItem.SystemProxyExceptions.IsNullOrEmpty())
|
if (config.SystemProxyItem.SystemProxyExceptions.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
@@ -217,6 +217,7 @@ namespace ServiceLib.Handler
|
|||||||
item.Remarks = profileItem.Remarks;
|
item.Remarks = profileItem.Remarks;
|
||||||
item.Address = profileItem.Address;
|
item.Address = profileItem.Address;
|
||||||
item.Port = profileItem.Port;
|
item.Port = profileItem.Port;
|
||||||
|
item.Ports = profileItem.Ports;
|
||||||
|
|
||||||
item.Id = profileItem.Id;
|
item.Id = profileItem.Id;
|
||||||
item.AlterId = profileItem.AlterId;
|
item.AlterId = profileItem.AlterId;
|
||||||
@@ -295,7 +296,7 @@ namespace ServiceLib.Handler
|
|||||||
/// <param name="config"></param>
|
/// <param name="config"></param>
|
||||||
/// <param name="indexes"></param>
|
/// <param name="indexes"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<int> RemoveServer(Config config, List<ProfileItem> indexes)
|
public static async Task<int> RemoveServers(Config config, List<ProfileItem> indexes)
|
||||||
{
|
{
|
||||||
var subid = "TempRemoveSubId";
|
var subid = "TempRemoveSubId";
|
||||||
foreach (var item in indexes)
|
foreach (var item in indexes)
|
||||||
@@ -304,7 +305,7 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
await SQLiteHelper.Instance.UpdateAllAsync(indexes);
|
await SQLiteHelper.Instance.UpdateAllAsync(indexes);
|
||||||
await RemoveServerViaSubid(config, subid, false);
|
await RemoveServersViaSubid(config, subid, false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -353,7 +354,7 @@ namespace ServiceLib.Handler
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<int> SetDefaultServerIndex(Config config, string? indexId)
|
public static async Task<int> SetDefaultServerIndex(Config config, string? indexId)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(indexId))
|
if (indexId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -505,7 +506,7 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
profileItem.Address = newFileName;
|
profileItem.Address = newFileName;
|
||||||
profileItem.ConfigType = EConfigType.Custom;
|
profileItem.ConfigType = EConfigType.Custom;
|
||||||
if (Utils.IsNullOrEmpty(profileItem.Remarks))
|
if (profileItem.Remarks.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
profileItem.Remarks = $"import custom@{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}";
|
profileItem.Remarks = $"import custom@{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}";
|
||||||
}
|
}
|
||||||
@@ -623,7 +624,7 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
profileItem.Address = profileItem.Address.TrimEx();
|
profileItem.Address = profileItem.Address.TrimEx();
|
||||||
profileItem.Id = profileItem.Id.TrimEx();
|
profileItem.Id = profileItem.Id.TrimEx();
|
||||||
if (Utils.IsNullOrEmpty(profileItem.StreamSecurity))
|
if (profileItem.StreamSecurity.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
profileItem.StreamSecurity = Global.StreamSecurity;
|
profileItem.StreamSecurity = Global.StreamSecurity;
|
||||||
}
|
}
|
||||||
@@ -653,7 +654,7 @@ namespace ServiceLib.Handler
|
|||||||
profileItem.Path = profileItem.Path.TrimEx();
|
profileItem.Path = profileItem.Path.TrimEx();
|
||||||
profileItem.Network = string.Empty;
|
profileItem.Network = string.Empty;
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(profileItem.StreamSecurity))
|
if (profileItem.StreamSecurity.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
profileItem.StreamSecurity = Global.StreamSecurity;
|
profileItem.StreamSecurity = Global.StreamSecurity;
|
||||||
}
|
}
|
||||||
@@ -688,11 +689,11 @@ namespace ServiceLib.Handler
|
|||||||
profileItem.HeaderType = Global.TuicCongestionControls.FirstOrDefault()!;
|
profileItem.HeaderType = Global.TuicCongestionControls.FirstOrDefault()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(profileItem.StreamSecurity))
|
if (profileItem.StreamSecurity.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
profileItem.StreamSecurity = Global.StreamSecurity;
|
profileItem.StreamSecurity = Global.StreamSecurity;
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(profileItem.Alpn))
|
if (profileItem.Alpn.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
profileItem.Alpn = "h3";
|
profileItem.Alpn = "h3";
|
||||||
}
|
}
|
||||||
@@ -725,7 +726,7 @@ namespace ServiceLib.Handler
|
|||||||
profileItem.Network = string.Empty;
|
profileItem.Network = string.Empty;
|
||||||
if (profileItem.ShortId.IsNullOrEmpty())
|
if (profileItem.ShortId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
profileItem.ShortId = Global.TunMtus.FirstOrDefault();
|
profileItem.ShortId = Global.TunMtus.First().ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profileItem.Id.IsNullOrEmpty())
|
if (profileItem.Id.IsNullOrEmpty())
|
||||||
@@ -759,9 +760,9 @@ namespace ServiceLib.Handler
|
|||||||
Security = t.Security,
|
Security = t.Security,
|
||||||
Network = t.Network,
|
Network = t.Network,
|
||||||
StreamSecurity = t.StreamSecurity,
|
StreamSecurity = t.StreamSecurity,
|
||||||
Delay = t33 == null ? 0 : t33.Delay,
|
Delay = t33?.Delay ?? 0,
|
||||||
Speed = t33 == null ? 0 : t33.Speed,
|
Speed = t33?.Speed ?? 0,
|
||||||
Sort = t33 == null ? 0 : t33.Sort
|
Sort = t33?.Sort ?? 0
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
Enum.TryParse(colName, true, out EServerColName name);
|
Enum.TryParse(colName, true, out EServerColName name);
|
||||||
@@ -857,7 +858,7 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(profileItem.Security) && profileItem.Security != Global.None)
|
if (profileItem.Security.IsNotEmpty() && profileItem.Security != Global.None)
|
||||||
{
|
{
|
||||||
profileItem.Security = Global.None;
|
profileItem.Security = Global.None;
|
||||||
}
|
}
|
||||||
@@ -870,13 +871,19 @@ namespace ServiceLib.Handler
|
|||||||
public static async Task<Tuple<int, int>> DedupServerList(Config config, string subId)
|
public static async Task<Tuple<int, int>> DedupServerList(Config config, string subId)
|
||||||
{
|
{
|
||||||
var lstProfile = await AppHandler.Instance.ProfileItems(subId);
|
var lstProfile = await AppHandler.Instance.ProfileItems(subId);
|
||||||
|
if (lstProfile == null)
|
||||||
|
{
|
||||||
|
return new Tuple<int, int>(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
List<ProfileItem> lstKeep = new();
|
List<ProfileItem> lstKeep = new();
|
||||||
List<ProfileItem> lstRemove = new();
|
List<ProfileItem> lstRemove = new();
|
||||||
if (!config.GuiItem.KeepOlderDedupl)
|
if (!config.GuiItem.KeepOlderDedupl)
|
||||||
|
{
|
||||||
lstProfile.Reverse();
|
lstProfile.Reverse();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (ProfileItem item in lstProfile)
|
foreach (var item in lstProfile)
|
||||||
{
|
{
|
||||||
if (!lstKeep.Exists(i => CompareProfileItem(i, item, false)))
|
if (!lstKeep.Exists(i => CompareProfileItem(i, item, false)))
|
||||||
{
|
{
|
||||||
@@ -887,7 +894,7 @@ namespace ServiceLib.Handler
|
|||||||
lstRemove.Add(item);
|
lstRemove.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await RemoveServer(config, lstRemove);
|
await RemoveServers(config, lstRemove);
|
||||||
|
|
||||||
return new Tuple<int, int>(lstProfile.Count, lstKeep.Count);
|
return new Tuple<int, int>(lstProfile.Count, lstKeep.Count);
|
||||||
}
|
}
|
||||||
@@ -896,7 +903,7 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
profileItem.ConfigVersion = 2;
|
profileItem.ConfigVersion = 2;
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(profileItem.StreamSecurity))
|
if (profileItem.StreamSecurity.IsNotEmpty())
|
||||||
{
|
{
|
||||||
if (profileItem.StreamSecurity != Global.StreamSecurity
|
if (profileItem.StreamSecurity != Global.StreamSecurity
|
||||||
&& profileItem.StreamSecurity != Global.StreamSecurityReality)
|
&& profileItem.StreamSecurity != Global.StreamSecurityReality)
|
||||||
@@ -905,24 +912,24 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(profileItem.AllowInsecure))
|
if (profileItem.AllowInsecure.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
profileItem.AllowInsecure = config.CoreBasicItem.DefAllowInsecure.ToString().ToLower();
|
profileItem.AllowInsecure = config.CoreBasicItem.DefAllowInsecure.ToString().ToLower();
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(profileItem.Fingerprint) && profileItem.StreamSecurity == Global.StreamSecurityReality)
|
if (profileItem.Fingerprint.IsNullOrEmpty() && profileItem.StreamSecurity == Global.StreamSecurityReality)
|
||||||
{
|
{
|
||||||
profileItem.Fingerprint = config.CoreBasicItem.DefFingerprint;
|
profileItem.Fingerprint = config.CoreBasicItem.DefFingerprint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(profileItem.Network) && !Global.Networks.Contains(profileItem.Network))
|
if (profileItem.Network.IsNotEmpty() && !Global.Networks.Contains(profileItem.Network))
|
||||||
{
|
{
|
||||||
profileItem.Network = Global.DefaultNetwork;
|
profileItem.Network = Global.DefaultNetwork;
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxSort = -1;
|
var maxSort = -1;
|
||||||
if (Utils.IsNullOrEmpty(profileItem.IndexId))
|
if (profileItem.IndexId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
profileItem.IndexId = Utils.GetGuid(false);
|
profileItem.IndexId = Utils.GetGuid(false);
|
||||||
maxSort = ProfileExHandler.Instance.GetMaxSort();
|
maxSort = ProfileExHandler.Instance.GetMaxSort();
|
||||||
@@ -943,7 +950,7 @@ namespace ServiceLib.Handler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CompareProfileItem(ProfileItem o, ProfileItem n, bool remarks)
|
private static bool CompareProfileItem(ProfileItem? o, ProfileItem? n, bool remarks)
|
||||||
{
|
{
|
||||||
if (o == null || n == null)
|
if (o == null || n == null)
|
||||||
{
|
{
|
||||||
@@ -951,22 +958,27 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
return o.ConfigType == n.ConfigType
|
return o.ConfigType == n.ConfigType
|
||||||
&& o.Address == n.Address
|
&& AreEqual(o.Address, n.Address)
|
||||||
&& o.Port == n.Port
|
&& o.Port == n.Port
|
||||||
&& o.Id == n.Id
|
&& AreEqual(o.Id, n.Id)
|
||||||
&& o.Security == n.Security
|
&& AreEqual(o.Security, n.Security)
|
||||||
&& o.Network == n.Network
|
&& AreEqual(o.Network, n.Network)
|
||||||
&& o.HeaderType == n.HeaderType
|
&& AreEqual(o.HeaderType, n.HeaderType)
|
||||||
&& o.RequestHost == n.RequestHost
|
&& AreEqual(o.RequestHost, n.RequestHost)
|
||||||
&& o.Path == n.Path
|
&& AreEqual(o.Path, n.Path)
|
||||||
&& (o.ConfigType == EConfigType.Trojan || o.StreamSecurity == n.StreamSecurity)
|
&& (o.ConfigType == EConfigType.Trojan || o.StreamSecurity == n.StreamSecurity)
|
||||||
&& o.Flow == n.Flow
|
&& AreEqual(o.Flow, n.Flow)
|
||||||
&& o.Sni == n.Sni
|
&& AreEqual(o.Sni, n.Sni)
|
||||||
&& o.Alpn == n.Alpn
|
&& AreEqual(o.Alpn, n.Alpn)
|
||||||
&& o.Fingerprint == n.Fingerprint
|
&& AreEqual(o.Fingerprint, n.Fingerprint)
|
||||||
&& o.PublicKey == n.PublicKey
|
&& AreEqual(o.PublicKey, n.PublicKey)
|
||||||
&& o.ShortId == n.ShortId
|
&& AreEqual(o.ShortId, n.ShortId)
|
||||||
&& (!remarks || o.Remarks == n.Remarks);
|
&& (!remarks || o.Remarks == n.Remarks);
|
||||||
|
|
||||||
|
static bool AreEqual(string? a, string? b)
|
||||||
|
{
|
||||||
|
return string.Equals(a, b) || (string.IsNullOrEmpty(a) && string.IsNullOrEmpty(b));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<int> RemoveProfileItem(Config config, string indexId)
|
private static async Task<int> RemoveProfileItem(Config config, string indexId)
|
||||||
@@ -1004,8 +1016,7 @@ namespace ServiceLib.Handler
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileName = configPath;
|
if (!File.Exists(configPath))
|
||||||
if (!File.Exists(fileName))
|
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1052,6 +1063,24 @@ namespace ServiceLib.Handler
|
|||||||
return itemSocks;
|
return itemSocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<int> RemoveInvalidServerResult(Config config, string subid)
|
||||||
|
{
|
||||||
|
var lstModel = await AppHandler.Instance.ProfileItems(subid, "");
|
||||||
|
if (lstModel is { Count: <= 0 })
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var lstProfileExs = await ProfileExHandler.Instance.GetProfileExs();
|
||||||
|
var lstProfile = (from t in lstModel
|
||||||
|
join t2 in lstProfileExs on t.IndexId equals t2.IndexId
|
||||||
|
where t2.Delay == -1
|
||||||
|
select t).ToList();
|
||||||
|
|
||||||
|
await RemoveServers(config, JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(lstProfile)));
|
||||||
|
|
||||||
|
return lstProfile.Count;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Server
|
#endregion Server
|
||||||
|
|
||||||
#region Batch add servers
|
#region Batch add servers
|
||||||
@@ -1065,16 +1094,16 @@ namespace ServiceLib.Handler
|
|||||||
/// <returns>成功导入的数量</returns>
|
/// <returns>成功导入的数量</returns>
|
||||||
private static async Task<int> AddBatchServersCommon(Config config, string strData, string subid, bool isSub)
|
private static async Task<int> AddBatchServersCommon(Config config, string strData, string subid, bool isSub)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(strData))
|
if (strData.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var subFilter = string.Empty;
|
var subFilter = string.Empty;
|
||||||
//remove sub items
|
//remove sub items
|
||||||
if (isSub && Utils.IsNotEmpty(subid))
|
if (isSub && subid.IsNotEmpty())
|
||||||
{
|
{
|
||||||
await RemoveServerViaSubid(config, subid, isSub);
|
await RemoveServersViaSubid(config, subid, isSub);
|
||||||
subFilter = (await AppHandler.Instance.GetSubItem(subid))?.Filter ?? "";
|
subFilter = (await AppHandler.Instance.GetSubItem(subid))?.Filter ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1103,7 +1132,7 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
//exist sub items //filter
|
//exist sub items //filter
|
||||||
if (isSub && Utils.IsNotEmpty(subid) && Utils.IsNotEmpty(subFilter))
|
if (isSub && subid.IsNotEmpty() && subFilter.IsNotEmpty())
|
||||||
{
|
{
|
||||||
if (!Regex.IsMatch(profileItem.Remarks, subFilter))
|
if (!Regex.IsMatch(profileItem.Remarks, subFilter))
|
||||||
{
|
{
|
||||||
@@ -1144,7 +1173,7 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
private static async Task<int> AddBatchServers4Custom(Config config, string strData, string subid, bool isSub)
|
private static async Task<int> AddBatchServers4Custom(Config config, string strData, string subid, bool isSub)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(strData))
|
if (strData.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1166,9 +1195,9 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
if (lstProfiles != null && lstProfiles.Count > 0)
|
if (lstProfiles != null && lstProfiles.Count > 0)
|
||||||
{
|
{
|
||||||
if (isSub && Utils.IsNotEmpty(subid))
|
if (isSub && subid.IsNotEmpty())
|
||||||
{
|
{
|
||||||
await RemoveServerViaSubid(config, subid, isSub);
|
await RemoveServersViaSubid(config, subid, isSub);
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
foreach (var it in lstProfiles)
|
foreach (var it in lstProfiles)
|
||||||
@@ -1217,14 +1246,14 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
profileItem = NaiveproxyFmt.ResolveFull(strData, subRemarks);
|
profileItem = NaiveproxyFmt.ResolveFull(strData, subRemarks);
|
||||||
}
|
}
|
||||||
if (profileItem is null || Utils.IsNullOrEmpty(profileItem.Address))
|
if (profileItem is null || profileItem.Address.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSub && Utils.IsNotEmpty(subid))
|
if (isSub && subid.IsNotEmpty())
|
||||||
{
|
{
|
||||||
await RemoveServerViaSubid(config, subid, isSub);
|
await RemoveServersViaSubid(config, subid, isSub);
|
||||||
}
|
}
|
||||||
|
|
||||||
profileItem.Subid = subid;
|
profileItem.Subid = subid;
|
||||||
@@ -1242,14 +1271,14 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
private static async Task<int> AddBatchServers4SsSIP008(Config config, string strData, string subid, bool isSub)
|
private static async Task<int> AddBatchServers4SsSIP008(Config config, string strData, string subid, bool isSub)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(strData))
|
if (strData.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSub && Utils.IsNotEmpty(subid))
|
if (isSub && subid.IsNotEmpty())
|
||||||
{
|
{
|
||||||
await RemoveServerViaSubid(config, subid, isSub);
|
await RemoveServersViaSubid(config, subid, isSub);
|
||||||
}
|
}
|
||||||
|
|
||||||
var lstSsServer = ShadowsocksFmt.ResolveSip008(strData);
|
var lstSsServer = ShadowsocksFmt.ResolveSip008(strData);
|
||||||
@@ -1274,13 +1303,13 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
public static async Task<int> AddBatchServers(Config config, string strData, string subid, bool isSub)
|
public static async Task<int> AddBatchServers(Config config, string strData, string subid, bool isSub)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(strData))
|
if (strData.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
List<ProfileItem>? lstOriSub = null;
|
List<ProfileItem>? lstOriSub = null;
|
||||||
ProfileItem? activeProfile = null;
|
ProfileItem? activeProfile = null;
|
||||||
if (isSub && Utils.IsNotEmpty(subid))
|
if (isSub && subid.IsNotEmpty())
|
||||||
{
|
{
|
||||||
lstOriSub = await AppHandler.Instance.ProfileItems(subid);
|
lstOriSub = await AppHandler.Instance.ProfileItems(subid);
|
||||||
activeProfile = lstOriSub?.FirstOrDefault(t => t.IndexId == config.IndexId);
|
activeProfile = lstOriSub?.FirstOrDefault(t => t.IndexId == config.IndexId);
|
||||||
@@ -1405,7 +1434,7 @@ namespace ServiceLib.Handler
|
|||||||
item.Memo = subItem.Memo;
|
item.Memo = subItem.Memo;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(item.Id))
|
if (item.Id.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
item.Id = Utils.GetGuid(false);
|
item.Id = Utils.GetGuid(false);
|
||||||
|
|
||||||
@@ -1436,9 +1465,9 @@ namespace ServiceLib.Handler
|
|||||||
/// <param name="config"></param>
|
/// <param name="config"></param>
|
||||||
/// <param name="subid"></param>
|
/// <param name="subid"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<int> RemoveServerViaSubid(Config config, string subid, bool isSub)
|
public static async Task<int> RemoveServersViaSubid(Config config, string subid, bool isSub)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(subid))
|
if (subid.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1467,7 +1496,7 @@ namespace ServiceLib.Handler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
await SQLiteHelper.Instance.DeleteAsync(item);
|
await SQLiteHelper.Instance.DeleteAsync(item);
|
||||||
await RemoveServerViaSubid(config, id, false);
|
await RemoveServersViaSubid(config, id, false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1489,7 +1518,7 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
public static async Task<int> SaveRoutingItem(Config config, RoutingItem item)
|
public static async Task<int> SaveRoutingItem(Config config, RoutingItem item)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(item.Id))
|
if (item.Id.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
item.Id = Utils.GetGuid(false);
|
item.Id = Utils.GetGuid(false);
|
||||||
}
|
}
|
||||||
@@ -1512,7 +1541,7 @@ namespace ServiceLib.Handler
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<int> AddBatchRoutingRules(RoutingItem routingItem, string strData)
|
public static async Task<int> AddBatchRoutingRules(RoutingItem routingItem, string strData)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(strData))
|
if (strData.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1530,7 +1559,7 @@ namespace ServiceLib.Handler
|
|||||||
routingItem.RuleNum = lstRules.Count;
|
routingItem.RuleNum = lstRules.Count;
|
||||||
routingItem.RuleSet = JsonUtils.Serialize(lstRules, false);
|
routingItem.RuleSet = JsonUtils.Serialize(lstRules, false);
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(routingItem.Id))
|
if (routingItem.Id.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
routingItem.Id = Utils.GetGuid(false);
|
routingItem.Id = Utils.GetGuid(false);
|
||||||
}
|
}
|
||||||
@@ -1649,7 +1678,7 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
public static async Task<int> InitRouting(Config config, bool blImportAdvancedRules = false)
|
public static async Task<int> InitRouting(Config config, bool blImportAdvancedRules = false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(config.ConstItem.RouteRulesTemplateSourceUrl))
|
if (config.ConstItem.RouteRulesTemplateSourceUrl.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
await InitBuiltinRouting(config, blImportAdvancedRules);
|
await InitBuiltinRouting(config, blImportAdvancedRules);
|
||||||
}
|
}
|
||||||
@@ -1665,7 +1694,7 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
var downloadHandle = new DownloadService();
|
var downloadHandle = new DownloadService();
|
||||||
var templateContent = await downloadHandle.TryDownloadString(config.ConstItem.RouteRulesTemplateSourceUrl, true, "");
|
var templateContent = await downloadHandle.TryDownloadString(config.ConstItem.RouteRulesTemplateSourceUrl, true, "");
|
||||||
if (string.IsNullOrEmpty(templateContent))
|
if (templateContent.IsNullOrEmpty())
|
||||||
return await InitBuiltinRouting(config, blImportAdvancedRules); // fallback
|
return await InitBuiltinRouting(config, blImportAdvancedRules); // fallback
|
||||||
|
|
||||||
var template = JsonUtils.Deserialize<RoutingTemplate>(templateContent);
|
var template = JsonUtils.Deserialize<RoutingTemplate>(templateContent);
|
||||||
@@ -1682,14 +1711,14 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
var item = template.RoutingItems[i];
|
var item = template.RoutingItems[i];
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(item.Url) && string.IsNullOrEmpty(item.RuleSet))
|
if (item.Url.IsNullOrEmpty() && item.RuleSet.IsNullOrEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var ruleSetsString = !string.IsNullOrEmpty(item.RuleSet)
|
var ruleSetsString = !item.RuleSet.IsNullOrEmpty()
|
||||||
? item.RuleSet
|
? item.RuleSet
|
||||||
: await downloadHandle.TryDownloadString(item.Url, true, "");
|
: await downloadHandle.TryDownloadString(item.Url, true, "");
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(ruleSetsString))
|
if (ruleSetsString.IsNullOrEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
item.Remarks = $"{template.Version}-{item.Remarks}";
|
item.Remarks = $"{template.Version}-{item.Remarks}";
|
||||||
@@ -1801,7 +1830,7 @@ namespace ServiceLib.Handler
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(item.Id))
|
if (item.Id.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
item.Id = Utils.GetGuid(false);
|
item.Id = Utils.GetGuid(false);
|
||||||
}
|
}
|
||||||
@@ -1822,17 +1851,17 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
var downloadHandle = new DownloadService();
|
var downloadHandle = new DownloadService();
|
||||||
var templateContent = await downloadHandle.TryDownloadString(url, true, "");
|
var templateContent = await downloadHandle.TryDownloadString(url, true, "");
|
||||||
if (string.IsNullOrEmpty(templateContent))
|
if (templateContent.IsNullOrEmpty())
|
||||||
return currentItem;
|
return currentItem;
|
||||||
|
|
||||||
var template = JsonUtils.Deserialize<DNSItem>(templateContent);
|
var template = JsonUtils.Deserialize<DNSItem>(templateContent);
|
||||||
if (template == null)
|
if (template == null)
|
||||||
return currentItem;
|
return currentItem;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(template.NormalDNS))
|
if (!template.NormalDNS.IsNullOrEmpty())
|
||||||
template.NormalDNS = await downloadHandle.TryDownloadString(template.NormalDNS, true, "");
|
template.NormalDNS = await downloadHandle.TryDownloadString(template.NormalDNS, true, "");
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(template.TunDNS))
|
if (!template.TunDNS.IsNullOrEmpty())
|
||||||
template.TunDNS = await downloadHandle.TryDownloadString(template.TunDNS, true, "");
|
template.TunDNS = await downloadHandle.TryDownloadString(template.TunDNS, true, "");
|
||||||
|
|
||||||
template.Id = currentItem.Id;
|
template.Id = currentItem.Id;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Handler
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Core configuration file processing class
|
/// Core configuration file processing class
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(fileName) && result.Data != null)
|
if (fileName.IsNotEmpty() && result.Data != null)
|
||||||
{
|
{
|
||||||
await File.WriteAllTextAsync(fileName, result.Data.ToString());
|
await File.WriteAllTextAsync(fileName, result.Data.ToString());
|
||||||
}
|
}
|
||||||
@@ -109,6 +109,30 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<RetResult> GenerateClientSpeedtestConfig(Config config, ProfileItem node, ServerTestItem testItem, string fileName)
|
||||||
|
{
|
||||||
|
var result = new RetResult();
|
||||||
|
var initPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
|
||||||
|
var port = Utils.GetFreePort(initPort + testItem.QueueNum);
|
||||||
|
testItem.Port = port;
|
||||||
|
|
||||||
|
if (AppHandler.Instance.GetCoreType(node, node.ConfigType) == ECoreType.sing_box)
|
||||||
|
{
|
||||||
|
result = await new CoreConfigSingboxService(config).GenerateClientSpeedtestConfig(node, port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = await new CoreConfigV2rayService(config).GenerateClientSpeedtestConfig(node, port);
|
||||||
|
}
|
||||||
|
if (result.Success != true)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
await File.WriteAllTextAsync(fileName, result.Data.ToString());
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
var result = new RetResult();
|
var result = new RetResult();
|
||||||
@@ -129,4 +153,4 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace ServiceLib.Handler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileName = Utils.GetConfigPath(Global.CoreConfigFileName);
|
var fileName = Utils.GetBinConfigPath(Global.CoreConfigFileName);
|
||||||
var result = await CoreConfigHandler.GenerateClientConfig(node, fileName);
|
var result = await CoreConfigHandler.GenerateClientConfig(node, fileName);
|
||||||
if (result.Success != true)
|
if (result.Success != true)
|
||||||
{
|
{
|
||||||
@@ -101,7 +101,8 @@ namespace ServiceLib.Handler
|
|||||||
public async Task<int> LoadCoreConfigSpeedtest(List<ServerTestItem> selecteds)
|
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 or EConfigType.WireGuard) ? ECoreType.sing_box : ECoreType.Xray;
|
||||||
var configPath = Utils.GetConfigPath(Global.CoreSpeedtestConfigFileName);
|
var fileName = string.Format(Global.CoreSpeedtestConfigFileName, Utils.GetGuid(false));
|
||||||
|
var configPath = Utils.GetBinConfigPath(fileName);
|
||||||
var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType);
|
var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType);
|
||||||
UpdateFunc(false, result.Msg);
|
UpdateFunc(false, result.Msg);
|
||||||
if (result.Success != true)
|
if (result.Success != true)
|
||||||
@@ -113,7 +114,34 @@ namespace ServiceLib.Handler
|
|||||||
UpdateFunc(false, configPath);
|
UpdateFunc(false, configPath);
|
||||||
|
|
||||||
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType);
|
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType);
|
||||||
var proc = await RunProcess(coreInfo, Global.CoreSpeedtestConfigFileName, true, false);
|
var proc = await RunProcess(coreInfo, fileName, true, false);
|
||||||
|
if (proc is null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return proc.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> LoadCoreConfigSpeedtest(ServerTestItem testItem)
|
||||||
|
{
|
||||||
|
var node = await AppHandler.Instance.GetProfileItem(testItem.IndexId);
|
||||||
|
if (node is null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileName = string.Format(Global.CoreSpeedtestConfigFileName, Utils.GetGuid(false));
|
||||||
|
var configPath = Utils.GetBinConfigPath(fileName);
|
||||||
|
var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, node, testItem, configPath);
|
||||||
|
if (result.Success != true)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var coreType = AppHandler.Instance.GetCoreType(node, node.ConfigType);
|
||||||
|
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType);
|
||||||
|
var proc = await RunProcess(coreInfo, fileName, true, false);
|
||||||
if (proc is null)
|
if (proc is null)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
@@ -175,7 +203,7 @@ namespace ServiceLib.Handler
|
|||||||
if (itemSocks != null)
|
if (itemSocks != null)
|
||||||
{
|
{
|
||||||
var preCoreType = itemSocks.CoreType ?? ECoreType.sing_box;
|
var preCoreType = itemSocks.CoreType ?? ECoreType.sing_box;
|
||||||
var fileName = Utils.GetConfigPath(Global.CorePreConfigFileName);
|
var fileName = Utils.GetBinConfigPath(Global.CorePreConfigFileName);
|
||||||
var result = await CoreConfigHandler.GenerateClientConfig(itemSocks, fileName);
|
var result = await CoreConfigHandler.GenerateClientConfig(itemSocks, fileName);
|
||||||
if (result.Success)
|
if (result.Success)
|
||||||
{
|
{
|
||||||
@@ -212,7 +240,7 @@ namespace ServiceLib.Handler
|
|||||||
private async Task<Process?> RunProcess(CoreInfo? coreInfo, string configPath, bool displayLog, bool mayNeedSudo)
|
private async Task<Process?> RunProcess(CoreInfo? coreInfo, string configPath, bool displayLog, bool mayNeedSudo)
|
||||||
{
|
{
|
||||||
var fileName = CoreInfoHandler.Instance.GetCoreExecFile(coreInfo, out var msg);
|
var fileName = CoreInfoHandler.Instance.GetCoreExecFile(coreInfo, out var msg);
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
UpdateFunc(false, msg);
|
UpdateFunc(false, msg);
|
||||||
return null;
|
return null;
|
||||||
@@ -225,8 +253,8 @@ namespace ServiceLib.Handler
|
|||||||
StartInfo = new()
|
StartInfo = new()
|
||||||
{
|
{
|
||||||
FileName = fileName,
|
FileName = fileName,
|
||||||
Arguments = string.Format(coreInfo.Arguments, coreInfo.AbsolutePath ? Utils.GetConfigPath(configPath) : configPath),
|
Arguments = string.Format(coreInfo.Arguments, coreInfo.AbsolutePath ? Utils.GetBinConfigPath(configPath).AppendQuotes() : configPath),
|
||||||
WorkingDirectory = Utils.GetConfigPath(),
|
WorkingDirectory = Utils.GetBinConfigPath(),
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardOutput = displayLog,
|
RedirectStandardOutput = displayLog,
|
||||||
RedirectStandardError = displayLog,
|
RedirectStandardError = displayLog,
|
||||||
@@ -246,13 +274,13 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
proc.OutputDataReceived += (sender, e) =>
|
proc.OutputDataReceived += (sender, e) =>
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(e.Data))
|
if (e.Data.IsNullOrEmpty())
|
||||||
return;
|
return;
|
||||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||||
};
|
};
|
||||||
proc.ErrorDataReceived += (sender, e) =>
|
proc.ErrorDataReceived += (sender, e) =>
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(e.Data))
|
if (e.Data.IsNullOrEmpty())
|
||||||
return;
|
return;
|
||||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||||
};
|
};
|
||||||
@@ -287,7 +315,7 @@ namespace ServiceLib.Handler
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logging.SaveLog(_tag, ex);
|
Logging.SaveLog(_tag, ex);
|
||||||
UpdateFunc(true, ex.Message);
|
UpdateFunc(mayNeedSudo, ex.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +326,7 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
private async Task RunProcessAsLinuxSudo(Process proc, string fileName, CoreInfo coreInfo, string configPath)
|
private async Task RunProcessAsLinuxSudo(Process proc, string fileName, CoreInfo coreInfo, string configPath)
|
||||||
{
|
{
|
||||||
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetConfigPath(configPath).AppendQuotes())}";
|
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath).AppendQuotes())}";
|
||||||
|
|
||||||
var shFilePath = await CreateLinuxShellFile(cmdLine, "run_as_sudo.sh");
|
var shFilePath = await CreateLinuxShellFile(cmdLine, "run_as_sudo.sh");
|
||||||
proc.StartInfo.FileName = shFilePath;
|
proc.StartInfo.FileName = shFilePath;
|
||||||
@@ -352,7 +380,7 @@ namespace ServiceLib.Handler
|
|||||||
private async Task<string> CreateLinuxShellFile(string cmdLine, string fileName)
|
private async Task<string> CreateLinuxShellFile(string cmdLine, string fileName)
|
||||||
{
|
{
|
||||||
//Shell scripts
|
//Shell scripts
|
||||||
var shFilePath = Utils.GetBinPath(AppHandler.Instance.IsAdministrator ? "root_" + fileName : fileName);
|
var shFilePath = Utils.GetBinConfigPath(AppHandler.Instance.IsAdministrator ? "root_" + fileName : fileName);
|
||||||
File.Delete(shFilePath);
|
File.Delete(shFilePath);
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.AppendLine("#!/bin/sh");
|
sb.AppendLine("#!/bin/sh");
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace ServiceLib.Handler
|
|||||||
new CoreInfo
|
new CoreInfo
|
||||||
{
|
{
|
||||||
CoreType = ECoreType.v2fly,
|
CoreType = ECoreType.v2fly,
|
||||||
CoreExes = ["wv2ray", "v2ray"],
|
CoreExes = ["v2ray"],
|
||||||
Arguments = "{0}",
|
Arguments = "{0}",
|
||||||
Url = GetCoreUrl(ECoreType.v2fly),
|
Url = GetCoreUrl(ECoreType.v2fly),
|
||||||
Match = "V2Ray",
|
Match = "V2Ray",
|
||||||
@@ -95,7 +95,7 @@ namespace ServiceLib.Handler
|
|||||||
new CoreInfo
|
new CoreInfo
|
||||||
{
|
{
|
||||||
CoreType = ECoreType.Xray,
|
CoreType = ECoreType.Xray,
|
||||||
CoreExes = ["wxray","xray"],
|
CoreExes = ["xray"],
|
||||||
Arguments = "run -c {0}",
|
Arguments = "run -c {0}",
|
||||||
Url = GetCoreUrl(ECoreType.Xray),
|
Url = GetCoreUrl(ECoreType.Xray),
|
||||||
ReleaseApiUrl = urlXray.Replace(Global.GithubUrl, Global.GithubApiUrl),
|
ReleaseApiUrl = urlXray.Replace(Global.GithubUrl, Global.GithubApiUrl),
|
||||||
@@ -129,8 +129,8 @@ namespace ServiceLib.Handler
|
|||||||
new CoreInfo
|
new CoreInfo
|
||||||
{
|
{
|
||||||
CoreType = ECoreType.hysteria,
|
CoreType = ECoreType.hysteria,
|
||||||
CoreExes = ["hysteria-windows-amd64", "hysteria"],
|
CoreExes = ["hysteria"],
|
||||||
Arguments = "-c {0}",
|
Arguments = "",
|
||||||
Url = GetCoreUrl(ECoreType.hysteria),
|
Url = GetCoreUrl(ECoreType.hysteria),
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
CoreType = ECoreType.hysteria2,
|
CoreType = ECoreType.hysteria2,
|
||||||
CoreExes = ["hysteria-windows-amd64", "hysteria-linux-amd64", "hysteria"],
|
CoreExes = ["hysteria-windows-amd64", "hysteria-linux-amd64", "hysteria"],
|
||||||
Arguments = "-c {0}",
|
Arguments = "",
|
||||||
Url = GetCoreUrl(ECoreType.hysteria2),
|
Url = GetCoreUrl(ECoreType.hysteria2),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
|
|
||||||
protected static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
|
protected static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(item.Flow))
|
if (item.Flow.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("flow", item.Flow);
|
dicQuery.Add("flow", item.Flow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(item.StreamSecurity))
|
if (item.StreamSecurity.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("security", item.StreamSecurity);
|
dicQuery.Add("security", item.StreamSecurity);
|
||||||
}
|
}
|
||||||
@@ -32,27 +32,27 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
dicQuery.Add("security", securityDef);
|
dicQuery.Add("security", securityDef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Sni))
|
if (item.Sni.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("sni", item.Sni);
|
dicQuery.Add("sni", item.Sni);
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Alpn))
|
if (item.Alpn.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Fingerprint))
|
if (item.Fingerprint.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("fp", Utils.UrlEncode(item.Fingerprint));
|
dicQuery.Add("fp", Utils.UrlEncode(item.Fingerprint));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.PublicKey))
|
if (item.PublicKey.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("pbk", Utils.UrlEncode(item.PublicKey));
|
dicQuery.Add("pbk", Utils.UrlEncode(item.PublicKey));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.ShortId))
|
if (item.ShortId.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("sid", Utils.UrlEncode(item.ShortId));
|
dicQuery.Add("sid", Utils.UrlEncode(item.ShortId));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.SpiderX))
|
if (item.SpiderX.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("spx", Utils.UrlEncode(item.SpiderX));
|
dicQuery.Add("spx", Utils.UrlEncode(item.SpiderX));
|
||||||
}
|
}
|
||||||
@@ -61,21 +61,21 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
dicQuery.Add("allowInsecure", "1");
|
dicQuery.Add("allowInsecure", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
dicQuery.Add("type", Utils.IsNotEmpty(item.Network) ? item.Network : nameof(ETransport.tcp));
|
dicQuery.Add("type", item.Network.IsNotEmpty() ? item.Network : nameof(ETransport.tcp));
|
||||||
|
|
||||||
switch (item.Network)
|
switch (item.Network)
|
||||||
{
|
{
|
||||||
case nameof(ETransport.tcp):
|
case nameof(ETransport.tcp):
|
||||||
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
|
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
|
||||||
if (Utils.IsNotEmpty(item.RequestHost))
|
if (item.RequestHost.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nameof(ETransport.kcp):
|
case nameof(ETransport.kcp):
|
||||||
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
|
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
|
||||||
if (Utils.IsNotEmpty(item.Path))
|
if (item.Path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("seed", Utils.UrlEncode(item.Path));
|
dicQuery.Add("seed", Utils.UrlEncode(item.Path));
|
||||||
}
|
}
|
||||||
@@ -83,30 +83,30 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
|
|
||||||
case nameof(ETransport.ws):
|
case nameof(ETransport.ws):
|
||||||
case nameof(ETransport.httpupgrade):
|
case nameof(ETransport.httpupgrade):
|
||||||
if (Utils.IsNotEmpty(item.RequestHost))
|
if (item.RequestHost.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Path))
|
if (item.Path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nameof(ETransport.xhttp):
|
case nameof(ETransport.xhttp):
|
||||||
if (Utils.IsNotEmpty(item.RequestHost))
|
if (item.RequestHost.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Path))
|
if (item.Path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.HeaderType) && Global.XhttpMode.Contains(item.HeaderType))
|
if (item.HeaderType.IsNotEmpty() && Global.XhttpMode.Contains(item.HeaderType))
|
||||||
{
|
{
|
||||||
dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType));
|
dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Extra))
|
if (item.Extra.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("extra", Utils.UrlEncode(item.Extra));
|
dicQuery.Add("extra", Utils.UrlEncode(item.Extra));
|
||||||
}
|
}
|
||||||
@@ -115,24 +115,24 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
case nameof(ETransport.http):
|
case nameof(ETransport.http):
|
||||||
case nameof(ETransport.h2):
|
case nameof(ETransport.h2):
|
||||||
dicQuery["type"] = nameof(ETransport.http);
|
dicQuery["type"] = nameof(ETransport.http);
|
||||||
if (Utils.IsNotEmpty(item.RequestHost))
|
if (item.RequestHost.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Path))
|
if (item.Path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nameof(ETransport.quic):
|
case nameof(ETransport.quic):
|
||||||
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
|
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
|
||||||
dicQuery.Add("quicSecurity", Utils.UrlEncode(item.RequestHost));
|
dicQuery.Add("quicSecurity", Utils.UrlEncode(item.RequestHost));
|
||||||
dicQuery.Add("key", Utils.UrlEncode(item.Path));
|
dicQuery.Add("key", Utils.UrlEncode(item.Path));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nameof(ETransport.grpc):
|
case nameof(ETransport.grpc):
|
||||||
if (Utils.IsNotEmpty(item.Path))
|
if (item.Path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("authority", Utils.UrlEncode(item.RequestHost));
|
dicQuery.Add("authority", Utils.UrlEncode(item.RequestHost));
|
||||||
dicQuery.Add("serviceName", Utils.UrlEncode(item.Path));
|
dicQuery.Add("serviceName", Utils.UrlEncode(item.Path));
|
||||||
@@ -215,7 +215,9 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
foreach (var item in s)
|
foreach (var item in s)
|
||||||
{
|
{
|
||||||
if (str.Contains(item, StringComparison.OrdinalIgnoreCase))
|
if (str.Contains(item, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string str = config.TrimEx();
|
string str = config.TrimEx();
|
||||||
if (Utils.IsNullOrEmpty(str))
|
if (str.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedReadConfiguration;
|
msg = ResUI.FailedReadConfiguration;
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
item.Path = Utils.UrlDecode(query["obfs-password"] ?? "");
|
item.Path = Utils.UrlDecode(query["obfs-password"] ?? "");
|
||||||
item.AllowInsecure = (query["insecure"] ?? "") == "1" ? "true" : "false";
|
item.AllowInsecure = (query["insecure"] ?? "") == "1" ? "true" : "false";
|
||||||
|
|
||||||
|
item.Ports = Utils.UrlDecode(query["mport"] ?? "").Replace('-', ':');
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,25 +36,29 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
string url = string.Empty;
|
string url = string.Empty;
|
||||||
|
|
||||||
string remark = string.Empty;
|
string remark = string.Empty;
|
||||||
if (Utils.IsNotEmpty(item.Remarks))
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
}
|
}
|
||||||
var dicQuery = new Dictionary<string, string>();
|
var dicQuery = new Dictionary<string, string>();
|
||||||
if (Utils.IsNotEmpty(item.Sni))
|
if (item.Sni.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("sni", item.Sni);
|
dicQuery.Add("sni", item.Sni);
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Alpn))
|
if (item.Alpn.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Path))
|
if (item.Path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("obfs", "salamander");
|
dicQuery.Add("obfs", "salamander");
|
||||||
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
|
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
|
||||||
}
|
}
|
||||||
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0");
|
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0");
|
||||||
|
if (item.Ports.IsNotEmpty())
|
||||||
|
{
|
||||||
|
dicQuery.Add("mport", Utils.UrlEncode(item.Ports.Replace(':', '-')));
|
||||||
|
}
|
||||||
|
|
||||||
return ToUri(EConfigType.Hysteria2, item.Address, item.Port, item.Id, dicQuery, remark);
|
return ToUri(EConfigType.Hysteria2, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
var remark = string.Empty;
|
||||||
string remark = string.Empty;
|
if (item.Remarks.IsNotEmpty())
|
||||||
if (Utils.IsNotEmpty(item.Remarks))
|
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
}
|
}
|
||||||
@@ -53,12 +53,14 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
{
|
{
|
||||||
var match = UrlFinder.Match(result);
|
var match = UrlFinder.Match(result);
|
||||||
if (!match.Success)
|
if (!match.Success)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
ProfileItem item = new();
|
ProfileItem item = new();
|
||||||
var base64 = match.Groups["base64"].Value.TrimEnd('/');
|
var base64 = match.Groups["base64"].Value.TrimEnd('/');
|
||||||
var tag = match.Groups["tag"].Value;
|
var tag = match.Groups["tag"].Value;
|
||||||
if (Utils.IsNotEmpty(tag))
|
if (tag.IsNotEmpty())
|
||||||
{
|
{
|
||||||
item.Remarks = Utils.UrlDecode(tag);
|
item.Remarks = Utils.UrlDecode(tag);
|
||||||
}
|
}
|
||||||
@@ -72,11 +74,13 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!details.Success)
|
if (!details.Success)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
item.Security = details.Groups["method"].Value;
|
item.Security = details.Groups["method"].Value;
|
||||||
item.Id = details.Groups["password"].Value;
|
item.Id = details.Groups["password"].Value;
|
||||||
item.Address = details.Groups["hostname"].Value;
|
item.Address = details.Groups["hostname"].Value;
|
||||||
item.Port = Utils.ToInt(details.Groups["port"].Value);
|
item.Port = details.Groups["port"].Value.ToInt();
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +88,9 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
{
|
{
|
||||||
var parsedUrl = Utils.TryUri(result);
|
var parsedUrl = Utils.TryUri(result);
|
||||||
if (parsedUrl == null)
|
if (parsedUrl == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
ProfileItem item = new()
|
ProfileItem item = new()
|
||||||
{
|
{
|
||||||
@@ -96,7 +102,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
//2022-blake3
|
//2022-blake3
|
||||||
if (rawUserInfo.Contains(':'))
|
if (rawUserInfo.Contains(':'))
|
||||||
{
|
{
|
||||||
string[] userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
var userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
||||||
if (userInfoParts.Length != 2)
|
if (userInfoParts.Length != 2)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -107,8 +113,8 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// parse base64 UserInfo
|
// parse base64 UserInfo
|
||||||
string userInfo = Utils.Base64Decode(rawUserInfo);
|
var userInfo = Utils.Base64Decode(rawUserInfo);
|
||||||
string[] userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
var userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
||||||
if (userInfoParts.Length != 2)
|
if (userInfoParts.Length != 2)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -122,7 +128,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
{
|
{
|
||||||
//obfs-host exists
|
//obfs-host exists
|
||||||
var obfsHost = queryParameters["plugin"]?.Split(';').FirstOrDefault(t => t.Contains("obfs-host"));
|
var obfsHost = queryParameters["plugin"]?.Split(';').FirstOrDefault(t => t.Contains("obfs-host"));
|
||||||
if (queryParameters["plugin"].Contains("obfs=http") && Utils.IsNotEmpty(obfsHost))
|
if (queryParameters["plugin"].Contains("obfs=http") && obfsHost.IsNotEmpty())
|
||||||
{
|
{
|
||||||
obfsHost = obfsHost?.Replace("obfs-host=", "");
|
obfsHost = obfsHost?.Replace("obfs-host=", "");
|
||||||
item.Network = Global.DefaultNetwork;
|
item.Network = Global.DefaultNetwork;
|
||||||
@@ -162,7 +168,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
Security = it.method,
|
Security = it.method,
|
||||||
Id = it.password,
|
Id = it.password,
|
||||||
Address = it.server,
|
Address = it.server,
|
||||||
Port = Utils.ToInt(it.server_port)
|
Port = it.server_port.ToInt()
|
||||||
};
|
};
|
||||||
lst.Add(ssItem);
|
lst.Add(ssItem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,48 @@
|
|||||||
namespace ServiceLib.Handler.Fmt
|
namespace ServiceLib.Handler.Fmt
|
||||||
{
|
{
|
||||||
public class SingboxFmt : BaseFmt
|
public class SingboxFmt : BaseFmt
|
||||||
{
|
{
|
||||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||||
{
|
{
|
||||||
var configObjects = JsonUtils.Deserialize<Object[]>(strData);
|
var configObjects = JsonUtils.Deserialize<object[]>(strData);
|
||||||
if (configObjects != null && configObjects.Length > 0)
|
if (configObjects is not { Length: > 0 })
|
||||||
{
|
{
|
||||||
List<ProfileItem> lstResult = [];
|
return null;
|
||||||
foreach (var configObject in configObjects)
|
|
||||||
{
|
|
||||||
var objectString = JsonUtils.Serialize(configObject);
|
|
||||||
var singboxCon = JsonUtils.Deserialize<SingboxConfig>(objectString);
|
|
||||||
if (singboxCon?.inbounds?.Count > 0
|
|
||||||
&& singboxCon.outbounds?.Count > 0
|
|
||||||
&& singboxCon.route != null)
|
|
||||||
{
|
|
||||||
var fileName = WriteAllText(objectString);
|
|
||||||
|
|
||||||
var profileIt = new ProfileItem
|
|
||||||
{
|
|
||||||
CoreType = ECoreType.sing_box,
|
|
||||||
Address = fileName,
|
|
||||||
Remarks = subRemarks ?? "singbox_custom",
|
|
||||||
};
|
|
||||||
lstResult.Add(profileIt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lstResult;
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
List<ProfileItem> lstResult = [];
|
||||||
|
foreach (var configObject in configObjects)
|
||||||
|
{
|
||||||
|
var objectString = JsonUtils.Serialize(configObject);
|
||||||
|
var profileIt = ResolveFull(objectString, subRemarks);
|
||||||
|
if (profileIt != null)
|
||||||
|
{
|
||||||
|
lstResult.Add(profileIt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lstResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
||||||
{
|
{
|
||||||
var singboxConfig = JsonUtils.Deserialize<SingboxConfig>(strData);
|
var config = JsonUtils.ParseJson(strData);
|
||||||
if (singboxConfig?.inbounds?.Count > 0
|
if (config?["inbounds"] == null
|
||||||
&& singboxConfig.outbounds?.Count > 0
|
|| config["outbounds"] == null
|
||||||
&& singboxConfig.route != null)
|
|| config["route"] == null
|
||||||
|
|| config["dns"] == null)
|
||||||
{
|
{
|
||||||
var fileName = WriteAllText(strData);
|
return null;
|
||||||
var profileItem = new ProfileItem
|
|
||||||
{
|
|
||||||
CoreType = ECoreType.sing_box,
|
|
||||||
Address = fileName,
|
|
||||||
Remarks = subRemarks ?? "singbox_custom"
|
|
||||||
};
|
|
||||||
|
|
||||||
return profileItem;
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
var fileName = WriteAllText(strData);
|
||||||
|
var profileItem = new ProfileItem
|
||||||
|
{
|
||||||
|
CoreType = ECoreType.sing_box,
|
||||||
|
Address = fileName,
|
||||||
|
Remarks = subRemarks ?? "singbox_custom"
|
||||||
|
};
|
||||||
|
|
||||||
|
return profileItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
var url = string.Empty;
|
}
|
||||||
|
|
||||||
var remark = string.Empty;
|
var remark = string.Empty;
|
||||||
if (Utils.IsNotEmpty(item.Remarks))
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
item.Address = arr1[1][..indexPort];
|
item.Address = arr1[1][..indexPort];
|
||||||
item.Port = Utils.ToInt(arr1[1][(indexPort + 1)..]);
|
item.Port = arr1[1][(indexPort + 1)..].ToInt();
|
||||||
item.Security = arr21.First();
|
item.Security = arr21.First();
|
||||||
item.Id = arr21[1];
|
item.Id = arr21[1];
|
||||||
|
|
||||||
@@ -88,7 +88,9 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
{
|
{
|
||||||
var parsedUrl = Utils.TryUri(result);
|
var parsedUrl = Utils.TryUri(result);
|
||||||
if (parsedUrl == null)
|
if (parsedUrl == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
ProfileItem item = new()
|
ProfileItem item = new()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
@@ -21,7 +23,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
item.Id = Utils.UrlDecode(url.UserInfo);
|
item.Id = Utils.UrlDecode(url.UserInfo);
|
||||||
|
|
||||||
var query = Utils.ParseQueryString(url.Query);
|
var query = Utils.ParseQueryString(url.Query);
|
||||||
ResolveStdTransport(query, ref item);
|
_ = ResolveStdTransport(query, ref item);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -29,16 +31,16 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
var remark = string.Empty;
|
||||||
string remark = string.Empty;
|
if (item.Remarks.IsNotEmpty())
|
||||||
if (Utils.IsNotEmpty(item.Remarks))
|
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
}
|
}
|
||||||
var dicQuery = new Dictionary<string, string>();
|
var dicQuery = new Dictionary<string, string>();
|
||||||
GetStdTransport(item, null, ref dicQuery);
|
_ = GetStdTransport(item, null, ref dicQuery);
|
||||||
|
|
||||||
return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Id, dicQuery, remark);
|
return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
@@ -36,20 +38,21 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
|
||||||
string remark = string.Empty;
|
var remark = string.Empty;
|
||||||
if (Utils.IsNotEmpty(item.Remarks))
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
}
|
}
|
||||||
var dicQuery = new Dictionary<string, string>();
|
var dicQuery = new Dictionary<string, string>();
|
||||||
if (Utils.IsNotEmpty(item.Sni))
|
if (item.Sni.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("sni", item.Sni);
|
dicQuery.Add("sni", item.Sni);
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Alpn))
|
if (item.Alpn.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +1,49 @@
|
|||||||
namespace ServiceLib.Handler.Fmt
|
namespace ServiceLib.Handler.Fmt
|
||||||
{
|
{
|
||||||
public class V2rayFmt : BaseFmt
|
public class V2rayFmt : BaseFmt
|
||||||
{
|
{
|
||||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||||
{
|
{
|
||||||
var configObjects = JsonUtils.Deserialize<Object[]>(strData);
|
var configObjects = JsonUtils.Deserialize<object[]>(strData);
|
||||||
if (configObjects != null && configObjects.Length > 0)
|
if (configObjects is not { Length: > 0 })
|
||||||
{
|
{
|
||||||
List<ProfileItem> lstResult = [];
|
return null;
|
||||||
foreach (var configObject in configObjects)
|
|
||||||
{
|
|
||||||
var objectString = JsonUtils.Serialize(configObject);
|
|
||||||
var v2rayCon = JsonUtils.Deserialize<V2rayConfig>(objectString);
|
|
||||||
if (v2rayCon?.inbounds?.Count > 0
|
|
||||||
&& v2rayCon.outbounds?.Count > 0
|
|
||||||
&& v2rayCon.routing != null)
|
|
||||||
{
|
|
||||||
var fileName = WriteAllText(objectString);
|
|
||||||
|
|
||||||
var profileIt = new ProfileItem
|
|
||||||
{
|
|
||||||
CoreType = ECoreType.Xray,
|
|
||||||
Address = fileName,
|
|
||||||
Remarks = v2rayCon.remarks ?? subRemarks ?? "v2ray_custom",
|
|
||||||
};
|
|
||||||
lstResult.Add(profileIt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lstResult;
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
List<ProfileItem> lstResult = [];
|
||||||
|
foreach (var configObject in configObjects)
|
||||||
|
{
|
||||||
|
var objectString = JsonUtils.Serialize(configObject);
|
||||||
|
var profileIt = ResolveFull(objectString, subRemarks);
|
||||||
|
if (profileIt != null)
|
||||||
|
{
|
||||||
|
lstResult.Add(profileIt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lstResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
||||||
{
|
{
|
||||||
var v2rayConfig = JsonUtils.Deserialize<V2rayConfig>(strData);
|
var config = JsonUtils.ParseJson(strData);
|
||||||
if (v2rayConfig?.inbounds?.Count > 0
|
if (config?["inbounds"] == null
|
||||||
&& v2rayConfig.outbounds?.Count > 0
|
|| config["outbounds"] == null
|
||||||
&& v2rayConfig.routing != null)
|
|| config["routing"] == null)
|
||||||
{
|
{
|
||||||
var fileName = WriteAllText(strData);
|
return null;
|
||||||
|
|
||||||
var profileItem = new ProfileItem
|
|
||||||
{
|
|
||||||
CoreType = ECoreType.Xray,
|
|
||||||
Address = fileName,
|
|
||||||
Remarks = v2rayConfig.remarks ?? subRemarks ?? "v2ray_custom"
|
|
||||||
};
|
|
||||||
|
|
||||||
return profileItem;
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
var fileName = WriteAllText(strData);
|
||||||
|
|
||||||
|
var profileItem = new ProfileItem
|
||||||
|
{
|
||||||
|
CoreType = ECoreType.Xray,
|
||||||
|
Address = fileName,
|
||||||
|
Remarks = config?["remarks"]?.ToString() ?? subRemarks ?? "v2ray_custom"
|
||||||
|
};
|
||||||
|
|
||||||
|
return profileItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
@@ -24,7 +26,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
var query = Utils.ParseQueryString(url.Query);
|
var query = Utils.ParseQueryString(url.Query);
|
||||||
item.Security = query["encryption"] ?? Global.None;
|
item.Security = query["encryption"] ?? Global.None;
|
||||||
item.StreamSecurity = query["security"] ?? "";
|
item.StreamSecurity = query["security"] ?? "";
|
||||||
ResolveStdTransport(query, ref item);
|
_ = ResolveStdTransport(query, ref item);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -32,16 +34,17 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
|
||||||
string remark = string.Empty;
|
var remark = string.Empty;
|
||||||
if (Utils.IsNotEmpty(item.Remarks))
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
}
|
}
|
||||||
var dicQuery = new Dictionary<string, string>();
|
var dicQuery = new Dictionary<string, string>();
|
||||||
if (Utils.IsNotEmpty(item.Security))
|
if (item.Security.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("encryption", item.Security);
|
dicQuery.Add("encryption", item.Security);
|
||||||
}
|
}
|
||||||
@@ -49,7 +52,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
{
|
{
|
||||||
dicQuery.Add("encryption", Global.None);
|
dicQuery.Add("encryption", Global.None);
|
||||||
}
|
}
|
||||||
GetStdTransport(item, Global.None, ref dicQuery);
|
_ = GetStdTransport(item, Global.None, ref dicQuery);
|
||||||
|
|
||||||
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Id, dicQuery, remark);
|
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
var vmessQRCode = new VmessQRCode
|
||||||
VmessQRCode vmessQRCode = new()
|
|
||||||
{
|
{
|
||||||
v = item.ConfigVersion,
|
v = item.ConfigVersion,
|
||||||
ps = item.Remarks.TrimEx(),
|
ps = item.Remarks.TrimEx(),
|
||||||
@@ -42,7 +42,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
fp = item.Fingerprint
|
fp = item.Fingerprint
|
||||||
};
|
};
|
||||||
|
|
||||||
url = JsonUtils.Serialize(vmessQRCode);
|
var url = JsonUtils.Serialize(vmessQRCode);
|
||||||
url = Utils.Base64Encode(url);
|
url = Utils.Base64Encode(url);
|
||||||
url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}";
|
url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}";
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
result = result[Global.ProtocolShares[EConfigType.VMess].Length..];
|
result = result[Global.ProtocolShares[EConfigType.VMess].Length..];
|
||||||
result = Utils.Base64Decode(result);
|
result = Utils.Base64Decode(result);
|
||||||
|
|
||||||
VmessQRCode? vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
|
var vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
|
||||||
if (vmessQRCode == null)
|
if (vmessQRCode == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedConversionConfiguration;
|
msg = ResUI.FailedConversionConfiguration;
|
||||||
@@ -78,12 +78,12 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
item.AlterId = vmessQRCode.aid;
|
item.AlterId = vmessQRCode.aid;
|
||||||
item.Security = Utils.ToString(vmessQRCode.scy);
|
item.Security = Utils.ToString(vmessQRCode.scy);
|
||||||
|
|
||||||
item.Security = Utils.IsNotEmpty(vmessQRCode.scy) ? vmessQRCode.scy : Global.DefaultSecurity;
|
item.Security = vmessQRCode.scy.IsNotEmpty() ? vmessQRCode.scy : Global.DefaultSecurity;
|
||||||
if (Utils.IsNotEmpty(vmessQRCode.net))
|
if (vmessQRCode.net.IsNotEmpty())
|
||||||
{
|
{
|
||||||
item.Network = vmessQRCode.net;
|
item.Network = vmessQRCode.net;
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(vmessQRCode.type))
|
if (vmessQRCode.type.IsNotEmpty())
|
||||||
{
|
{
|
||||||
item.HeaderType = vmessQRCode.type;
|
item.HeaderType = vmessQRCode.type;
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
|
|
||||||
public static ProfileItem? ResolveStdVmess(string str)
|
public static ProfileItem? ResolveStdVmess(string str)
|
||||||
{
|
{
|
||||||
ProfileItem item = new()
|
var item = new ProfileItem
|
||||||
{
|
{
|
||||||
ConfigType = EConfigType.VMess,
|
ConfigType = EConfigType.VMess,
|
||||||
Security = "auto"
|
Security = "auto"
|
||||||
@@ -108,7 +108,9 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
@@ -33,29 +35,30 @@ namespace ServiceLib.Handler.Fmt
|
|||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
|
||||||
string remark = string.Empty;
|
var remark = string.Empty;
|
||||||
if (Utils.IsNotEmpty(item.Remarks))
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
}
|
}
|
||||||
|
|
||||||
var dicQuery = new Dictionary<string, string>();
|
var dicQuery = new Dictionary<string, string>();
|
||||||
if (Utils.IsNotEmpty(item.PublicKey))
|
if (item.PublicKey.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("publickey", Utils.UrlEncode(item.PublicKey));
|
dicQuery.Add("publickey", Utils.UrlEncode(item.PublicKey));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Path))
|
if (item.Path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("reserved", Utils.UrlEncode(item.Path));
|
dicQuery.Add("reserved", Utils.UrlEncode(item.Path));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.RequestHost))
|
if (item.RequestHost.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("address", Utils.UrlEncode(item.RequestHost));
|
dicQuery.Add("address", Utils.UrlEncode(item.RequestHost));
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.ShortId))
|
if (item.ShortId.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dicQuery.Add("mtu", Utils.UrlEncode(item.ShortId));
|
dicQuery.Add("mtu", Utils.UrlEncode(item.ShortId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
public static async Task Start(string configPath, int httpPort, int pacPort)
|
public static async Task Start(string configPath, int httpPort, int pacPort)
|
||||||
{
|
{
|
||||||
_needRestart = (configPath != _configPath || httpPort != _httpPort || pacPort != _pacPort || !_isRunning);
|
_needRestart = configPath != _configPath || httpPort != _httpPort || pacPort != _pacPort || !_isRunning;
|
||||||
|
|
||||||
_configPath = configPath;
|
_configPath = configPath;
|
||||||
_httpPort = httpPort;
|
_httpPort = httpPort;
|
||||||
@@ -33,6 +33,13 @@ namespace ServiceLib.Handler
|
|||||||
private static async Task InitText()
|
private static async Task InitText()
|
||||||
{
|
{
|
||||||
var path = Path.Combine(_configPath, "pac.txt");
|
var path = Path.Combine(_configPath, "pac.txt");
|
||||||
|
|
||||||
|
// Delete the old pac file
|
||||||
|
if (File.Exists(path) && Utils.GetFileHash(path).Equals("b590c07280f058ef05d5394aa2f927fe"))
|
||||||
|
{
|
||||||
|
File.Delete(path);
|
||||||
|
}
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
var pac = EmbedUtils.GetEmbedText(Global.PacFileName);
|
var pac = EmbedUtils.GetEmbedText(Global.PacFileName);
|
||||||
@@ -70,7 +77,7 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
var client = await _tcpListener.AcceptTcpClientAsync();
|
var client = await _tcpListener.AcceptTcpClientAsync();
|
||||||
await Task.Run(() => { WriteContent(client); });
|
await Task.Run(() => WriteContent(client));
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -90,7 +97,9 @@ namespace ServiceLib.Handler
|
|||||||
public static void Stop()
|
public static void Stop()
|
||||||
{
|
{
|
||||||
if (_tcpListener == null)
|
if (_tcpListener == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_isRunning = false;
|
_isRunning = false;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
//using System.Reactive.Linq;
|
//using System.Reactive.Linq;
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ namespace ServiceLib.Handler
|
|||||||
{
|
{
|
||||||
private static readonly Lazy<ProfileExHandler> _instance = new(() => new());
|
private static readonly Lazy<ProfileExHandler> _instance = new(() => new());
|
||||||
private ConcurrentBag<ProfileExItem> _lstProfileEx = [];
|
private ConcurrentBag<ProfileExItem> _lstProfileEx = [];
|
||||||
private Queue<string> _queIndexIds = new();
|
private readonly Queue<string> _queIndexIds = new();
|
||||||
public static ProfileExHandler Instance => _instance.Value;
|
public static ProfileExHandler Instance => _instance.Value;
|
||||||
private static readonly string _tag = "ProfileExHandler";
|
private static readonly string _tag = "ProfileExHandler";
|
||||||
|
|
||||||
@@ -20,14 +20,6 @@ namespace ServiceLib.Handler
|
|||||||
public async Task Init()
|
public async Task Init()
|
||||||
{
|
{
|
||||||
await InitData();
|
await InitData();
|
||||||
_ = Task.Run(async () =>
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
await Task.Delay(1000 * 600);
|
|
||||||
await SaveQueueIndexIds();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ConcurrentBag<ProfileExItem>> GetProfileExs()
|
public async Task<ConcurrentBag<ProfileExItem>> GetProfileExs()
|
||||||
@@ -44,7 +36,7 @@ namespace ServiceLib.Handler
|
|||||||
|
|
||||||
private void IndexIdEnqueue(string indexId)
|
private void IndexIdEnqueue(string indexId)
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(indexId) && !_queIndexIds.Contains(indexId))
|
if (indexId.IsNotEmpty() && !_queIndexIds.Contains(indexId))
|
||||||
{
|
{
|
||||||
_queIndexIds.Enqueue(indexId);
|
_queIndexIds.Enqueue(indexId);
|
||||||
}
|
}
|
||||||
@@ -59,7 +51,7 @@ namespace ServiceLib.Handler
|
|||||||
List<ProfileExItem> lstInserts = [];
|
List<ProfileExItem> lstInserts = [];
|
||||||
List<ProfileExItem> lstUpdates = [];
|
List<ProfileExItem> lstUpdates = [];
|
||||||
|
|
||||||
for (int i = 0; i < cnt; i++)
|
for (var i = 0; i < cnt; i++)
|
||||||
{
|
{
|
||||||
var id = _queIndexIds.Dequeue();
|
var id = _queIndexIds.Dequeue();
|
||||||
var item = lstExists.FirstOrDefault(t => t.IndexId == id);
|
var item = lstExists.FirstOrDefault(t => t.IndexId == id);
|
||||||
@@ -78,13 +70,18 @@ namespace ServiceLib.Handler
|
|||||||
lstInserts.Add(itemNew);
|
lstInserts.Add(itemNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (lstInserts.Count() > 0)
|
if (lstInserts.Count > 0)
|
||||||
|
{
|
||||||
await SQLiteHelper.Instance.InsertAllAsync(lstInserts);
|
await SQLiteHelper.Instance.InsertAllAsync(lstInserts);
|
||||||
|
}
|
||||||
|
|
||||||
if (lstUpdates.Count() > 0)
|
if (lstUpdates.Count > 0)
|
||||||
|
{
|
||||||
await SQLiteHelper.Instance.UpdateAllAsync(lstUpdates);
|
await SQLiteHelper.Instance.UpdateAllAsync(lstUpdates);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -93,17 +90,24 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddProfileEx(string indexId, ref ProfileExItem? profileEx)
|
private ProfileExItem AddProfileEx(string indexId)
|
||||||
{
|
{
|
||||||
profileEx = new()
|
var profileEx = new ProfileExItem()
|
||||||
{
|
{
|
||||||
IndexId = indexId,
|
IndexId = indexId,
|
||||||
Delay = 0,
|
Delay = 0,
|
||||||
Speed = 0,
|
Speed = 0,
|
||||||
Sort = 0
|
Sort = 0,
|
||||||
|
Message = string.Empty
|
||||||
};
|
};
|
||||||
_lstProfileEx.Add(profileEx);
|
_lstProfileEx.Add(profileEx);
|
||||||
IndexIdEnqueue(indexId);
|
IndexIdEnqueue(indexId);
|
||||||
|
return profileEx;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProfileExItem GetProfileExItem(string? indexId)
|
||||||
|
{
|
||||||
|
return _lstProfileEx.FirstOrDefault(t => t.IndexId == indexId) ?? AddProfileEx(indexId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ClearAll()
|
public async Task ClearAll()
|
||||||
@@ -124,39 +128,34 @@ namespace ServiceLib.Handler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTestDelay(string indexId, string delayVal)
|
public void SetTestDelay(string indexId, int delay)
|
||||||
{
|
{
|
||||||
var profileEx = _lstProfileEx.FirstOrDefault(t => t.IndexId == indexId);
|
var profileEx = GetProfileExItem(indexId);
|
||||||
if (profileEx == null)
|
|
||||||
{
|
|
||||||
AddProfileEx(indexId, ref profileEx);
|
|
||||||
}
|
|
||||||
|
|
||||||
int.TryParse(delayVal, out int delay);
|
|
||||||
profileEx.Delay = delay;
|
profileEx.Delay = delay;
|
||||||
IndexIdEnqueue(indexId);
|
IndexIdEnqueue(indexId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTestSpeed(string indexId, string speedVal)
|
public void SetTestSpeed(string indexId, decimal speed)
|
||||||
{
|
{
|
||||||
var profileEx = _lstProfileEx.FirstOrDefault(t => t.IndexId == indexId);
|
var profileEx = GetProfileExItem(indexId);
|
||||||
if (profileEx == null)
|
|
||||||
{
|
|
||||||
AddProfileEx(indexId, ref profileEx);
|
|
||||||
}
|
|
||||||
|
|
||||||
decimal.TryParse(speedVal, out decimal speed);
|
|
||||||
profileEx.Speed = speed;
|
profileEx.Speed = speed;
|
||||||
IndexIdEnqueue(indexId);
|
IndexIdEnqueue(indexId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetTestMessage(string indexId, string message)
|
||||||
|
{
|
||||||
|
var profileEx = GetProfileExItem(indexId);
|
||||||
|
|
||||||
|
profileEx.Message = message;
|
||||||
|
IndexIdEnqueue(indexId);
|
||||||
|
}
|
||||||
|
|
||||||
public void SetSort(string indexId, int sort)
|
public void SetSort(string indexId, int sort)
|
||||||
{
|
{
|
||||||
var profileEx = _lstProfileEx.FirstOrDefault(t => t.IndexId == indexId);
|
var profileEx = GetProfileExItem(indexId);
|
||||||
if (profileEx == null)
|
|
||||||
{
|
|
||||||
AddProfileEx(indexId, ref profileEx);
|
|
||||||
}
|
|
||||||
profileEx.Sort = sort;
|
profileEx.Sort = sort;
|
||||||
IndexIdEnqueue(indexId);
|
IndexIdEnqueue(indexId);
|
||||||
}
|
}
|
||||||
@@ -180,4 +179,4 @@ namespace ServiceLib.Handler
|
|||||||
return _lstProfileEx.Max(t => t == null ? 0 : t.Sort);
|
return _lstProfileEx.Max(t => t == null ? 0 : t.Sort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,202 +1,33 @@
|
|||||||
namespace ServiceLib.Handler.SysProxy
|
namespace ServiceLib.Handler.SysProxy
|
||||||
{
|
{
|
||||||
public class ProxySettingLinux
|
public class ProxySettingLinux
|
||||||
{
|
{
|
||||||
|
private static readonly string _proxySetFileName = $"{Global.ProxySetLinuxShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
||||||
|
|
||||||
public static async Task SetProxy(string host, int port, string exceptions)
|
public static async Task SetProxy(string host, int port, string exceptions)
|
||||||
{
|
{
|
||||||
var lstCmd = GetSetCmds(host, port, exceptions);
|
List<string> args = ["manual", host, port.ToString(), exceptions];
|
||||||
|
await ExecCmd(args);
|
||||||
await ExecCmd(lstCmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task UnsetProxy()
|
public static async Task UnsetProxy()
|
||||||
{
|
{
|
||||||
var lstCmd = GetUnsetCmds();
|
List<string> args = ["none"];
|
||||||
|
await ExecCmd(args);
|
||||||
await ExecCmd(lstCmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task ExecCmd(List<CmdItem> lstCmd)
|
private static async Task ExecCmd(List<string> args)
|
||||||
{
|
{
|
||||||
foreach (var cmd in lstCmd)
|
var fileName = Utils.GetBinConfigPath(_proxySetFileName);
|
||||||
|
if (!File.Exists(fileName))
|
||||||
{
|
{
|
||||||
if (cmd is null || cmd.Cmd.IsNullOrEmpty() || cmd.Arguments is null)
|
var contents = EmbedUtils.GetEmbedText(Global.ProxySetLinuxShellFileName);
|
||||||
{
|
await File.AppendAllTextAsync(fileName, contents);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
await Task.Delay(10);
|
|
||||||
await Utils.GetCliWrapOutput(cmd.Cmd, cmd.Arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<CmdItem> GetSetCmds(string host, int port, string exceptions)
|
await Utils.SetLinuxChmod(fileName);
|
||||||
{
|
|
||||||
var isKde = IsKde(out var configDir);
|
|
||||||
List<string> lstType = ["", "http", "https", "socks", "ftp"];
|
|
||||||
List<CmdItem> lstCmd = [];
|
|
||||||
|
|
||||||
//GNOME
|
|
||||||
foreach (var type in lstType)
|
|
||||||
{
|
|
||||||
lstCmd.AddRange(GetSetCmd4Gnome(type, host, port));
|
|
||||||
}
|
|
||||||
if (exceptions.IsNotEmpty())
|
|
||||||
{
|
|
||||||
lstCmd.AddRange(GetSetCmd4Gnome("exceptions", exceptions, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isKde)
|
await Utils.GetCliWrapOutput(fileName, args);
|
||||||
{
|
|
||||||
foreach (var type in lstType)
|
|
||||||
{
|
|
||||||
lstCmd.AddRange(GetSetCmd4Kde(type, host, port, configDir));
|
|
||||||
}
|
|
||||||
if (exceptions.IsNotEmpty())
|
|
||||||
{
|
|
||||||
lstCmd.AddRange(GetSetCmd4Kde("exceptions", exceptions, 0, configDir));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify system to reload
|
|
||||||
lstCmd.Add(new CmdItem()
|
|
||||||
{
|
|
||||||
Cmd = "dbus-send",
|
|
||||||
Arguments = ["--type=signal", "/KIO/Scheduler", "org.kde.KIO.Scheduler.reparseSlaveConfiguration", "string:''"]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return lstCmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<CmdItem> GetUnsetCmds()
|
|
||||||
{
|
|
||||||
var isKde = IsKde(out var configDir);
|
|
||||||
List<CmdItem> lstCmd = [];
|
|
||||||
|
|
||||||
//GNOME
|
|
||||||
lstCmd.Add(new CmdItem()
|
|
||||||
{
|
|
||||||
Cmd = "gsettings",
|
|
||||||
Arguments = ["set", "org.gnome.system.proxy", "mode", "none"]
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isKde)
|
|
||||||
{
|
|
||||||
lstCmd.Add(new CmdItem()
|
|
||||||
{
|
|
||||||
Cmd = GetKdeVersion(),
|
|
||||||
Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", "ProxyType", "0"]
|
|
||||||
});
|
|
||||||
|
|
||||||
// Notify system to reload
|
|
||||||
lstCmd.Add(new CmdItem()
|
|
||||||
{
|
|
||||||
Cmd = "dbus-send",
|
|
||||||
Arguments = ["--type=signal", "/KIO/Scheduler", "org.kde.KIO.Scheduler.reparseSlaveConfiguration", "string:''"]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return lstCmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<CmdItem> GetSetCmd4Kde(string type, string host, int port, string configDir)
|
|
||||||
{
|
|
||||||
List<CmdItem> lstCmd = [];
|
|
||||||
var cmd = GetKdeVersion();
|
|
||||||
|
|
||||||
if (type.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
lstCmd.Add(new()
|
|
||||||
{
|
|
||||||
Cmd = cmd,
|
|
||||||
Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", "ProxyType", "1"]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (type == "exceptions")
|
|
||||||
{
|
|
||||||
lstCmd.Add(new()
|
|
||||||
{
|
|
||||||
Cmd = cmd,
|
|
||||||
Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", "NoProxyFor", host]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var type2 = type.Equals("https") ? "http" : type;
|
|
||||||
lstCmd.Add(new CmdItem()
|
|
||||||
{
|
|
||||||
Cmd = cmd,
|
|
||||||
Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", $"{type}Proxy", $"{type2}://{host}:{port}"]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return lstCmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<CmdItem> GetSetCmd4Gnome(string type, string host, int port)
|
|
||||||
{
|
|
||||||
List<CmdItem> lstCmd = [];
|
|
||||||
|
|
||||||
if (type.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
lstCmd.Add(new()
|
|
||||||
{
|
|
||||||
Cmd = "gsettings",
|
|
||||||
Arguments = ["set", "org.gnome.system.proxy", "mode", "manual"]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (type == "exceptions")
|
|
||||||
{
|
|
||||||
lstCmd.Add(new()
|
|
||||||
{
|
|
||||||
Cmd = "gsettings",
|
|
||||||
Arguments = ["set", $"org.gnome.system.proxy", "ignore-hosts", JsonUtils.Serialize(host.Split(','), false)]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lstCmd.Add(new()
|
|
||||||
{
|
|
||||||
Cmd = "gsettings",
|
|
||||||
Arguments = ["set", $"org.gnome.system.proxy.{type}", "host", host]
|
|
||||||
});
|
|
||||||
|
|
||||||
lstCmd.Add(new()
|
|
||||||
{
|
|
||||||
Cmd = "gsettings",
|
|
||||||
Arguments = ["set", $"org.gnome.system.proxy.{type}", "port", $"{port}"]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return lstCmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsKde(out string configDir)
|
|
||||||
{
|
|
||||||
configDir = "/home";
|
|
||||||
var desktop = Environment.GetEnvironmentVariable("XDG_CURRENT_DESKTOP");
|
|
||||||
var desktop2 = Environment.GetEnvironmentVariable("XDG_SESSION_DESKTOP");
|
|
||||||
var isKde = string.Equals(desktop, "KDE", StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| string.Equals(desktop, "plasma", StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| string.Equals(desktop2, "KDE", StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| string.Equals(desktop2, "plasma", StringComparison.OrdinalIgnoreCase);
|
|
||||||
if (isKde)
|
|
||||||
{
|
|
||||||
var homeDir = Environment.GetEnvironmentVariable("HOME");
|
|
||||||
if (homeDir != null)
|
|
||||||
{
|
|
||||||
configDir = Path.Combine(homeDir, ".config");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return isKde;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetKdeVersion()
|
|
||||||
{
|
|
||||||
var ver = Environment.GetEnvironmentVariable("KDE_SESSION_VERSION") ?? "0";
|
|
||||||
return ver switch
|
|
||||||
{
|
|
||||||
"6" => "kwriteconfig6",
|
|
||||||
_ => "kwriteconfig5"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,101 +1,38 @@
|
|||||||
namespace ServiceLib.Handler.SysProxy
|
namespace ServiceLib.Handler.SysProxy
|
||||||
{
|
{
|
||||||
public class ProxySettingOSX
|
public class ProxySettingOSX
|
||||||
{
|
{
|
||||||
/// <summary>
|
private static readonly string _proxySetFileName = $"{Global.ProxySetOSXShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
||||||
/// 应用接口类型
|
|
||||||
/// </summary>
|
|
||||||
private static readonly List<string> LstInterface = ["Ethernet", "Wi-Fi", "Thunderbolt Bridge", "USB 10/100/1000 LAN"];
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 代理类型,对应 http,https,socks
|
|
||||||
/// </summary>
|
|
||||||
private static readonly List<string> LstTypes = ["setwebproxy", "setsecurewebproxy", "setsocksfirewallproxy"];
|
|
||||||
|
|
||||||
public static async Task SetProxy(string host, int port, string exceptions)
|
public static async Task SetProxy(string host, int port, string exceptions)
|
||||||
{
|
{
|
||||||
var lstInterface = await GetListNetworkServices();
|
List<string> args = ["set", host, port.ToString()];
|
||||||
var lstCmd = GetSetCmds(lstInterface, host, port, exceptions);
|
if (exceptions.IsNotEmpty())
|
||||||
await ExecCmd(lstCmd);
|
{
|
||||||
|
args.AddRange(exceptions.Split(','));
|
||||||
|
}
|
||||||
|
|
||||||
|
await ExecCmd(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task UnsetProxy()
|
public static async Task UnsetProxy()
|
||||||
{
|
{
|
||||||
var lstInterface = await GetListNetworkServices();
|
List<string> args = ["clear"];
|
||||||
var lstCmd = GetUnsetCmds(lstInterface);
|
await ExecCmd(args);
|
||||||
await ExecCmd(lstCmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task ExecCmd(List<CmdItem> lstCmd)
|
private static async Task ExecCmd(List<string> args)
|
||||||
{
|
{
|
||||||
foreach (var cmd in lstCmd)
|
var fileName = Utils.GetBinConfigPath(_proxySetFileName);
|
||||||
|
if (!File.Exists(fileName))
|
||||||
{
|
{
|
||||||
if (cmd is null || cmd.Cmd.IsNullOrEmpty() || cmd.Arguments is null)
|
var contents = EmbedUtils.GetEmbedText(Global.ProxySetOSXShellFileName);
|
||||||
{
|
await File.AppendAllTextAsync(fileName, contents);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(10);
|
await Utils.SetLinuxChmod(fileName);
|
||||||
await Utils.GetCliWrapOutput(cmd.Cmd, cmd.Arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<CmdItem> GetSetCmds(List<string> lstInterface, string host, int port, string exceptions)
|
|
||||||
{
|
|
||||||
List<CmdItem> lstCmd = [];
|
|
||||||
foreach (var interf in lstInterface)
|
|
||||||
{
|
|
||||||
foreach (var type in LstTypes)
|
|
||||||
{
|
|
||||||
lstCmd.Add(new CmdItem()
|
|
||||||
{
|
|
||||||
Cmd = "networksetup",
|
|
||||||
Arguments = [$"-{type}", interf, host, port.ToString()]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (exceptions.IsNotEmpty())
|
|
||||||
{
|
|
||||||
List<string> args = [$"-setproxybypassdomains", interf];
|
|
||||||
args.AddRange(exceptions.Split(','));
|
|
||||||
lstCmd.Add(new CmdItem()
|
|
||||||
{
|
|
||||||
Cmd = "networksetup",
|
|
||||||
Arguments = args
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lstCmd;
|
await Utils.GetCliWrapOutput(fileName, args);
|
||||||
}
|
|
||||||
|
|
||||||
private static List<CmdItem> GetUnsetCmds(List<string> lstInterface)
|
|
||||||
{
|
|
||||||
List<CmdItem> lstCmd = [];
|
|
||||||
foreach (var interf in lstInterface)
|
|
||||||
{
|
|
||||||
foreach (var type in LstTypes)
|
|
||||||
{
|
|
||||||
lstCmd.Add(new CmdItem()
|
|
||||||
{
|
|
||||||
Cmd = "networksetup",
|
|
||||||
Arguments = [$"-{type}state", interf, "off"]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lstCmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<List<string>> GetListNetworkServices()
|
|
||||||
{
|
|
||||||
var services = await Utils.GetListNetworkServices();
|
|
||||||
if (services.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return LstInterface;
|
|
||||||
}
|
|
||||||
|
|
||||||
var lst = services.Split(Environment.NewLine).Where(t => t.Length > 0 && t.Contains('*') == false);
|
|
||||||
return lst.ToList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace ServiceLib.Handler.SysProxy
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// set proxy for LAN
|
// set proxy for LAN
|
||||||
bool result = SetConnectionProxy(null, strProxy, exceptions, type);
|
var result = SetConnectionProxy(null, strProxy, exceptions, type);
|
||||||
// set proxy for dial up connections
|
// set proxy for dial up connections
|
||||||
var connections = EnumerateRasEntries();
|
var connections = EnumerateRasEntries();
|
||||||
foreach (var connection in connections)
|
foreach (var connection in connections)
|
||||||
@@ -71,27 +71,27 @@ namespace ServiceLib.Handler.SysProxy
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
SetProxyFallback(strProxy, exceptions, type);
|
_ = SetProxyFallback(strProxy, exceptions, type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool SetConnectionProxy(string? connectionName, string? strProxy, string? exceptions, int type)
|
private static bool SetConnectionProxy(string? connectionName, string? strProxy, string? exceptions, int type)
|
||||||
{
|
{
|
||||||
InternetPerConnOptionList list = new();
|
var list = new InternetPerConnOptionList();
|
||||||
|
|
||||||
int optionCount = 1;
|
var optionCount = 1;
|
||||||
if (type == 1) // No proxy
|
if (type == 1) // No proxy
|
||||||
{
|
{
|
||||||
optionCount = 1;
|
optionCount = 1;
|
||||||
}
|
}
|
||||||
else if (type is 2 or 4) // named proxy or autoproxy script URL
|
else if (type is 2 or 4) // named proxy or autoproxy script URL
|
||||||
{
|
{
|
||||||
optionCount = string.IsNullOrEmpty(exceptions) ? 2 : 3;
|
optionCount = exceptions.IsNullOrEmpty() ? 2 : 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_Int = (int)PerConnFlags.PROXY_TYPE_DIRECT;
|
var m_Int = (int)PerConnFlags.PROXY_TYPE_DIRECT;
|
||||||
PerConnOption m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
var m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
||||||
if (type == 2) // named proxy
|
if (type == 2) // named proxy
|
||||||
{
|
{
|
||||||
m_Int = (int)(PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY);
|
m_Int = (int)(PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY);
|
||||||
@@ -103,11 +103,9 @@ namespace ServiceLib.Handler.SysProxy
|
|||||||
m_Option = PerConnOption.INTERNET_PER_CONN_AUTOCONFIG_URL;
|
m_Option = PerConnOption.INTERNET_PER_CONN_AUTOCONFIG_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//int optionCount = Utile.IsNullOrEmpty(strProxy) ? 1 : (Utile.IsNullOrEmpty(exceptions) ? 2 : 3);
|
var options = new InternetConnectionOption[optionCount];
|
||||||
InternetConnectionOption[] options = new InternetConnectionOption[optionCount];
|
|
||||||
// USE a proxy server ...
|
// USE a proxy server ...
|
||||||
options[0].m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
options[0].m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
||||||
//options[0].m_Value.m_Int = (int)((optionCount < 2) ? PerConnFlags.PROXY_TYPE_DIRECT : (PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY));
|
|
||||||
options[0].m_Value.m_Int = m_Int;
|
options[0].m_Value.m_Int = m_Int;
|
||||||
// use THIS proxy server
|
// use THIS proxy server
|
||||||
if (optionCount > 1)
|
if (optionCount > 1)
|
||||||
@@ -135,20 +133,20 @@ namespace ServiceLib.Handler.SysProxy
|
|||||||
list.dwOptionCount = options.Length;
|
list.dwOptionCount = options.Length;
|
||||||
list.dwOptionError = 0;
|
list.dwOptionError = 0;
|
||||||
|
|
||||||
int optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
|
var optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
|
||||||
// make a pointer out of all that ...
|
// make a pointer out of all that ...
|
||||||
nint optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length); // !! remember to deallocate memory 4
|
var optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length); // !! remember to deallocate memory 4
|
||||||
// copy the array over into that spot in memory ...
|
// copy the array over into that spot in memory ...
|
||||||
for (int i = 0; i < options.Length; ++i)
|
for (var i = 0; i < options.Length; ++i)
|
||||||
{
|
{
|
||||||
if (Environment.Is64BitOperatingSystem)
|
if (Environment.Is64BitOperatingSystem)
|
||||||
{
|
{
|
||||||
nint opt = new(optionsPtr.ToInt64() + (i * optSize));
|
var opt = new nint(optionsPtr.ToInt64() + (i * optSize));
|
||||||
Marshal.StructureToPtr(options[i], opt, false);
|
Marshal.StructureToPtr(options[i], opt, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nint opt = new(optionsPtr.ToInt32() + (i * optSize));
|
var opt = new nint(optionsPtr.ToInt32() + (i * optSize));
|
||||||
Marshal.StructureToPtr(options[i], opt, false);
|
Marshal.StructureToPtr(options[i], opt, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,14 +154,14 @@ namespace ServiceLib.Handler.SysProxy
|
|||||||
list.options = optionsPtr;
|
list.options = optionsPtr;
|
||||||
|
|
||||||
// and then make a pointer out of the whole list
|
// and then make a pointer out of the whole list
|
||||||
nint ipcoListPtr = Marshal.AllocCoTaskMem(list.dwSize); // !! remember to deallocate memory 5
|
var ipcoListPtr = Marshal.AllocCoTaskMem(list.dwSize); // !! remember to deallocate memory 5
|
||||||
Marshal.StructureToPtr(list, ipcoListPtr, false);
|
Marshal.StructureToPtr(list, ipcoListPtr, false);
|
||||||
|
|
||||||
// and finally, call the API method!
|
// and finally, call the API method!
|
||||||
bool isSuccess = NativeMethods.InternetSetOption(nint.Zero,
|
var isSuccess = NativeMethods.InternetSetOption(nint.Zero,
|
||||||
InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,
|
InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,
|
||||||
ipcoListPtr, list.dwSize);
|
ipcoListPtr, list.dwSize);
|
||||||
int returnvalue = 0; // ERROR_SUCCESS
|
var returnvalue = 0; // ERROR_SUCCESS
|
||||||
if (!isSuccess)
|
if (!isSuccess)
|
||||||
{ // get the error codes, they might be helpful
|
{ // get the error codes, they might be helpful
|
||||||
returnvalue = Marshal.GetLastPInvokeError();
|
returnvalue = Marshal.GetLastPInvokeError();
|
||||||
@@ -171,13 +169,15 @@ namespace ServiceLib.Handler.SysProxy
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Notify the system that the registry settings have been changed and cause them to be refreshed
|
// Notify the system that the registry settings have been changed and cause them to be refreshed
|
||||||
NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_SETTINGS_CHANGED, nint.Zero, 0);
|
_ = NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_SETTINGS_CHANGED, nint.Zero, 0);
|
||||||
NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_REFRESH, nint.Zero, 0);
|
_ = NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_REFRESH, nint.Zero, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FREE the data ASAP
|
// FREE the data ASAP
|
||||||
if (list.szConnection != nint.Zero)
|
if (list.szConnection != nint.Zero)
|
||||||
|
{
|
||||||
Marshal.FreeHGlobal(list.szConnection); // release mem 3
|
Marshal.FreeHGlobal(list.szConnection); // release mem 3
|
||||||
|
}
|
||||||
if (optionCount > 1)
|
if (optionCount > 1)
|
||||||
{
|
{
|
||||||
Marshal.FreeHGlobal(options[1].m_Value.m_StringPtr); // release mem 1
|
Marshal.FreeHGlobal(options[1].m_Value.m_StringPtr); // release mem 1
|
||||||
@@ -204,18 +204,18 @@ namespace ServiceLib.Handler.SysProxy
|
|||||||
/// <exception cref="ApplicationException">Error message with win32 error code</exception>
|
/// <exception cref="ApplicationException">Error message with win32 error code</exception>
|
||||||
private static IEnumerable<string> EnumerateRasEntries()
|
private static IEnumerable<string> EnumerateRasEntries()
|
||||||
{
|
{
|
||||||
int entries = 0;
|
var entries = 0;
|
||||||
// attempt to query with 1 entry buffer
|
// attempt to query with 1 entry buffer
|
||||||
RASENTRYNAME[] rasEntryNames = new RASENTRYNAME[1];
|
var rasEntryNames = new RASENTRYNAME[1];
|
||||||
int bufferSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
var bufferSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||||
rasEntryNames[0].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
rasEntryNames[0].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||||
|
|
||||||
uint result = NativeMethods.RasEnumEntries(null, null, rasEntryNames, ref bufferSize, ref entries);
|
var result = NativeMethods.RasEnumEntries(null, null, rasEntryNames, ref bufferSize, ref entries);
|
||||||
// increase buffer if the buffer is not large enough
|
// increase buffer if the buffer is not large enough
|
||||||
if (result == (uint)ErrorCode.ERROR_BUFFER_TOO_SMALL)
|
if (result == (uint)ErrorCode.ERROR_BUFFER_TOO_SMALL)
|
||||||
{
|
{
|
||||||
rasEntryNames = new RASENTRYNAME[bufferSize / Marshal.SizeOf(typeof(RASENTRYNAME))];
|
rasEntryNames = new RASENTRYNAME[bufferSize / Marshal.SizeOf(typeof(RASENTRYNAME))];
|
||||||
for (int i = 0; i < rasEntryNames.Length; i++)
|
for (var i = 0; i < rasEntryNames.Length; i++)
|
||||||
{
|
{
|
||||||
rasEntryNames[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
rasEntryNames[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||||
}
|
}
|
||||||
@@ -225,7 +225,7 @@ namespace ServiceLib.Handler.SysProxy
|
|||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
var entryNames = new List<string>();
|
var entryNames = new List<string>();
|
||||||
for (int i = 0; i < entries; i++)
|
for (var i = 0; i < entries; i++)
|
||||||
{
|
{
|
||||||
entryNames.Add(rasEntryNames[i].szEntryName);
|
entryNames.Add(rasEntryNames[i].szEntryName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
strProxy = string.Empty;
|
strProxy = string.Empty;
|
||||||
if (Utils.IsNullOrEmpty(config.SystemProxyItem.SystemProxyAdvancedProtocol))
|
if (config.SystemProxyItem.SystemProxyAdvancedProtocol.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
strProxy = $"{Global.Loopback}:{port}";
|
strProxy = $"{Global.Loopback}:{port}";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Handler
|
||||||
{
|
{
|
||||||
public class TaskHandler
|
public class TaskHandler
|
||||||
{
|
{
|
||||||
@@ -7,66 +7,92 @@
|
|||||||
|
|
||||||
public void RegUpdateTask(Config config, Action<bool, string> updateFunc)
|
public void RegUpdateTask(Config config, Action<bool, string> updateFunc)
|
||||||
{
|
{
|
||||||
Task.Run(() => UpdateTaskRunSubscription(config, updateFunc));
|
Task.Run(() => ScheduledTasks(config, updateFunc));
|
||||||
Task.Run(() => UpdateTaskRunGeo(config, updateFunc));
|
}
|
||||||
|
|
||||||
|
private async Task ScheduledTasks(Config config, Action<bool, string> updateFunc)
|
||||||
|
{
|
||||||
|
Logging.SaveLog("Setup Scheduled Tasks");
|
||||||
|
|
||||||
|
var numOfExecuted = 1;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
//1 minute
|
||||||
|
await Task.Delay(1000 * 60);
|
||||||
|
|
||||||
|
//Execute once 1 minute
|
||||||
|
await UpdateTaskRunSubscription(config, updateFunc);
|
||||||
|
|
||||||
|
//Execute once 20 minute
|
||||||
|
if (numOfExecuted % 20 == 0)
|
||||||
|
{
|
||||||
|
//Logging.SaveLog("Execute save config");
|
||||||
|
|
||||||
|
await ConfigHandler.SaveConfig(config);
|
||||||
|
await ProfileExHandler.Instance.SaveTo();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Execute once 1 hour
|
||||||
|
if (numOfExecuted % 60 == 0)
|
||||||
|
{
|
||||||
|
//Logging.SaveLog("Execute delete expired files");
|
||||||
|
|
||||||
|
FileManager.DeleteExpiredFiles(Utils.GetBinConfigPath(), DateTime.Now.AddHours(-1));
|
||||||
|
FileManager.DeleteExpiredFiles(Utils.GetLogPath(), DateTime.Now.AddMonths(-1));
|
||||||
|
FileManager.DeleteExpiredFiles(Utils.GetTempPath(), DateTime.Now.AddMonths(-1));
|
||||||
|
|
||||||
|
//Check once 1 hour
|
||||||
|
await UpdateTaskRunGeo(config, numOfExecuted / 60, updateFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfExecuted++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> updateFunc)
|
private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> updateFunc)
|
||||||
{
|
{
|
||||||
await Task.Delay(60000);
|
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
|
||||||
Logging.SaveLog("UpdateTaskRunSubscription");
|
var lstSubs = (await AppHandler.Instance.SubItems())?
|
||||||
|
.Where(t => t.AutoUpdateInterval > 0)
|
||||||
|
.Where(t => updateTime - t.UpdateTime >= t.AutoUpdateInterval * 60)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
var updateHandle = new UpdateService();
|
if (lstSubs is not { Count: > 0 })
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
|
return;
|
||||||
var lstSubs = (await AppHandler.Instance.SubItems())
|
}
|
||||||
.Where(t => t.AutoUpdateInterval > 0)
|
|
||||||
.Where(t => updateTime - t.UpdateTime >= t.AutoUpdateInterval * 60)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
foreach (var item in lstSubs)
|
Logging.SaveLog("Execute update subscription");
|
||||||
|
var updateHandle = new UpdateService();
|
||||||
|
|
||||||
|
foreach (var item in lstSubs)
|
||||||
|
{
|
||||||
|
await updateHandle.UpdateSubscriptionProcess(config, item.Id, true, (bool success, string msg) =>
|
||||||
{
|
{
|
||||||
await updateHandle.UpdateSubscriptionProcess(config, item.Id, true, (bool success, string msg) =>
|
updateFunc?.Invoke(success, msg);
|
||||||
{
|
if (success)
|
||||||
updateFunc?.Invoke(success, msg);
|
{
|
||||||
if (success)
|
Logging.SaveLog($"Update subscription end. {msg}");
|
||||||
Logging.SaveLog("subscription" + msg);
|
}
|
||||||
});
|
});
|
||||||
item.UpdateTime = updateTime;
|
item.UpdateTime = updateTime;
|
||||||
await ConfigHandler.AddSubItem(config, item);
|
await ConfigHandler.AddSubItem(config, item);
|
||||||
|
await Task.Delay(1000);
|
||||||
await Task.Delay(5000);
|
|
||||||
}
|
|
||||||
await Task.Delay(60000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateTaskRunGeo(Config config, Action<bool, string> updateFunc)
|
private async Task UpdateTaskRunGeo(Config config, int hours, Action<bool, string> updateFunc)
|
||||||
{
|
{
|
||||||
var autoUpdateGeoTime = DateTime.Now;
|
if (config.GuiItem.AutoUpdateInterval > 0 && hours > 0 && hours % config.GuiItem.AutoUpdateInterval == 0)
|
||||||
|
|
||||||
//await Task.Delay(1000 * 120);
|
|
||||||
Logging.SaveLog("UpdateTaskRunGeo");
|
|
||||||
|
|
||||||
var updateHandle = new UpdateService();
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
await Task.Delay(1000 * 3600);
|
Logging.SaveLog("Execute update geo files");
|
||||||
|
|
||||||
var dtNow = DateTime.Now;
|
var updateHandle = new UpdateService();
|
||||||
if (config.GuiItem.AutoUpdateInterval > 0)
|
await updateHandle.UpdateGeoFileAll(config, (bool success, string msg) =>
|
||||||
{
|
{
|
||||||
if ((dtNow - autoUpdateGeoTime).Hours % config.GuiItem.AutoUpdateInterval == 0)
|
updateFunc?.Invoke(false, msg);
|
||||||
{
|
});
|
||||||
await updateHandle.UpdateGeoFileAll(config, (bool success, string msg) =>
|
|
||||||
{
|
|
||||||
updateFunc?.Invoke(false, msg);
|
|
||||||
});
|
|
||||||
autoUpdateGeoTime = dtNow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace ServiceLib.Handler
|
|||||||
private static readonly Lazy<WebDavHandler> _instance = new(() => new());
|
private static readonly Lazy<WebDavHandler> _instance = new(() => new());
|
||||||
public static WebDavHandler Instance => _instance.Value;
|
public static WebDavHandler Instance => _instance.Value;
|
||||||
|
|
||||||
private Config? _config;
|
private readonly Config? _config;
|
||||||
private WebDavClient? _client;
|
private WebDavClient? _client;
|
||||||
private string? _lastDescription;
|
private string? _lastDescription;
|
||||||
private string _webDir = Global.AppName + "_backup";
|
private string _webDir = Global.AppName + "_backup";
|
||||||
@@ -62,7 +62,9 @@ namespace ServiceLib.Handler
|
|||||||
private async Task<bool> TryCreateDir()
|
private async Task<bool> TryCreateDir()
|
||||||
{
|
{
|
||||||
if (_client is null)
|
if (_client is null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result2 = await _client.Mkcol(_webDir);
|
var result2 = await _client.Mkcol(_webDir);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace ServiceLib.Models
|
namespace ServiceLib.Models
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class CoreBasicItem
|
public class CoreBasicItem
|
||||||
@@ -156,7 +156,7 @@
|
|||||||
public int SpeedTestTimeout { get; set; }
|
public int SpeedTestTimeout { get; set; }
|
||||||
public string SpeedTestUrl { get; set; }
|
public string SpeedTestUrl { get; set; }
|
||||||
public string SpeedPingTestUrl { get; set; }
|
public string SpeedPingTestUrl { get; set; }
|
||||||
public int SpeedTestPageSize { get; set; }
|
public int MixedConcurrencyCount { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@@ -197,6 +197,7 @@
|
|||||||
{
|
{
|
||||||
public int UpMbps { get; set; }
|
public int UpMbps { get; set; }
|
||||||
public int DownMbps { get; set; }
|
public int DownMbps { get; set; }
|
||||||
|
public int HopInterval { get; set; } = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@@ -244,4 +245,4 @@
|
|||||||
public string? Length { get; set; }
|
public string? Length { get; set; }
|
||||||
public string? Interval { get; set; }
|
public string? Interval { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using SQLite;
|
using SQLite;
|
||||||
|
|
||||||
namespace ServiceLib.Models
|
namespace ServiceLib.Models
|
||||||
{
|
{
|
||||||
@@ -11,5 +11,6 @@ namespace ServiceLib.Models
|
|||||||
public int Delay { get; set; }
|
public int Delay { get; set; }
|
||||||
public decimal Speed { get; set; }
|
public decimal Speed { get; set; }
|
||||||
public int Sort { get; set; }
|
public int Sort { get; set; }
|
||||||
|
public string? Message { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using SQLite;
|
using SQLite;
|
||||||
|
|
||||||
namespace ServiceLib.Models
|
namespace ServiceLib.Models
|
||||||
{
|
{
|
||||||
@@ -48,12 +48,12 @@ namespace ServiceLib.Models
|
|||||||
|
|
||||||
public List<string>? GetAlpn()
|
public List<string>? GetAlpn()
|
||||||
{
|
{
|
||||||
return Utils.IsNullOrEmpty(Alpn) ? null : Utils.String2List(Alpn);
|
return Alpn.IsNullOrEmpty() ? null : Utils.String2List(Alpn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetNetwork()
|
public string GetNetwork()
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(Network) || !Global.Networks.Contains(Network))
|
if (Network.IsNullOrEmpty() || !Global.Networks.Contains(Network))
|
||||||
{
|
{
|
||||||
return Global.DefaultNetwork;
|
return Global.DefaultNetwork;
|
||||||
}
|
}
|
||||||
@@ -64,11 +64,11 @@ namespace ServiceLib.Models
|
|||||||
|
|
||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
public string IndexId { get; set; }
|
public string IndexId { get; set; }
|
||||||
|
|
||||||
public EConfigType ConfigType { get; set; }
|
public EConfigType ConfigType { get; set; }
|
||||||
public int ConfigVersion { get; set; }
|
public int ConfigVersion { get; set; }
|
||||||
public string Address { get; set; }
|
public string Address { get; set; }
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
public string Ports { get; set; }
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public int AlterId { get; set; }
|
public int AlterId { get; set; }
|
||||||
public string Security { get; set; }
|
public string Security { get; set; }
|
||||||
@@ -93,4 +93,4 @@ namespace ServiceLib.Models
|
|||||||
public string SpiderX { get; set; }
|
public string SpiderX { get; set; }
|
||||||
public string Extra { get; set; }
|
public string Extra { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace ServiceLib.Models
|
namespace ServiceLib.Models
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ServerTestItem
|
public class ServerTestItem
|
||||||
@@ -8,6 +8,6 @@
|
|||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
public EConfigType ConfigType { get; set; }
|
public EConfigType ConfigType { get; set; }
|
||||||
public bool AllowTest { get; set; }
|
public bool AllowTest { get; set; }
|
||||||
public int Delay { get; set; }
|
public int QueueNum { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace ServiceLib.Models
|
namespace ServiceLib.Models
|
||||||
{
|
{
|
||||||
public class SingboxConfig
|
public class SingboxConfig
|
||||||
{
|
{
|
||||||
@@ -101,21 +101,23 @@
|
|||||||
public string tag { get; set; }
|
public string tag { get; set; }
|
||||||
public string? server { get; set; }
|
public string? server { get; set; }
|
||||||
public int? server_port { get; set; }
|
public int? server_port { get; set; }
|
||||||
public string uuid { get; set; }
|
public List<string>? server_ports { get; set; }
|
||||||
public string security { get; set; }
|
public string? uuid { get; set; }
|
||||||
|
public string? security { get; set; }
|
||||||
public int? alter_id { get; set; }
|
public int? alter_id { get; set; }
|
||||||
public string flow { get; set; }
|
public string? flow { get; set; }
|
||||||
|
public string? hop_interval { get; set; }
|
||||||
public int? up_mbps { get; set; }
|
public int? up_mbps { get; set; }
|
||||||
public int? down_mbps { get; set; }
|
public int? down_mbps { get; set; }
|
||||||
public string auth_str { get; set; }
|
public string? auth_str { get; set; }
|
||||||
public int? recv_window_conn { get; set; }
|
public int? recv_window_conn { get; set; }
|
||||||
public int? recv_window { get; set; }
|
public int? recv_window { get; set; }
|
||||||
public bool? disable_mtu_discovery { get; set; }
|
public bool? disable_mtu_discovery { get; set; }
|
||||||
public string? detour { get; set; }
|
public string? detour { get; set; }
|
||||||
public string method { get; set; }
|
public string? method { get; set; }
|
||||||
public string username { get; set; }
|
public string? username { get; set; }
|
||||||
public string password { get; set; }
|
public string? password { get; set; }
|
||||||
public string congestion_control { get; set; }
|
public string? congestion_control { get; set; }
|
||||||
public string? version { get; set; }
|
public string? version { get; set; }
|
||||||
public string? network { get; set; }
|
public string? network { get; set; }
|
||||||
public string? packet_encoding { get; set; }
|
public string? packet_encoding { get; set; }
|
||||||
@@ -252,4 +254,4 @@
|
|||||||
public string? download_detour { get; set; }
|
public string? download_detour { get; set; }
|
||||||
public string? update_interval { get; set; }
|
public string? update_interval { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,23 +4,15 @@ namespace ServiceLib.Models
|
|||||||
{
|
{
|
||||||
public class V2rayConfig
|
public class V2rayConfig
|
||||||
{
|
{
|
||||||
public string? remarks { get; set; }
|
|
||||||
|
|
||||||
public Log4Ray log { get; set; }
|
public Log4Ray log { get; set; }
|
||||||
|
|
||||||
public List<Inbounds4Ray> inbounds { get; set; }
|
|
||||||
|
|
||||||
public List<Outbounds4Ray> outbounds { get; set; }
|
|
||||||
|
|
||||||
public Stats4Ray? stats { get; set; }
|
|
||||||
|
|
||||||
public Metrics4Ray? metrics { get; set; }
|
|
||||||
|
|
||||||
public Policy4Ray? policy { get; set; }
|
|
||||||
|
|
||||||
public object dns { get; set; }
|
public object dns { get; set; }
|
||||||
|
public List<Inbounds4Ray> inbounds { get; set; }
|
||||||
|
public List<Outbounds4Ray> outbounds { get; set; }
|
||||||
public Routing4Ray routing { get; set; }
|
public Routing4Ray routing { get; set; }
|
||||||
|
public Metrics4Ray? metrics { get; set; }
|
||||||
|
public Policy4Ray? policy { get; set; }
|
||||||
|
public Stats4Ray? stats { get; set; }
|
||||||
|
public string? remarks { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Stats4Ray
|
public class Stats4Ray
|
||||||
@@ -299,6 +291,8 @@ namespace ServiceLib.Models
|
|||||||
public object request { get; set; }
|
public object request { get; set; }
|
||||||
|
|
||||||
public object response { get; set; }
|
public object response { get; set; }
|
||||||
|
|
||||||
|
public string? domain { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class KcpSettings4Ray
|
public class KcpSettings4Ray
|
||||||
@@ -398,4 +392,4 @@ namespace ServiceLib.Models
|
|||||||
public string? length { get; set; }
|
public string? length { get; set; }
|
||||||
public string? interval { get; set; }
|
public string? interval { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
113
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
113
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
@@ -61,7 +61,7 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Do you want to append rules? Choose yes to append, choose otherwise to replace 的本地化字符串。
|
/// 查找类似 Do you want to append rules? Choose yes to append, choose otherwise to replace. 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string AddBatchRoutingRulesYesNo {
|
public static string AddBatchRoutingRulesYesNo {
|
||||||
get {
|
get {
|
||||||
@@ -196,7 +196,7 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Failed to run Core, please see the log 的本地化字符串。
|
/// 查找类似 Failed to run Core, please check the prompt information 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string FailedToRunCore {
|
public static string FailedToRunCore {
|
||||||
get {
|
get {
|
||||||
@@ -1311,6 +1311,15 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Remove invalid by test results 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string menuRemoveInvalidServerResult {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("menuRemoveInvalidServerResult", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Remove selected servers (Delete) 的本地化字符串。
|
/// 查找类似 Remove selected servers (Delete) 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1680,6 +1689,15 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 By test result 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string menuTestServerResult {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("menuTestServerResult", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 {0} Website 的本地化字符串。
|
/// 查找类似 {0} Website 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1689,15 +1707,6 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查找类似 Clear original subscription content 的本地化字符串。
|
|
||||||
/// </summary>
|
|
||||||
public static string MsgClearSubscription {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("MsgClearSubscription", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Download GeoFile: {0} successfully 的本地化字符串。
|
/// 查找类似 Download GeoFile: {0} successfully 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -2004,6 +2013,15 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Removed {0} invalid test results. 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string RemoveInvalidServerResultTip {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("RemoveInvalidServerResultTip", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Are you sure to remove the rules? 的本地化字符串。
|
/// 查找类似 Are you sure to remove the rules? 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -2094,6 +2112,15 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Starting retesting failed parts, {0} remaining. Press ESC to terminate... 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string SpeedtestingTestFailedPart {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("SpeedtestingTestFailedPart", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Waiting for testing (press ESC to terminate)... 的本地化字符串。
|
/// 查找类似 Waiting for testing (press ESC to terminate)... 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -2195,7 +2222,7 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 AutoRefresh 的本地化字符串。
|
/// 查找类似 Auto refresh 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string TbAutoRefresh {
|
public static string TbAutoRefresh {
|
||||||
get {
|
get {
|
||||||
@@ -2204,7 +2231,7 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Auto ScrollToEnd 的本地化字符串。
|
/// 查找类似 Auto scroll to end 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string TbAutoScrollToEnd {
|
public static string TbAutoScrollToEnd {
|
||||||
get {
|
get {
|
||||||
@@ -2456,7 +2483,7 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Address(Ip,Ipv6) 的本地化字符串。
|
/// 查找类似 Address(Ipv4,Ipv6) 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string TbLocalAddress {
|
public static string TbLocalAddress {
|
||||||
get {
|
get {
|
||||||
@@ -2509,6 +2536,24 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Server port range 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string TbPorts7 {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("TbPorts7", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Will cover the port, separate with commas (,) 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string TbPorts7Tips {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("TbPorts7Tips", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Socks port 的本地化字符串。
|
/// 查找类似 Socks port 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -2852,7 +2897,7 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Install the font to the system and restart the settings 的本地化字符串。
|
/// 查找类似 Install the font to the system, select or fill in the font name, restart the settings 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string TbSettingsCurrentFontFamilyLinuxTip {
|
public static string TbSettingsCurrentFontFamilyLinuxTip {
|
||||||
get {
|
get {
|
||||||
@@ -3103,15 +3148,6 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查找类似 HTTP Port 的本地化字符串。
|
|
||||||
/// </summary>
|
|
||||||
public static string TbSettingsHttpPort {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("TbSettingsHttpPort", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Hysteria Max bandwidth (Up/Dw) 的本地化字符串。
|
/// 查找类似 Hysteria Max bandwidth (Up/Dw) 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -3167,7 +3203,7 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 The password is encrypted and stored only in local files. 的本地化字符串。
|
/// 查找类似 The password is encrypted and stored only in local files 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string TbSettingsLinuxSudoPasswordTip {
|
public static string TbSettingsLinuxSudoPasswordTip {
|
||||||
get {
|
get {
|
||||||
@@ -3211,6 +3247,15 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 The number of concurrent during multi-test 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string TbSettingsMixedConcurrencyCount {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("TbSettingsMixedConcurrencyCount", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 sing-box Mux Protocol 的本地化字符串。
|
/// 查找类似 sing-box Mux Protocol 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -3346,15 +3391,6 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查找类似 Number per time for auto batch during speedtest(max 1000) 的本地化字符串。
|
|
||||||
/// </summary>
|
|
||||||
public static string TbSettingsSpeedTestPageSize {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("TbSettingsSpeedTestPageSize", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 SpeedTest Single Timeout Value 的本地化字符串。
|
/// 查找类似 SpeedTest Single Timeout Value 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -3868,15 +3904,6 @@ namespace ServiceLib.Resx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查找类似 You are currently running a standalone package, please manually download the SelfContained.7z file to unzip and overwrite it! 的本地化字符串。
|
|
||||||
/// </summary>
|
|
||||||
public static string UpdateStandalonePackageTip {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("UpdateStandalonePackageTip", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 UpgradeApp does not exist 的本地化字符串。
|
/// 查找类似 UpgradeApp does not exist 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
@@ -210,9 +210,6 @@
|
|||||||
<data name="LvTransportProtocol" xml:space="preserve">
|
<data name="LvTransportProtocol" xml:space="preserve">
|
||||||
<value>جابجایی</value>
|
<value>جابجایی</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgClearSubscription" xml:space="preserve">
|
|
||||||
<value>محتوای اشتراک اصلی را پاک کنید</value>
|
|
||||||
</data>
|
|
||||||
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
||||||
<value>دانلود Core با موفقیت</value>
|
<value>دانلود Core با موفقیت</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -344,10 +341,10 @@
|
|||||||
<value>لطفاً DNS سفارشی صحیح را پر کنید</value>
|
<value>لطفاً DNS سفارشی صحیح را پر کنید</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TransportPathTip1" xml:space="preserve">
|
<data name="TransportPathTip1" xml:space="preserve">
|
||||||
<value>*ws path</value>
|
<value>* مسیر ws</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TransportPathTip2" xml:space="preserve">
|
<data name="TransportPathTip2" xml:space="preserve">
|
||||||
<value>*h2 path</value>
|
<value>* مسیر h2</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TransportPathTip3" xml:space="preserve">
|
<data name="TransportPathTip3" xml:space="preserve">
|
||||||
<value>*QUIC key/Kcp seed</value>
|
<value>*QUIC key/Kcp seed</value>
|
||||||
@@ -356,13 +353,13 @@
|
|||||||
<value>*grpc serviceName</value>
|
<value>*grpc serviceName</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TransportRequestHostTip1" xml:space="preserve">
|
<data name="TransportRequestHostTip1" xml:space="preserve">
|
||||||
<value>*http host Separated by commas (,)</value>
|
<value>*هاست http جدا شده با کاما (،)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TransportRequestHostTip2" xml:space="preserve">
|
<data name="TransportRequestHostTip2" xml:space="preserve">
|
||||||
<value>*ws host</value>
|
<value>*هاست ws</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TransportRequestHostTip3" xml:space="preserve">
|
<data name="TransportRequestHostTip3" xml:space="preserve">
|
||||||
<value>*h2 host Separated by commas (,)</value>
|
<value>*هاست h2 با کاما (،) جدا شده است</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TransportRequestHostTip4" xml:space="preserve">
|
<data name="TransportRequestHostTip4" xml:space="preserve">
|
||||||
<value>*QUIC securty</value>
|
<value>*QUIC securty</value>
|
||||||
@@ -377,7 +374,7 @@
|
|||||||
<value>*QUIC camouflage type</value>
|
<value>*QUIC camouflage type</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TransportHeaderTypeTip4" xml:space="preserve">
|
<data name="TransportHeaderTypeTip4" xml:space="preserve">
|
||||||
<value>*grpc mode</value>
|
<value>*حالت grpc</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="LvTLS" xml:space="preserve">
|
<data name="LvTLS" xml:space="preserve">
|
||||||
<value>TLS</value>
|
<value>TLS</value>
|
||||||
@@ -404,7 +401,7 @@
|
|||||||
<value>درحال تست کردن...</value>
|
<value>درحال تست کردن...</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="LabLAN" xml:space="preserve">
|
<data name="LabLAN" xml:space="preserve">
|
||||||
<value>LAN</value>
|
<value>شبکه محلی</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="LabLocal" xml:space="preserve">
|
<data name="LabLocal" xml:space="preserve">
|
||||||
<value>محلی</value>
|
<value>محلی</value>
|
||||||
@@ -715,9 +712,6 @@
|
|||||||
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
||||||
<value>استثناها: از سرور پروکسی برای آدرس هایی که با موارد زیر شروع می شوند استفاده نکنید. برای جدا کردن ورودی ها از نقطه ویرگول (;) استفاده کنید.</value>
|
<value>استثناها: از سرور پروکسی برای آدرس هایی که با موارد زیر شروع می شوند استفاده نکنید. برای جدا کردن ورودی ها از نقطه ویرگول (;) استفاده کنید.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsHttpPort" xml:space="preserve">
|
|
||||||
<value>پورت Http</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
||||||
<value>نمایش سرعت واقعی (نیاز به راه اندازی مجدد)</value>
|
<value>نمایش سرعت واقعی (نیاز به راه اندازی مجدد)</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1051,9 +1045,6 @@
|
|||||||
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
||||||
<value>نمایش یا پنهان کردن پنجره اصلی</value>
|
<value>نمایش یا پنهان کردن پنجره اصلی</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UpdateStandalonePackageTip" xml:space="preserve">
|
|
||||||
<value>شما در حال حاضر در حال اجرای یک بسته مستقل هستید، لطفاً فایل SelfContained.7z را به صورت دستی دانلود کنید تا آن را از حالت فشرده خارج کرده و بازنویسی کنید!</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
||||||
<value>پیکربندی سفارشی ساکس پورت</value>
|
<value>پیکربندی سفارشی ساکس پورت</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1328,7 +1319,7 @@
|
|||||||
<value>Previous proxy remarks</value>
|
<value>Previous proxy remarks</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>آدرس (IP, IPv6)</value>
|
<value>آدرس (IPv4, IPv6)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbReserved" xml:space="preserve">
|
<data name="TbReserved" xml:space="preserve">
|
||||||
<value>Reserved(2,3,4)</value>
|
<value>Reserved(2,3,4)</value>
|
||||||
@@ -1372,8 +1363,8 @@
|
|||||||
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
||||||
<value>هنگام بستن پنجره در سینی پنهان شوید</value>
|
<value>هنگام بستن پنجره در سینی پنهان شوید</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsMixedConcurrencyCount" xml:space="preserve">
|
||||||
<value>تعداد در هر زمان برای دسته خودکار در طول تست سرعت (حداکثر 1000)</value>
|
<value>The number of concurrent during multi-test</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
<value>موارد استثنا: از سرور پروکسی برای آدرس های زیر استفاده نکنید. برای جدا کردن ورودی ها از کاما (،) استفاده کنید.</value>
|
<value>موارد استثنا: از سرور پروکسی برای آدرس های زیر استفاده نکنید. برای جدا کردن ورودی ها از کاما (،) استفاده کنید.</value>
|
||||||
@@ -1393,4 +1384,22 @@
|
|||||||
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
||||||
<value>کپی کردن دستور پروکسی در کلیپ بورد</value>
|
<value>کپی کردن دستور پروکسی در کلیپ بورد</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
<data name="SpeedtestingTestFailedPart" xml:space="preserve">
|
||||||
|
<value>شروع آزمایش مجدد قطعات ناموفق، {0} باقی مانده است. برای خاتمه ESC را فشار دهید...</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuTestServerResult" xml:space="preserve">
|
||||||
|
<value>By test result</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuRemoveInvalidServerResult" xml:space="preserve">
|
||||||
|
<value>Remove invalid by test results</value>
|
||||||
|
</data>
|
||||||
|
<data name="RemoveInvalidServerResultTip" xml:space="preserve">
|
||||||
|
<value>Removed {0} invalid test results.</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7" xml:space="preserve">
|
||||||
|
<value>Server port range</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7Tips" xml:space="preserve">
|
||||||
|
<value>Will cover the port, separate with commas (,)</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
@@ -210,9 +210,6 @@
|
|||||||
<data name="LvTransportProtocol" xml:space="preserve">
|
<data name="LvTransportProtocol" xml:space="preserve">
|
||||||
<value>Szállítás</value>
|
<value>Szállítás</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgClearSubscription" xml:space="preserve">
|
|
||||||
<value>Eredeti előfizetési tartalom törlése</value>
|
|
||||||
</data>
|
|
||||||
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
||||||
<value>A Core letöltése sikerült</value>
|
<value>A Core letöltése sikerült</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -715,9 +712,6 @@
|
|||||||
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
||||||
<value>Kivétel. Ne használjon proxy szervert a címek esetében, amelyek pontosan itt kezdődnek, használjon pontosvesszőt (;)</value>
|
<value>Kivétel. Ne használjon proxy szervert a címek esetében, amelyek pontosan itt kezdődnek, használjon pontosvesszőt (;)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsHttpPort" xml:space="preserve">
|
|
||||||
<value>HTTP Port</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
||||||
<value>Display real-time speed</value>
|
<value>Display real-time speed</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1106,7 +1100,7 @@
|
|||||||
<value>Fenntartva (2,3,4)</value>
|
<value>Fenntartva (2,3,4)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Cím (Ip,Ipv6)</value>
|
<value>Cím (Ipv4,Ipv6)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbPath7" xml:space="preserve">
|
<data name="TbPath7" xml:space="preserve">
|
||||||
<value>obfs jelszó</value>
|
<value>obfs jelszó</value>
|
||||||
@@ -1255,9 +1249,6 @@
|
|||||||
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
||||||
<value>Fő ablak megjelenítése vagy elrejtése</value>
|
<value>Fő ablak megjelenítése vagy elrejtése</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UpdateStandalonePackageTip" xml:space="preserve">
|
|
||||||
<value>Jelenleg egy önálló csomagot futtatsz, kérlek, töltsd le manuálisan a SelfContained.7z fájlt, bontsd ki és írd felül!</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
||||||
<value>Testreszabott konfigurációs socks port</value>
|
<value>Testreszabott konfigurációs socks port</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1372,8 +1363,8 @@
|
|||||||
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
||||||
<value>Minimálás tálcára ablak zárásakor</value>
|
<value>Minimálás tálcára ablak zárásakor</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsMixedConcurrencyCount" xml:space="preserve">
|
||||||
<value>Szám / időszak az automatikus batch során a sebességvizsgálat során (maximum 1000)</value>
|
<value>The number of concurrent during multi-test</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
<value>Kivétel. Ne használj proxy szervert a címeknél, évezz pontosvesszőt (,)</value>
|
<value>Kivétel. Ne használj proxy szervert a címeknél, évezz pontosvesszőt (,)</value>
|
||||||
@@ -1393,4 +1384,22 @@
|
|||||||
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
||||||
<value>Copy proxy command to clipboard</value>
|
<value>Copy proxy command to clipboard</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="SpeedtestingTestFailedPart" xml:space="preserve">
|
||||||
|
<value>Starting retesting failed parts, {0} remaining. Press ESC to terminate...</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuTestServerResult" xml:space="preserve">
|
||||||
|
<value>By test result</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuRemoveInvalidServerResult" xml:space="preserve">
|
||||||
|
<value>Remove invalid by test results</value>
|
||||||
|
</data>
|
||||||
|
<data name="RemoveInvalidServerResultTip" xml:space="preserve">
|
||||||
|
<value>Removed {0} invalid test results.</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7" xml:space="preserve">
|
||||||
|
<value>Server port range</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7Tips" xml:space="preserve">
|
||||||
|
<value>Will cover the port, separate with commas (,)</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
@@ -210,9 +210,6 @@
|
|||||||
<data name="LvTransportProtocol" xml:space="preserve">
|
<data name="LvTransportProtocol" xml:space="preserve">
|
||||||
<value>Transport</value>
|
<value>Transport</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgClearSubscription" xml:space="preserve">
|
|
||||||
<value>Clear original subscription content</value>
|
|
||||||
</data>
|
|
||||||
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
||||||
<value>Download Core successfully</value>
|
<value>Download Core successfully</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -329,7 +326,7 @@
|
|||||||
<value>Please fill in the URL</value>
|
<value>Please fill in the URL</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="AddBatchRoutingRulesYesNo" xml:space="preserve">
|
<data name="AddBatchRoutingRulesYesNo" xml:space="preserve">
|
||||||
<value>Do you want to append rules? Choose yes to append, choose otherwise to replace</value>
|
<value>Do you want to append rules? Choose yes to append, choose otherwise to replace.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgDownloadGeoFileSuccessfully" xml:space="preserve">
|
<data name="MsgDownloadGeoFileSuccessfully" xml:space="preserve">
|
||||||
<value>Download GeoFile: {0} successfully</value>
|
<value>Download GeoFile: {0} successfully</value>
|
||||||
@@ -715,9 +712,6 @@
|
|||||||
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
||||||
<value>Exclusions: Do not use proxy server for addresses beginning with the following. Use semicolon (;) to separate entries.</value>
|
<value>Exclusions: Do not use proxy server for addresses beginning with the following. Use semicolon (;) to separate entries.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsHttpPort" xml:space="preserve">
|
|
||||||
<value>HTTP Port</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
||||||
<value>Display real-time speed (requires restart)</value>
|
<value>Display real-time speed (requires restart)</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -926,7 +920,7 @@
|
|||||||
<value>Speed(M/s)</value>
|
<value>Speed(M/s)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="FailedToRunCore" xml:space="preserve">
|
<data name="FailedToRunCore" xml:space="preserve">
|
||||||
<value>Failed to run Core, please see the log</value>
|
<value>Failed to run Core, please check the prompt information</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="LvFilter" xml:space="preserve">
|
<data name="LvFilter" xml:space="preserve">
|
||||||
<value>Remarks regular filter</value>
|
<value>Remarks regular filter</value>
|
||||||
@@ -950,7 +944,7 @@
|
|||||||
<value>Enable sorting servers by drag-n-drop (requires restart)</value>
|
<value>Enable sorting servers by drag-n-drop (requires restart)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbAutoRefresh" xml:space="preserve">
|
<data name="TbAutoRefresh" xml:space="preserve">
|
||||||
<value>AutoRefresh</value>
|
<value>Auto refresh</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="SpeedtestingSkip" xml:space="preserve">
|
<data name="SpeedtestingSkip" xml:space="preserve">
|
||||||
<value>Skip test</value>
|
<value>Skip test</value>
|
||||||
@@ -1106,7 +1100,7 @@
|
|||||||
<value>Reserved(2,3,4)</value>
|
<value>Reserved(2,3,4)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Address(Ip,Ipv6)</value>
|
<value>Address(Ipv4,Ipv6)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbPath7" xml:space="preserve">
|
<data name="TbPath7" xml:space="preserve">
|
||||||
<value>obfs password</value>
|
<value>obfs password</value>
|
||||||
@@ -1115,7 +1109,7 @@
|
|||||||
<value>(Domain or IP or ProcName) and Port and Protocol and InboundTag => OutboundTag</value>
|
<value>(Domain or IP or ProcName) and Port and Protocol and InboundTag => OutboundTag</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbAutoScrollToEnd" xml:space="preserve">
|
<data name="TbAutoScrollToEnd" xml:space="preserve">
|
||||||
<value>Auto ScrollToEnd</value>
|
<value>Auto scroll to end</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSpeedPingTestUrl" xml:space="preserve">
|
<data name="TbSettingsSpeedPingTestUrl" xml:space="preserve">
|
||||||
<value>Speed Ping Test URL</value>
|
<value>Speed Ping Test URL</value>
|
||||||
@@ -1255,9 +1249,6 @@
|
|||||||
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
||||||
<value>Show or hide the main window</value>
|
<value>Show or hide the main window</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UpdateStandalonePackageTip" xml:space="preserve">
|
|
||||||
<value>You are currently running a standalone package, please manually download the SelfContained.7z file to unzip and overwrite it!</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
||||||
<value>Custom config socks port</value>
|
<value>Custom config socks port</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1343,7 +1334,7 @@
|
|||||||
<value>Please do not use the insecure HTTP protocol subscription address</value>
|
<value>Please do not use the insecure HTTP protocol subscription address</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||||
<value>Install the font to the system and restart the settings</value>
|
<value>Install the font to the system, select or fill in the font name, restart the settings</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="menuExitTips" xml:space="preserve">
|
<data name="menuExitTips" xml:space="preserve">
|
||||||
<value>Are you sure to exit?</value>
|
<value>Are you sure to exit?</value>
|
||||||
@@ -1355,7 +1346,7 @@
|
|||||||
<value>System sudo password</value>
|
<value>System sudo password</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
|
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
|
||||||
<value>The password is encrypted and stored only in local files.</value>
|
<value>The password is encrypted and stored only in local files</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsLinuxSudoPasswordIsEmpty" xml:space="preserve">
|
<data name="TbSettingsLinuxSudoPasswordIsEmpty" xml:space="preserve">
|
||||||
<value>Please set the sudo password in Tun mode settings first</value>
|
<value>Please set the sudo password in Tun mode settings first</value>
|
||||||
@@ -1372,8 +1363,8 @@
|
|||||||
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
||||||
<value>Hide to tray when closing the window</value>
|
<value>Hide to tray when closing the window</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsMixedConcurrencyCount" xml:space="preserve">
|
||||||
<value>Number per time for auto batch during speedtest(max 1000)</value>
|
<value>The number of concurrent during multi-test</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
<value>Exclusions: Do not use proxy server for the following addresses. Use comma (,) to separate entries.</value>
|
<value>Exclusions: Do not use proxy server for the following addresses. Use comma (,) to separate entries.</value>
|
||||||
@@ -1393,4 +1384,22 @@
|
|||||||
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
||||||
<value>Copy proxy command to clipboard</value>
|
<value>Copy proxy command to clipboard</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
<data name="SpeedtestingTestFailedPart" xml:space="preserve">
|
||||||
|
<value>Starting retesting failed parts, {0} remaining. Press ESC to terminate...</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuTestServerResult" xml:space="preserve">
|
||||||
|
<value>By test result</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuRemoveInvalidServerResult" xml:space="preserve">
|
||||||
|
<value>Remove invalid by test results</value>
|
||||||
|
</data>
|
||||||
|
<data name="RemoveInvalidServerResultTip" xml:space="preserve">
|
||||||
|
<value>Removed {0} invalid test results.</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7" xml:space="preserve">
|
||||||
|
<value>Server port range</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7Tips" xml:space="preserve">
|
||||||
|
<value>Will cover the port, separate with commas (,)</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
@@ -210,9 +210,6 @@
|
|||||||
<data name="LvTransportProtocol" xml:space="preserve">
|
<data name="LvTransportProtocol" xml:space="preserve">
|
||||||
<value>Протокол</value>
|
<value>Протокол</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgClearSubscription" xml:space="preserve">
|
|
||||||
<value>Очистить контент оригинальной подписки</value>
|
|
||||||
</data>
|
|
||||||
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
||||||
<value>Ядро успешно загружено</value>
|
<value>Ядро успешно загружено</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -721,9 +718,6 @@
|
|||||||
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
||||||
<value>Исключение. Не используйте прокси-сервер для адресов, начинающихся с (,), используйте точку с запятой (;)</value>
|
<value>Исключение. Не используйте прокси-сервер для адресов, начинающихся с (,), используйте точку с запятой (;)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsHttpPort" xml:space="preserve">
|
|
||||||
<value>HTTP порт</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
||||||
<value>Display real-time speed</value>
|
<value>Display real-time speed</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1058,7 +1052,7 @@
|
|||||||
<value>obfs password</value>
|
<value>obfs password</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Address(Ip,Ipv6)</value>
|
<value>Address(Ipv4,Ipv6)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsDomainStrategy4Out" xml:space="preserve">
|
<data name="TbSettingsDomainStrategy4Out" xml:space="preserve">
|
||||||
<value>Default domain strategy for outbound</value>
|
<value>Default domain strategy for outbound</value>
|
||||||
@@ -1210,9 +1204,6 @@
|
|||||||
<data name="menuAddTuicServer" xml:space="preserve">
|
<data name="menuAddTuicServer" xml:space="preserve">
|
||||||
<value>Add [TUIC] server</value>
|
<value>Add [TUIC] server</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UpdateStandalonePackageTip" xml:space="preserve">
|
|
||||||
<value>You are currently running a standalone package, please manually download the SelfContained.7z file to unzip and overwrite it!</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbSettingsEnableIPv6Address" xml:space="preserve">
|
<data name="TbSettingsEnableIPv6Address" xml:space="preserve">
|
||||||
<value>Enable IPv6 Address</value>
|
<value>Enable IPv6 Address</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1372,8 +1363,8 @@
|
|||||||
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
||||||
<value>Hide to tray when closing the window</value>
|
<value>Hide to tray when closing the window</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsMixedConcurrencyCount" xml:space="preserve">
|
||||||
<value>Number per time for auto batch during speedtest(max 1000)</value>
|
<value>The number of concurrent during multi-test</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
|
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
|
||||||
@@ -1393,4 +1384,22 @@
|
|||||||
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
||||||
<value>Copy proxy command to clipboard</value>
|
<value>Copy proxy command to clipboard</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="SpeedtestingTestFailedPart" xml:space="preserve">
|
||||||
|
<value>Starting retesting failed parts, {0} remaining. Press ESC to terminate...</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuTestServerResult" xml:space="preserve">
|
||||||
|
<value>By test result</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuRemoveInvalidServerResult" xml:space="preserve">
|
||||||
|
<value>Remove invalid by test results</value>
|
||||||
|
</data>
|
||||||
|
<data name="RemoveInvalidServerResultTip" xml:space="preserve">
|
||||||
|
<value>Removed {0} invalid test results.</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7" xml:space="preserve">
|
||||||
|
<value>Server port range</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7Tips" xml:space="preserve">
|
||||||
|
<value>Will cover the port, separate with commas (,)</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
@@ -175,10 +175,10 @@
|
|||||||
<value>初始化配置</value>
|
<value>初始化配置</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="IsLatestCore" xml:space="preserve">
|
<data name="IsLatestCore" xml:space="preserve">
|
||||||
<value>{0} {1} 已是最新版本</value>
|
<value>{0} {1} 已是最新版本。</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="IsLatestN" xml:space="preserve">
|
<data name="IsLatestN" xml:space="preserve">
|
||||||
<value>{0} {1} 已是最新版本</value>
|
<value>{0} {1} 已是最新版本。</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="LvAddress" xml:space="preserve">
|
<data name="LvAddress" xml:space="preserve">
|
||||||
<value>地址</value>
|
<value>地址</value>
|
||||||
@@ -210,9 +210,6 @@
|
|||||||
<data name="LvTransportProtocol" xml:space="preserve">
|
<data name="LvTransportProtocol" xml:space="preserve">
|
||||||
<value>传输协议</value>
|
<value>传输协议</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgClearSubscription" xml:space="preserve">
|
|
||||||
<value>清除原订阅内容</value>
|
|
||||||
</data>
|
|
||||||
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
||||||
<value>下载Core成功</value>
|
<value>下载Core成功</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -277,7 +274,7 @@
|
|||||||
<value>请先选择服务器</value>
|
<value>请先选择服务器</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="RemoveDuplicateServerResult" xml:space="preserve">
|
<data name="RemoveDuplicateServerResult" xml:space="preserve">
|
||||||
<value>服务器去重完成。原数量: {0},现数量: {1}</value>
|
<value>服务器去重完成。原数量: {0},现数量: {1}。</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="RemoveServer" xml:space="preserve">
|
<data name="RemoveServer" xml:space="preserve">
|
||||||
<value>是否确定移除服务器?</value>
|
<value>是否确定移除服务器?</value>
|
||||||
@@ -715,9 +712,6 @@
|
|||||||
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
||||||
<value>例外:对于下列字符开头的地址,不使用代理配置文件。使用分号(;)分隔。</value>
|
<value>例外:对于下列字符开头的地址,不使用代理配置文件。使用分号(;)分隔。</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsHttpPort" xml:space="preserve">
|
|
||||||
<value>本地http监听端口</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
||||||
<value>显示实时速度(需重启)</value>
|
<value>显示实时速度(需重启)</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -926,7 +920,7 @@
|
|||||||
<value>速度(M/s)</value>
|
<value>速度(M/s)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="FailedToRunCore" xml:space="preserve">
|
<data name="FailedToRunCore" xml:space="preserve">
|
||||||
<value>运行Core失败,请查看日志</value>
|
<value>运行 Core 失败,请查看提示信息</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="LvFilter" xml:space="preserve">
|
<data name="LvFilter" xml:space="preserve">
|
||||||
<value>别名正则过滤</value>
|
<value>别名正则过滤</value>
|
||||||
@@ -1103,7 +1097,7 @@
|
|||||||
<value>Reserved(2,3,4)</value>
|
<value>Reserved(2,3,4)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Address(Ip,Ipv6)</value>
|
<value>Address(Ipv4,Ipv6)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbPath7" xml:space="preserve">
|
<data name="TbPath7" xml:space="preserve">
|
||||||
<value>混淆密码(obfs password)</value>
|
<value>混淆密码(obfs password)</value>
|
||||||
@@ -1252,9 +1246,6 @@
|
|||||||
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
||||||
<value>显示或隐藏主界面</value>
|
<value>显示或隐藏主界面</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UpdateStandalonePackageTip" xml:space="preserve">
|
|
||||||
<value>您当前运行的是独立包,请手动下载 SelfContained.7z文件解压覆盖!</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
||||||
<value>自定义配置的Socks端口</value>
|
<value>自定义配置的Socks端口</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1340,7 +1331,7 @@
|
|||||||
<value>请不要使用不安全的HTTP协议订阅地址</value>
|
<value>请不要使用不安全的HTTP协议订阅地址</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||||
<value>安装字体到系统中,重启设置</value>
|
<value>安装字体到系统中,选择或填入字体名称,重启设置</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="menuExitTips" xml:space="preserve">
|
<data name="menuExitTips" xml:space="preserve">
|
||||||
<value>是否确定退出?</value>
|
<value>是否确定退出?</value>
|
||||||
@@ -1369,8 +1360,8 @@
|
|||||||
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
||||||
<value>关闭窗口时隐藏至托盘</value>
|
<value>关闭窗口时隐藏至托盘</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsMixedConcurrencyCount" xml:space="preserve">
|
||||||
<value>测试时自动分批的每批数量(最大1000)</value>
|
<value>多线程测试时的并发数量</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
<value>例外:对于下列地址不使用代理配置文件。使用逗号(,)分隔。</value>
|
<value>例外:对于下列地址不使用代理配置文件。使用逗号(,)分隔。</value>
|
||||||
@@ -1390,4 +1381,22 @@
|
|||||||
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
||||||
<value>复制终端代理命令至剪贴板</value>
|
<value>复制终端代理命令至剪贴板</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="SpeedtestingTestFailedPart" xml:space="preserve">
|
||||||
|
<value>开始对失败部分进行重新测试,剩余 {0} 个。可按 ESC 终止...</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuTestServerResult" xml:space="preserve">
|
||||||
|
<value>按测试结果</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuRemoveInvalidServerResult" xml:space="preserve">
|
||||||
|
<value>按测试结果移除无效</value>
|
||||||
|
</data>
|
||||||
|
<data name="RemoveInvalidServerResultTip" xml:space="preserve">
|
||||||
|
<value>移除无效测试结果 {0} 个。</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7" xml:space="preserve">
|
||||||
|
<value>跳跃端口范围</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7Tips" xml:space="preserve">
|
||||||
|
<value>会覆盖端口,多组时用逗号(,)隔开</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -175,10 +175,10 @@
|
|||||||
<value>初始化設定</value>
|
<value>初始化設定</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="IsLatestCore" xml:space="preserve">
|
<data name="IsLatestCore" xml:space="preserve">
|
||||||
<value>{0} {1} 已是最新版本</value>
|
<value>{0} {1} 已是最新版本。</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="IsLatestN" xml:space="preserve">
|
<data name="IsLatestN" xml:space="preserve">
|
||||||
<value>{0} {1} 已是最新版本</value>
|
<value>{0} {1} 已是最新版本。</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="LvAddress" xml:space="preserve">
|
<data name="LvAddress" xml:space="preserve">
|
||||||
<value>位址</value>
|
<value>位址</value>
|
||||||
@@ -210,9 +210,6 @@
|
|||||||
<data name="LvTransportProtocol" xml:space="preserve">
|
<data name="LvTransportProtocol" xml:space="preserve">
|
||||||
<value>傳輸協定</value>
|
<value>傳輸協定</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgClearSubscription" xml:space="preserve">
|
|
||||||
<value>清除原訂閱內容</value>
|
|
||||||
</data>
|
|
||||||
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
||||||
<value>下載Core成功</value>
|
<value>下載Core成功</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -277,7 +274,7 @@
|
|||||||
<value>請先選擇伺服器</value>
|
<value>請先選擇伺服器</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="RemoveDuplicateServerResult" xml:space="preserve">
|
<data name="RemoveDuplicateServerResult" xml:space="preserve">
|
||||||
<value>伺服器去重完成。原數量: {0},現數量: {1}</value>
|
<value>伺服器去重完成。原數量: {0},現數量: {1}。</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="RemoveServer" xml:space="preserve">
|
<data name="RemoveServer" xml:space="preserve">
|
||||||
<value>是否確定移除伺服器?</value>
|
<value>是否確定移除伺服器?</value>
|
||||||
@@ -716,9 +713,6 @@
|
|||||||
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
<data name="TbSettingsExceptionTip" xml:space="preserve">
|
||||||
<value>例外:對於下列字元開頭的位址,不使用代理設定檔。使用分號(;)分隔。</value>
|
<value>例外:對於下列字元開頭的位址,不使用代理設定檔。使用分號(;)分隔。</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsHttpPort" xml:space="preserve">
|
|
||||||
<value>本機HTTP偵聽埠</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
<data name="TbSettingsDisplayRealTimeSpeed" xml:space="preserve">
|
||||||
<value>顯示即時速度(需重啟)</value>
|
<value>顯示即時速度(需重啟)</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -927,7 +921,7 @@
|
|||||||
<value>速度(M/s)</value>
|
<value>速度(M/s)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="FailedToRunCore" xml:space="preserve">
|
<data name="FailedToRunCore" xml:space="preserve">
|
||||||
<value>執行Core失敗,請查閲日誌</value>
|
<value>執行Core失敗,請查看提示訊息</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="LvFilter" xml:space="preserve">
|
<data name="LvFilter" xml:space="preserve">
|
||||||
<value>別名正則過濾</value>
|
<value>別名正則過濾</value>
|
||||||
@@ -1133,9 +1127,6 @@
|
|||||||
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
<data name="menuShowOrHideMainWindow" xml:space="preserve">
|
||||||
<value>顯示或隱藏主介面</value>
|
<value>顯示或隱藏主介面</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UpdateStandalonePackageTip" xml:space="preserve">
|
|
||||||
<value>您目前運行的是獨立包,請手動下載 SelfContained.7z檔案解壓縮覆蓋!</value>
|
|
||||||
</data>
|
|
||||||
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
<data name="TbPreSocksPort4Sub" xml:space="preserve">
|
||||||
<value>自訂設定的Socks連接埠</value>
|
<value>自訂設定的Socks連接埠</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1221,7 +1212,7 @@
|
|||||||
<value>請不要使用不安全的HTTP協定訂閱位址</value>
|
<value>請不要使用不安全的HTTP協定訂閱位址</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||||
<value>安裝字型到系統中,重新啟動設定</value>
|
<value>安裝字體到系統中,選擇或填入字體名稱,重新啟動設定</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="menuExitTips" xml:space="preserve">
|
<data name="menuExitTips" xml:space="preserve">
|
||||||
<value>是否確定退出?</value>
|
<value>是否確定退出?</value>
|
||||||
@@ -1335,7 +1326,7 @@
|
|||||||
<value>Reserved(2,3,4)</value>
|
<value>Reserved(2,3,4)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Address(Ip,Ipv6)</value>
|
<value>Address(Ipv4,Ipv6)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsUseSystemHosts" xml:space="preserve">
|
<data name="TbSettingsUseSystemHosts" xml:space="preserve">
|
||||||
<value>使用系統hosts</value>
|
<value>使用系統hosts</value>
|
||||||
@@ -1370,8 +1361,8 @@
|
|||||||
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
|
||||||
<value>關閉視窗時隱藏至托盤</value>
|
<value>關閉視窗時隱藏至托盤</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsMixedConcurrencyCount" xml:space="preserve">
|
||||||
<value>測試時自動分批的每批數量(最大1000)</value>
|
<value>多執行緒測試時的並發數量</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
<value>例外:對於下列位址不使用代理設定檔,使用逗號(,)分隔。</value>
|
<value>例外:對於下列位址不使用代理設定檔,使用逗號(,)分隔。</value>
|
||||||
@@ -1391,4 +1382,22 @@
|
|||||||
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
<data name="menuCopyProxyCmdToClipboard" xml:space="preserve">
|
||||||
<value>複製終端代理指令至剪貼簿</value>
|
<value>複製終端代理指令至剪貼簿</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="SpeedtestingTestFailedPart" xml:space="preserve">
|
||||||
|
<value>開始對失敗部分進行重新測試,剩餘 {0} 個。可按 ESC 終止...</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuTestServerResult" xml:space="preserve">
|
||||||
|
<value>按測試結果</value>
|
||||||
|
</data>
|
||||||
|
<data name="menuRemoveInvalidServerResult" xml:space="preserve">
|
||||||
|
<value>按測試結果移除無效</value>
|
||||||
|
</data>
|
||||||
|
<data name="RemoveInvalidServerResultTip" xml:space="preserve">
|
||||||
|
<value>移除無效測試結果 {0} 個。</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7" xml:space="preserve">
|
||||||
|
<value>跳躍端口範圍</value>
|
||||||
|
</data>
|
||||||
|
<data name="TbPorts7Tips" xml:space="preserve">
|
||||||
|
<value>會覆蓋端口,多組時用逗號(,)隔開</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
File diff suppressed because it is too large
Load Diff
124
v2rayN/ServiceLib/Sample/proxy_set_linux_sh
Normal file
124
v2rayN/ServiceLib/Sample/proxy_set_linux_sh
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Function to set proxy for GNOME
|
||||||
|
set_gnome_proxy() {
|
||||||
|
local MODE=$1
|
||||||
|
local PROXY_IP=$2
|
||||||
|
local PROXY_PORT=$3
|
||||||
|
local IGNORE_HOSTS=$4
|
||||||
|
|
||||||
|
# Set the proxy mode
|
||||||
|
gsettings set org.gnome.system.proxy mode "$MODE"
|
||||||
|
|
||||||
|
if [ "$MODE" == "manual" ]; then
|
||||||
|
# List of protocols
|
||||||
|
local PROTOCOLS=("http" "https" "ftp" "socks")
|
||||||
|
|
||||||
|
# Loop through protocols to set the proxy
|
||||||
|
for PROTOCOL in "${PROTOCOLS[@]}"; do
|
||||||
|
gsettings set org.gnome.system.proxy.$PROTOCOL host "$PROXY_IP"
|
||||||
|
gsettings set org.gnome.system.proxy.$PROTOCOL port "$PROXY_PORT"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Set ignored hosts
|
||||||
|
gsettings set org.gnome.system.proxy ignore-hosts "['$IGNORE_HOSTS']"
|
||||||
|
|
||||||
|
echo "GNOME: Manual proxy settings applied."
|
||||||
|
echo "Proxy IP: $PROXY_IP"
|
||||||
|
echo "Proxy Port: $PROXY_PORT"
|
||||||
|
echo "Ignored Hosts: $IGNORE_HOSTS"
|
||||||
|
elif [ "$MODE" == "none" ]; then
|
||||||
|
echo "GNOME: Proxy disabled."
|
||||||
|
else
|
||||||
|
echo "GNOME: Invalid mode. Use 'none' or 'manual'."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to set proxy for KDE
|
||||||
|
set_kde_proxy() {
|
||||||
|
local MODE=$1
|
||||||
|
local PROXY_IP=$2
|
||||||
|
local PROXY_PORT=$3
|
||||||
|
local IGNORE_HOSTS=$4
|
||||||
|
|
||||||
|
# Determine the correct kwriteconfig command based on KDE_SESSION_VERSION
|
||||||
|
if [ "$KDE_SESSION_VERSION" == "6" ]; then
|
||||||
|
KWRITECONFIG="kwriteconfig6"
|
||||||
|
else
|
||||||
|
KWRITECONFIG="kwriteconfig5"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# KDE uses kwriteconfig to modify proxy settings
|
||||||
|
if [ "$MODE" == "manual" ]; then
|
||||||
|
# Set proxy for all protocols
|
||||||
|
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key ProxyType 1
|
||||||
|
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key httpProxy "http://$PROXY_IP:$PROXY_PORT"
|
||||||
|
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key httpsProxy "http://$PROXY_IP:$PROXY_PORT"
|
||||||
|
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key ftpProxy "http://$PROXY_IP:$PROXY_PORT"
|
||||||
|
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key socksProxy "http://$PROXY_IP:$PROXY_PORT"
|
||||||
|
|
||||||
|
# Set ignored hosts
|
||||||
|
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key NoProxyFor "$IGNORE_HOSTS"
|
||||||
|
|
||||||
|
echo "KDE: Manual proxy settings applied."
|
||||||
|
echo "Proxy IP: $PROXY_IP"
|
||||||
|
echo "Proxy Port: $PROXY_PORT"
|
||||||
|
echo "Ignored Hosts: $IGNORE_HOSTS"
|
||||||
|
elif [ "$MODE" == "none" ]; then
|
||||||
|
# Disable proxy
|
||||||
|
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key ProxyType 0
|
||||||
|
echo "KDE: Proxy disabled."
|
||||||
|
else
|
||||||
|
echo "KDE: Invalid mode. Use 'none' or 'manual'."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Apply changes by restarting KDE's network settings
|
||||||
|
dbus-send --type=signal /KIO/Scheduler org.kde.KIO.Scheduler.reparseSlaveConfiguration string:""
|
||||||
|
}
|
||||||
|
|
||||||
|
# Detect the current desktop environment
|
||||||
|
detect_desktop_environment() {
|
||||||
|
if [[ "$XDG_CURRENT_DESKTOP" == *"GNOME"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"GNOME"* ]]; then
|
||||||
|
echo "gnome"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local KDE_ENVIRONMENTS=("KDE" "plasma")
|
||||||
|
for ENV in "${KDE_ENVIRONMENTS[@]}"; do
|
||||||
|
if [ "$XDG_CURRENT_DESKTOP" == "$ENV" ] || [ "$XDG_SESSION_DESKTOP" == "$ENV" ]; then
|
||||||
|
echo "kde"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "unsupported"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main script logic
|
||||||
|
if [ "$#" -lt 1 ]; then
|
||||||
|
echo "Usage: $0 <mode> [proxy_ip proxy_port ignore_hosts]"
|
||||||
|
echo " mode: 'none' or 'manual'"
|
||||||
|
echo " If mode is 'manual', provide proxy IP, port, and ignore hosts."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get the mode
|
||||||
|
MODE=$1
|
||||||
|
PROXY_IP=$2
|
||||||
|
PROXY_PORT=$3
|
||||||
|
IGNORE_HOSTS=$4
|
||||||
|
|
||||||
|
# Detect desktop environment
|
||||||
|
DE=$(detect_desktop_environment)
|
||||||
|
|
||||||
|
# Apply settings based on the desktop environment
|
||||||
|
if [ "$DE" == "gnome" ]; then
|
||||||
|
set_gnome_proxy "$MODE" "$PROXY_IP" "$PROXY_PORT" "$IGNORE_HOSTS"
|
||||||
|
elif [ "$DE" == "kde" ]; then
|
||||||
|
set_gnome_proxy "$MODE" "$PROXY_IP" "$PROXY_PORT" "$IGNORE_HOSTS"
|
||||||
|
set_kde_proxy "$MODE" "$PROXY_IP" "$PROXY_PORT" "$IGNORE_HOSTS"
|
||||||
|
else
|
||||||
|
echo "Unsupported desktop environment: $DE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
74
v2rayN/ServiceLib/Sample/proxy_set_osx_sh
Normal file
74
v2rayN/ServiceLib/Sample/proxy_set_osx_sh
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Function to set proxy
|
||||||
|
set_proxy() {
|
||||||
|
PROXY_IP=$1
|
||||||
|
PROXY_PORT=$2
|
||||||
|
|
||||||
|
shift 2
|
||||||
|
BYPASS_DOMAINS=("$@")
|
||||||
|
# If no bypass domains are provided, set it to empty by default
|
||||||
|
if [ ${#BYPASS_DOMAINS[@]} -eq 0 ]; then
|
||||||
|
BYPASS_DOMAINS=("")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get all network service names
|
||||||
|
SERVICES=$(networksetup -listallnetworkservices | grep -v '*')
|
||||||
|
|
||||||
|
# Loop through each network service
|
||||||
|
echo "$SERVICES" | while read -r SERVICE; do
|
||||||
|
echo "Setting proxy for network service '$SERVICE'..."
|
||||||
|
# Set HTTP proxy
|
||||||
|
networksetup -setwebproxy "$SERVICE" "$PROXY_IP" "$PROXY_PORT"
|
||||||
|
|
||||||
|
# Set HTTPS proxy
|
||||||
|
networksetup -setsecurewebproxy "$SERVICE" "$PROXY_IP" "$PROXY_PORT"
|
||||||
|
|
||||||
|
# Set SOCKS proxy
|
||||||
|
networksetup -setsocksfirewallproxy "$SERVICE" "$PROXY_IP" "$PROXY_PORT"
|
||||||
|
|
||||||
|
# Set bypass domains
|
||||||
|
networksetup -setproxybypassdomains "$SERVICE" "${BYPASS_DOMAINS[@]}"
|
||||||
|
echo "Proxy for network service '$SERVICE' has been set to $PROXY_IP:$PROXY_PORT"
|
||||||
|
done
|
||||||
|
echo "Proxy settings for all network services are complete!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to disable proxy
|
||||||
|
clear_proxy() {
|
||||||
|
# Get all network service names
|
||||||
|
SERVICES=$(networksetup -listallnetworkservices | grep -v '*')
|
||||||
|
|
||||||
|
# Loop through each network service
|
||||||
|
echo "$SERVICES" | while read -r SERVICE; do
|
||||||
|
echo "Disabling proxy and clearing bypass domains for network service '$SERVICE'..."
|
||||||
|
# Disable HTTP proxy
|
||||||
|
networksetup -setwebproxystate "$SERVICE" off
|
||||||
|
|
||||||
|
# Disable HTTPS proxy
|
||||||
|
networksetup -setsecurewebproxystate "$SERVICE" off
|
||||||
|
|
||||||
|
# Disable SOCKS proxy
|
||||||
|
networksetup -setsocksfirewallproxystate "$SERVICE" off
|
||||||
|
|
||||||
|
echo "Proxy for network service '$SERVICE' has been disabled"
|
||||||
|
done
|
||||||
|
echo "Proxy for all network services has been disabled!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main script logic
|
||||||
|
if [ "$1" == "set" ]; then
|
||||||
|
# Check if enough parameters are passed for setting proxy
|
||||||
|
if [ "$#" -lt 3 ]; then
|
||||||
|
echo "Usage: $0 set <IP Address> <Port> [Bypass Domain 1 Bypass Domain 2 ...]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
set_proxy "$2" "$3" "${@:4}"
|
||||||
|
elif [ "$1" == "clear" ]; then
|
||||||
|
clear_proxy
|
||||||
|
else
|
||||||
|
echo "Usage:"
|
||||||
|
echo " To set proxy: $0 set <IP Address> <Port> [Bypass Domain 1 Bypass Domain 2 ...]"
|
||||||
|
echo " To clear proxy: $0 clear"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -29,6 +29,8 @@
|
|||||||
<EmbeddedResource Include="Sample\dns_singbox_normal" />
|
<EmbeddedResource Include="Sample\dns_singbox_normal" />
|
||||||
<EmbeddedResource Include="Sample\dns_v2ray_normal" />
|
<EmbeddedResource Include="Sample\dns_v2ray_normal" />
|
||||||
<EmbeddedResource Include="Sample\pac" />
|
<EmbeddedResource Include="Sample\pac" />
|
||||||
|
<EmbeddedResource Include="Sample\proxy_set_linux_sh" />
|
||||||
|
<EmbeddedResource Include="Sample\proxy_set_osx_sh" />
|
||||||
<EmbeddedResource Include="Sample\SampleClientConfig" />
|
<EmbeddedResource Include="Sample\SampleClientConfig" />
|
||||||
<EmbeddedResource Include="Sample\SampleHttpRequest" />
|
<EmbeddedResource Include="Sample\SampleHttpRequest" />
|
||||||
<EmbeddedResource Include="Sample\SampleHttpResponse" />
|
<EmbeddedResource Include="Sample\SampleHttpResponse" />
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
File.Delete(fileName);
|
File.Delete(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
string addressFileName = node.Address;
|
var addressFileName = node.Address;
|
||||||
if (Utils.IsNullOrEmpty(addressFileName))
|
if (addressFileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -60,9 +60,9 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
string tagYamlStr1 = "!<str>";
|
var tagYamlStr1 = "!<str>";
|
||||||
string tagYamlStr2 = "__strn__";
|
var tagYamlStr2 = "__strn__";
|
||||||
string tagYamlStr3 = "!!str";
|
var tagYamlStr3 = "!!str";
|
||||||
var txtFile = File.ReadAllText(addressFileName);
|
var txtFile = File.ReadAllText(addressFileName);
|
||||||
txtFile = txtFile.Replace(tagYamlStr1, tagYamlStr2);
|
txtFile = txtFile.Replace(tagYamlStr1, tagYamlStr2);
|
||||||
|
|
||||||
@@ -116,19 +116,21 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
//enable tun mode
|
//enable tun mode
|
||||||
if (_config.TunModeItem.EnableTun)
|
if (_config.TunModeItem.EnableTun)
|
||||||
{
|
{
|
||||||
string tun = EmbedUtils.GetEmbedText(Global.ClashTunYaml);
|
var tun = EmbedUtils.GetEmbedText(Global.ClashTunYaml);
|
||||||
if (Utils.IsNotEmpty(tun))
|
if (tun.IsNotEmpty())
|
||||||
{
|
{
|
||||||
var tunContent = YamlUtils.FromYaml<Dictionary<string, object>>(tun);
|
var tunContent = YamlUtils.FromYaml<Dictionary<string, object>>(tun);
|
||||||
if (tunContent != null)
|
if (tunContent != null)
|
||||||
|
{
|
||||||
fileContent["tun"] = tunContent["tun"];
|
fileContent["tun"] = tunContent["tun"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Mixin
|
//Mixin
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MixinContent(fileContent, node);
|
await MixinContent(fileContent, node);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -158,20 +160,21 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MixinContent(Dictionary<string, object> fileContent, ProfileItem node)
|
private async Task MixinContent(Dictionary<string, object> fileContent, ProfileItem node)
|
||||||
{
|
{
|
||||||
//if (!_config.clashUIItem.enableMixinContent)
|
if (!_config.ClashUIItem.EnableMixinContent)
|
||||||
//{
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
|
|
||||||
var path = Utils.GetConfigPath(Global.ClashMixinConfigFileName);
|
|
||||||
if (!File.Exists(path))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var txtFile = File.ReadAllText(Utils.GetConfigPath(Global.ClashMixinConfigFileName));
|
var path = Utils.GetConfigPath(Global.ClashMixinConfigFileName);
|
||||||
|
if (!File.Exists(path))
|
||||||
|
{
|
||||||
|
var mixin = EmbedUtils.GetEmbedText(Global.ClashMixinYaml);
|
||||||
|
await File.AppendAllTextAsync(path, mixin);
|
||||||
|
}
|
||||||
|
|
||||||
|
var txtFile = await File.ReadAllTextAsync(Utils.GetConfigPath(Global.ClashMixinConfigFileName));
|
||||||
|
|
||||||
var mixinContent = YamlUtils.FromYaml<Dictionary<string, object>>(txtFile);
|
var mixinContent = YamlUtils.FromYaml<Dictionary<string, object>>(txtFile);
|
||||||
if (mixinContent == null)
|
if (mixinContent == null)
|
||||||
@@ -201,8 +204,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
|
|
||||||
private void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
|
private void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
|
||||||
{
|
{
|
||||||
bool blPrepend = false;
|
var blPrepend = false;
|
||||||
bool blRemoved = false;
|
var blRemoved = false;
|
||||||
if (key.StartsWith("prepend-"))
|
if (key.StartsWith("prepend-"))
|
||||||
{
|
{
|
||||||
blPrepend = true;
|
blPrepend = true;
|
||||||
@@ -243,17 +246,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
if (blPrepend)
|
if (blPrepend)
|
||||||
{
|
{
|
||||||
lstValue.Reverse();
|
lstValue.Reverse();
|
||||||
foreach (var item in lstValue)
|
lstValue.ForEach(item => lstOri.Insert(0, item));
|
||||||
{
|
|
||||||
lstOri.Insert(0, item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var item in lstValue)
|
lstValue.ForEach(item => lstOri.Add(item));
|
||||||
{
|
|
||||||
lstOri.Add(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,4 +266,4 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
ret.Msg = ResUI.InitialConfiguration;
|
ret.Msg = ResUI.InitialConfiguration;
|
||||||
|
|
||||||
string result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
string result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (result.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -93,7 +93,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
|
|
||||||
var result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
var result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
||||||
var txtOutbound = EmbedUtils.GetEmbedText(Global.SingboxSampleOutbound);
|
var txtOutbound = EmbedUtils.GetEmbedText(Global.SingboxSampleOutbound);
|
||||||
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
|
if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -138,7 +138,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
||||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||||
{
|
{
|
||||||
if (item is null || Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id))
|
if (item is null || item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -242,6 +242,66 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<RetResult> GenerateClientSpeedtestConfig(ProfileItem node, int port)
|
||||||
|
{
|
||||||
|
var ret = new RetResult();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (node is not { Port: > 0 })
|
||||||
|
{
|
||||||
|
ret.Msg = ResUI.CheckServerSettings;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
if (node.GetNetwork() is nameof(ETransport.kcp) or nameof(ETransport.xhttp))
|
||||||
|
{
|
||||||
|
ret.Msg = ResUI.Incorrectconfiguration + $" - {node.GetNetwork()}";
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.Msg = ResUI.InitialConfiguration;
|
||||||
|
|
||||||
|
var result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
||||||
|
if (result.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
var singboxConfig = JsonUtils.Deserialize<SingboxConfig>(result);
|
||||||
|
if (singboxConfig == null)
|
||||||
|
{
|
||||||
|
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
await GenLog(singboxConfig);
|
||||||
|
await GenOutbound(node, singboxConfig.outbounds.First());
|
||||||
|
await GenMoreOutbounds(node, singboxConfig);
|
||||||
|
await GenDnsDomains(null, singboxConfig, null);
|
||||||
|
|
||||||
|
singboxConfig.route.rules.Clear();
|
||||||
|
singboxConfig.inbounds.Clear();
|
||||||
|
singboxConfig.inbounds.Add(new()
|
||||||
|
{
|
||||||
|
tag = $"{EInboundProtocol.mixed}{port}",
|
||||||
|
listen = Global.Loopback,
|
||||||
|
listen_port = port,
|
||||||
|
type = EInboundProtocol.mixed.ToString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
||||||
|
ret.Success = true;
|
||||||
|
ret.Data = JsonUtils.Serialize(singboxConfig);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<RetResult> GenerateClientMultipleLoadConfig(List<ProfileItem> selecteds)
|
public async Task<RetResult> GenerateClientMultipleLoadConfig(List<ProfileItem> selecteds)
|
||||||
{
|
{
|
||||||
var ret = new RetResult();
|
var ret = new RetResult();
|
||||||
@@ -257,7 +317,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
|
|
||||||
string result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
string result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
||||||
string txtOutbound = EmbedUtils.GetEmbedText(Global.SingboxSampleOutbound);
|
string txtOutbound = EmbedUtils.GetEmbedText(Global.SingboxSampleOutbound);
|
||||||
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
|
if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -294,7 +354,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id))
|
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -383,7 +443,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
string addressFileName = node.Address;
|
string addressFileName = node.Address;
|
||||||
if (Utils.IsNullOrEmpty(addressFileName))
|
if (addressFileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -500,10 +560,10 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
inbound.listen_port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
inbound.listen_port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||||
inbound.sniff = _config.Inbound.First().SniffingEnabled;
|
inbound.sniff = _config.Inbound.First().SniffingEnabled;
|
||||||
inbound.sniff_override_destination = _config.Inbound.First().RouteOnly ? false : _config.Inbound.First().SniffingEnabled;
|
inbound.sniff_override_destination = _config.Inbound.First().RouteOnly ? false : _config.Inbound.First().SniffingEnabled;
|
||||||
inbound.domain_strategy = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainStrategy4Singbox) ? null : _config.RoutingBasicItem.DomainStrategy4Singbox;
|
inbound.domain_strategy = _config.RoutingBasicItem.DomainStrategy4Singbox.IsNullOrEmpty() ? null : _config.RoutingBasicItem.DomainStrategy4Singbox;
|
||||||
|
|
||||||
var routing = await ConfigHandler.GetDefaultRouting(_config);
|
var routing = await ConfigHandler.GetDefaultRouting(_config);
|
||||||
if (Utils.IsNotEmpty(routing.DomainStrategy4Singbox))
|
if (routing.DomainStrategy4Singbox.IsNotEmpty())
|
||||||
{
|
{
|
||||||
inbound.domain_strategy = routing.DomainStrategy4Singbox;
|
inbound.domain_strategy = routing.DomainStrategy4Singbox;
|
||||||
}
|
}
|
||||||
@@ -523,7 +583,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
singboxConfig.inbounds.Add(inbound3);
|
singboxConfig.inbounds.Add(inbound3);
|
||||||
|
|
||||||
//auth
|
//auth
|
||||||
if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass))
|
if (_config.Inbound.First().User.IsNotEmpty() && _config.Inbound.First().Pass.IsNotEmpty())
|
||||||
{
|
{
|
||||||
inbound3.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } };
|
inbound3.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } };
|
||||||
}
|
}
|
||||||
@@ -539,9 +599,9 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
{
|
{
|
||||||
if (_config.TunModeItem.Mtu <= 0)
|
if (_config.TunModeItem.Mtu <= 0)
|
||||||
{
|
{
|
||||||
_config.TunModeItem.Mtu = Utils.ToInt(Global.TunMtus.First());
|
_config.TunModeItem.Mtu = Global.TunMtus.First();
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(_config.TunModeItem.Stack))
|
if (_config.TunModeItem.Stack.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
_config.TunModeItem.Stack = Global.TunStacks.First();
|
_config.TunModeItem.Stack = Global.TunStacks.First();
|
||||||
}
|
}
|
||||||
@@ -614,8 +674,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
case EConfigType.SOCKS:
|
case EConfigType.SOCKS:
|
||||||
{
|
{
|
||||||
outbound.version = "5";
|
outbound.version = "5";
|
||||||
if (Utils.IsNotEmpty(node.Security)
|
if (node.Security.IsNotEmpty()
|
||||||
&& Utils.IsNotEmpty(node.Id))
|
&& node.Id.IsNotEmpty())
|
||||||
{
|
{
|
||||||
outbound.username = node.Security;
|
outbound.username = node.Security;
|
||||||
outbound.password = node.Id;
|
outbound.password = node.Id;
|
||||||
@@ -624,8 +684,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
case EConfigType.HTTP:
|
case EConfigType.HTTP:
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(node.Security)
|
if (node.Security.IsNotEmpty()
|
||||||
&& Utils.IsNotEmpty(node.Id))
|
&& node.Id.IsNotEmpty())
|
||||||
{
|
{
|
||||||
outbound.username = node.Security;
|
outbound.username = node.Security;
|
||||||
outbound.password = node.Id;
|
outbound.password = node.Id;
|
||||||
@@ -638,7 +698,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
|
|
||||||
outbound.packet_encoding = "xudp";
|
outbound.packet_encoding = "xudp";
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(node.Flow))
|
if (node.Flow.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
await GenOutboundMux(node, outbound);
|
await GenOutboundMux(node, outbound);
|
||||||
}
|
}
|
||||||
@@ -659,7 +719,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
{
|
{
|
||||||
outbound.password = node.Id;
|
outbound.password = node.Id;
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(node.Path))
|
if (node.Path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
outbound.obfs = new()
|
outbound.obfs = new()
|
||||||
{
|
{
|
||||||
@@ -670,6 +730,16 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
|
|
||||||
outbound.up_mbps = _config.HysteriaItem.UpMbps > 0 ? _config.HysteriaItem.UpMbps : null;
|
outbound.up_mbps = _config.HysteriaItem.UpMbps > 0 ? _config.HysteriaItem.UpMbps : null;
|
||||||
outbound.down_mbps = _config.HysteriaItem.DownMbps > 0 ? _config.HysteriaItem.DownMbps : null;
|
outbound.down_mbps = _config.HysteriaItem.DownMbps > 0 ? _config.HysteriaItem.DownMbps : null;
|
||||||
|
if (node.Ports.IsNotEmpty())
|
||||||
|
{
|
||||||
|
outbound.server_port = null;
|
||||||
|
outbound.server_ports = node.Ports.Split(',')
|
||||||
|
.Where(p => p.Trim().IsNotEmpty())
|
||||||
|
.Select(p => p.Replace('-', ':'))
|
||||||
|
.ToList();
|
||||||
|
outbound.hop_interval = _config.HysteriaItem.HopInterval > 0 ? $"{_config.HysteriaItem.HopInterval}s" : null;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EConfigType.TUIC:
|
case EConfigType.TUIC:
|
||||||
@@ -685,7 +755,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
outbound.peer_public_key = node.PublicKey;
|
outbound.peer_public_key = node.PublicKey;
|
||||||
outbound.reserved = Utils.String2List(node.Path)?.Select(int.Parse).ToList();
|
outbound.reserved = Utils.String2List(node.Path)?.Select(int.Parse).ToList();
|
||||||
outbound.local_address = Utils.String2List(node.RequestHost);
|
outbound.local_address = Utils.String2List(node.RequestHost);
|
||||||
outbound.mtu = Utils.ToInt(node.ShortId.IsNullOrEmpty() ? Global.TunMtus.FirstOrDefault() : node.ShortId);
|
outbound.mtu = node.ShortId.IsNullOrEmpty() ? Global.TunMtus.First() : node.ShortId.ToInt();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -705,7 +775,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_config.CoreBasicItem.MuxEnabled && Utils.IsNotEmpty(_config.Mux4SboxItem.Protocol))
|
if (_config.CoreBasicItem.MuxEnabled && _config.Mux4SboxItem.Protocol.IsNotEmpty())
|
||||||
{
|
{
|
||||||
var mux = new Multiplex4Sbox()
|
var mux = new Multiplex4Sbox()
|
||||||
{
|
{
|
||||||
@@ -731,11 +801,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
if (node.StreamSecurity == Global.StreamSecurityReality || node.StreamSecurity == Global.StreamSecurity)
|
if (node.StreamSecurity == Global.StreamSecurityReality || node.StreamSecurity == Global.StreamSecurity)
|
||||||
{
|
{
|
||||||
var server_name = string.Empty;
|
var server_name = string.Empty;
|
||||||
if (Utils.IsNotEmpty(node.Sni))
|
if (node.Sni.IsNotEmpty())
|
||||||
{
|
{
|
||||||
server_name = node.Sni;
|
server_name = node.Sni;
|
||||||
}
|
}
|
||||||
else if (Utils.IsNotEmpty(node.RequestHost))
|
else if (node.RequestHost.IsNotEmpty())
|
||||||
{
|
{
|
||||||
server_name = Utils.String2List(node.RequestHost)?.First();
|
server_name = Utils.String2List(node.RequestHost)?.First();
|
||||||
}
|
}
|
||||||
@@ -746,7 +816,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
insecure = Utils.ToBool(node.AllowInsecure.IsNullOrEmpty() ? _config.CoreBasicItem.DefAllowInsecure.ToString().ToLower() : node.AllowInsecure),
|
insecure = Utils.ToBool(node.AllowInsecure.IsNullOrEmpty() ? _config.CoreBasicItem.DefAllowInsecure.ToString().ToLower() : node.AllowInsecure),
|
||||||
alpn = node.GetAlpn(),
|
alpn = node.GetAlpn(),
|
||||||
};
|
};
|
||||||
if (Utils.IsNotEmpty(node.Fingerprint))
|
if (node.Fingerprint.IsNotEmpty())
|
||||||
{
|
{
|
||||||
tls.utls = new Utls4Sbox()
|
tls.utls = new Utls4Sbox()
|
||||||
{
|
{
|
||||||
@@ -784,8 +854,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
{
|
{
|
||||||
case nameof(ETransport.h2):
|
case nameof(ETransport.h2):
|
||||||
transport.type = nameof(ETransport.http);
|
transport.type = nameof(ETransport.http);
|
||||||
transport.host = Utils.IsNullOrEmpty(node.RequestHost) ? null : Utils.String2List(node.RequestHost);
|
transport.host = node.RequestHost.IsNullOrEmpty() ? null : Utils.String2List(node.RequestHost);
|
||||||
transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path;
|
transport.path = node.Path.IsNullOrEmpty() ? null : node.Path;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nameof(ETransport.tcp): //http
|
case nameof(ETransport.tcp): //http
|
||||||
@@ -799,16 +869,16 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
transport.type = nameof(ETransport.http);
|
transport.type = nameof(ETransport.http);
|
||||||
transport.host = Utils.IsNullOrEmpty(node.RequestHost) ? null : Utils.String2List(node.RequestHost);
|
transport.host = node.RequestHost.IsNullOrEmpty() ? null : Utils.String2List(node.RequestHost);
|
||||||
transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path;
|
transport.path = node.Path.IsNullOrEmpty() ? null : node.Path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nameof(ETransport.ws):
|
case nameof(ETransport.ws):
|
||||||
transport.type = nameof(ETransport.ws);
|
transport.type = nameof(ETransport.ws);
|
||||||
transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path;
|
transport.path = node.Path.IsNullOrEmpty() ? null : node.Path;
|
||||||
if (Utils.IsNotEmpty(node.RequestHost))
|
if (node.RequestHost.IsNotEmpty())
|
||||||
{
|
{
|
||||||
transport.headers = new()
|
transport.headers = new()
|
||||||
{
|
{
|
||||||
@@ -819,8 +889,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
|
|
||||||
case nameof(ETransport.httpupgrade):
|
case nameof(ETransport.httpupgrade):
|
||||||
transport.type = nameof(ETransport.httpupgrade);
|
transport.type = nameof(ETransport.httpupgrade);
|
||||||
transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path;
|
transport.path = node.Path.IsNullOrEmpty() ? null : node.Path;
|
||||||
transport.host = Utils.IsNullOrEmpty(node.RequestHost) ? null : node.RequestHost;
|
transport.host = node.RequestHost.IsNullOrEmpty() ? null : node.RequestHost;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1015,7 +1085,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
outbound = item.OutboundTag,
|
outbound = item.OutboundTag,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(item.Port))
|
if (item.Port.IsNotEmpty())
|
||||||
{
|
{
|
||||||
if (item.Port.Contains("-"))
|
if (item.Port.Contains("-"))
|
||||||
{
|
{
|
||||||
@@ -1023,10 +1093,10 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rule.port = new List<int> { Utils.ToInt(item.Port) };
|
rule.port = new List<int> { item.Port.ToInt() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(item.Network))
|
if (item.Network.IsNotEmpty())
|
||||||
{
|
{
|
||||||
rule.network = Utils.String2List(item.Network);
|
rule.network = Utils.String2List(item.Network);
|
||||||
}
|
}
|
||||||
@@ -1171,11 +1241,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
var strDNS = string.Empty;
|
var strDNS = string.Empty;
|
||||||
if (_config.TunModeItem.EnableTun)
|
if (_config.TunModeItem.EnableTun)
|
||||||
{
|
{
|
||||||
strDNS = Utils.IsNullOrEmpty(item?.TunDNS) ? EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName) : item?.TunDNS;
|
strDNS = string.IsNullOrEmpty(item?.TunDNS) ? EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName) : item?.TunDNS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strDNS = Utils.IsNullOrEmpty(item?.NormalDNS) ? EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName) : item?.NormalDNS;
|
strDNS = string.IsNullOrEmpty(item?.NormalDNS) ? EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName) : item?.NormalDNS;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dns4Sbox = JsonUtils.Deserialize<Dns4Sbox>(strDNS);
|
var dns4Sbox = JsonUtils.Deserialize<Dns4Sbox>(strDNS);
|
||||||
@@ -1204,9 +1274,9 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
dns4Sbox.servers.Add(new()
|
dns4Sbox.servers.Add(new()
|
||||||
{
|
{
|
||||||
tag = tag,
|
tag = tag,
|
||||||
address = Utils.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
address = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
||||||
detour = Global.DirectTag,
|
detour = Global.DirectTag,
|
||||||
strategy = Utils.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom,
|
strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom,
|
||||||
});
|
});
|
||||||
dns4Sbox.rules.Insert(0, new()
|
dns4Sbox.rules.Insert(0, new()
|
||||||
{
|
{
|
||||||
@@ -1220,7 +1290,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
});
|
});
|
||||||
|
|
||||||
var lstDomain = singboxConfig.outbounds
|
var lstDomain = singboxConfig.outbounds
|
||||||
.Where(t => Utils.IsNotEmpty(t.server) && Utils.IsDomain(t.server))
|
.Where(t => t.server.IsNotEmpty() && Utils.IsDomain(t.server))
|
||||||
.Select(t => t.server)
|
.Select(t => t.server)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToList();
|
.ToList();
|
||||||
@@ -1264,7 +1334,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
singboxConfig.experimental.cache_file = new CacheFile4Sbox()
|
singboxConfig.experimental.cache_file = new CacheFile4Sbox()
|
||||||
{
|
{
|
||||||
enabled = true,
|
enabled = true,
|
||||||
path = Utils.GetConfigPath("cache.db")
|
path = Utils.GetBinPath("cache.db")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1324,10 +1394,10 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
List<Ruleset4Sbox> customRulesets = [];
|
List<Ruleset4Sbox> customRulesets = [];
|
||||||
|
|
||||||
var routing = await ConfigHandler.GetDefaultRouting(_config);
|
var routing = await ConfigHandler.GetDefaultRouting(_config);
|
||||||
if (Utils.IsNotEmpty(routing.CustomRulesetPath4Singbox))
|
if (routing.CustomRulesetPath4Singbox.IsNotEmpty())
|
||||||
{
|
{
|
||||||
var result = EmbedUtils.LoadResource(routing.CustomRulesetPath4Singbox);
|
var result = EmbedUtils.LoadResource(routing.CustomRulesetPath4Singbox);
|
||||||
if (Utils.IsNotEmpty(result))
|
if (result.IsNotEmpty())
|
||||||
{
|
{
|
||||||
customRulesets = (JsonUtils.Deserialize<List<Ruleset4Sbox>>(result) ?? [])
|
customRulesets = (JsonUtils.Deserialize<List<Ruleset4Sbox>>(result) ?? [])
|
||||||
.Where(t => t.tag != null)
|
.Where(t => t.tag != null)
|
||||||
@@ -1344,7 +1414,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
singboxConfig.route.rule_set = [];
|
singboxConfig.route.rule_set = [];
|
||||||
foreach (var item in new HashSet<string>(ruleSets))
|
foreach (var item in new HashSet<string>(ruleSets))
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(item))
|
if (item.IsNullOrEmpty())
|
||||||
{ continue; }
|
{ continue; }
|
||||||
var customRuleset = customRulesets.FirstOrDefault(t => t.tag != null && t.tag.Equals(item));
|
var customRuleset = customRulesets.FirstOrDefault(t => t.tag != null && t.tag.Equals(item));
|
||||||
if (customRuleset is null)
|
if (customRuleset is null)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
ret.Msg = ResUI.InitialConfiguration;
|
ret.Msg = ResUI.InitialConfiguration;
|
||||||
|
|
||||||
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (result.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -93,7 +93,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
|
|
||||||
string result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
string result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
||||||
string txtOutbound = EmbedUtils.GetEmbedText(Global.V2raySampleOutbound);
|
string txtOutbound = EmbedUtils.GetEmbedText(Global.V2raySampleOutbound);
|
||||||
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
|
if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -135,7 +135,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id))
|
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -182,12 +182,24 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
rule.balancerTag = balancer.tag;
|
rule.balancerTag = balancer.tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v2rayConfig.routing.rules.Add(new()
|
if (v2rayConfig.routing.domainStrategy == "IPIfNonMatch")
|
||||||
{
|
{
|
||||||
network = "tcp,udp",
|
v2rayConfig.routing.rules.Add(new()
|
||||||
balancerTag = balancer.tag,
|
{
|
||||||
type = "field"
|
ip = ["0.0.0.0/0", "::/0"],
|
||||||
});
|
balancerTag = balancer.tag,
|
||||||
|
type = "field"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v2rayConfig.routing.rules.Add(new()
|
||||||
|
{
|
||||||
|
network = "tcp,udp",
|
||||||
|
balancerTag = balancer.tag,
|
||||||
|
type = "field"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ret.Success = true;
|
ret.Success = true;
|
||||||
ret.Data = JsonUtils.Serialize(v2rayConfig);
|
ret.Data = JsonUtils.Serialize(v2rayConfig);
|
||||||
@@ -216,7 +228,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
|
|
||||||
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
||||||
var txtOutbound = EmbedUtils.GetEmbedText(Global.V2raySampleOutbound);
|
var txtOutbound = EmbedUtils.GetEmbedText(Global.V2raySampleOutbound);
|
||||||
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
|
if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -261,7 +273,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
||||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||||
{
|
{
|
||||||
if (item is null || Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id))
|
if (item is null || item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -353,6 +365,64 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<RetResult> GenerateClientSpeedtestConfig(ProfileItem node, int port)
|
||||||
|
{
|
||||||
|
var ret = new RetResult();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (node is not { Port: > 0 })
|
||||||
|
{
|
||||||
|
ret.Msg = ResUI.CheckServerSettings;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.GetNetwork() is nameof(ETransport.quic))
|
||||||
|
{
|
||||||
|
ret.Msg = ResUI.Incorrectconfiguration + $" - {node.GetNetwork()}";
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
||||||
|
if (result.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
var v2rayConfig = JsonUtils.Deserialize<V2rayConfig>(result);
|
||||||
|
if (v2rayConfig == null)
|
||||||
|
{
|
||||||
|
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
await GenLog(v2rayConfig);
|
||||||
|
await GenOutbound(node, v2rayConfig.outbounds.First());
|
||||||
|
await GenMoreOutbounds(node, v2rayConfig);
|
||||||
|
|
||||||
|
v2rayConfig.routing.rules.Clear();
|
||||||
|
v2rayConfig.inbounds.Clear();
|
||||||
|
v2rayConfig.inbounds.Add(new()
|
||||||
|
{
|
||||||
|
tag = $"{EInboundProtocol.socks}{port}",
|
||||||
|
listen = Global.Loopback,
|
||||||
|
port = port,
|
||||||
|
protocol = EInboundProtocol.socks.ToString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
||||||
|
ret.Success = true;
|
||||||
|
ret.Data = JsonUtils.Serialize(v2rayConfig);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion public gen function
|
#endregion public gen function
|
||||||
|
|
||||||
#region private gen function
|
#region private gen function
|
||||||
@@ -407,7 +477,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
v2rayConfig.inbounds.Add(inbound3);
|
v2rayConfig.inbounds.Add(inbound3);
|
||||||
|
|
||||||
//auth
|
//auth
|
||||||
if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass))
|
if (_config.Inbound.First().User.IsNotEmpty() && _config.Inbound.First().Pass.IsNotEmpty())
|
||||||
{
|
{
|
||||||
inbound3.settings.auth = "password";
|
inbound3.settings.auth = "password";
|
||||||
inbound3.settings.accounts = new List<AccountsItem4Ray> { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } };
|
inbound3.settings.accounts = new List<AccountsItem4Ray> { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } };
|
||||||
@@ -429,7 +499,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
private Inbounds4Ray GetInbound(InItem inItem, EInboundProtocol protocol, bool bSocks)
|
private Inbounds4Ray GetInbound(InItem inItem, EInboundProtocol protocol, bool bSocks)
|
||||||
{
|
{
|
||||||
string result = EmbedUtils.GetEmbedText(Global.V2raySampleInbound);
|
string result = EmbedUtils.GetEmbedText(Global.V2raySampleInbound);
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (result.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
@@ -457,12 +527,12 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
if (v2rayConfig.routing?.rules != null)
|
if (v2rayConfig.routing?.rules != null)
|
||||||
{
|
{
|
||||||
v2rayConfig.routing.domainStrategy = _config.RoutingBasicItem.DomainStrategy;
|
v2rayConfig.routing.domainStrategy = _config.RoutingBasicItem.DomainStrategy;
|
||||||
v2rayConfig.routing.domainMatcher = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainMatcher) ? null : _config.RoutingBasicItem.DomainMatcher;
|
v2rayConfig.routing.domainMatcher = _config.RoutingBasicItem.DomainMatcher.IsNullOrEmpty() ? null : _config.RoutingBasicItem.DomainMatcher;
|
||||||
|
|
||||||
var routing = await ConfigHandler.GetDefaultRouting(_config);
|
var routing = await ConfigHandler.GetDefaultRouting(_config);
|
||||||
if (routing != null)
|
if (routing != null)
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(routing.DomainStrategy))
|
if (routing.DomainStrategy.IsNotEmpty())
|
||||||
{
|
{
|
||||||
v2rayConfig.routing.domainStrategy = routing.DomainStrategy;
|
v2rayConfig.routing.domainStrategy = routing.DomainStrategy;
|
||||||
}
|
}
|
||||||
@@ -493,11 +563,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(rule.port))
|
if (rule.port.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
rule.port = null;
|
rule.port = null;
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(rule.network))
|
if (rule.network.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
rule.network = null;
|
rule.network = null;
|
||||||
}
|
}
|
||||||
@@ -524,7 +594,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
var it = JsonUtils.DeepCopy(rule);
|
var it = JsonUtils.DeepCopy(rule);
|
||||||
it.ip = null;
|
it.ip = null;
|
||||||
it.type = "field";
|
it.type = "field";
|
||||||
for (int k = it.domain.Count - 1; k >= 0; k--)
|
for (var k = it.domain.Count - 1; k >= 0; k--)
|
||||||
{
|
{
|
||||||
if (it.domain[k].StartsWith("#"))
|
if (it.domain[k].StartsWith("#"))
|
||||||
{
|
{
|
||||||
@@ -545,7 +615,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
}
|
}
|
||||||
if (!hasDomainIp)
|
if (!hasDomainIp)
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(rule.port)
|
if (rule.port.IsNotEmpty()
|
||||||
|| rule.protocol?.Count > 0
|
|| rule.protocol?.Count > 0
|
||||||
|| rule.inboundTag?.Count > 0
|
|| rule.inboundTag?.Count > 0
|
||||||
)
|
)
|
||||||
@@ -656,8 +726,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
serversItem.method = null;
|
serversItem.method = null;
|
||||||
serversItem.password = null;
|
serversItem.password = null;
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(node.Security)
|
if (node.Security.IsNotEmpty()
|
||||||
&& Utils.IsNotEmpty(node.Id))
|
&& node.Id.IsNotEmpty())
|
||||||
{
|
{
|
||||||
SocksUsersItem4Ray socksUsersItem = new()
|
SocksUsersItem4Ray socksUsersItem = new()
|
||||||
{
|
{
|
||||||
@@ -810,11 +880,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
alpn = node.GetAlpn(),
|
alpn = node.GetAlpn(),
|
||||||
fingerprint = node.Fingerprint.IsNullOrEmpty() ? _config.CoreBasicItem.DefFingerprint : node.Fingerprint
|
fingerprint = node.Fingerprint.IsNullOrEmpty() ? _config.CoreBasicItem.DefFingerprint : node.Fingerprint
|
||||||
};
|
};
|
||||||
if (Utils.IsNotEmpty(sni))
|
if (sni.IsNotEmpty())
|
||||||
{
|
{
|
||||||
tlsSettings.serverName = sni;
|
tlsSettings.serverName = sni;
|
||||||
}
|
}
|
||||||
else if (Utils.IsNotEmpty(host))
|
else if (host.IsNotEmpty())
|
||||||
{
|
{
|
||||||
tlsSettings.serverName = Utils.String2List(host)?.First();
|
tlsSettings.serverName = Utils.String2List(host)?.First();
|
||||||
}
|
}
|
||||||
@@ -857,9 +927,10 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
kcpSettings.writeBufferSize = _config.KcpItem.WriteBufferSize;
|
kcpSettings.writeBufferSize = _config.KcpItem.WriteBufferSize;
|
||||||
kcpSettings.header = new Header4Ray
|
kcpSettings.header = new Header4Ray
|
||||||
{
|
{
|
||||||
type = node.HeaderType
|
type = node.HeaderType,
|
||||||
|
domain = host.IsNullOrEmpty() ? null : host
|
||||||
};
|
};
|
||||||
if (Utils.IsNotEmpty(path))
|
if (path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
kcpSettings.seed = path;
|
kcpSettings.seed = path;
|
||||||
}
|
}
|
||||||
@@ -870,16 +941,16 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
WsSettings4Ray wsSettings = new();
|
WsSettings4Ray wsSettings = new();
|
||||||
wsSettings.headers = new Headers4Ray();
|
wsSettings.headers = new Headers4Ray();
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(host))
|
if (host.IsNotEmpty())
|
||||||
{
|
{
|
||||||
wsSettings.host = host;
|
wsSettings.host = host;
|
||||||
wsSettings.headers.Host = host;
|
wsSettings.headers.Host = host;
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(path))
|
if (path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
wsSettings.path = path;
|
wsSettings.path = path;
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(useragent))
|
if (useragent.IsNotEmpty())
|
||||||
{
|
{
|
||||||
wsSettings.headers.UserAgent = useragent;
|
wsSettings.headers.UserAgent = useragent;
|
||||||
}
|
}
|
||||||
@@ -890,11 +961,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
case nameof(ETransport.httpupgrade):
|
case nameof(ETransport.httpupgrade):
|
||||||
HttpupgradeSettings4Ray httpupgradeSettings = new();
|
HttpupgradeSettings4Ray httpupgradeSettings = new();
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(path))
|
if (path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
httpupgradeSettings.path = path;
|
httpupgradeSettings.path = path;
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(host))
|
if (host.IsNotEmpty())
|
||||||
{
|
{
|
||||||
httpupgradeSettings.host = host;
|
httpupgradeSettings.host = host;
|
||||||
}
|
}
|
||||||
@@ -906,19 +977,19 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
streamSettings.network = ETransport.xhttp.ToString();
|
streamSettings.network = ETransport.xhttp.ToString();
|
||||||
XhttpSettings4Ray xhttpSettings = new();
|
XhttpSettings4Ray xhttpSettings = new();
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(path))
|
if (path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
xhttpSettings.path = path;
|
xhttpSettings.path = path;
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(host))
|
if (host.IsNotEmpty())
|
||||||
{
|
{
|
||||||
xhttpSettings.host = host;
|
xhttpSettings.host = host;
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(node.HeaderType) && Global.XhttpMode.Contains(node.HeaderType))
|
if (node.HeaderType.IsNotEmpty() && Global.XhttpMode.Contains(node.HeaderType))
|
||||||
{
|
{
|
||||||
xhttpSettings.mode = node.HeaderType;
|
xhttpSettings.mode = node.HeaderType;
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(node.Extra))
|
if (node.Extra.IsNotEmpty())
|
||||||
{
|
{
|
||||||
xhttpSettings.extra = JsonUtils.ParseJson(node.Extra);
|
xhttpSettings.extra = JsonUtils.ParseJson(node.Extra);
|
||||||
}
|
}
|
||||||
@@ -931,7 +1002,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
case nameof(ETransport.h2):
|
case nameof(ETransport.h2):
|
||||||
HttpSettings4Ray httpSettings = new();
|
HttpSettings4Ray httpSettings = new();
|
||||||
|
|
||||||
if (Utils.IsNotEmpty(host))
|
if (host.IsNotEmpty())
|
||||||
{
|
{
|
||||||
httpSettings.host = Utils.String2List(host);
|
httpSettings.host = Utils.String2List(host);
|
||||||
}
|
}
|
||||||
@@ -954,7 +1025,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
streamSettings.quicSettings = quicsettings;
|
streamSettings.quicSettings = quicsettings;
|
||||||
if (node.StreamSecurity == Global.StreamSecurity)
|
if (node.StreamSecurity == Global.StreamSecurity)
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(sni))
|
if (sni.IsNotEmpty())
|
||||||
{
|
{
|
||||||
streamSettings.tlsSettings.serverName = sni;
|
streamSettings.tlsSettings.serverName = sni;
|
||||||
}
|
}
|
||||||
@@ -968,7 +1039,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
case nameof(ETransport.grpc):
|
case nameof(ETransport.grpc):
|
||||||
GrpcSettings4Ray grpcSettings = new()
|
GrpcSettings4Ray grpcSettings = new()
|
||||||
{
|
{
|
||||||
authority = Utils.IsNullOrEmpty(host) ? null : host,
|
authority = host.IsNullOrEmpty() ? null : host,
|
||||||
serviceName = path,
|
serviceName = path,
|
||||||
multiMode = node.HeaderType == Global.GrpcMultiMode,
|
multiMode = node.HeaderType == Global.GrpcMultiMode,
|
||||||
idle_timeout = _config.GrpcItem.IdleTimeout,
|
idle_timeout = _config.GrpcItem.IdleTimeout,
|
||||||
@@ -999,7 +1070,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
request = request.Replace("$requestUserAgent$", $"{useragent.AppendQuotes()}");
|
request = request.Replace("$requestUserAgent$", $"{useragent.AppendQuotes()}");
|
||||||
//Path
|
//Path
|
||||||
string pathHttp = @"/";
|
string pathHttp = @"/";
|
||||||
if (Utils.IsNotEmpty(path))
|
if (path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
string[] arrPath = path.Split(',');
|
string[] arrPath = path.Split(',');
|
||||||
pathHttp = string.Join(",".AppendQuotes(), arrPath);
|
pathHttp = string.Join(",".AppendQuotes(), arrPath);
|
||||||
@@ -1026,13 +1097,13 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
||||||
var normalDNS = item?.NormalDNS;
|
var normalDNS = item?.NormalDNS;
|
||||||
var domainStrategy4Freedom = item?.DomainStrategy4Freedom;
|
var domainStrategy4Freedom = item?.DomainStrategy4Freedom;
|
||||||
if (Utils.IsNullOrEmpty(normalDNS))
|
if (normalDNS.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
normalDNS = EmbedUtils.GetEmbedText(Global.DNSV2rayNormalFileName);
|
normalDNS = EmbedUtils.GetEmbedText(Global.DNSV2rayNormalFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Outbound Freedom domainStrategy
|
//Outbound Freedom domainStrategy
|
||||||
if (Utils.IsNotEmpty(domainStrategy4Freedom))
|
if (domainStrategy4Freedom.IsNotEmpty())
|
||||||
{
|
{
|
||||||
var outbound = v2rayConfig.outbounds.FirstOrDefault(t => t is { protocol: "freedom", tag: Global.DirectTag });
|
var outbound = v2rayConfig.outbounds.FirstOrDefault(t => t is { protocol: "freedom", tag: Global.DirectTag });
|
||||||
if (outbound != null)
|
if (outbound != null)
|
||||||
@@ -1097,7 +1168,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
{
|
{
|
||||||
var dnsServer = new DnsServer4Ray()
|
var dnsServer = new DnsServer4Ray()
|
||||||
{
|
{
|
||||||
address = Utils.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.DomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
address = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.DomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
||||||
domains = [node.Address]
|
domains = [node.Address]
|
||||||
};
|
};
|
||||||
servers.AsArray().Add(JsonUtils.SerializeToNode(dnsServer));
|
servers.AsArray().Add(JsonUtils.SerializeToNode(dnsServer));
|
||||||
@@ -1157,7 +1228,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||||||
{
|
{
|
||||||
//fragment proxy
|
//fragment proxy
|
||||||
if (_config.CoreBasicItem.EnableFragment
|
if (_config.CoreBasicItem.EnableFragment
|
||||||
&& Utils.IsNotEmpty(v2rayConfig.outbounds.First().streamSettings?.security))
|
&& v2rayConfig.outbounds.First().streamSettings?.security.IsNullOrEmpty() == false)
|
||||||
{
|
{
|
||||||
var fragmentOutbound = new Outbounds4Ray
|
var fragmentOutbound = new Outbounds4Ray
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
@@ -23,14 +23,7 @@ namespace ServiceLib.Services
|
|||||||
SetSecurityProtocol(AppHandler.Instance.Config.GuiItem.EnableSecurityProtocolTls13);
|
SetSecurityProtocol(AppHandler.Instance.Config.GuiItem.EnableSecurityProtocolTls13);
|
||||||
|
|
||||||
var progress = new Progress<string>();
|
var progress = new Progress<string>();
|
||||||
progress.ProgressChanged += (sender, value) =>
|
progress.ProgressChanged += (sender, value) => updateFunc?.Invoke(false, $"{value}");
|
||||||
{
|
|
||||||
if (updateFunc != null)
|
|
||||||
{
|
|
||||||
string msg = $"{value}";
|
|
||||||
updateFunc?.Invoke(false, msg);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
await DownloaderHelper.Instance.DownloadDataAsync4Speed(webProxy,
|
await DownloaderHelper.Instance.DownloadDataAsync4Speed(webProxy,
|
||||||
url,
|
url,
|
||||||
@@ -56,10 +49,7 @@ namespace ServiceLib.Services
|
|||||||
UpdateCompleted?.Invoke(this, new RetResult(false, $"{ResUI.Downloading} {url}"));
|
UpdateCompleted?.Invoke(this, new RetResult(false, $"{ResUI.Downloading} {url}"));
|
||||||
|
|
||||||
var progress = new Progress<double>();
|
var progress = new Progress<double>();
|
||||||
progress.ProgressChanged += (sender, value) =>
|
progress.ProgressChanged += (sender, value) => UpdateCompleted?.Invoke(this, new RetResult(value > 100, $"...{value}%"));
|
||||||
{
|
|
||||||
UpdateCompleted?.Invoke(this, new RetResult(value > 100, $"...{value}%"));
|
|
||||||
};
|
|
||||||
|
|
||||||
var webProxy = await GetWebProxy(blProxy);
|
var webProxy = await GetWebProxy(blProxy);
|
||||||
await DownloaderHelper.Instance.DownloadFileAsync(webProxy,
|
await DownloaderHelper.Instance.DownloadFileAsync(webProxy,
|
||||||
@@ -108,7 +98,7 @@ namespace ServiceLib.Services
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result1 = await DownloadStringAsync(url, blProxy, userAgent, 15);
|
var result1 = await DownloadStringAsync(url, blProxy, userAgent, 15);
|
||||||
if (Utils.IsNotEmpty(result1))
|
if (result1.IsNotEmpty())
|
||||||
{
|
{
|
||||||
return result1;
|
return result1;
|
||||||
}
|
}
|
||||||
@@ -126,7 +116,7 @@ namespace ServiceLib.Services
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result2 = await DownloadStringViaDownloader(url, blProxy, userAgent, 15);
|
var result2 = await DownloadStringViaDownloader(url, blProxy, userAgent, 15);
|
||||||
if (Utils.IsNotEmpty(result2))
|
if (result2.IsNotEmpty())
|
||||||
{
|
{
|
||||||
return result2;
|
return result2;
|
||||||
}
|
}
|
||||||
@@ -160,7 +150,7 @@ namespace ServiceLib.Services
|
|||||||
UseProxy = webProxy != null
|
UseProxy = webProxy != null
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(userAgent))
|
if (userAgent.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
userAgent = Utils.GetVersion(false);
|
userAgent = Utils.GetVersion(false);
|
||||||
}
|
}
|
||||||
@@ -168,7 +158,7 @@ namespace ServiceLib.Services
|
|||||||
|
|
||||||
Uri uri = new(url);
|
Uri uri = new(url);
|
||||||
//Authorization Header
|
//Authorization Header
|
||||||
if (Utils.IsNotEmpty(uri.UserInfo))
|
if (uri.UserInfo.IsNotEmpty())
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Utils.Base64Encode(uri.UserInfo));
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Utils.Base64Encode(uri.UserInfo));
|
||||||
}
|
}
|
||||||
@@ -201,7 +191,7 @@ namespace ServiceLib.Services
|
|||||||
|
|
||||||
var webProxy = await GetWebProxy(blProxy);
|
var webProxy = await GetWebProxy(blProxy);
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(userAgent))
|
if (userAgent.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
userAgent = Utils.GetVersion(false);
|
userAgent = Utils.GetVersion(false);
|
||||||
}
|
}
|
||||||
@@ -222,20 +212,20 @@ namespace ServiceLib.Services
|
|||||||
|
|
||||||
public async Task<int> RunAvailabilityCheck(IWebProxy? webProxy)
|
public async Task<int> RunAvailabilityCheck(IWebProxy? webProxy)
|
||||||
{
|
{
|
||||||
|
var responseTime = -1;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
webProxy ??= await GetWebProxy(true);
|
webProxy ??= await GetWebProxy(true);
|
||||||
|
var config = AppHandler.Instance.Config;
|
||||||
|
|
||||||
try
|
for (var i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
var config = AppHandler.Instance.Config;
|
responseTime = await GetRealPingTime(config.SpeedTestItem.SpeedPingTestUrl, webProxy, 10);
|
||||||
var responseTime = await GetRealPingTime(config.SpeedTestItem.SpeedPingTestUrl, webProxy, 10);
|
if (responseTime > 0)
|
||||||
return responseTime;
|
{
|
||||||
}
|
break;
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
await Task.Delay(500);
|
||||||
Logging.SaveLog(_tag, ex);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -243,6 +233,7 @@ namespace ServiceLib.Services
|
|||||||
Logging.SaveLog(_tag, ex);
|
Logging.SaveLog(_tag, ex);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
return responseTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int downloadTimeout)
|
public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int downloadTimeout)
|
||||||
@@ -262,7 +253,7 @@ namespace ServiceLib.Services
|
|||||||
for (var i = 0; i < 2; i++)
|
for (var i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
var timer = Stopwatch.StartNew();
|
var timer = Stopwatch.StartNew();
|
||||||
await client.GetAsync(url, cts.Token);
|
await client.GetAsync(url, cts.Token).ConfigureAwait(false);
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
oneTime.Add((int)timer.Elapsed.TotalMilliseconds);
|
oneTime.Add((int)timer.Elapsed.TotalMilliseconds);
|
||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
@@ -319,4 +310,4 @@ namespace ServiceLib.Services
|
|||||||
ServicePointManager.DefaultConnectionLimit = 256;
|
ServicePointManager.DefaultConnectionLimit = 256;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,72 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using ReactiveUI;
|
|
||||||
|
|
||||||
namespace ServiceLib.Services
|
namespace ServiceLib.Services
|
||||||
{
|
{
|
||||||
public class SpeedtestService
|
public class SpeedtestService
|
||||||
{
|
{
|
||||||
|
private static readonly string _tag = "SpeedtestService";
|
||||||
private Config? _config;
|
private Config? _config;
|
||||||
private Action<SpeedTestResult>? _updateFunc;
|
private Action<SpeedTestResult>? _updateFunc;
|
||||||
|
private static readonly ConcurrentBag<string> _lstExitLoop = new();
|
||||||
|
|
||||||
private bool _exitLoop = false;
|
public SpeedtestService(Config config, Action<SpeedTestResult> updateFunc)
|
||||||
private static readonly string _tag = "SpeedtestService";
|
|
||||||
|
|
||||||
public SpeedtestService(Config config, List<ProfileItem> selecteds, ESpeedActionType actionType, Action<SpeedTestResult> updateFunc)
|
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_updateFunc = updateFunc;
|
_updateFunc = updateFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RunLoop(ESpeedActionType actionType, List<ProfileItem> selecteds)
|
||||||
|
{
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await RunAsync(actionType, selecteds);
|
||||||
|
await ProfileExHandler.Instance.SaveTo();
|
||||||
|
UpdateFunc("", ResUI.SpeedtestingCompleted);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ExitLoop()
|
||||||
|
{
|
||||||
|
if (_lstExitLoop.Count > 0)
|
||||||
|
{
|
||||||
|
UpdateFunc("", ResUI.SpeedtestingStop);
|
||||||
|
|
||||||
|
_lstExitLoop.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RunAsync(ESpeedActionType actionType, List<ProfileItem> selecteds)
|
||||||
|
{
|
||||||
|
var exitLoopKey = Utils.GetGuid(false);
|
||||||
|
_lstExitLoop.Add(exitLoopKey);
|
||||||
|
|
||||||
|
var lstSelected = GetClearItem(actionType, selecteds);
|
||||||
|
|
||||||
|
switch (actionType)
|
||||||
|
{
|
||||||
|
case ESpeedActionType.Tcping:
|
||||||
|
await RunTcpingAsync(lstSelected);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ESpeedActionType.Realping:
|
||||||
|
await RunRealPingBatchAsync(lstSelected, exitLoopKey);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ESpeedActionType.Speedtest:
|
||||||
|
await RunMixedTestAsync(lstSelected, 1, true, exitLoopKey);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ESpeedActionType.Mixedtest:
|
||||||
|
await RunMixedTestAsync(lstSelected, _config.SpeedTestItem.MixedConcurrencyCount, true, exitLoopKey);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ServerTestItem> GetClearItem(ESpeedActionType actionType, List<ProfileItem> selecteds)
|
||||||
|
{
|
||||||
var lstSelected = new List<ServerTestItem>();
|
var lstSelected = new List<ServerTestItem>();
|
||||||
foreach (var it in selecteds)
|
foreach (var it in selecteds)
|
||||||
{
|
{
|
||||||
@@ -25,16 +74,19 @@ namespace ServiceLib.Services
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it.Port <= 0)
|
if (it.Port <= 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
lstSelected.Add(new ServerTestItem()
|
lstSelected.Add(new ServerTestItem()
|
||||||
{
|
{
|
||||||
IndexId = it.IndexId,
|
IndexId = it.IndexId,
|
||||||
Address = it.Address,
|
Address = it.Address,
|
||||||
Port = it.Port,
|
Port = it.Port,
|
||||||
ConfigType = it.ConfigType
|
ConfigType = it.ConfigType,
|
||||||
|
QueueNum = selecteds.IndexOf(it)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,125 +98,95 @@ namespace ServiceLib.Services
|
|||||||
case ESpeedActionType.Tcping:
|
case ESpeedActionType.Tcping:
|
||||||
case ESpeedActionType.Realping:
|
case ESpeedActionType.Realping:
|
||||||
UpdateFunc(it.IndexId, ResUI.Speedtesting, "");
|
UpdateFunc(it.IndexId, ResUI.Speedtesting, "");
|
||||||
ProfileExHandler.Instance.SetTestDelay(it.IndexId, "0");
|
ProfileExHandler.Instance.SetTestDelay(it.IndexId, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESpeedActionType.Speedtest:
|
case ESpeedActionType.Speedtest:
|
||||||
UpdateFunc(it.IndexId, "", ResUI.SpeedtestingWait);
|
UpdateFunc(it.IndexId, "", ResUI.SpeedtestingWait);
|
||||||
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, "0");
|
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESpeedActionType.Mixedtest:
|
case ESpeedActionType.Mixedtest:
|
||||||
UpdateFunc(it.IndexId, ResUI.Speedtesting, ResUI.SpeedtestingWait);
|
UpdateFunc(it.IndexId, ResUI.Speedtesting, ResUI.SpeedtestingWait);
|
||||||
ProfileExHandler.Instance.SetTestDelay(it.IndexId, "0");
|
ProfileExHandler.Instance.SetTestDelay(it.IndexId, 0);
|
||||||
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, "0");
|
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.StopSpeedtest.ToString()).Subscribe(ExitLoop);
|
return lstSelected;
|
||||||
|
|
||||||
Task.Run(async () => { await RunAsync(actionType, lstSelected); });
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task RunAsync(ESpeedActionType actionType, List<ServerTestItem> lstSelected)
|
|
||||||
{
|
|
||||||
if (actionType == ESpeedActionType.Tcping)
|
|
||||||
{
|
|
||||||
await RunTcpingAsync(lstSelected);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var pageSize = _config.SpeedTestItem.SpeedTestPageSize;
|
|
||||||
if (pageSize is <= 0 or > 1000)
|
|
||||||
{
|
|
||||||
pageSize = 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<List<ServerTestItem>> lstTest = new();
|
|
||||||
var lst1 = lstSelected.Where(t => t.ConfigType is not (EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.WireGuard)).ToList();
|
|
||||||
var lst2 = lstSelected.Where(t => t.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.WireGuard).ToList();
|
|
||||||
|
|
||||||
for (var num = 0; num < (int)Math.Ceiling(lst1.Count * 1.0 / pageSize); num++)
|
|
||||||
{
|
|
||||||
lstTest.Add(lst1.Skip(num * pageSize).Take(pageSize).ToList());
|
|
||||||
}
|
|
||||||
for (var num = 0; num < (int)Math.Ceiling(lst2.Count * 1.0 / pageSize); num++)
|
|
||||||
{
|
|
||||||
lstTest.Add(lst2.Skip(num * pageSize).Take(pageSize).ToList());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var lst in lstTest)
|
|
||||||
{
|
|
||||||
switch (actionType)
|
|
||||||
{
|
|
||||||
case ESpeedActionType.Realping:
|
|
||||||
await RunRealPingAsync(lst);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESpeedActionType.Speedtest:
|
|
||||||
await RunSpeedTestAsync(lst);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESpeedActionType.Mixedtest:
|
|
||||||
await RunMixedTestAsync(lst);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateFunc("", ResUI.SpeedtestingCompleted);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ExitLoop(string x)
|
|
||||||
{
|
|
||||||
if (_exitLoop)
|
|
||||||
return;
|
|
||||||
_exitLoop = true;
|
|
||||||
UpdateFunc("", ResUI.SpeedtestingStop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RunTcpingAsync(List<ServerTestItem> selecteds)
|
private async Task RunTcpingAsync(List<ServerTestItem> selecteds)
|
||||||
{
|
{
|
||||||
try
|
List<Task> tasks = [];
|
||||||
|
foreach (var it in selecteds)
|
||||||
{
|
{
|
||||||
List<Task> tasks = [];
|
if (it.ConfigType == EConfigType.Custom)
|
||||||
foreach (var it in selecteds)
|
|
||||||
{
|
{
|
||||||
if (it.ConfigType == EConfigType.Custom)
|
continue;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
tasks.Add(Task.Run(async () =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var time = await GetTcpingTime(it.Address, it.Port);
|
|
||||||
var output = FormatOut(time, Global.DelayUnit);
|
|
||||||
|
|
||||||
ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
|
|
||||||
UpdateFunc(it.IndexId, output);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logging.SaveLog(_tag, ex);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
Task.WaitAll([.. tasks]);
|
tasks.Add(Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var responseTime = await GetTcpingTime(it.Address, it.Port);
|
||||||
|
|
||||||
|
ProfileExHandler.Instance.SetTestDelay(it.IndexId, responseTime);
|
||||||
|
UpdateFunc(it.IndexId, responseTime.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
await Task.WhenAll(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RunRealPingBatchAsync(List<ServerTestItem> lstSelected, string exitLoopKey, int pageSize = 0)
|
||||||
|
{
|
||||||
|
if (pageSize <= 0)
|
||||||
{
|
{
|
||||||
Logging.SaveLog(_tag, ex);
|
pageSize = lstSelected.Count < Global.SpeedTestPageSize ? lstSelected.Count : Global.SpeedTestPageSize;
|
||||||
}
|
}
|
||||||
finally
|
var lstTest = GetTestBatchItem(lstSelected, pageSize);
|
||||||
|
|
||||||
|
List<ServerTestItem> lstFailed = new();
|
||||||
|
foreach (var lst in lstTest)
|
||||||
{
|
{
|
||||||
await ProfileExHandler.Instance.SaveTo();
|
var ret = await RunRealPingAsync(lst, exitLoopKey);
|
||||||
|
if (ret == false)
|
||||||
|
{
|
||||||
|
lstFailed.AddRange(lst);
|
||||||
|
}
|
||||||
|
await Task.Delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Retest the failed part
|
||||||
|
var pageSizeNext = pageSize / 2;
|
||||||
|
if (lstFailed.Count > 0 && pageSizeNext > 0)
|
||||||
|
{
|
||||||
|
if (_lstExitLoop.Any(p => p == exitLoopKey) == false)
|
||||||
|
{
|
||||||
|
UpdateFunc("", ResUI.SpeedtestingSkip);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateFunc("", string.Format(ResUI.SpeedtestingTestFailedPart, lstFailed.Count));
|
||||||
|
|
||||||
|
if (pageSizeNext > _config.SpeedTestItem.MixedConcurrencyCount)
|
||||||
|
{
|
||||||
|
await RunRealPingBatchAsync(lstFailed, exitLoopKey, pageSizeNext);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await RunMixedTestAsync(lstSelected, _config.SpeedTestItem.MixedConcurrencyCount, false, exitLoopKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RunRealPingAsync(List<ServerTestItem> selecteds)
|
private async Task<bool> RunRealPingAsync(List<ServerTestItem> selecteds, string exitLoopKey)
|
||||||
{
|
{
|
||||||
var pid = -1;
|
var pid = -1;
|
||||||
try
|
try
|
||||||
@@ -172,8 +194,7 @@ namespace ServiceLib.Services
|
|||||||
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(selecteds);
|
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(selecteds);
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
{
|
{
|
||||||
UpdateFunc("", ResUI.FailedToRunCore);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var downloadHandle = new DownloadService();
|
var downloadHandle = new DownloadService();
|
||||||
@@ -191,23 +212,10 @@ namespace ServiceLib.Services
|
|||||||
}
|
}
|
||||||
tasks.Add(Task.Run(async () =>
|
tasks.Add(Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
await DoRealPing(downloadHandle, it);
|
||||||
{
|
|
||||||
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}");
|
|
||||||
var output = await GetRealPingTime(downloadHandle, webProxy);
|
|
||||||
|
|
||||||
ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
|
|
||||||
UpdateFunc(it.IndexId, output);
|
|
||||||
int.TryParse(output, out var delay);
|
|
||||||
it.Delay = delay;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logging.SaveLog(_tag, ex);
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
Task.WaitAll(tasks.ToArray());
|
await Task.WhenAll(tasks);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -219,151 +227,98 @@ namespace ServiceLib.Services
|
|||||||
{
|
{
|
||||||
await ProcUtils.ProcessKill(pid);
|
await ProcUtils.ProcessKill(pid);
|
||||||
}
|
}
|
||||||
await ProfileExHandler.Instance.SaveTo();
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RunSpeedTestAsync(List<ServerTestItem> selecteds)
|
private async Task RunMixedTestAsync(List<ServerTestItem> selecteds, int concurrencyCount, bool blSpeedTest, string exitLoopKey)
|
||||||
{
|
{
|
||||||
var pid = -1;
|
using var concurrencySemaphore = new SemaphoreSlim(concurrencyCount);
|
||||||
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(selecteds);
|
var downloadHandle = new DownloadService();
|
||||||
if (pid < 0)
|
List<Task> tasks = new();
|
||||||
{
|
|
||||||
UpdateFunc("", ResUI.FailedToRunCore);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var url = _config.SpeedTestItem.SpeedTestUrl;
|
|
||||||
var timeout = _config.SpeedTestItem.SpeedTestTimeout;
|
|
||||||
|
|
||||||
DownloadService downloadHandle = new();
|
|
||||||
|
|
||||||
foreach (var it in selecteds)
|
foreach (var it in selecteds)
|
||||||
{
|
{
|
||||||
if (_exitLoop)
|
if (_lstExitLoop.Any(p => p == exitLoopKey) == false)
|
||||||
{
|
{
|
||||||
UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
|
UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!it.AllowTest)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (it.ConfigType == EConfigType.Custom)
|
if (it.ConfigType == EConfigType.Custom)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//if (it.delay < 0)
|
await concurrencySemaphore.WaitAsync();
|
||||||
//{
|
|
||||||
// UpdateFunc(it.indexId, "", ResUI.SpeedtestingSkip);
|
|
||||||
// continue;
|
|
||||||
//}
|
|
||||||
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, "-1");
|
|
||||||
UpdateFunc(it.IndexId, "", ResUI.Speedtesting);
|
|
||||||
|
|
||||||
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
tasks.Add(Task.Run(async () =>
|
||||||
if (item is null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}");
|
|
||||||
|
|
||||||
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
|
|
||||||
{
|
{
|
||||||
decimal.TryParse(msg, out var dec);
|
var pid = -1;
|
||||||
if (dec > 0)
|
try
|
||||||
{
|
{
|
||||||
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, msg);
|
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(it);
|
||||||
|
if (pid > 0)
|
||||||
|
{
|
||||||
|
await Task.Delay(500);
|
||||||
|
var delay = await DoRealPing(downloadHandle, it);
|
||||||
|
if (blSpeedTest)
|
||||||
|
{
|
||||||
|
if (delay > 0)
|
||||||
|
{
|
||||||
|
await DoSpeedTest(downloadHandle, it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateFunc(it.IndexId, "", ResUI.FailedToRunCore);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
UpdateFunc(it.IndexId, "", msg);
|
catch (Exception ex)
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid > 0)
|
|
||||||
{
|
|
||||||
await ProcUtils.ProcessKill(pid);
|
|
||||||
}
|
|
||||||
await ProfileExHandler.Instance.SaveTo();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task RunSpeedTestMulti(List<ServerTestItem> selecteds)
|
|
||||||
{
|
|
||||||
var pid = -1;
|
|
||||||
pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(selecteds);
|
|
||||||
if (pid < 0)
|
|
||||||
{
|
|
||||||
UpdateFunc("", ResUI.FailedToRunCore);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var url = _config.SpeedTestItem.SpeedTestUrl;
|
|
||||||
var timeout = _config.SpeedTestItem.SpeedTestTimeout;
|
|
||||||
|
|
||||||
DownloadService downloadHandle = new();
|
|
||||||
|
|
||||||
foreach (var it in selecteds)
|
|
||||||
{
|
|
||||||
if (_exitLoop)
|
|
||||||
{
|
|
||||||
UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!it.AllowTest)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (it.ConfigType == EConfigType.Custom)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (it.Delay < 0)
|
|
||||||
{
|
|
||||||
UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, "-1");
|
|
||||||
UpdateFunc(it.IndexId, "", ResUI.Speedtesting);
|
|
||||||
|
|
||||||
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
|
||||||
if (item is null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}");
|
|
||||||
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
|
|
||||||
{
|
|
||||||
decimal.TryParse(msg, out var dec);
|
|
||||||
if (dec > 0)
|
|
||||||
{
|
{
|
||||||
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, msg);
|
Logging.SaveLog(_tag, ex);
|
||||||
}
|
}
|
||||||
UpdateFunc(it.IndexId, "", msg);
|
finally
|
||||||
});
|
{
|
||||||
await Task.Delay(2000);
|
if (pid > 0)
|
||||||
|
{
|
||||||
|
await ProcUtils.ProcessKill(pid);
|
||||||
|
}
|
||||||
|
concurrencySemaphore.Release();
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
await Task.Delay((timeout + 2) * 1000);
|
|
||||||
|
|
||||||
if (pid > 0)
|
|
||||||
{
|
|
||||||
await ProcUtils.ProcessKill(pid);
|
|
||||||
}
|
|
||||||
await ProfileExHandler.Instance.SaveTo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RunMixedTestAsync(List<ServerTestItem> selecteds)
|
private async Task<int> DoRealPing(DownloadService downloadHandle, ServerTestItem it)
|
||||||
{
|
|
||||||
await RunRealPingAsync(selecteds);
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
await RunSpeedTestMulti(selecteds);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<string> GetRealPingTime(DownloadService downloadHandle, IWebProxy webProxy)
|
|
||||||
{
|
{
|
||||||
|
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}");
|
||||||
var responseTime = await downloadHandle.GetRealPingTime(_config.SpeedTestItem.SpeedPingTestUrl, webProxy, 10);
|
var responseTime = await downloadHandle.GetRealPingTime(_config.SpeedTestItem.SpeedPingTestUrl, webProxy, 10);
|
||||||
//string output = Utile.IsNullOrEmpty(status) ? FormatOut(responseTime, "ms") : status;
|
|
||||||
return FormatOut(responseTime, Global.DelayUnit);
|
ProfileExHandler.Instance.SetTestDelay(it.IndexId, responseTime);
|
||||||
|
UpdateFunc(it.IndexId, responseTime.ToString());
|
||||||
|
return responseTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DoSpeedTest(DownloadService downloadHandle, ServerTestItem it)
|
||||||
|
{
|
||||||
|
UpdateFunc(it.IndexId, "", ResUI.Speedtesting);
|
||||||
|
|
||||||
|
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}");
|
||||||
|
var url = _config.SpeedTestItem.SpeedTestUrl;
|
||||||
|
var timeout = _config.SpeedTestItem.SpeedTestTimeout;
|
||||||
|
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
|
||||||
|
{
|
||||||
|
decimal.TryParse(msg, out var dec);
|
||||||
|
if (dec > 0)
|
||||||
|
{
|
||||||
|
ProfileExHandler.Instance.SetTestSpeed(it.IndexId, dec);
|
||||||
|
}
|
||||||
|
UpdateFunc(it.IndexId, "", msg);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<int> GetTcpingTime(string url, int port)
|
private async Task<int> GetTcpingTime(string url, int port)
|
||||||
@@ -378,18 +333,19 @@ namespace ServiceLib.Services
|
|||||||
ipAddress = ipHostInfo.AddressList.First();
|
ipAddress = ipHostInfo.AddressList.First();
|
||||||
}
|
}
|
||||||
|
|
||||||
var timer = Stopwatch.StartNew();
|
|
||||||
|
|
||||||
IPEndPoint endPoint = new(ipAddress, port);
|
IPEndPoint endPoint = new(ipAddress, port);
|
||||||
using Socket clientSocket = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
using Socket clientSocket = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
|
||||||
|
var timer = Stopwatch.StartNew();
|
||||||
var result = clientSocket.BeginConnect(endPoint, null, null);
|
var result = clientSocket.BeginConnect(endPoint, null, null);
|
||||||
if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5)))
|
if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5)))
|
||||||
|
{
|
||||||
throw new TimeoutException("connect timeout (5s): " + url);
|
throw new TimeoutException("connect timeout (5s): " + url);
|
||||||
clientSocket.EndConnect(result);
|
}
|
||||||
|
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
responseTime = (int)timer.Elapsed.TotalMilliseconds;
|
responseTime = (int)timer.Elapsed.TotalMilliseconds;
|
||||||
|
|
||||||
|
clientSocket.EndConnect(result);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -398,14 +354,31 @@ namespace ServiceLib.Services
|
|||||||
return responseTime;
|
return responseTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string FormatOut(object time, string unit)
|
private List<List<ServerTestItem>> GetTestBatchItem(List<ServerTestItem> lstSelected, int pageSize)
|
||||||
{
|
{
|
||||||
return $"{time}";
|
List<List<ServerTestItem>> lstTest = new();
|
||||||
|
var lst1 = lstSelected.Where(t => t.ConfigType is not (EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.WireGuard)).ToList();
|
||||||
|
var lst2 = lstSelected.Where(t => t.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.WireGuard).ToList();
|
||||||
|
|
||||||
|
for (var num = 0; num < (int)Math.Ceiling(lst1.Count * 1.0 / pageSize); num++)
|
||||||
|
{
|
||||||
|
lstTest.Add(lst1.Skip(num * pageSize).Take(pageSize).ToList());
|
||||||
|
}
|
||||||
|
for (var num = 0; num < (int)Math.Ceiling(lst2.Count * 1.0 / pageSize); num++)
|
||||||
|
{
|
||||||
|
lstTest.Add(lst2.Skip(num * pageSize).Take(pageSize).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return lstTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateFunc(string indexId, string delay, string speed = "")
|
private void UpdateFunc(string indexId, string delay, string speed = "")
|
||||||
{
|
{
|
||||||
_updateFunc?.Invoke(new() { IndexId = indexId, Delay = delay, Speed = speed });
|
_updateFunc?.Invoke(new() { IndexId = indexId, Delay = delay, Speed = speed });
|
||||||
|
if (indexId.IsNotEmpty() && speed.IsNotEmpty())
|
||||||
|
{
|
||||||
|
ProfileExHandler.Instance.SetTestMessage(indexId, speed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace ServiceLib.Services.Statistics
|
|||||||
{
|
{
|
||||||
public class StatisticsSingboxService
|
public class StatisticsSingboxService
|
||||||
{
|
{
|
||||||
private Config _config;
|
private readonly Config _config;
|
||||||
private bool _exitFlag;
|
private bool _exitFlag;
|
||||||
private ClientWebSocket? webSocket;
|
private ClientWebSocket? webSocket;
|
||||||
private Action<ServerSpeedItem>? _updateFunc;
|
private Action<ServerSpeedItem>? _updateFunc;
|
||||||
@@ -18,10 +18,10 @@ namespace ServiceLib.Services.Statistics
|
|||||||
_updateFunc = updateFunc;
|
_updateFunc = updateFunc;
|
||||||
_exitFlag = false;
|
_exitFlag = false;
|
||||||
|
|
||||||
Task.Run(Run);
|
_ = Task.Run(Run);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Init()
|
private async Task Init()
|
||||||
{
|
{
|
||||||
await Task.Delay(5000);
|
await Task.Delay(5000);
|
||||||
|
|
||||||
@@ -53,9 +53,9 @@ namespace ServiceLib.Services.Statistics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Run()
|
private async Task Run()
|
||||||
{
|
{
|
||||||
Init();
|
await Init();
|
||||||
|
|
||||||
while (!_exitFlag)
|
while (!_exitFlag)
|
||||||
{
|
{
|
||||||
@@ -68,12 +68,11 @@ namespace ServiceLib.Services.Statistics
|
|||||||
}
|
}
|
||||||
if (webSocket != null)
|
if (webSocket != null)
|
||||||
{
|
{
|
||||||
if (webSocket.State == WebSocketState.Aborted
|
if (webSocket.State is WebSocketState.Aborted or WebSocketState.Closed)
|
||||||
|| webSocket.State == WebSocketState.Closed)
|
|
||||||
{
|
{
|
||||||
webSocket.Abort();
|
webSocket.Abort();
|
||||||
webSocket = null;
|
webSocket = null;
|
||||||
Init();
|
await Init();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,9 +86,9 @@ namespace ServiceLib.Services.Statistics
|
|||||||
while (!res.CloseStatus.HasValue)
|
while (!res.CloseStatus.HasValue)
|
||||||
{
|
{
|
||||||
var result = Encoding.UTF8.GetString(buffer, 0, res.Count);
|
var result = Encoding.UTF8.GetString(buffer, 0, res.Count);
|
||||||
if (Utils.IsNotEmpty(result))
|
if (result.IsNotEmpty())
|
||||||
{
|
{
|
||||||
ParseOutput(result, out ulong up, out ulong down);
|
ParseOutput(result, out var up, out var down);
|
||||||
|
|
||||||
_updateFunc?.Invoke(new ServerSpeedItem()
|
_updateFunc?.Invoke(new ServerSpeedItem()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace ServiceLib.Services.Statistics
|
|||||||
{
|
{
|
||||||
private const long linkBase = 1024;
|
private const long linkBase = 1024;
|
||||||
private ServerSpeedItem _serverSpeedItem = new();
|
private ServerSpeedItem _serverSpeedItem = new();
|
||||||
private Config _config;
|
private readonly Config _config;
|
||||||
private bool _exitFlag;
|
private bool _exitFlag;
|
||||||
private Action<ServerSpeedItem>? _updateFunc;
|
private Action<ServerSpeedItem>? _updateFunc;
|
||||||
private string Url => $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort}/debug/vars";
|
private string Url => $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort}/debug/vars";
|
||||||
@@ -15,7 +15,7 @@ namespace ServiceLib.Services.Statistics
|
|||||||
_updateFunc = updateFunc;
|
_updateFunc = updateFunc;
|
||||||
_exitFlag = false;
|
_exitFlag = false;
|
||||||
|
|
||||||
Task.Run(Run);
|
_ = Task.Run(Run);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
@@ -23,7 +23,7 @@ namespace ServiceLib.Services.Statistics
|
|||||||
_exitFlag = true;
|
_exitFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Run()
|
private async Task Run()
|
||||||
{
|
{
|
||||||
while (!_exitFlag)
|
while (!_exitFlag)
|
||||||
{
|
{
|
||||||
@@ -60,11 +60,13 @@ namespace ServiceLib.Services.Statistics
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServerSpeedItem server = new();
|
ServerSpeedItem server = new();
|
||||||
foreach (string key in source.stats.outbound.Keys)
|
foreach (var key in source.stats.outbound.Keys.Cast<string>())
|
||||||
{
|
{
|
||||||
var value = source.stats.outbound[key];
|
var value = source.stats.outbound[key];
|
||||||
if (value == null)
|
if (value == null)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
var state = JsonUtils.Deserialize<V2rayMetricsVarsLink>(value.ToString());
|
var state = JsonUtils.Deserialize<V2rayMetricsVarsLink>(value.ToString());
|
||||||
|
|
||||||
if (key.StartsWith(Global.ProxyTag))
|
if (key.StartsWith(Global.ProxyTag))
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace ServiceLib.Services
|
|||||||
var url = item.Url.TrimEx();
|
var url = item.Url.TrimEx();
|
||||||
var userAgent = item.UserAgent.TrimEx();
|
var userAgent = item.UserAgent.TrimEx();
|
||||||
var hashCode = $"{item.Remarks}->";
|
var hashCode = $"{item.Remarks}->";
|
||||||
if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || (Utils.IsNotEmpty(subId) && item.Id != subId))
|
if (id.IsNullOrEmpty() || url.IsNullOrEmpty() || (subId.IsNotEmpty() && item.Id != subId))
|
||||||
{
|
{
|
||||||
//_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
|
//_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
|
||||||
continue;
|
continue;
|
||||||
@@ -149,9 +149,9 @@ namespace ServiceLib.Services
|
|||||||
//one url
|
//one url
|
||||||
url = Utils.GetPunycode(url);
|
url = Utils.GetPunycode(url);
|
||||||
//convert
|
//convert
|
||||||
if (Utils.IsNotEmpty(item.ConvertTarget))
|
if (item.ConvertTarget.IsNotEmpty())
|
||||||
{
|
{
|
||||||
var subConvertUrl = Utils.IsNullOrEmpty(config.ConstItem.SubConvertUrl) ? Global.SubConvertUrls.FirstOrDefault() : config.ConstItem.SubConvertUrl;
|
var subConvertUrl = config.ConstItem.SubConvertUrl.IsNullOrEmpty() ? Global.SubConvertUrls.FirstOrDefault() : config.ConstItem.SubConvertUrl;
|
||||||
url = string.Format(subConvertUrl!, Utils.UrlEncode(url));
|
url = string.Format(subConvertUrl!, Utils.UrlEncode(url));
|
||||||
if (!url.Contains("target="))
|
if (!url.Contains("target="))
|
||||||
{
|
{
|
||||||
@@ -163,15 +163,15 @@ namespace ServiceLib.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var result = await downloadHandle.TryDownloadString(url, blProxy, userAgent);
|
var result = await downloadHandle.TryDownloadString(url, blProxy, userAgent);
|
||||||
if (blProxy && Utils.IsNullOrEmpty(result))
|
if (blProxy && result.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
result = await downloadHandle.TryDownloadString(url, false, userAgent);
|
result = await downloadHandle.TryDownloadString(url, false, userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
//more url
|
//more url
|
||||||
if (Utils.IsNullOrEmpty(item.ConvertTarget) && Utils.IsNotEmpty(item.MoreUrl.TrimEx()))
|
if (item.ConvertTarget.IsNullOrEmpty() && item.MoreUrl.TrimEx().IsNotEmpty())
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(result) && Utils.IsBase64String(result))
|
if (result.IsNotEmpty() && Utils.IsBase64String(result))
|
||||||
{
|
{
|
||||||
result = Utils.Base64Decode(result);
|
result = Utils.Base64Decode(result);
|
||||||
}
|
}
|
||||||
@@ -180,17 +180,17 @@ namespace ServiceLib.Services
|
|||||||
foreach (var it in lstUrl)
|
foreach (var it in lstUrl)
|
||||||
{
|
{
|
||||||
var url2 = Utils.GetPunycode(it);
|
var url2 = Utils.GetPunycode(it);
|
||||||
if (Utils.IsNullOrEmpty(url2))
|
if (url2.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result2 = await downloadHandle.TryDownloadString(url2, blProxy, userAgent);
|
var result2 = await downloadHandle.TryDownloadString(url2, blProxy, userAgent);
|
||||||
if (blProxy && Utils.IsNullOrEmpty(result2))
|
if (blProxy && result2.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
result2 = await downloadHandle.TryDownloadString(url2, false, userAgent);
|
result2 = await downloadHandle.TryDownloadString(url2, false, userAgent);
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(result2))
|
if (result2.IsNotEmpty())
|
||||||
{
|
{
|
||||||
if (Utils.IsBase64String(result2))
|
if (Utils.IsBase64String(result2))
|
||||||
{
|
{
|
||||||
@@ -204,7 +204,7 @@ namespace ServiceLib.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (result.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}");
|
_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}");
|
||||||
}
|
}
|
||||||
@@ -237,13 +237,13 @@ namespace ServiceLib.Services
|
|||||||
|
|
||||||
public async Task UpdateGeoFileAll(Config config, Action<bool, string> updateFunc)
|
public async Task UpdateGeoFileAll(Config config, Action<bool, string> updateFunc)
|
||||||
{
|
{
|
||||||
await UpdateGeoFile("geosite", config, updateFunc);
|
await UpdateGeoFiles(config, updateFunc);
|
||||||
await UpdateGeoFile("geoip", config, updateFunc);
|
await UpdateOtherFiles(config, updateFunc);
|
||||||
await UpdateSrsFileAll(config, updateFunc);
|
await UpdateSrsFileAll(config, updateFunc);
|
||||||
_updateFunc?.Invoke(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo"));
|
_updateFunc?.Invoke(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RunAvailabilityCheck(Action<bool, string> updateFunc)
|
public async Task<string> RunAvailabilityCheck()
|
||||||
{
|
{
|
||||||
var downloadHandle = new DownloadService();
|
var downloadHandle = new DownloadService();
|
||||||
var time = await downloadHandle.RunAvailabilityCheck(null);
|
var time = await downloadHandle.RunAvailabilityCheck(null);
|
||||||
@@ -255,7 +255,7 @@ namespace ServiceLib.Services
|
|||||||
ip = $"({ipInfo?.country_code}) {ipInfo?.ip}";
|
ip = $"({ipInfo?.country_code}) {ipInfo?.ip}";
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFunc?.Invoke(false, string.Format(ResUI.TestMeOutput, time, ip));
|
return string.Format(ResUI.TestMeOutput, time, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region CheckUpdate private
|
#region CheckUpdate private
|
||||||
@@ -287,7 +287,7 @@ namespace ServiceLib.Services
|
|||||||
{
|
{
|
||||||
var url = coreInfo?.ReleaseApiUrl;
|
var url = coreInfo?.ReleaseApiUrl;
|
||||||
var result = await downloadHandle.TryDownloadString(url, true, Global.AppName);
|
var result = await downloadHandle.TryDownloadString(url, true, Global.AppName);
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (result.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return new RetResult(false, "");
|
return new RetResult(false, "");
|
||||||
}
|
}
|
||||||
@@ -427,22 +427,32 @@ namespace ServiceLib.Services
|
|||||||
{
|
{
|
||||||
if (Utils.IsWindows())
|
if (Utils.IsWindows())
|
||||||
{
|
{
|
||||||
//Check for standalone windows .Net version
|
var url = RuntimeInformation.ProcessArchitecture switch
|
||||||
if (coreInfo?.CoreType == ECoreType.v2rayN && RuntimeInformation.ProcessArchitecture == Architecture.X64)
|
|
||||||
{
|
|
||||||
var runtimes = await Utils.GetCliWrapOutput("dotnet", "--list-runtimes");
|
|
||||||
if (runtimes == null || runtimes.Contains("Microsoft.WindowsDesktop.App 8") == false)
|
|
||||||
{
|
|
||||||
return coreInfo?.DownloadUrlWin64?.Replace(".zip", "-SelfContained.zip");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return RuntimeInformation.ProcessArchitecture switch
|
|
||||||
{
|
{
|
||||||
Architecture.Arm64 => coreInfo?.DownloadUrlWinArm64,
|
Architecture.Arm64 => coreInfo?.DownloadUrlWinArm64,
|
||||||
Architecture.X64 => coreInfo?.DownloadUrlWin64,
|
Architecture.X64 => coreInfo?.DownloadUrlWin64,
|
||||||
_ => null,
|
_ => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (coreInfo?.CoreType != ECoreType.v2rayN)
|
||||||
|
{
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check for standalone windows .Net version
|
||||||
|
if (File.Exists(Path.Combine(Utils.GetBaseDirectory(), "wpfgfx_cor3.dll"))
|
||||||
|
&& File.Exists(Path.Combine(Utils.GetBaseDirectory(), "D3DCompiler_47_cor3.dll")))
|
||||||
|
{
|
||||||
|
return url?.Replace(".zip", "-SelfContained.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check for avalonia desktop windows version
|
||||||
|
if (File.Exists(Path.Combine(Utils.GetBaseDirectory(), "libHarfBuzzSharp.dll")))
|
||||||
|
{
|
||||||
|
return url?.Replace(".zip", "-desktop.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
}
|
}
|
||||||
else if (Utils.IsLinux())
|
else if (Utils.IsLinux())
|
||||||
{
|
{
|
||||||
@@ -462,14 +472,14 @@ namespace ServiceLib.Services
|
|||||||
_ => null,
|
_ => null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return null;
|
return await Task.FromResult("");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion CheckUpdate private
|
#endregion CheckUpdate private
|
||||||
|
|
||||||
#region Geo private
|
#region Geo private
|
||||||
|
|
||||||
private async Task UpdateGeoFile(string geoName, Config config, Action<bool, string> updateFunc)
|
private async Task UpdateGeoFiles(Config config, Action<bool, string> updateFunc)
|
||||||
{
|
{
|
||||||
_updateFunc = updateFunc;
|
_updateFunc = updateFunc;
|
||||||
|
|
||||||
@@ -477,11 +487,28 @@ namespace ServiceLib.Services
|
|||||||
? Global.GeoUrl
|
? Global.GeoUrl
|
||||||
: config.ConstItem.GeoSourceUrl;
|
: config.ConstItem.GeoSourceUrl;
|
||||||
|
|
||||||
var fileName = $"{geoName}.dat";
|
List<string> files = ["geosite", "geoip"];
|
||||||
var targetPath = Utils.GetBinPath($"{fileName}");
|
foreach (var geoName in files)
|
||||||
var url = string.Format(geoUrl, geoName);
|
{
|
||||||
|
var fileName = $"{geoName}.dat";
|
||||||
|
var targetPath = Utils.GetBinPath($"{fileName}");
|
||||||
|
var url = string.Format(geoUrl, geoName);
|
||||||
|
|
||||||
await DownloadGeoFile(url, fileName, targetPath, updateFunc);
|
await DownloadGeoFile(url, fileName, targetPath, updateFunc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task UpdateOtherFiles(Config config, Action<bool, string> updateFunc)
|
||||||
|
{
|
||||||
|
_updateFunc = updateFunc;
|
||||||
|
|
||||||
|
foreach (var url in Global.OtherGeoUrls)
|
||||||
|
{
|
||||||
|
var fileName = Path.GetFileName(url);
|
||||||
|
var targetPath = Utils.GetBinPath($"{fileName}");
|
||||||
|
|
||||||
|
await DownloadGeoFile(url, fileName, targetPath, updateFunc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateSrsFileAll(Config config, Action<bool, string> updateFunc)
|
private async Task UpdateSrsFileAll(Config config, Action<bool, string> updateFunc)
|
||||||
|
|||||||
@@ -42,14 +42,14 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task SaveServerAsync()
|
private async Task SaveServerAsync()
|
||||||
{
|
{
|
||||||
string remarks = SelectedSource.Remarks;
|
var remarks = SelectedSource.Remarks;
|
||||||
if (Utils.IsNullOrEmpty(remarks))
|
if (remarks.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(SelectedSource.Address))
|
if (SelectedSource.Address.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom);
|
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom);
|
||||||
return;
|
return;
|
||||||
@@ -69,7 +69,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task BrowseServer(string fileName)
|
public async Task BrowseServer(string fileName)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ namespace ServiceLib.ViewModels
|
|||||||
if (await ConfigHandler.AddCustomServer(_config, item, false) == 0)
|
if (await ConfigHandler.AddCustomServer(_config, item, false) == 0)
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.SuccessfullyImportedCustomServer);
|
NoticeHandler.Instance.Enqueue(ResUI.SuccessfullyImportedCustomServer);
|
||||||
if (Utils.IsNotEmpty(item.IndexId))
|
if (item.IndexId.IsNotEmpty())
|
||||||
{
|
{
|
||||||
SelectedSource = JsonUtils.DeepCopy(item);
|
SelectedSource = JsonUtils.DeepCopy(item);
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ namespace ServiceLib.ViewModels
|
|||||||
private async Task EditServer()
|
private async Task EditServer()
|
||||||
{
|
{
|
||||||
var address = SelectedSource.Address;
|
var address = SelectedSource.Address;
|
||||||
if (Utils.IsNullOrEmpty(address))
|
if (address.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom);
|
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -41,19 +41,19 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task SaveServerAsync()
|
private async Task SaveServerAsync()
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(SelectedSource.Remarks))
|
if (SelectedSource.Remarks.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(SelectedSource.Address))
|
if (SelectedSource.Address.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddress);
|
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddress);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var port = SelectedSource.Port.ToString();
|
var port = SelectedSource.Port.ToString();
|
||||||
if (Utils.IsNullOrEmpty(port) || !Utils.IsNumeric(port)
|
if (port.IsNullOrEmpty() || !Utils.IsNumeric(port)
|
||||||
|| SelectedSource.Port <= 0 || SelectedSource.Port >= Global.MaxPort)
|
|| SelectedSource.Port <= 0 || SelectedSource.Port >= Global.MaxPort)
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectServerPort);
|
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectServerPort);
|
||||||
@@ -61,21 +61,20 @@ namespace ServiceLib.ViewModels
|
|||||||
}
|
}
|
||||||
if (SelectedSource.ConfigType == EConfigType.Shadowsocks)
|
if (SelectedSource.ConfigType == EConfigType.Shadowsocks)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(SelectedSource.Id))
|
if (SelectedSource.Id.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillPassword);
|
NoticeHandler.Instance.Enqueue(ResUI.FillPassword);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(SelectedSource.Security))
|
if (SelectedSource.Security.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectEncryption);
|
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectEncryption);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (SelectedSource.ConfigType != EConfigType.SOCKS
|
if (SelectedSource.ConfigType is not EConfigType.SOCKS and not EConfigType.HTTP)
|
||||||
&& SelectedSource.ConfigType != EConfigType.HTTP)
|
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(SelectedSource.Id))
|
if (SelectedSource.Id.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillUUID);
|
NoticeHandler.Instance.Enqueue(ResUI.FillUUID);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
DisplayOperationMsg();
|
DisplayOperationMsg();
|
||||||
_config.WebDavItem = SelectedSource;
|
_config.WebDavItem = SelectedSource;
|
||||||
await ConfigHandler.SaveConfig(_config);
|
_ = await ConfigHandler.SaveConfig(_config);
|
||||||
|
|
||||||
var result = await WebDavHandler.Instance.CheckConnection();
|
var result = await WebDavHandler.Instance.CheckConnection();
|
||||||
if (result)
|
if (result)
|
||||||
@@ -114,7 +114,7 @@ namespace ServiceLib.ViewModels
|
|||||||
public async Task LocalRestore(string fileName)
|
public async Task LocalRestore(string fileName)
|
||||||
{
|
{
|
||||||
DisplayOperationMsg();
|
DisplayOperationMsg();
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
if (Utils.UpgradeAppExists(out var upgradeFileName))
|
if (Utils.UpgradeAppExists(out var upgradeFileName))
|
||||||
{
|
{
|
||||||
ProcUtils.ProcessStart(upgradeFileName, Global.RebootAs, Utils.StartupPath());
|
_ = ProcUtils.ProcessStart(upgradeFileName, Global.RebootAs, Utils.StartupPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
service?.Shutdown(true);
|
service?.Shutdown(true);
|
||||||
@@ -164,7 +164,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task<bool> CreateZipFileFromDirectory(string fileName)
|
private async Task<bool> CreateZipFileFromDirectory(string fileName)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ namespace ServiceLib.ViewModels
|
|||||||
var configDirZipTemp = Utils.GetTempPath($"v2rayN_{DateTime.Now:yyyyMMddHHmmss}");
|
var configDirZipTemp = Utils.GetTempPath($"v2rayN_{DateTime.Now:yyyyMMddHHmmss}");
|
||||||
var configDirTemp = Path.Combine(configDirZipTemp, _guiConfigs);
|
var configDirTemp = Path.Combine(configDirZipTemp, _guiConfigs);
|
||||||
|
|
||||||
FileManager.CopyDirectory(configDir, configDirTemp, false, true, "cache.db");
|
FileManager.CopyDirectory(configDir, configDirTemp, false, true, "");
|
||||||
var ret = FileManager.CreateFromDirectory(configDirZipTemp, fileName);
|
var ret = FileManager.CreateFromDirectory(configDirZipTemp, fileName);
|
||||||
Directory.Delete(configDirZipTemp, true);
|
Directory.Delete(configDirZipTemp, true);
|
||||||
return await Task.FromResult(ret);
|
return await Task.FromResult(ret);
|
||||||
|
|||||||
@@ -74,6 +74,14 @@ namespace ServiceLib.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task CheckUpdate()
|
private async Task CheckUpdate()
|
||||||
|
{
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await CheckUpdateTask();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task CheckUpdateTask()
|
||||||
{
|
{
|
||||||
_lstUpdated.Clear();
|
_lstUpdated.Clear();
|
||||||
_lstUpdated = _checkUpdateModel.Where(x => x.IsSelected == true)
|
_lstUpdated = _checkUpdateModel.Where(x => x.IsSelected == true)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
var canEditRemove = this.WhenAnyValue(
|
var canEditRemove = this.WhenAnyValue(
|
||||||
x => x.SelectedSource,
|
x => x.SelectedSource,
|
||||||
selectedSource => selectedSource != null && Utils.IsNotEmpty(selectedSource.Id));
|
selectedSource => selectedSource != null && selectedSource.Id.IsNotEmpty());
|
||||||
|
|
||||||
this.WhenAnyValue(
|
this.WhenAnyValue(
|
||||||
x => x.AutoRefresh,
|
x => x.AutoRefresh,
|
||||||
@@ -53,38 +53,18 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task Init()
|
private async Task Init()
|
||||||
{
|
{
|
||||||
var lastTime = DateTime.Now;
|
await DelayTestTask();
|
||||||
|
|
||||||
Observable.Interval(TimeSpan.FromSeconds(5))
|
|
||||||
.Subscribe(async x =>
|
|
||||||
{
|
|
||||||
if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box)))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var dtNow = DateTime.Now;
|
|
||||||
if (_config.ClashUIItem.ConnectionsRefreshInterval > 0)
|
|
||||||
{
|
|
||||||
if ((dtNow - lastTime).Minutes % _config.ClashUIItem.ConnectionsRefreshInterval == 0)
|
|
||||||
{
|
|
||||||
await GetClashConnections();
|
|
||||||
lastTime = dtNow;
|
|
||||||
}
|
|
||||||
Task.Delay(1000).Wait();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
await Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task GetClashConnections()
|
private async Task GetClashConnections()
|
||||||
{
|
{
|
||||||
var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync(_config);
|
var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync();
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateView?.Invoke(EViewAction.DispatcherRefreshConnections, ret?.connections);
|
_ = _updateView?.Invoke(EViewAction.DispatcherRefreshConnections, ret?.connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshConnections(List<ConnectionItem>? connections)
|
public void RefreshConnections(List<ConnectionItem>? connections)
|
||||||
@@ -95,28 +75,29 @@ namespace ServiceLib.ViewModels
|
|||||||
var lstModel = new List<ClashConnectionModel>();
|
var lstModel = new List<ClashConnectionModel>();
|
||||||
foreach (var item in connections ?? new())
|
foreach (var item in connections ?? new())
|
||||||
{
|
{
|
||||||
var host = $"{(Utils.IsNullOrEmpty(item.metadata.host) ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}";
|
var host = $"{(item.metadata.host.IsNullOrEmpty() ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}";
|
||||||
if (HostFilter.IsNotEmpty() && !host.Contains(HostFilter))
|
if (HostFilter.IsNotEmpty() && !host.Contains(HostFilter))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClashConnectionModel model = new();
|
var model = new ClashConnectionModel
|
||||||
|
{
|
||||||
model.Id = item.id;
|
Id = item.id,
|
||||||
model.Network = item.metadata.network;
|
Network = item.metadata.network,
|
||||||
model.Type = item.metadata.type;
|
Type = item.metadata.type,
|
||||||
model.Host = host;
|
Host = host,
|
||||||
var sp = (dtNow - item.start);
|
Time = (dtNow - item.start).TotalSeconds < 0 ? 1 : (dtNow - item.start).TotalSeconds,
|
||||||
model.Time = sp.TotalSeconds < 0 ? 1 : sp.TotalSeconds;
|
Elapsed = (dtNow - item.start).ToString(@"hh\:mm\:ss"),
|
||||||
model.Elapsed = sp.ToString(@"hh\:mm\:ss");
|
Chain = $"{item.rule} , {string.Join("->", item.chains ?? new())}"
|
||||||
item.chains?.Reverse();
|
};
|
||||||
model.Chain = $"{item.rule} , {string.Join("->", item.chains ?? new())}";
|
|
||||||
|
|
||||||
lstModel.Add(model);
|
lstModel.Add(model);
|
||||||
}
|
}
|
||||||
if (lstModel.Count <= 0)
|
if (lstModel.Count <= 0)
|
||||||
{ return; }
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_connectionItems.AddRange(lstModel);
|
_connectionItems.AddRange(lstModel);
|
||||||
}
|
}
|
||||||
@@ -140,5 +121,35 @@ namespace ServiceLib.ViewModels
|
|||||||
await ClashApiHandler.Instance.ClashConnectionClose(id);
|
await ClashApiHandler.Instance.ClashConnectionClose(id);
|
||||||
await GetClashConnections();
|
await GetClashConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DelayTestTask()
|
||||||
|
{
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
var numOfExecuted = 1;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
await Task.Delay(1000 * 5);
|
||||||
|
numOfExecuted++;
|
||||||
|
if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_config.ClashUIItem.ConnectionsRefreshInterval <= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numOfExecuted % _config.ClashUIItem.ConnectionsRefreshInterval != 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await GetClashConnections();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
private Dictionary<string, ProxiesItem>? _proxies;
|
private Dictionary<string, ProxiesItem>? _proxies;
|
||||||
private Dictionary<string, ProvidersItem>? _providers;
|
private Dictionary<string, ProvidersItem>? _providers;
|
||||||
private int _delayTimeout = 99999999;
|
private readonly int _delayTimeout = 99999999;
|
||||||
|
|
||||||
private IObservableCollection<ClashProxyModel> _proxyGroups = new ObservableCollectionExtended<ClashProxyModel>();
|
private IObservableCollection<ClashProxyModel> _proxyGroups = new ObservableCollectionExtended<ClashProxyModel>();
|
||||||
private IObservableCollection<ClashProxyModel> _proxyDetails = new ObservableCollectionExtended<ClashProxyModel>();
|
private IObservableCollection<ClashProxyModel> _proxyDetails = new ObservableCollectionExtended<ClashProxyModel>();
|
||||||
@@ -28,8 +28,8 @@ namespace ServiceLib.ViewModels
|
|||||||
public ClashProxyModel SelectedDetail { get; set; }
|
public ClashProxyModel SelectedDetail { get; set; }
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> ProxiesReloadCmd { get; }
|
public ReactiveCommand<Unit, Unit> ProxiesReloadCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> ProxiesDelaytestCmd { get; }
|
public ReactiveCommand<Unit, Unit> ProxiesDelayTestCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> ProxiesDelaytestPartCmd { get; }
|
public ReactiveCommand<Unit, Unit> ProxiesDelayTestPartCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> ProxiesSelectActivityCmd { get; }
|
public ReactiveCommand<Unit, Unit> ProxiesSelectActivityCmd { get; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
@@ -50,12 +50,12 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
await ProxiesReload();
|
await ProxiesReload();
|
||||||
});
|
});
|
||||||
ProxiesDelaytestCmd = ReactiveCommand.CreateFromTask(async () =>
|
ProxiesDelayTestCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
await ProxiesDelayTest(true);
|
await ProxiesDelayTest(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
ProxiesDelaytestPartCmd = ReactiveCommand.CreateFromTask(async () =>
|
ProxiesDelayTestPartCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
await ProxiesDelayTest(false);
|
await ProxiesDelayTest(false);
|
||||||
});
|
});
|
||||||
@@ -72,13 +72,13 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
this.WhenAnyValue(
|
this.WhenAnyValue(
|
||||||
x => x.SelectedGroup,
|
x => x.SelectedGroup,
|
||||||
y => y != null && Utils.IsNotEmpty(y.Name))
|
y => y != null && y.Name.IsNotEmpty())
|
||||||
.Subscribe(c => RefreshProxyDetails(c));
|
.Subscribe(c => RefreshProxyDetails(c));
|
||||||
|
|
||||||
this.WhenAnyValue(
|
this.WhenAnyValue(
|
||||||
x => x.RuleModeSelected,
|
x => x.RuleModeSelected,
|
||||||
y => y >= 0)
|
y => y >= 0)
|
||||||
.Subscribe(async c => await DoRulemodeSelected(c));
|
.Subscribe(async c => await DoRuleModeSelected(c));
|
||||||
|
|
||||||
this.WhenAnyValue(
|
this.WhenAnyValue(
|
||||||
x => x.SortingSelected,
|
x => x.SortingSelected,
|
||||||
@@ -95,11 +95,10 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task Init()
|
private async Task Init()
|
||||||
{
|
{
|
||||||
await ProxiesReload();
|
await DelayTestTask();
|
||||||
_ = DelayTestTask();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DoRulemodeSelected(bool c)
|
private async Task DoRuleModeSelected(bool c)
|
||||||
{
|
{
|
||||||
if (!c)
|
if (!c)
|
||||||
{
|
{
|
||||||
@@ -135,22 +134,12 @@ namespace ServiceLib.ViewModels
|
|||||||
RefreshProxyDetails(c);
|
RefreshProxyDetails(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateHandler(bool notify, string msg)
|
|
||||||
{
|
|
||||||
NoticeHandler.Instance.SendMessageEx(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task ProxiesReload()
|
public async Task ProxiesReload()
|
||||||
{
|
{
|
||||||
await GetClashProxies(true);
|
await GetClashProxies(true);
|
||||||
await ProxiesDelayTest();
|
await ProxiesDelayTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProxiesDelayTest()
|
|
||||||
{
|
|
||||||
await ProxiesDelayTest(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region proxy function
|
#region proxy function
|
||||||
|
|
||||||
private async Task SetRuleMode(ERuleMode mode)
|
private async Task SetRuleMode(ERuleMode mode)
|
||||||
@@ -169,7 +158,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task GetClashProxies(bool refreshUI)
|
private async Task GetClashProxies(bool refreshUI)
|
||||||
{
|
{
|
||||||
var ret = await ClashApiHandler.Instance.GetClashProxiesAsync(_config);
|
var ret = await ClashApiHandler.Instance.GetClashProxiesAsync();
|
||||||
if (ret?.Item1 == null || ret.Item2 == null)
|
if (ret?.Item1 == null || ret.Item2 == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -193,7 +182,7 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
foreach (var it in proxyGroups)
|
foreach (var it in proxyGroups)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(it.name) || !_proxies.ContainsKey(it.name))
|
if (it.name.IsNullOrEmpty() || !_proxies.ContainsKey(it.name))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -218,8 +207,8 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var item = _proxyGroups.Where(t => t.Name == kv.Key).FirstOrDefault();
|
var item = _proxyGroups.FirstOrDefault(t => t.Name == kv.Key);
|
||||||
if (item != null && Utils.IsNotEmpty(item.Name))
|
if (item != null && item.Name.IsNotEmpty())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -256,7 +245,7 @@ namespace ServiceLib.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var name = SelectedGroup?.Name;
|
var name = SelectedGroup?.Name;
|
||||||
if (Utils.IsNullOrEmpty(name))
|
if (name.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -266,29 +255,23 @@ namespace ServiceLib.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
_proxies.TryGetValue(name, out var proxy);
|
_proxies.TryGetValue(name, out var proxy);
|
||||||
if (proxy == null || proxy.all == null)
|
if (proxy?.all == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var lstDetails = new List<ClashProxyModel>();
|
var lstDetails = new List<ClashProxyModel>();
|
||||||
foreach (var item in proxy.all)
|
foreach (var item in proxy.all)
|
||||||
{
|
{
|
||||||
var IsActive = item == proxy.now;
|
|
||||||
|
|
||||||
var proxy2 = TryGetProxy(item);
|
var proxy2 = TryGetProxy(item);
|
||||||
if (proxy2 == null)
|
if (proxy2 == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int delay = -1;
|
var delay = proxy2.history?.Count > 0 ? proxy2.history.Last().delay : -1;
|
||||||
if (proxy2.history.Count > 0)
|
|
||||||
{
|
|
||||||
delay = proxy2.history[proxy2.history.Count - 1].delay;
|
|
||||||
}
|
|
||||||
|
|
||||||
lstDetails.Add(new ClashProxyModel()
|
lstDetails.Add(new ClashProxyModel()
|
||||||
{
|
{
|
||||||
IsActive = IsActive,
|
IsActive = item == proxy.now,
|
||||||
Name = item,
|
Name = item,
|
||||||
Type = proxy2.type,
|
Type = proxy2.type,
|
||||||
Delay = delay <= 0 ? _delayTimeout : delay,
|
Delay = delay <= 0 ? _delayTimeout : delay,
|
||||||
@@ -341,21 +324,21 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task SetActiveProxy()
|
public async Task SetActiveProxy()
|
||||||
{
|
{
|
||||||
if (SelectedGroup == null || Utils.IsNullOrEmpty(SelectedGroup.Name))
|
if (SelectedGroup == null || SelectedGroup.Name.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SelectedDetail == null || Utils.IsNullOrEmpty(SelectedDetail.Name))
|
if (SelectedDetail == null || SelectedDetail.Name.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var name = SelectedGroup.Name;
|
var name = SelectedGroup.Name;
|
||||||
if (Utils.IsNullOrEmpty(name))
|
if (name.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var nameNode = SelectedDetail.Name;
|
var nameNode = SelectedDetail.Name;
|
||||||
if (Utils.IsNullOrEmpty(nameNode))
|
if (nameNode.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -369,7 +352,7 @@ namespace ServiceLib.ViewModels
|
|||||||
await ClashApiHandler.Instance.ClashSetActiveProxy(name, nameNode);
|
await ClashApiHandler.Instance.ClashSetActiveProxy(name, nameNode);
|
||||||
|
|
||||||
selectedProxy.now = nameNode;
|
selectedProxy.now = nameNode;
|
||||||
var group = _proxyGroups.Where(it => it.Name == SelectedGroup.Name).FirstOrDefault();
|
var group = _proxyGroups.FirstOrDefault(it => it.Name == SelectedGroup.Name);
|
||||||
if (group != null)
|
if (group != null)
|
||||||
{
|
{
|
||||||
group.Now = nameNode;
|
group.Now = nameNode;
|
||||||
@@ -381,18 +364,11 @@ namespace ServiceLib.ViewModels
|
|||||||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ProxiesDelayTest(bool blAll)
|
private async Task ProxiesDelayTest(bool blAll = true)
|
||||||
{
|
{
|
||||||
//UpdateHandler(false, "Clash Proxies Latency Test");
|
ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), (item, result) =>
|
||||||
|
|
||||||
ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), async (item, result) =>
|
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null || result.IsNullOrEmpty())
|
||||||
{
|
|
||||||
await GetClashProxies(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Utils.IsNullOrEmpty(result))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -405,27 +381,29 @@ namespace ServiceLib.ViewModels
|
|||||||
public void ProxiesDelayTestResult(SpeedTestResult result)
|
public void ProxiesDelayTestResult(SpeedTestResult result)
|
||||||
{
|
{
|
||||||
//UpdateHandler(false, $"{item.name}={result}");
|
//UpdateHandler(false, $"{item.name}={result}");
|
||||||
var detail = _proxyDetails.Where(it => it.Name == result.IndexId).FirstOrDefault();
|
var detail = _proxyDetails.FirstOrDefault(it => it.Name == result.IndexId);
|
||||||
if (detail != null)
|
if (detail == null)
|
||||||
{
|
{
|
||||||
var dicResult = JsonUtils.Deserialize<Dictionary<string, object>>(result.Delay);
|
return;
|
||||||
if (dicResult != null && dicResult.ContainsKey("delay"))
|
|
||||||
{
|
|
||||||
detail.Delay = Convert.ToInt32(dicResult["delay"].ToString());
|
|
||||||
detail.DelayName = $"{detail.Delay}ms";
|
|
||||||
}
|
|
||||||
else if (dicResult != null && dicResult.ContainsKey("message"))
|
|
||||||
{
|
|
||||||
detail.Delay = _delayTimeout;
|
|
||||||
detail.DelayName = $"{dicResult["message"]}";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
detail.Delay = _delayTimeout;
|
|
||||||
detail.DelayName = string.Empty;
|
|
||||||
}
|
|
||||||
_proxyDetails.Replace(detail, JsonUtils.DeepCopy(detail));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dicResult = JsonUtils.Deserialize<Dictionary<string, object>>(result.Delay);
|
||||||
|
if (dicResult != null && dicResult.TryGetValue("delay", out var value))
|
||||||
|
{
|
||||||
|
detail.Delay = Convert.ToInt32(value.ToString());
|
||||||
|
detail.DelayName = $"{detail.Delay}ms";
|
||||||
|
}
|
||||||
|
else if (dicResult != null && dicResult.TryGetValue("message", out var value1))
|
||||||
|
{
|
||||||
|
detail.Delay = _delayTimeout;
|
||||||
|
detail.DelayName = $"{value1}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
detail.Delay = _delayTimeout;
|
||||||
|
detail.DelayName = string.Empty;
|
||||||
|
}
|
||||||
|
_proxyDetails.Replace(detail, JsonUtils.DeepCopy(detail));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion proxy function
|
#endregion proxy function
|
||||||
@@ -434,30 +412,28 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task DelayTestTask()
|
public async Task DelayTestTask()
|
||||||
{
|
{
|
||||||
var lastTime = DateTime.Now;
|
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
while (true)
|
var numOfExecuted = 1;
|
||||||
{
|
while (true)
|
||||||
await Task.Delay(1000 * 60);
|
{
|
||||||
|
await Task.Delay(1000 * 60);
|
||||||
if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box)))
|
numOfExecuted++;
|
||||||
{
|
if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box)))
|
||||||
continue;
|
{
|
||||||
}
|
continue;
|
||||||
if (_config.ClashUIItem.ProxiesAutoDelayTestInterval <= 0)
|
}
|
||||||
{
|
if (_config.ClashUIItem.ProxiesAutoDelayTestInterval <= 0)
|
||||||
continue;
|
{
|
||||||
}
|
continue;
|
||||||
var dtNow = DateTime.Now;
|
}
|
||||||
if ((dtNow - lastTime).Minutes % _config.ClashUIItem.ProxiesAutoDelayTestInterval != 0)
|
if (numOfExecuted % _config.ClashUIItem.ProxiesAutoDelayTestInterval != 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await ProxiesDelayTest();
|
await ProxiesDelayTest();
|
||||||
lastTime = dtNow;
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
public class DNSSettingViewModel : MyReactiveObject
|
public class DNSSettingViewModel : MyReactiveObject
|
||||||
{
|
{
|
||||||
[Reactive] public bool useSystemHosts { get; set; }
|
[Reactive] public bool UseSystemHosts { get; set; }
|
||||||
[Reactive] public string domainStrategy4Freedom { get; set; }
|
[Reactive] public string DomainStrategy4Freedom { get; set; }
|
||||||
[Reactive] public string domainDNSAddress { get; set; }
|
[Reactive] public string DomainDNSAddress { get; set; }
|
||||||
[Reactive] public string normalDNS { get; set; }
|
[Reactive] public string NormalDNS { get; set; }
|
||||||
|
|
||||||
[Reactive] public string domainStrategy4Freedom2 { get; set; }
|
[Reactive] public string DomainStrategy4Freedom2 { get; set; }
|
||||||
[Reactive] public string domainDNSAddress2 { get; set; }
|
[Reactive] public string DomainDNSAddress2 { get; set; }
|
||||||
[Reactive] public string normalDNS2 { get; set; }
|
[Reactive] public string NormalDNS2 { get; set; }
|
||||||
[Reactive] public string tunDNS2 { get; set; }
|
[Reactive] public string TunDNS2 { get; set; }
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
|
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> ImportDefConfig4V2rayCmd { get; }
|
public ReactiveCommand<Unit, Unit> ImportDefConfig4V2rayCmd { get; }
|
||||||
@@ -31,14 +31,14 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
ImportDefConfig4V2rayCmd = ReactiveCommand.CreateFromTask(async () =>
|
ImportDefConfig4V2rayCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
normalDNS = EmbedUtils.GetEmbedText(Global.DNSV2rayNormalFileName);
|
NormalDNS = EmbedUtils.GetEmbedText(Global.DNSV2rayNormalFileName);
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
});
|
});
|
||||||
|
|
||||||
ImportDefConfig4SingboxCmd = ReactiveCommand.CreateFromTask(async () =>
|
ImportDefConfig4SingboxCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
normalDNS2 = EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName);
|
NormalDNS2 = EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName);
|
||||||
tunDNS2 = EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName);
|
TunDNS2 = EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName);
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -48,47 +48,47 @@ namespace ServiceLib.ViewModels
|
|||||||
private async Task Init()
|
private async Task Init()
|
||||||
{
|
{
|
||||||
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
||||||
useSystemHosts = item.UseSystemHosts;
|
UseSystemHosts = item.UseSystemHosts;
|
||||||
domainStrategy4Freedom = item?.DomainStrategy4Freedom ?? string.Empty;
|
DomainStrategy4Freedom = item?.DomainStrategy4Freedom ?? string.Empty;
|
||||||
domainDNSAddress = item?.DomainDNSAddress ?? string.Empty;
|
DomainDNSAddress = item?.DomainDNSAddress ?? string.Empty;
|
||||||
normalDNS = item?.NormalDNS ?? string.Empty;
|
NormalDNS = item?.NormalDNS ?? string.Empty;
|
||||||
|
|
||||||
var item2 = await AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
|
var item2 = await AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
|
||||||
domainStrategy4Freedom2 = item2?.DomainStrategy4Freedom ?? string.Empty;
|
DomainStrategy4Freedom2 = item2?.DomainStrategy4Freedom ?? string.Empty;
|
||||||
domainDNSAddress2 = item2?.DomainDNSAddress ?? string.Empty;
|
DomainDNSAddress2 = item2?.DomainDNSAddress ?? string.Empty;
|
||||||
normalDNS2 = item2?.NormalDNS ?? string.Empty;
|
NormalDNS2 = item2?.NormalDNS ?? string.Empty;
|
||||||
tunDNS2 = item2?.TunDNS ?? string.Empty;
|
TunDNS2 = item2?.TunDNS ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SaveSettingAsync()
|
private async Task SaveSettingAsync()
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(normalDNS))
|
if (NormalDNS.IsNotEmpty())
|
||||||
{
|
{
|
||||||
var obj = JsonUtils.ParseJson(normalDNS);
|
var obj = JsonUtils.ParseJson(NormalDNS);
|
||||||
if (obj != null && obj["servers"] != null)
|
if (obj != null && obj["servers"] != null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (normalDNS.Contains('{') || normalDNS.Contains('}'))
|
if (NormalDNS.Contains('{') || NormalDNS.Contains('}'))
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
|
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(normalDNS2))
|
if (NormalDNS2.IsNotEmpty())
|
||||||
{
|
{
|
||||||
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(normalDNS2);
|
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(NormalDNS2);
|
||||||
if (obj2 == null)
|
if (obj2 == null)
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
|
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Utils.IsNotEmpty(tunDNS2))
|
if (TunDNS2.IsNotEmpty())
|
||||||
{
|
{
|
||||||
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(tunDNS2);
|
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(TunDNS2);
|
||||||
if (obj2 == null)
|
if (obj2 == null)
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
|
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
|
||||||
@@ -97,21 +97,21 @@ namespace ServiceLib.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
||||||
item.DomainStrategy4Freedom = domainStrategy4Freedom;
|
item.DomainStrategy4Freedom = DomainStrategy4Freedom;
|
||||||
item.DomainDNSAddress = domainDNSAddress;
|
item.DomainDNSAddress = DomainDNSAddress;
|
||||||
item.UseSystemHosts = useSystemHosts;
|
item.UseSystemHosts = UseSystemHosts;
|
||||||
item.NormalDNS = normalDNS;
|
item.NormalDNS = NormalDNS;
|
||||||
await ConfigHandler.SaveDNSItems(_config, item);
|
await ConfigHandler.SaveDNSItems(_config, item);
|
||||||
|
|
||||||
var item2 = await AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
|
var item2 = await AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
|
||||||
item2.DomainStrategy4Freedom = domainStrategy4Freedom2;
|
item2.DomainStrategy4Freedom = DomainStrategy4Freedom2;
|
||||||
item2.DomainDNSAddress = domainDNSAddress2;
|
item2.DomainDNSAddress = DomainDNSAddress2;
|
||||||
item2.NormalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2));
|
item2.NormalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(NormalDNS2));
|
||||||
item2.TunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2));
|
item2.TunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(TunDNS2));
|
||||||
await ConfigHandler.SaveDNSItems(_config, item2);
|
await ConfigHandler.SaveDNSItems(_config, item2);
|
||||||
|
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||||
_updateView?.Invoke(EViewAction.CloseWindow, null);
|
_ = _updateView?.Invoke(EViewAction.CloseWindow, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
65
v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs
Normal file
65
v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
using System.Reactive;
|
||||||
|
using ReactiveUI;
|
||||||
|
|
||||||
|
namespace ServiceLib.ViewModels
|
||||||
|
{
|
||||||
|
public class GlobalHotkeySettingViewModel : MyReactiveObject
|
||||||
|
{
|
||||||
|
private readonly List<KeyEventItem> _globalHotkeys;
|
||||||
|
|
||||||
|
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
|
||||||
|
|
||||||
|
public GlobalHotkeySettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
|
||||||
|
{
|
||||||
|
_config = AppHandler.Instance.Config;
|
||||||
|
_updateView = updateView;
|
||||||
|
|
||||||
|
_globalHotkeys = JsonUtils.DeepCopy(_config.GlobalHotkeys);
|
||||||
|
|
||||||
|
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
|
{
|
||||||
|
await SaveSettingAsync();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyEventItem GetKeyEventItem(EGlobalHotkey eg)
|
||||||
|
{
|
||||||
|
var item = _globalHotkeys.FirstOrDefault((it) => it.EGlobalHotkey == eg);
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
item = new()
|
||||||
|
{
|
||||||
|
EGlobalHotkey = eg,
|
||||||
|
Control = false,
|
||||||
|
Alt = false,
|
||||||
|
Shift = false,
|
||||||
|
KeyCode = null
|
||||||
|
};
|
||||||
|
_globalHotkeys.Add(item);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetKeyEventItem()
|
||||||
|
{
|
||||||
|
_globalHotkeys.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveSettingAsync()
|
||||||
|
{
|
||||||
|
_config.GlobalHotkeys = _globalHotkeys;
|
||||||
|
|
||||||
|
if (await ConfigHandler.SaveConfig(_config) == 0)
|
||||||
|
{
|
||||||
|
_updateView?.Invoke(EViewAction.CloseWindow, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -287,14 +287,15 @@ namespace ServiceLib.ViewModels
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logging.SaveLog("MyAppExitAsync Begin");
|
Logging.SaveLog("MyAppExitAsync Begin");
|
||||||
|
|
||||||
|
await SysProxyHandler.UpdateSysProxy(_config, true);
|
||||||
MessageBus.Current.SendMessage("", EMsgCommand.AppExit.ToString());
|
MessageBus.Current.SendMessage("", EMsgCommand.AppExit.ToString());
|
||||||
|
|
||||||
await ConfigHandler.SaveConfig(_config);
|
await ConfigHandler.SaveConfig(_config);
|
||||||
await SysProxyHandler.UpdateSysProxy(_config, true);
|
|
||||||
await ProfileExHandler.Instance.SaveTo();
|
await ProfileExHandler.Instance.SaveTo();
|
||||||
await StatisticsHandler.Instance.SaveTo();
|
await StatisticsHandler.Instance.SaveTo();
|
||||||
StatisticsHandler.Instance.Close();
|
|
||||||
await CoreHandler.Instance.CoreStop();
|
await CoreHandler.Instance.CoreStop();
|
||||||
|
StatisticsHandler.Instance.Close();
|
||||||
|
|
||||||
Logging.SaveLog("MyAppExitAsync End");
|
Logging.SaveLog("MyAppExitAsync End");
|
||||||
}
|
}
|
||||||
@@ -420,7 +421,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task ScanImageResult(string fileName)
|
public async Task ScanImageResult(string fileName)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -431,7 +432,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task AddScanResultAsync(string? result)
|
private async Task AddScanResultAsync(string? result)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (result.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.NoValidQRcodeFound);
|
NoticeHandler.Instance.Enqueue(ResUI.NoValidQRcodeFound);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace ServiceLib.ViewModels
|
|||||||
[Reactive] public int SpeedTestTimeout { get; set; }
|
[Reactive] public int SpeedTestTimeout { get; set; }
|
||||||
[Reactive] public string SpeedTestUrl { get; set; }
|
[Reactive] public string SpeedTestUrl { get; set; }
|
||||||
[Reactive] public string SpeedPingTestUrl { get; set; }
|
[Reactive] public string SpeedPingTestUrl { get; set; }
|
||||||
[Reactive] public int SpeedTestPageSize { get; set; }
|
[Reactive] public int MixedConcurrencyCount { get; set; }
|
||||||
[Reactive] public bool EnableHWA { get; set; }
|
[Reactive] public bool EnableHWA { get; set; }
|
||||||
[Reactive] public string SubConvertUrl { get; set; }
|
[Reactive] public string SubConvertUrl { get; set; }
|
||||||
[Reactive] public int MainGirdOrientation { get; set; }
|
[Reactive] public int MainGirdOrientation { get; set; }
|
||||||
@@ -178,7 +178,7 @@ namespace ServiceLib.ViewModels
|
|||||||
CurrentFontFamily = _config.UiItem.CurrentFontFamily;
|
CurrentFontFamily = _config.UiItem.CurrentFontFamily;
|
||||||
SpeedTestTimeout = _config.SpeedTestItem.SpeedTestTimeout;
|
SpeedTestTimeout = _config.SpeedTestItem.SpeedTestTimeout;
|
||||||
SpeedTestUrl = _config.SpeedTestItem.SpeedTestUrl;
|
SpeedTestUrl = _config.SpeedTestItem.SpeedTestUrl;
|
||||||
SpeedTestPageSize = _config.SpeedTestItem.SpeedTestPageSize;
|
MixedConcurrencyCount = _config.SpeedTestItem.MixedConcurrencyCount;
|
||||||
SpeedPingTestUrl = _config.SpeedTestItem.SpeedPingTestUrl;
|
SpeedPingTestUrl = _config.SpeedTestItem.SpeedPingTestUrl;
|
||||||
EnableHWA = _config.GuiItem.EnableHWA;
|
EnableHWA = _config.GuiItem.EnableHWA;
|
||||||
SubConvertUrl = _config.ConstItem.SubConvertUrl;
|
SubConvertUrl = _config.ConstItem.SubConvertUrl;
|
||||||
@@ -266,7 +266,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task SaveSettingAsync()
|
private async Task SaveSettingAsync()
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(localPort.ToString()) || !Utils.IsNumeric(localPort.ToString())
|
if (localPort.ToString().IsNullOrEmpty() || !Utils.IsNumeric(localPort.ToString())
|
||||||
|| localPort <= 0 || localPort >= Global.MaxPort)
|
|| localPort <= 0 || localPort >= Global.MaxPort)
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.FillLocalListeningPort);
|
NoticeHandler.Instance.Enqueue(ResUI.FillLocalListeningPort);
|
||||||
@@ -332,7 +332,7 @@ namespace ServiceLib.ViewModels
|
|||||||
_config.GuiItem.TrayMenuServersLimit = TrayMenuServersLimit;
|
_config.GuiItem.TrayMenuServersLimit = TrayMenuServersLimit;
|
||||||
_config.UiItem.CurrentFontFamily = CurrentFontFamily;
|
_config.UiItem.CurrentFontFamily = CurrentFontFamily;
|
||||||
_config.SpeedTestItem.SpeedTestTimeout = SpeedTestTimeout;
|
_config.SpeedTestItem.SpeedTestTimeout = SpeedTestTimeout;
|
||||||
_config.SpeedTestItem.SpeedTestPageSize = SpeedTestPageSize;
|
_config.SpeedTestItem.MixedConcurrencyCount = MixedConcurrencyCount;
|
||||||
_config.SpeedTestItem.SpeedTestUrl = SpeedTestUrl;
|
_config.SpeedTestItem.SpeedTestUrl = SpeedTestUrl;
|
||||||
_config.SpeedTestItem.SpeedPingTestUrl = SpeedPingTestUrl;
|
_config.SpeedTestItem.SpeedPingTestUrl = SpeedPingTestUrl;
|
||||||
_config.GuiItem.EnableHWA = EnableHWA;
|
_config.GuiItem.EnableHWA = EnableHWA;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace ServiceLib.ViewModels
|
|||||||
private List<ProfileItem> _lstProfile;
|
private List<ProfileItem> _lstProfile;
|
||||||
private string _serverFilter = string.Empty;
|
private string _serverFilter = string.Empty;
|
||||||
private Dictionary<string, bool> _dicHeaderSort = new();
|
private Dictionary<string, bool> _dicHeaderSort = new();
|
||||||
|
private SpeedtestService? _speedtestService;
|
||||||
|
|
||||||
#endregion private prop
|
#endregion private prop
|
||||||
|
|
||||||
@@ -78,6 +79,7 @@ namespace ServiceLib.ViewModels
|
|||||||
public ReactiveCommand<Unit, Unit> RealPingServerCmd { get; }
|
public ReactiveCommand<Unit, Unit> RealPingServerCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> SpeedServerCmd { get; }
|
public ReactiveCommand<Unit, Unit> SpeedServerCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> SortServerResultCmd { get; }
|
public ReactiveCommand<Unit, Unit> SortServerResultCmd { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> RemoveInvalidServerResultCmd { get; }
|
||||||
|
|
||||||
//servers export
|
//servers export
|
||||||
public ReactiveCommand<Unit, Unit> Export2ClientConfigCmd { get; }
|
public ReactiveCommand<Unit, Unit> Export2ClientConfigCmd { get; }
|
||||||
@@ -196,6 +198,10 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
await SortServer(EServerColName.DelayVal.ToString());
|
await SortServer(EServerColName.DelayVal.ToString());
|
||||||
});
|
});
|
||||||
|
RemoveInvalidServerResultCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
|
{
|
||||||
|
await RemoveInvalidServerResult();
|
||||||
|
});
|
||||||
//servers export
|
//servers export
|
||||||
Export2ClientConfigCmd = ReactiveCommand.CreateFromTask(async () =>
|
Export2ClientConfigCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
@@ -259,41 +265,38 @@ namespace ServiceLib.ViewModels
|
|||||||
Locator.Current.GetService<MainWindowViewModel>()?.Reload();
|
Locator.Current.GetService<MainWindowViewModel>()?.Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateSpeedtestHandler(SpeedTestResult result)
|
|
||||||
{
|
|
||||||
_updateView?.Invoke(EViewAction.DispatcherSpeedTest, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetSpeedTestResult(SpeedTestResult result)
|
public void SetSpeedTestResult(SpeedTestResult result)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(result.IndexId))
|
if (result.IndexId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.SendMessageEx(result.Delay);
|
NoticeHandler.Instance.SendMessageEx(result.Delay);
|
||||||
NoticeHandler.Instance.Enqueue(result.Delay);
|
NoticeHandler.Instance.Enqueue(result.Delay);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var item = _profileItems.Where(it => it.IndexId == result.IndexId).FirstOrDefault();
|
var item = _profileItems.FirstOrDefault(it => it.IndexId == result.IndexId);
|
||||||
if (item != null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
if (Utils.IsNotEmpty(result.Delay))
|
return;
|
||||||
{
|
|
||||||
int.TryParse(result.Delay, out int temp);
|
|
||||||
item.Delay = temp;
|
|
||||||
item.DelayVal = $"{result.Delay} {Global.DelayUnit}";
|
|
||||||
}
|
|
||||||
if (Utils.IsNotEmpty(result.Speed))
|
|
||||||
{
|
|
||||||
item.SpeedVal = $"{result.Speed} {Global.SpeedUnit}";
|
|
||||||
}
|
|
||||||
_profileItems.Replace(item, JsonUtils.DeepCopy(item));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.Delay.IsNotEmpty())
|
||||||
|
{
|
||||||
|
int.TryParse(result.Delay, out var temp);
|
||||||
|
item.Delay = temp;
|
||||||
|
item.DelayVal = result.Delay ?? string.Empty;
|
||||||
|
}
|
||||||
|
if (result.Speed.IsNotEmpty())
|
||||||
|
{
|
||||||
|
item.SpeedVal = result.Speed ?? string.Empty;
|
||||||
|
}
|
||||||
|
_profileItems.Replace(item, JsonUtils.DeepCopy(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateStatistics(ServerSpeedItem update)
|
public void UpdateStatistics(ServerSpeedItem update)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var item = _profileItems.Where(it => it.IndexId == update.IndexId).FirstOrDefault();
|
var item = _profileItems.FirstOrDefault(it => it.IndexId == update.IndexId);
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
item.TodayDown = Utils.HumanFy(update.TodayDown);
|
item.TodayDown = Utils.HumanFy(update.TodayDown);
|
||||||
@@ -347,7 +350,7 @@ namespace ServiceLib.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_serverFilter = ServerFilter;
|
_serverFilter = ServerFilter;
|
||||||
if (Utils.IsNullOrEmpty(_serverFilter))
|
if (_serverFilter.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
RefreshServers();
|
RefreshServers();
|
||||||
}
|
}
|
||||||
@@ -425,10 +428,11 @@ namespace ServiceLib.ViewModels
|
|||||||
Subid = t.Subid,
|
Subid = t.Subid,
|
||||||
SubRemarks = t.SubRemarks,
|
SubRemarks = t.SubRemarks,
|
||||||
IsActive = t.IndexId == _config.IndexId,
|
IsActive = t.IndexId == _config.IndexId,
|
||||||
Sort = t33 == null ? 0 : t33.Sort,
|
Sort = t33?.Sort ?? 0,
|
||||||
Delay = t33 == null ? 0 : t33.Delay,
|
Delay = t33?.Delay ?? 0,
|
||||||
DelayVal = t33?.Delay != 0 ? $"{t33?.Delay} {Global.DelayUnit}" : string.Empty,
|
Speed = t33?.Speed ?? 0,
|
||||||
SpeedVal = t33?.Speed != 0 ? $"{t33?.Speed} {Global.SpeedUnit}" : string.Empty,
|
DelayVal = t33?.Delay != 0 ? $"{t33?.Delay}" : string.Empty,
|
||||||
|
SpeedVal = t33?.Speed > 0 ? $"{t33?.Speed}" : t33?.Message ?? string.Empty,
|
||||||
TodayDown = t22 == null ? "" : Utils.HumanFy(t22.TodayDown),
|
TodayDown = t22 == null ? "" : Utils.HumanFy(t22.TodayDown),
|
||||||
TodayUp = t22 == null ? "" : Utils.HumanFy(t22.TodayUp),
|
TodayUp = t22 == null ? "" : Utils.HumanFy(t22.TodayUp),
|
||||||
TotalDown = t22 == null ? "" : Utils.HumanFy(t22.TotalDown),
|
TotalDown = t22 == null ? "" : Utils.HumanFy(t22.TotalDown),
|
||||||
@@ -444,7 +448,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task<List<ProfileItem>?> GetProfileItems(bool latest)
|
private async Task<List<ProfileItem>?> GetProfileItems(bool latest)
|
||||||
{
|
{
|
||||||
var lstSelecteds = new List<ProfileItem>();
|
var lstSelected = new List<ProfileItem>();
|
||||||
if (SelectedProfiles == null || SelectedProfiles.Count <= 0)
|
if (SelectedProfiles == null || SelectedProfiles.Count <= 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -458,21 +462,21 @@ namespace ServiceLib.ViewModels
|
|||||||
var item = await AppHandler.Instance.GetProfileItem(profile.IndexId);
|
var item = await AppHandler.Instance.GetProfileItem(profile.IndexId);
|
||||||
if (item is not null)
|
if (item is not null)
|
||||||
{
|
{
|
||||||
lstSelecteds.Add(item);
|
lstSelected.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lstSelecteds = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(orderProfiles));
|
lstSelected = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(orderProfiles));
|
||||||
}
|
}
|
||||||
|
|
||||||
return lstSelecteds;
|
return lstSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task EditServerAsync(EConfigType eConfigType)
|
public async Task EditServerAsync(EConfigType eConfigType)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(SelectedProfile?.IndexId))
|
if (string.IsNullOrEmpty(SelectedProfile?.IndexId))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -505,8 +509,8 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task RemoveServerAsync()
|
public async Task RemoveServerAsync()
|
||||||
{
|
{
|
||||||
var lstSelecteds = await GetProfileItems(true);
|
var lstSelected = await GetProfileItems(true);
|
||||||
if (lstSelecteds == null)
|
if (lstSelected == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -514,11 +518,11 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var exists = lstSelecteds.Exists(t => t.IndexId == _config.IndexId);
|
var exists = lstSelected.Exists(t => t.IndexId == _config.IndexId);
|
||||||
|
|
||||||
await ConfigHandler.RemoveServer(_config, lstSelecteds);
|
await ConfigHandler.RemoveServers(_config, lstSelected);
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||||
if (lstSelecteds.Count == _profileItems.Count)
|
if (lstSelected.Count == _profileItems.Count)
|
||||||
{
|
{
|
||||||
_profileItems.Clear();
|
_profileItems.Clear();
|
||||||
}
|
}
|
||||||
@@ -532,19 +536,22 @@ namespace ServiceLib.ViewModels
|
|||||||
private async Task RemoveDuplicateServer()
|
private async Task RemoveDuplicateServer()
|
||||||
{
|
{
|
||||||
var tuple = await ConfigHandler.DedupServerList(_config, _config.SubIndexId);
|
var tuple = await ConfigHandler.DedupServerList(_config, _config.SubIndexId);
|
||||||
RefreshServers();
|
if (tuple.Item1 > 0 || tuple.Item2 > 0)
|
||||||
Reload();
|
{
|
||||||
|
RefreshServers();
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
NoticeHandler.Instance.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2));
|
NoticeHandler.Instance.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CopyServer()
|
private async Task CopyServer()
|
||||||
{
|
{
|
||||||
var lstSelecteds = await GetProfileItems(false);
|
var lstSelected = await GetProfileItems(false);
|
||||||
if (lstSelecteds == null)
|
if (lstSelected == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (await ConfigHandler.CopyServer(_config, lstSelecteds) == 0)
|
if (await ConfigHandler.CopyServer(_config, lstSelected) == 0)
|
||||||
{
|
{
|
||||||
RefreshServers();
|
RefreshServers();
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||||
@@ -553,16 +560,16 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task SetDefaultServer()
|
public async Task SetDefaultServer()
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(SelectedProfile?.IndexId))
|
if (string.IsNullOrEmpty(SelectedProfile?.IndexId))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await SetDefaultServer(SelectedProfile.IndexId);
|
await SetDefaultServer(SelectedProfile.IndexId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetDefaultServer(string indexId)
|
public async Task SetDefaultServer(string? indexId)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(indexId))
|
if (indexId.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -590,11 +597,7 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SelectedServer == null)
|
if (SelectedServer == null || SelectedServer.ID.IsNullOrEmpty())
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Utils.IsNullOrEmpty(SelectedServer.ID))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -610,7 +613,7 @@ namespace ServiceLib.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var url = FmtHandler.GetShareUri(item);
|
var url = FmtHandler.GetShareUri(item);
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -620,13 +623,13 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task SetDefaultMultipleServer(ECoreType coreType)
|
private async Task SetDefaultMultipleServer(ECoreType coreType)
|
||||||
{
|
{
|
||||||
var lstSelecteds = await GetProfileItems(true);
|
var lstSelected = await GetProfileItems(true);
|
||||||
if (lstSelecteds == null)
|
if (lstSelected == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret = await ConfigHandler.AddCustomServer4Multiple(_config, lstSelecteds, coreType);
|
var ret = await ConfigHandler.AddCustomServer4Multiple(_config, lstSelected, coreType);
|
||||||
if (ret.Success != true)
|
if (ret.Success != true)
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
|
NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
|
||||||
@@ -645,7 +648,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task SortServer(string colName)
|
public async Task SortServer(string colName)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(colName))
|
if (colName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -660,6 +663,13 @@ namespace ServiceLib.ViewModels
|
|||||||
RefreshServers();
|
RefreshServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task RemoveInvalidServerResult()
|
||||||
|
{
|
||||||
|
var count = await ConfigHandler.RemoveInvalidServerResult(_config, _config.SubIndexId);
|
||||||
|
RefreshServers();
|
||||||
|
NoticeHandler.Instance.Enqueue(string.Format(ResUI.RemoveInvalidServerResultTip, count));
|
||||||
|
}
|
||||||
|
|
||||||
//move server
|
//move server
|
||||||
private async Task MoveToGroup(bool c)
|
private async Task MoveToGroup(bool c)
|
||||||
{
|
{
|
||||||
@@ -668,19 +678,18 @@ namespace ServiceLib.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lstSelecteds = await GetProfileItems(true);
|
var lstSelected = await GetProfileItems(true);
|
||||||
if (lstSelecteds == null)
|
if (lstSelected == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ConfigHandler.MoveToGroup(_config, lstSelecteds, SelectedMoveToGroup.Id);
|
await ConfigHandler.MoveToGroup(_config, lstSelected, SelectedMoveToGroup.Id);
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||||
|
|
||||||
RefreshServers();
|
RefreshServers();
|
||||||
SelectedMoveToGroup = null;
|
SelectedMoveToGroup = null;
|
||||||
SelectedMoveToGroup = new();
|
SelectedMoveToGroup = new();
|
||||||
//Reload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task MoveServer(EMove eMove)
|
public async Task MoveServer(EMove eMove)
|
||||||
@@ -692,7 +701,7 @@ namespace ServiceLib.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = _lstProfile.IndexOf(item);
|
var index = _lstProfile.IndexOf(item);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -721,19 +730,19 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
SelectedProfiles = _profileItems;
|
SelectedProfiles = _profileItems;
|
||||||
}
|
}
|
||||||
var lstSelecteds = await GetProfileItems(false);
|
var lstSelected = await GetProfileItems(false);
|
||||||
if (lstSelecteds == null)
|
if (lstSelected == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//ClearTestResult();
|
|
||||||
|
|
||||||
_ = new SpeedtestService(_config, lstSelecteds, actionType, UpdateSpeedtestHandler);
|
_speedtestService ??= new SpeedtestService(_config, (SpeedTestResult result) => _updateView?.Invoke(EViewAction.DispatcherSpeedTest, result));
|
||||||
|
_speedtestService?.RunLoop(actionType, lstSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ServerSpeedtestStop()
|
public void ServerSpeedtestStop()
|
||||||
{
|
{
|
||||||
MessageBus.Current.SendMessage("", EMsgCommand.StopSpeedtest.ToString());
|
_speedtestService?.ExitLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Export2ClientConfigAsync(bool blClipboard)
|
private async Task Export2ClientConfigAsync(bool blClipboard)
|
||||||
@@ -765,7 +774,7 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task Export2ClientConfigResult(string fileName, ProfileItem item)
|
public async Task Export2ClientConfigResult(string fileName, ProfileItem item)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -782,17 +791,17 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task Export2ShareUrlAsync(bool blEncode)
|
public async Task Export2ShareUrlAsync(bool blEncode)
|
||||||
{
|
{
|
||||||
var lstSelecteds = await GetProfileItems(true);
|
var lstSelected = await GetProfileItems(true);
|
||||||
if (lstSelecteds == null)
|
if (lstSelected == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
foreach (var it in lstSelecteds)
|
foreach (var it in lstSelected)
|
||||||
{
|
{
|
||||||
var url = FmtHandler.GetShareUri(it);
|
var url = FmtHandler.GetShareUri(it);
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ namespace ServiceLib.ViewModels
|
|||||||
|| SelectedSource.Ip?.Count > 0
|
|| SelectedSource.Ip?.Count > 0
|
||||||
|| SelectedSource.Protocol?.Count > 0
|
|| SelectedSource.Protocol?.Count > 0
|
||||||
|| SelectedSource.Process?.Count > 0
|
|| SelectedSource.Process?.Count > 0
|
||||||
|| Utils.IsNotEmpty(SelectedSource.Port)
|
|| SelectedSource.Port.IsNotEmpty()
|
||||||
|| Utils.IsNotEmpty(SelectedSource.Network);
|
|| SelectedSource.Network.IsNotEmpty();
|
||||||
|
|
||||||
if (!hasRule)
|
if (!hasRule)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ namespace ServiceLib.ViewModels
|
|||||||
private async Task SaveRoutingAsync()
|
private async Task SaveRoutingAsync()
|
||||||
{
|
{
|
||||||
string remarks = SelectedRouting.Remarks;
|
string remarks = SelectedRouting.Remarks;
|
||||||
if (Utils.IsNullOrEmpty(remarks))
|
if (remarks.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
||||||
return;
|
return;
|
||||||
@@ -252,13 +252,13 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
public async Task ImportRulesFromFileAsync(string fileName)
|
public async Task ImportRulesFromFileAsync(string fileName)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (fileName.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = EmbedUtils.LoadResource(fileName);
|
var result = EmbedUtils.LoadResource(fileName);
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (result.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,7 @@ namespace ServiceLib.ViewModels
|
|||||||
private async Task ImportRulesFromUrl()
|
private async Task ImportRulesFromUrl()
|
||||||
{
|
{
|
||||||
var url = SelectedRouting.Url;
|
var url = SelectedRouting.Url;
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (url.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.MsgNeedUrl);
|
NoticeHandler.Instance.Enqueue(ResUI.MsgNeedUrl);
|
||||||
return;
|
return;
|
||||||
@@ -311,7 +311,7 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
blReplace = true;
|
blReplace = true;
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(clipboardData))
|
if (clipboardData.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ namespace ServiceLib.ViewModels
|
|||||||
public IList<RoutingItemModel> SelectedSources { get; set; }
|
public IList<RoutingItemModel> SelectedSources { get; set; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string domainStrategy { get; set; }
|
public string DomainStrategy { get; set; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string domainMatcher { get; set; }
|
public string DomainMatcher { get; set; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string domainStrategy4Singbox { get; set; }
|
public string DomainStrategy4Singbox { get; set; }
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> RoutingAdvancedAddCmd { get; }
|
public ReactiveCommand<Unit, Unit> RoutingAdvancedAddCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> RoutingAdvancedRemoveCmd { get; }
|
public ReactiveCommand<Unit, Unit> RoutingAdvancedRemoveCmd { get; }
|
||||||
@@ -74,9 +74,9 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
SelectedSource = new();
|
SelectedSource = new();
|
||||||
|
|
||||||
domainStrategy = _config.RoutingBasicItem.DomainStrategy;
|
DomainStrategy = _config.RoutingBasicItem.DomainStrategy;
|
||||||
domainMatcher = _config.RoutingBasicItem.DomainMatcher;
|
DomainMatcher = _config.RoutingBasicItem.DomainMatcher;
|
||||||
domainStrategy4Singbox = _config.RoutingBasicItem.DomainStrategy4Singbox;
|
DomainStrategy4Singbox = _config.RoutingBasicItem.DomainStrategy4Singbox;
|
||||||
|
|
||||||
await ConfigHandler.InitBuiltinRouting(_config);
|
await ConfigHandler.InitBuiltinRouting(_config);
|
||||||
await RefreshRoutingItems();
|
await RefreshRoutingItems();
|
||||||
@@ -91,11 +91,7 @@ namespace ServiceLib.ViewModels
|
|||||||
var routings = await AppHandler.Instance.RoutingItems();
|
var routings = await AppHandler.Instance.RoutingItems();
|
||||||
foreach (var item in routings)
|
foreach (var item in routings)
|
||||||
{
|
{
|
||||||
bool def = false;
|
var def = item.Id == _config.RoutingBasicItem.RoutingIndexId;
|
||||||
if (item.Id == _config.RoutingBasicItem.RoutingIndexId)
|
|
||||||
{
|
|
||||||
def = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var it = new RoutingItemModel()
|
var it = new RoutingItemModel()
|
||||||
{
|
{
|
||||||
@@ -114,9 +110,9 @@ namespace ServiceLib.ViewModels
|
|||||||
|
|
||||||
private async Task SaveRoutingAsync()
|
private async Task SaveRoutingAsync()
|
||||||
{
|
{
|
||||||
_config.RoutingBasicItem.DomainStrategy = domainStrategy;
|
_config.RoutingBasicItem.DomainStrategy = DomainStrategy;
|
||||||
_config.RoutingBasicItem.DomainMatcher = domainMatcher;
|
_config.RoutingBasicItem.DomainMatcher = DomainMatcher;
|
||||||
_config.RoutingBasicItem.DomainStrategy4Singbox = domainStrategy4Singbox;
|
_config.RoutingBasicItem.DomainStrategy4Singbox = DomainStrategy4Singbox;
|
||||||
|
|
||||||
if (await ConfigHandler.SaveConfig(_config) == 0)
|
if (await ConfigHandler.SaveConfig(_config) == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ namespace ServiceLib.ViewModels
|
|||||||
[Reactive]
|
[Reactive]
|
||||||
public int SystemProxySelected { get; set; }
|
public int SystemProxySelected { get; set; }
|
||||||
|
|
||||||
|
[Reactive]
|
||||||
|
public bool BlSystemProxyPacVisible { get; set; }
|
||||||
|
|
||||||
#endregion System Proxy
|
#endregion System Proxy
|
||||||
|
|
||||||
#region UI
|
#region UI
|
||||||
@@ -96,6 +99,7 @@ namespace ServiceLib.ViewModels
|
|||||||
SelectedRouting = new();
|
SelectedRouting = new();
|
||||||
SelectedServer = new();
|
SelectedServer = new();
|
||||||
RunningServerToolTipText = "-";
|
RunningServerToolTipText = "-";
|
||||||
|
BlSystemProxyPacVisible = Utils.IsWindows();
|
||||||
|
|
||||||
if (_config.TunModeItem.EnableTun && AllowEnableTun())
|
if (_config.TunModeItem.EnableTun && AllowEnableTun())
|
||||||
{
|
{
|
||||||
@@ -297,7 +301,7 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(SelectedServer.ID))
|
if (SelectedServer.ID.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -311,11 +315,13 @@ namespace ServiceLib.ViewModels
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await (new UpdateService()).RunAvailabilityCheck(async (bool success, string msg) =>
|
|
||||||
{
|
_updateView?.Invoke(EViewAction.DispatcherServerAvailability, ResUI.Speedtesting);
|
||||||
NoticeHandler.Instance.SendMessageEx(msg);
|
|
||||||
_updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg);
|
var msg = await (new UpdateService()).RunAvailabilityCheck();
|
||||||
});
|
|
||||||
|
NoticeHandler.Instance.SendMessageEx(msg);
|
||||||
|
_updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TestServerAvailabilityResult(string msg)
|
public void TestServerAvailabilityResult(string msg)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace ServiceLib.ViewModels
|
|||||||
private async Task SaveSubAsync()
|
private async Task SaveSubAsync()
|
||||||
{
|
{
|
||||||
var remarks = SelectedSource.Remarks;
|
var remarks = SelectedSource.Remarks;
|
||||||
if (Utils.IsNullOrEmpty(remarks))
|
if (remarks.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<ResourceInclude Source="Assets/GlobalResources.axaml" />
|
<ResourceInclude Source="Assets/GlobalResources.axaml" />
|
||||||
|
<ResourceInclude Source="Controls/AutoCompleteBox.axaml" />
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
@@ -46,6 +47,12 @@
|
|||||||
Header="{x:Static resx:ResUI.menuSystemProxyNothing}"
|
Header="{x:Static resx:ResUI.menuSystemProxyNothing}"
|
||||||
IsChecked="{Binding BlSystemProxyNothing}"
|
IsChecked="{Binding BlSystemProxyNothing}"
|
||||||
ToggleType="Radio" />
|
ToggleType="Radio" />
|
||||||
|
<NativeMenuItem
|
||||||
|
Command="{Binding SystemProxyPacCmd}"
|
||||||
|
Header="{x:Static resx:ResUI.menuSystemProxyPac}"
|
||||||
|
IsChecked="{Binding BlSystemProxyPac}"
|
||||||
|
IsVisible="{Binding BlSystemProxyPacVisible}"
|
||||||
|
ToggleType="Radio" />
|
||||||
<NativeMenuItemSeparator />
|
<NativeMenuItemSeparator />
|
||||||
<NativeMenuItem Click="MenuAddServerViaClipboardClick" Header="{x:Static resx:ResUI.menuAddServerViaClipboard}" />
|
<NativeMenuItem Click="MenuAddServerViaClipboardClick" Header="{x:Static resx:ResUI.menuAddServerViaClipboard}" />
|
||||||
<NativeMenuItem Header="{x:Static resx:ResUI.menuAddServerViaScan}" IsVisible="False" />
|
<NativeMenuItem Header="{x:Static resx:ResUI.menuAddServerViaScan}" IsVisible="False" />
|
||||||
@@ -61,4 +68,4 @@
|
|||||||
</TrayIcon>
|
</TrayIcon>
|
||||||
</TrayIcons>
|
</TrayIcons>
|
||||||
</TrayIcon.Icons>
|
</TrayIcon.Icons>
|
||||||
</Application>
|
</Application>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public partial class App : Application
|
|||||||
|
|
||||||
var ViewModel = new StatusBarViewModel(null);
|
var ViewModel = new StatusBarViewModel(null);
|
||||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
||||||
this.DataContext = ViewModel;
|
DataContext = ViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
@@ -65,7 +65,9 @@ public partial class App : Application
|
|||||||
var clipboardData = await AvaUtils.GetClipboardData(desktop.MainWindow);
|
var clipboardData = await AvaUtils.GetClipboardData(desktop.MainWindow);
|
||||||
var service = Locator.Current.GetService<MainWindowViewModel>();
|
var service = Locator.Current.GetService<MainWindowViewModel>();
|
||||||
if (service != null)
|
if (service != null)
|
||||||
|
{
|
||||||
_ = service.AddServerViaClipboardAsync(clipboardData);
|
_ = service.AddServerViaClipboardAsync(clipboardData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,7 +76,9 @@ public partial class App : Application
|
|||||||
{
|
{
|
||||||
var service = Locator.Current.GetService<MainWindowViewModel>();
|
var service = Locator.Current.GetService<MainWindowViewModel>();
|
||||||
if (service != null)
|
if (service != null)
|
||||||
|
{
|
||||||
await service.MyAppExitAsync(true);
|
await service.MyAppExitAsync(true);
|
||||||
|
}
|
||||||
service?.Shutdown(true);
|
service?.Shutdown(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user