# 自动下载安装 NSIS $ErrorActionPreference = "Stop" Write-Host "==> 检查 NSIS 是否已安装..." -ForegroundColor Cyan $existingNsis = Get-Command makensis.exe -ErrorAction SilentlyContinue if ($existingNsis) { Write-Host " NSIS 已安装: $($existingNsis.Source)" -ForegroundColor Green Write-Host " 跳过安装,可以直接执行打包命令。" -ForegroundColor Yellow exit 0 } $nsisVersion = "3.10" $nsisUrl = "https://sourceforge.net/projects/nsis/files/NSIS%203/$nsisVersion/nsis-$nsisVersion-setup.exe/download" $installerPath = "$env:TEMP\nsis-$nsisVersion-setup.exe" Write-Host "==> 下载 NSIS $nsisVersion 安装程序..." -ForegroundColor Cyan Write-Host " 从: $nsisUrl" -ForegroundColor Gray Write-Host " 到: $installerPath" -ForegroundColor Gray try { $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri $nsisUrl -OutFile $installerPath -UseBasicParsing -TimeoutSec 300 Write-Host " 下载完成 ($('{0:N2}' -f ((Get-Item $installerPath).Length / 1MB)) MB)" -ForegroundColor Green } catch { Write-Host " 下载失败: $($_.Exception.Message)" -ForegroundColor Red Write-Host "" Write-Host "请手动下载并安装 NSIS:" -ForegroundColor Yellow Write-Host " 1. 访问: https://nsis.sourceforge.io/Download" -ForegroundColor Cyan Write-Host " 2. 下载 NSIS 3.10 或更高版本" -ForegroundColor Cyan Write-Host " 3. 运行安装程序(默认安装路径即可)" -ForegroundColor Cyan exit 1 } Write-Host "" Write-Host "==> 正在安装 NSIS..." -ForegroundColor Cyan Write-Host " 安装位置: C:\Program Files (x86)\NSIS" -ForegroundColor Gray Write-Host " (如果弹出 UAC 提示,请点击'是'授权)" -ForegroundColor Yellow try { Start-Process -FilePath $installerPath -ArgumentList "/S" -Wait -Verb RunAs Write-Host " 安装完成" -ForegroundColor Green } catch { Write-Host " 安装失败: $($_.Exception.Message)" -ForegroundColor Red Write-Host " 请手动运行: $installerPath" -ForegroundColor Yellow exit 1 } Write-Host "" Write-Host "==> 清理临时文件..." -ForegroundColor Cyan Remove-Item $installerPath -Force -ErrorAction SilentlyContinue Write-Host "" Write-Host "==> NSIS 安装完成!" -ForegroundColor Green Write-Host "" Write-Host "下一步操作:" -ForegroundColor Yellow Write-Host " 1. 关闭当前 PowerShell 窗口" -ForegroundColor Cyan Write-Host " 2. 重新打开 PowerShell(让 PATH 环境变量生效)" -ForegroundColor Cyan Write-Host " 3. 执行打包命令: .\打包.bat -Installer" -ForegroundColor Cyan Write-Host "" Write-Host "打包完成后,安装包会在 build\bin\ 目录,文件名带时间戳" -ForegroundColor Gray