# 生成应用图标 assets\icon.ico (System.Drawing 绘制 64x64 气缸简图 → PNG 内嵌 ICO)
# 用法: powershell -NoProfile -ExecutionPolicy Bypass -File tools\make-icon.ps1
param(
  [string]$Out = (Join-Path $PSScriptRoot '..\assets\icon.ico')
)
Add-Type -AssemblyName System.Drawing

$bmp = New-Object System.Drawing.Bitmap(64, 64)
$g = [System.Drawing.Graphics]::FromImage($bmp)
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
$g.Clear([System.Drawing.Color]::FromArgb(0x1B, 0x4F, 0x8C))   # 深蓝底

$blue = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::FromArgb(0x4A, 0x90, 0xD9))
$white = [System.Drawing.Brushes]::White
$g.FillRectangle($blue, 16, 18, 32, 38)                          # 缸体
$g.FillEllipse($blue, 16, 10, 32, 16)                            # 顶盖椭圆
$g.FillEllipse($blue, 16, 48, 32, 16)                            # 底盖椭圆
$g.FillRectangle($white, 28, 2, 8, 14)                           # 活塞杆
$g.FillRectangle($white, 18, 24, 4, 26)                          # 高光

# PNG 字节
$ms = New-Object System.IO.MemoryStream
$bmp.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
$png = $ms.ToArray()
$g.Dispose(); $bmp.Dispose(); $ms.Dispose()

# ICO 包装: 6 字节头 + 16 字节目录项 + PNG 数据
$outDir = Split-Path $Out
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
$fs = [System.IO.File]::Create($Out)
$w = New-Object System.IO.BinaryWriter($fs)
$w.Write([UInt16]0); $w.Write([UInt16]1); $w.Write([UInt16]1)    # 保留/类型/数量
$w.Write([byte]64); $w.Write([byte]64); $w.Write([byte]0); $w.Write([byte]0)   # 宽高
$w.Write([UInt16]1); $w.Write([UInt16]32)                        # 平面/位深
$w.Write([UInt32]$png.Length); $w.Write([UInt32]22)              # 数据大小/偏移
$w.Write($png)
$w.Close()
Write-Output ("图标: " + $Out)
