Files
ngzz-mc/scripts/make_nsis.ps1
2026-08-16 23:46:36 +08:00

49 lines
2.7 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 年糕历险记 —— NSIS 正式安装器构建脚本(构建与发布.md §8 交付方案)
# 用法pwsh -File scripts/make_nsis.ps1 [-Version 0.1.0]
# 前置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
# 1) 构建 bin/(复用 build.ps1定位 zig/gcc产出 mc-client.exe / mc-server.exe 及资源)
& (Join-Path $PSScriptRoot "build.ps1")
if ($LASTEXITCODE -ne 0) { throw "构建失败build.ps1" }
# 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) 确保安装器图标存在(游戏 logomake_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 带 BOMNSIS 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=="