feat(build): 程序图标使用原版素材 logo + 安装器运行/快捷方式选项

- scripts/make_icon.ps1:素材包 pack.png → go-winres 生成 icon.syso
  (嵌入 exe 图标与版本信息);窗口图标运行时 SetWindowIcon
- 安装.bat:桌面快捷方式 [Y/n](默认 Y)、安装后立即运行 [Y/n](默认 Y)
- build.ps1 在 syso 缺失时自动生成图标
This commit is contained in:
NianGao Dev
2026-08-16 23:23:31 +08:00
parent b0b632df05
commit 9e7d4d20e2
8 changed files with 83 additions and 6 deletions

BIN
cmd/client/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
cmd/client/icon.syso Normal file

Binary file not shown.

25
cmd/client/winres.json Normal file
View File

@@ -0,0 +1,25 @@
{
"RT_GROUP_ICON": {
"APP": {
"0001": ["icon.png"]
}
},
"RT_VERSION": {
"#1": {
"0000": {
"fixed": {
"file_version": "0.1.0.0",
"product_version": "0.1.0.0"
},
"info": {
"0409": {
"ProductName": "年糕历险记",
"FileDescription": "年糕历险记NianGao Adventure",
"CompanyName": "NianGao Dev",
"OriginalFilename": "mc-client.exe"
}
}
}
}
}
}

View File

