实现 .NET 10 托盘版网关保活

包含分层探测、可补偿的 IPv4 路由/DNS 切换、自动策略、托盘与分组设置界面、只读诊断工具、离线测试和发布脚本。
This commit is contained in:
chuzhongzai
2026-10-23 23:35:20 +08:00
parent 59a2982b2c
commit 2d85527656
57 changed files with 8623 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
param([string]$Source, [string]$Target, [int]$X, [int]$Y, [int]$Width, [int]$Height, [int]$Zoom = 2)
Add-Type -AssemblyName System.Drawing
$image = [System.Drawing.Image]::FromFile((Resolve-Path -LiteralPath $Source))
try {
$crop = New-Object System.Drawing.Bitmap($Width, $Height)
$graphics = [System.Drawing.Graphics]::FromImage($crop)
try {
$graphics.DrawImage($image, (New-Object System.Drawing.Rectangle(0, 0, $Width, $Height)), $X, $Y, $Width, $Height, [System.Drawing.GraphicsUnit]::Pixel)
} finally { $graphics.Dispose() }
$factor = [int]$Zoom
$zoomWidth = [int]$Width * $factor
$zoomHeight = [int]$Height * $factor
$scaled = New-Object System.Drawing.Bitmap($zoomWidth, $zoomHeight)
$scaledGraphics = [System.Drawing.Graphics]::FromImage($scaled)
try {
$scaledGraphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::NearestNeighbor
$scaledGraphics.DrawImage($crop, 0, 0, $zoomWidth, $zoomHeight)
} finally { $scaledGraphics.Dispose() }
$scaled.Save($Target, [System.Drawing.Imaging.ImageFormat]::Png)
$scaled.Dispose(); $crop.Dispose()
} finally { $image.Dispose() }
+27
View File
@@ -0,0 +1,27 @@
param([switch]$SelfContained)
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
$dotnet = Join-Path $env:USERPROFILE '.dotnet-sdk\dotnet.exe'
$flavor = if ($SelfContained) { 'standalone' } else { 'runtime-dependent' }
$out = Join-Path $root "artifacts\publish\$flavor"
$env:DOTNET_ROOT = Split-Path -Parent $dotnet
& $dotnet publish (Join-Path $root 'src\GatewayKeepalive.Tray\GatewayKeepalive.Tray.csproj') -c Release -r win-x64 --self-contained $SelfContained -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=embedded -o $out | Select-Object -Last 2
if ($LASTEXITCODE -ne 0) { throw 'publish failed' }
& $dotnet publish (Join-Path $root 'src\GatewayKeepalive.Cli\GatewayKeepalive.Cli.csproj') -c Release -r win-x64 --self-contained $SelfContained -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=embedded -o (Join-Path $out 'diagnostics') | Select-Object -Last 2
if ($LASTEXITCODE -ne 0) { throw 'cli publish failed' }
$preview = Join-Path $root "artifacts\preview-$flavor"
Remove-Item -LiteralPath $preview -Recurse -Force -ErrorAction SilentlyContinue
$stderr = Join-Path $root "artifacts\$flavor-stderr.txt"
# Arguments containing spaces must be quoted explicitly; Start-Process does not escape them.
$process = Start-Process -FilePath (Join-Path $out 'GatewayKeepalive.exe') -ArgumentList @('--preview', ('"' + $preview + '"')) -WindowStyle Hidden -PassThru -Wait -RedirectStandardError $stderr
$pngs = @(Get-ChildItem -LiteralPath $preview -Filter '*.png' -ErrorAction SilentlyContinue).Count
$report = Join-Path $root "artifacts\$flavor-diagnostics.json"
& (Join-Path $out 'diagnostics\GatewayKeepalive.Cli.exe') --diagnose --output $report | Out-Null
$cliExit = $LASTEXITCODE
$diagnostics = Get-Content -LiteralPath $report -Raw | ConvertFrom-Json
$guiError = ''
if (Test-Path -LiteralPath $stderr) {
$rawError = Get-Content -LiteralPath $stderr -Raw -ErrorAction SilentlyContinue
if ($null -ne $rawError) { $guiError = $rawError.Trim() }
}
[pscustomobject]@{ Flavor = $flavor; GuiExit = $process.ExitCode; PreviewPngs = $pngs; GuiStderr = $guiError; CliExit = $cliExit; ReadOnly = $diagnostics.ReadOnly; Gateway = $diagnostics.BestRoute.Gateway; Interface = $diagnostics.BestRoute.InterfaceIndex; Files = @(Get-ChildItem -LiteralPath $out -File | Select-Object Name, Length) } | ConvertTo-Json -Depth 4