补充打包方式
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# 年糕历险记 —— 程序图标生成(构建与发布.md §8:exe/窗口使用原版素材 logo)
|
||||
# 年糕历险记 —— 程序图标生成(构建与发布.md §8:exe/窗口/快捷方式/安装器使用原版素材 logo)
|
||||
# 用法:pwsh -File scripts/make_icon.ps1
|
||||
# 流程:素材包 pack.png → cmd/client/icon.png → go-winres 生成 cmd/client/icon.syso
|
||||
# (资源目录树格式,Go 链接器自动嵌入 exe;资源管理器/任务栏/快捷方式显示图标)。
|
||||
# 流程:素材包 pack.png → cmd/client/icon.png → go-winres 生成 icon.syso(嵌入游戏 exe)
|
||||
# → 同时生成多尺寸 cmd/client/icon.ico(供 NSIS 安装器 MUI_ICON / MUI_UNICON 使用)
|
||||
$ErrorActionPreference = "Stop"
|
||||
$root = Split-Path $PSScriptRoot -Parent
|
||||
|
||||
@@ -20,9 +20,47 @@ $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 生成失败" }
|
||||
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 =="
|
||||
Write-Host "== 图标资源已嵌入:cmd/client/icon.syso =="
|
||||
|
||||
# 3) 生成多尺寸 icon.ico(16/24/32/48/64/128/256,PNG 压缩,供 NSIS 安装器/卸载器使用)
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
$src = [System.Drawing.Image]::FromFile((Join-Path $root "cmd\client\icon.png"))
|
||||
$sizes = @(16, 24, 32, 48, 64, 128, 256)
|
||||
$ms = New-Object System.IO.MemoryStream
|
||||
$bw = New-Object System.IO.BinaryWriter($ms)
|
||||
# ICONDIR:reserved(2)=0, type(2)=1, count(2)
|
||||
$bw.Write([uint16]0); $bw.Write([uint16]1); $bw.Write([uint16]$sizes.Count)
|
||||
$offset = 6 + 16 * $sizes.Count
|
||||
$images = @()
|
||||
foreach ($s in $sizes) {
|
||||
$bmp = New-Object System.Drawing.Bitmap($s, $s)
|
||||
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
||||
$g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
|
||||
$g.DrawImage($src, 0, 0, $s, $s)
|
||||
$g.Dispose()
|
||||
$pngMs = New-Object System.IO.MemoryStream
|
||||
$bmp.Save($pngMs, [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
$images += ,$pngMs.ToArray()
|
||||
$bmp.Dispose(); $pngMs.Dispose()
|
||||
}
|
||||
for ($i = 0; $i -lt $sizes.Count; $i++) {
|
||||
$s = $sizes[$i]
|
||||
$dim = if ($s -ge 256) { 0 } else { $s } # 256 用 0 表示
|
||||
$bw.Write([byte]$dim); $bw.Write([byte]$dim)
|
||||
$bw.Write([byte]0); $bw.Write([byte]0) # colors / reserved
|
||||
$bw.Write([uint16]1); $bw.Write([uint16]32) # planes / bpp
|
||||
$bw.Write([uint32]$images[$i].Length)
|
||||
$bw.Write([uint32]$offset)
|
||||
$offset += $images[$i].Length
|
||||
}
|
||||
foreach ($d in $images) { $bw.Write($d) }
|
||||
$bw.Flush()
|
||||
[System.IO.File]::WriteAllBytes((Join-Path $root "cmd\client\icon.ico"), $ms.ToArray())
|
||||
$src.Dispose()
|
||||
$bw.Close(); $ms.Dispose()
|
||||
Write-Host "== 安装器图标已生成:cmd/client/icon.ico($($sizes -join '/') px)=="
|
||||
|
||||
Reference in New Issue
Block a user