Files
QFT/VERIFY_WINDOWS_HOST.ps1
T
zhy200308 0f0dbaef47 fix(desktop): 防火墙提权改为手动触发;构建前检测占用;清理警告
三个问题一起处理。

1. 提权改为手动
上一版会在点「启动接收」时自动弹 UAC。实际用下来太侵入——多数人
只是想收个文件,却先被要求管理员授权。现在:
- 检测保持自动,但**只读**,无任何副作用
- 提权只在用户点「放行防火墙(需要管理员授权)」时发生
- 按钮无条件保留,不再只在"检测到被拦"时出现:检测可能不准,
  而用户遇到「对方连不上」时需要有地方可点
- 同时移除了拒绝标记的持久化——提权已不自动发生,无需记忆

2. Windows 构建报 os error 5
  error: failed to remove file `...\target\release\qft-desktop.exe`
  Caused by: 拒绝访问。 (os error 5)
原因是 QFT 窗口还开着,运行中的 exe 锁住了产物文件,而 cargo 的报错
完全看不出这一层。VERIFY_WINDOWS_HOST.ps1 现在会在构建前检测
qft-desktop 进程,列出 PID 并询问是否结束;README 也补了说明
(含 Defender 扫描导致的偶发同类报错)。

3. 构建警告 15 → 5
长期堆积的警告会训练人忽略所有警告,所以逐条处理:
- 真实问题:if 条件多余的括号,已修
- 为后续里程碑准备但尚未接线的 API(client::ping、download_file、
  platform::direct_ap_support/ensure_dir),加 #[allow(dead_code)]
  并注明将在哪个阶段使用
- 仅特定平台构造的项(firewall::RULE_NAME 只用于 Windows,
  FirewallStatus::Unsupported 只在 Linux 返回),改用
  #[cfg_attr(not(...), allow(dead_code))],避免无条件放行
剩余 5 个均为本次改动之前既有(cache_mib、v/transport、security、
path),不属本次范围,未改动。

验证:cargo test 35/35,release 构建 5 个警告且全部是既有的。
2026-08-11 18:28:43 +08:00

63 lines
2.7 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
Write-Host "== QFT v0.4.7 Windows host verification ==" -ForegroundColor Cyan
if (Get-Command python -ErrorAction SilentlyContinue) {
Write-Host "[1/4] Core protocol/selftests"
& python "$Root\scripts\run_all_selftests.py"
if ($LASTEXITCODE -ne 0) {
Write-Host "If Python reports missing qrcode/cv2, run: python -m pip install -r `"$Root\scripts\requirements-test.txt`"" -ForegroundColor Yellow
throw "repository Python selftests failed"
}
} else {
Write-Warning "python not found; skipping repository Python selftests"
}
Write-Host "[2/4] Desktop Rust compile/test/release"
# 正在运行的 qft-desktop.exe 会锁住产物文件,cargo 只会抛出
# "failed to remove file ... 拒绝访问 (os error 5)" 这种看不出原因的错误。
# 这里提前识别并说清楚,而不是让用户去猜。
$Running = Get-Process -Name 'qft-desktop' -ErrorAction SilentlyContinue
if ($Running) {
Write-Host ""
Write-Warning "检测到 qft-desktop.exe 正在运行(PID: $($Running.Id -join ', '))。"
Write-Warning "它会锁住 target\release\qft-desktop.exe,导致构建报 'os error 5 拒绝访问'。"
$Answer = Read-Host "是否结束这些进程后继续构建?(y/N)"
if ($Answer -eq 'y' -or $Answer -eq 'Y') {
$Running | Stop-Process -Force
Start-Sleep -Milliseconds 500
Write-Host "已结束,继续构建。"
} else {
throw "请先关闭 QFT 窗口再重新运行本脚本"
}
}
Push-Location "$Root\desktop"
try {
& cargo check
if ($LASTEXITCODE -ne 0) { throw "cargo check failed" }
& cargo test
if ($LASTEXITCODE -ne 0) { throw "cargo test failed" }
& cargo build --release
if ($LASTEXITCODE -ne 0) { throw "cargo build --release failed" }
} finally { Pop-Location }
Write-Host "[3/4] Android unit/build"
Push-Location "$Root\android"
try {
if (!(Test-Path '.\gradle\wrapper\gradle-wrapper.jar')) {
Write-Host "Gradle wrapper jar missing; attempting bootstrap..."
& powershell -ExecutionPolicy Bypass -File '.\bootstrap-wrapper.ps1'
}
& .\gradlew.bat :app:testDebugUnitTest :app:assembleDebug --stacktrace
if ($LASTEXITCODE -ne 0) { throw "Android Gradle verification failed" }
} finally { Pop-Location }
Write-Host "[4/4] Artifact locations" -ForegroundColor Cyan
Write-Host "Windows EXE: $Root\desktop\target\release\qft-desktop.exe"
Write-Host "Android APK: $Root\android\app\build\outputs\apk\debug\app-debug.apk"
Write-Host "`nHOST BUILD VERIFICATION PASSED" -ForegroundColor Green
Write-Host "Next: perform the physical display/camera and Wi-Fi Direct acceptance matrix in TEST_REPORT.md."