@@ -35,6 +35,11 @@ if (-not $Release) { $tags = "$tags dev" }
Push-Location $root
try {
New-Item -ItemType Directory -Force -Path bin | Out-Null
# exe 图标(原版素材 logo缺失时自动生成 .sysomake_icon.ps1
if (-not (Test-Path (Join-Path $root "cmd\client\icon.syso"))) {
& (Join-Path $PSScriptRoot "make_icon.ps1")
if ($LASTEXITCODE -ne 0) { throw "图标生成失败make_icon.ps1" }
}
go build -tags $tags -trimpath -ldflags "-s -w" -o bin/mc-client.exe ./cmd/client
go build -trimpath -ldflags "-s -w" -o bin/mc-server.exe ./cmd/server

View File

@@ -21,13 +21,30 @@ if not exist "!INSTALL_DIR!" mkdir "!INSTALL_DIR!"
echo 复制游戏文件...
xcopy /e /i /y "%~dp0*" "!INSTALL_DIR!\" >nul 2>&1
echo 创建桌面快捷方式...
powershell -NoProfile -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\年糕历险记.lnk'); $s.TargetPath = '!INSTALL_DIR!\mc-client.exe'; $s.WorkingDirectory = '!INSTALL_DIR!'; $s.Save()"
rem 选项 1创建桌面快捷方式默认选中 Y
set "MAKE_LNK=Y"
set /p "MAKE_LNK=是否创建桌面快捷方式 [Y/n](默认 Y"
if /i "!MAKE_LNK!"=="" set "MAKE_LNK=Y"
if /i "!MAKE_LNK!"=="y" (
echo 创建桌面快捷方式...
powershell -NoProfile -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\年糕历险记.lnk'); $s.TargetPath = '!INSTALL_DIR!\mc-client.exe'; $s.WorkingDirectory = '!INSTALL_DIR!'; $s.IconLocation = '!INSTALL_DIR!\mc-client.exe,0'; $s.Save()"
)
echo.
echo ============================================
echo 安装完成!桌面已创建「年糕历险记」快捷方式。
echo 安装完成!
echo 游戏存档保存在安装目录 worlds\ 下。
echo 按任意键退出...
echo ============================================
rem 选项 2安装完成后是否立即运行默认选中 Y
set "RUN_NOW=Y"
set /p "RUN_NOW=是否立即运行游戏 [Y/n](默认 Y"
if /i "!RUN_NOW!"=="" set "RUN_NOW=Y"
if /i "!RUN_NOW!"=="y" (
echo 正在启动游戏...
start "" /D "!INSTALL_DIR!" "!INSTALL_DIR!\mc-client.exe"
)
echo.
echo 按任意键退出...
pause >nul

28
scripts/make_icon.ps1 Normal file
View File

@@ -0,0 +1,28 @@
# 年糕历险记 —— 程序图标生成(构建与发布.md §8exe/窗口使用原版素材 logo
# 用法pwsh -File scripts/make_icon.ps1
# 流程:素材包 pack.png → cmd/client/icon.png → go-winres 生成 cmd/client/icon.syso
# 资源目录树格式Go 链接器自动嵌入 exe资源管理器/任务栏/快捷方式显示图标)。
$ErrorActionPreference = "Stop"
$root = Split-Path $PSScriptRoot -Parent
# 1) 定位素材包 pack.png原版 logo高优先级包在前→ 复制为 icon.png
$png = $null
foreach ($dir in Get-ChildItem (Join-Path $root "resourcepacks") -Directory -ErrorAction SilentlyContinue) {
$cand = Join-Path $dir.FullName "pack.png"
if (Test-Path $cand) { $png = $cand; break }
}
if (-not $png) { throw "未找到素材包 pack.pngresourcepacks/*/pack.png" }
Copy-Item $png (Join-Path $root "cmd\client\icon.png") -Force
Write-Host "== 图标来源:$png =="
# 2) go-winres 生成 .syso多尺寸图标组 + 版本资源winres.json 引用 icon.png
$env:GOCACHE = Join-Path $root ".gocache"
Push-Location (Join-Path $root "cmd\client")
try {
go run github.com/tc-hib/go-winres@latest make --in winres.json --out icon --arch amd64 --no-suffix
if ($LASTEXITCODE -ne 0) { throw "go-winres 生成失败" }
Move-Item -Force (Join-Path (Get-Location) "icon") (Join-Path (Get-Location) "icon.syso")
} finally {
Pop-Location
}
Write-Host "== 图标资源已嵌入cmd/client/icon.syso =="

View File

@@ -33,7 +33,8 @@ Copy-Item (Join-Path $PSScriptRoot "installer\安装.bat") (Join-Path $stage "
v$Version
====================
.bat
.bat
worlds/
/ mods/ Minecraft

View File

@@ -77,9 +77,10 @@ mc-v1.2.0/
- 产品名称:**年糕历险记**(安装包文件名 `年糕历险记-Setup-v<版本>`;产品、快捷方式、卸载项同名)。
- **两条交付路径**
1. **便携安装包(当前交付)**`pwsh scripts/make_installer.ps1` 生成 `dist/年糕历险记-Setup-v<版本>.zip`,解压后运行 `安装.bat`——全中文交互(选择安装目录、复制文件、创建桌面快捷方式「年糕历险记」)。
1. **便携安装包(当前交付)**`pwsh scripts/make_installer.ps1` 生成 `dist/年糕历险记-Setup-v<版本>.zip`,解压后运行 `安装.bat`——全中文交互(选择安装目录、复制文件、可选创建桌面快捷方式「年糕历险记」默认选中、安装完成后可选立即运行游戏默认选中)。
2. **NSIS 正式安装器(发布时)**`scripts/installer.nsi`(简体中文界面、开始菜单、卸载器),需发布环境安装 NSIS 3`makensis /DVERSION=<版本> scripts/installer.nsi`
- 安装内容:`mc-client.exe``mc-server.exe``config/``mods/`README`resourcepacks/`(默认素材包)。
- **程序图标exe/窗口/快捷方式)**:使用素材包原版 logo`resourcepacks/*/pack.png`)。`scripts/make_icon.ps1` 生成 `cmd/client/icon.syso`go-winres 资源目录树格式Go 链接器自动嵌入 exe 图标与版本信息);窗口图标运行时读取 pack.png 经 `render.SetWindowIcon` 设置。`build.ps1` 在 syso 缺失时自动调用 make_icon.ps1。
- 中文要求:安装脚本全中文;游戏内 `lang/zh_cn.json` 随安装包提供;缺失翻译键回退 en_us。
- 存档位置:安装目录 `worlds/`便携式NSIS 版卸载时保留存档)。