param( [switch]$NoPause ) $ErrorActionPreference = "Stop" # Standalone pairing entry point. The download page exposes this file by # itself, so make it self-contained instead of assuming that Python modules # were copied beside it. Secrets and the one-time code stay local. $root = Split-Path -Parent $MyInvocation.MyCommand.Path $bundleUrl = "https://geo.rxbp.top/downloads/geo-windows-h3-worker-0.4.2-source.zip" $data = Join-Path $env:ProgramData "GEO\WindowsWorker" $log = Join-Path $data "pair.log" New-Item -ItemType Directory -Force -Path $data | Out-Null function Write-PairStatus { param( [string]$Message, [ConsoleColor]$Color = [ConsoleColor]::Gray ) $line = "[{0}] {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message Write-Host $line -ForegroundColor $Color try { Add-Content -LiteralPath $log -Value $line -Encoding UTF8 } catch { } } try { if (-not (Test-Path (Join-Path $data "windows_h3_pair.py"))) { Write-PairStatus "正在准备本地配对组件..." Cyan $zip = Join-Path $env:TEMP "geo-h3-worker-0.4.2-pair.zip" Invoke-WebRequest -UseBasicParsing -Uri $bundleUrl -OutFile $zip Expand-Archive -Path $zip -DestinationPath $data -Force $bundle = Get-ChildItem $data -Directory | Where-Object { Test-Path (Join-Path $_.FullName "windows_h3_pair.py") } | Sort-Object LastWriteTime -Descending | Select-Object -First 1 if (-not $bundle) { throw "H3 Worker 源码包解压失败" } Copy-Item (Join-Path $bundle.FullName "*.py") $data -Force } $root = $data $code = Read-Host "请输入 GEO 后台的一次性配对码" if ([string]::IsNullOrWhiteSpace($code)) { throw "未输入配对码,已取消。" } $python = (Get-Command python.exe -ErrorAction Stop).Source $pair = Join-Path $root "windows_h3_pair.py" Write-PairStatus "正在向 GEO 注册本机 Worker(配对码不会写入日志)..." Cyan & $python $pair --pairing-code $code --version "0.4.2" if ($LASTEXITCODE -ne 0) { throw "配对失败,退出码 $LASTEXITCODE" } Write-PairStatus "配对成功。现在运行 start_windows_h3_worker.cmd。" Green } catch { Write-PairStatus ("配对失败:" + $_.Exception.Message) Red Write-PairStatus ("非敏感诊断日志:" + $log) Yellow if (-not $NoPause) { Read-Host "按回车关闭窗口" } exit 1 } if (-not $NoPause) { Read-Host "配对完成。按回车关闭窗口" } exit 0