Files
ngzz-mc/scripts/make_nsis.ps1

50 lines
2.7 KiB
PowerShell
Raw Permalink Normal View History

2026-08-16 23:46:36 +08:00
# 年糕历险记 —— NSIS 正式安装器构建脚本(构建与发布.md §8 交付方案)
2026-09-19 14:21:08 +08:00
# 用法:根目录 打包-安装包.bat [版本]
# 或 pwsh -File scripts/make_nsis.ps1 [-Version 0.1.0]
2026-08-16 23:46:36 +08:00
# 前置:C 工具链(tools/ 下 zig 或 MinGW,构建 GL 客户端需要);
# NSIS 3(自动查找 tools/nsis/nsis-*/makensis.exe,其次 PATH 中的 makensis)
# 产物:dist/年糕历险记-Setup-v<版本>.exe(简体中文向导、快捷方式选项、完成页运行选项)
param([string]$Version = "0.1.0")
$ErrorActionPreference = "Stop"
$root = Split-Path $PSScriptRoot -Parent
2026-09-19 14:21:08 +08:00
# 1) 构建 bin/(Release:tags gl,无 dev;构建与发布.md §3 / §8)
& (Join-Path $PSScriptRoot "build.ps1") -Release
if ($LASTEXITCODE -ne 0) { throw "构建失败(build.ps1 -Release)" }
2026-08-16 23:46:36 +08:00
# 2) 定位 makensis:优先 tools/nsis/(本项目自带 NSIS 3.10),其次系统 PATH
$makensisPath = (Get-ChildItem (Join-Path $root "tools\nsis") -Recurse -Filter makensis.exe -ErrorAction SilentlyContinue | Select-Object -First 1).FullName
if (-not $makensisPath) {
$cmd = Get-Command makensis -ErrorAction SilentlyContinue
if ($cmd) { $makensisPath = $cmd.Source }
}
if (-not $makensisPath) {
throw "未找到 NSIS:请把 NSIS 3 放到 tools/nsis/(如 nsis-3.10)或加入 PATH。下载:https://nsis.sourceforge.io/Download"
}
# 3) 确保安装器图标存在(游戏 logo:make_icon.ps1 生成 icon.syso 与 icon.ico;
# 缺失时调用;规范见 构建与发布.md §8「安装器图标」)
if (-not (Test-Path (Join-Path $root "cmd\client\icon.ico"))) {
& (Join-Path $PSScriptRoot "make_icon.ps1")
if ($LASTEXITCODE -ne 0) { throw "图标生成失败(make_icon.ps1)" }
}
# 3) 编译安装器(中文界面、快捷方式选项、安装完成后运行选项)
# installer.nsi 需为 UTF-8 带 BOM(NSIS 3 按 BOM 识别编码;文本编辑器保存可能去掉 BOM,这里自动补回)
$nsi = Join-Path $PSScriptRoot "installer.nsi"
$nsiBytes = [System.IO.File]::ReadAllBytes($nsi)
if (-not ($nsiBytes.Length -ge 3 -and $nsiBytes[0] -eq 0xEF -and $nsiBytes[1] -eq 0xBB -and $nsiBytes[2] -eq 0xBF)) {
[System.IO.File]::WriteAllText($nsi, [System.IO.File]::ReadAllText($nsi), (New-Object System.Text.UTF8Encoding($true)))
Write-Host "== installer.nsi 已补 UTF-8 BOM =="
}
New-Item -ItemType Directory -Force -Path (Join-Path $root "dist") | Out-Null
& $makensisPath "/DVERSION=$Version" $nsi
if ($LASTEXITCODE -ne 0) { throw "makensis 编译失败" }
$exe = Join-Path $root "dist\年糕历险记-Setup-v$Version.exe"
if (-not (Test-Path $exe)) { throw "未找到安装器产物:$exe" }
$sizeMB = [math]::Round((Get-Item $exe).Length / 1MB, 1)
Write-Host "== NSIS 安装器就绪:$exe($sizeMB MB)=="