$ErrorActionPreference = "Stop" [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13 $InstallDir = if ($env:WEIBIANJI_DIR) { $env:WEIBIANJI_DIR } else { "C:\weibianji" } $CandidateManifestUrls = @( "https://weibianji-update.pages.dev/latest.json", "https://ai8user00-a11y.github.io/weibianji/latest.json", "https://github.com/ai8user00-a11y/weibianji/releases/latest/download/latest.json", "https://cdn.jsdelivr.net/gh/ai8user00-a11y/weibianji@main/latest.json", "https://raw.githubusercontent.com/ai8user00-a11y/weibianji/main/latest.json" ) if ($env:WEIBIANJI_UPDATE_URL) { $CandidateManifestUrls = @($env:WEIBIANJI_UPDATE_URL) + $CandidateManifestUrls } $ActiveManifestUrl = $null $Manifest = $null foreach ($u in $CandidateManifestUrls) { try { $sep = if ($u.Contains("?")) { "&" } else { "?" } $Manifest = Invoke-RestMethod -Uri "${u}${sep}t=$([DateTimeOffset]::UtcNow.ToUnixTimeSeconds())" -TimeoutSec 8 if ($Manifest -and $Manifest.version -and $Manifest.sha256) { $ActiveManifestUrl = $u break } } catch {} } if (-not $ActiveManifestUrl) { Write-Error "无法连接到 Cloudflare Pages 或 GitHub (ai8user00-a11y/weibianji) 云端更新源,请检查网络。" exit 1 } $BaseUri = [Uri]$ActiveManifestUrl $PackageUri = [Uri]::new($BaseUri, $Manifest.packageUrl).AbsoluteUri Write-Host "==> 发现云端最新版本 v$($Manifest.version) (源: $($BaseUri.Host)),正在通过 HTTPS 下载..." -ForegroundColor Cyan $ZipFile = Join-Path $env:TEMP "weibianji-win-x64-v$($Manifest.version).zip" Invoke-WebRequest -Uri $PackageUri -OutFile $ZipFile $ActualHash = (Get-FileHash -Path $ZipFile -Algorithm SHA256).Hash.ToLowerInvariant() if ($ActualHash -ne $Manifest.sha256.ToLowerInvariant()) { Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue Write-Error "SHA256 校验失败!期望: $($Manifest.sha256),实际: $ActualHash" exit 1 } Write-Host "==> SHA256 完整性校验通过 ($ActualHash)" -ForegroundColor Green Get-Process -Name "weibianji" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue Start-Sleep -Milliseconds 600 New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null Expand-Archive -Path $ZipFile -DestinationPath $InstallDir -Force Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue $ExePath = Join-Path $InstallDir "weibianji.exe" Start-Process -FilePath $ExePath -WorkingDirectory $InstallDir Write-Host "==> 微边记 v$($Manifest.version) 已从云端安全安装并启动!路径: $ExePath" -ForegroundColor Green Write-Host "==> 此后在 Mac 发布新版本后,只需在 Windows 端点击‘检查更新 / 检查升级’按钮即可手动拉取升级!" -ForegroundColor Green