- scripts/make_icon.ps1:素材包 pack.png → go-winres 生成 icon.syso (嵌入 exe 图标与版本信息);窗口图标运行时 SetWindowIcon - 安装.bat:桌面快捷方式 [Y/n](默认 Y)、安装后立即运行 [Y/n](默认 Y) - build.ps1 在 syso 缺失时自动生成图标
28 lines
1.5 KiB
PowerShell
28 lines
1.5 KiB
PowerShell
# 年糕历险记 —— 程序图标生成(构建与发布.md §8:exe/窗口使用原版素材 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.png(resourcepacks/*/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 ==" |