|
| 1 | +#Requires -Version 7.0 |
| 2 | +$ErrorActionPreference = 'Stop' |
| 3 | + |
| 4 | +$root = $PSScriptRoot |
| 5 | +$appSvg = Join-Path $root 'ContextMenuManager\Properties\AppIcon.svg' |
| 6 | +$propsDir = Join-Path $root 'ContextMenuManager\Properties' |
| 7 | +$ico = Join-Path $propsDir 'AppIcon.ico' |
| 8 | +$logoPng = Join-Path $propsDir 'Resources\Images\Logo.png' |
| 9 | + |
| 10 | +$missing = @() |
| 11 | +if (-not (Get-Command resvg -ErrorAction SilentlyContinue)) { $missing += 'resvg' } |
| 12 | +if (-not (Get-Command magick -ErrorAction SilentlyContinue)) { $missing += 'magick' } |
| 13 | +if ($missing.Count) { |
| 14 | + Write-Host "Missing required tool(s): $($missing -join ', ')" -ForegroundColor Red |
| 15 | + if ($missing -contains 'resvg') { |
| 16 | + Write-Host "Install resvg: https://github.com/linebender/resvg/releases (or: cargo install resvg)" -ForegroundColor Yellow |
| 17 | + } |
| 18 | + if ($missing -contains 'magick') { |
| 19 | + Write-Host "Install ImageMagick: https://imagemagick.org/script/download.php#windows (or: winget install ImageMagick.ImageMagick)" -ForegroundColor Yellow |
| 20 | + } |
| 21 | + exit 1 |
| 22 | +} |
| 23 | + |
| 24 | +if (-not (Test-Path $appSvg)) { |
| 25 | + Write-Host "SVG not found: $appSvg" -ForegroundColor Red |
| 26 | + exit 1 |
| 27 | +} |
| 28 | + |
| 29 | +$icoSizes = 16, 20, 24, 32, 40, 48, 64, 96, 128, 256 |
| 30 | +$tempPngs = foreach ($s in $icoSizes) { Join-Path $propsDir "icon_$s.png" } |
| 31 | + |
| 32 | +$iconTasks = @() |
| 33 | +for ($i = 0; $i -lt $icoSizes.Count; $i++) { |
| 34 | + $iconTasks += [pscustomobject]@{ Size = $icoSizes[$i]; Output = $tempPngs[$i] } |
| 35 | +} |
| 36 | +$iconTasks += [pscustomobject]@{ Size = 256; Output = $logoPng } |
| 37 | + |
| 38 | +Write-Host "=== Rasterizing app icon (parallel) ===" |
| 39 | +$iconTasks | ForEach-Object -ThrottleLimit 16 -Parallel { |
| 40 | + $ErrorActionPreference = 'Stop' |
| 41 | + $t = $_ |
| 42 | + & resvg $using:appSvg $t.Output -w $t.Size -h $t.Size |
| 43 | + if ($LASTEXITCODE -ne 0) { throw "resvg failed for $($t.Output)" } |
| 44 | +} |
| 45 | + |
| 46 | +Write-Host "=== Packing AppIcon.ico ===" |
| 47 | +& magick @tempPngs -define png:exclude-chunks=date,time $ico |
| 48 | +if ($LASTEXITCODE -ne 0) { |
| 49 | + Write-Host "magick failed to pack AppIcon.ico." -ForegroundColor Red |
| 50 | + exit 1 |
| 51 | +} |
| 52 | +$tempPngs | Where-Object { Test-Path $_ } | Remove-Item |
| 53 | + |
| 54 | +$bannerTasks = @( |
| 55 | + [pscustomobject]@{ Svg = (Join-Path $root 'Logo\Logo.svg'); Png = (Join-Path $root 'Logo\Logo.png') } |
| 56 | + [pscustomobject]@{ Svg = (Join-Path $root 'Logo\Logo-en.svg'); Png = (Join-Path $root 'Logo\Logo-en.png') } |
| 57 | +) |
| 58 | + |
| 59 | +Write-Host "=== Rasterizing + trimming logo banners (parallel) ===" |
| 60 | +$trimmed = $bannerTasks | ForEach-Object -ThrottleLimit 4 -Parallel { |
| 61 | + $ErrorActionPreference = 'Stop' |
| 62 | + $t = $_ |
| 63 | + if (-not (Test-Path $t.Svg)) { throw "SVG not found: $($t.Svg)" } |
| 64 | + $tmp = "$($t.Png).tmp.png" |
| 65 | + & resvg $t.Svg $tmp -h 512 |
| 66 | + if ($LASTEXITCODE -ne 0) { throw "resvg failed for $($t.Svg)" } |
| 67 | + & magick $tmp -trim +repage $tmp |
| 68 | + if ($LASTEXITCODE -ne 0) { throw "magick trim failed for $tmp" } |
| 69 | + $wh = (& magick identify -format "%w %h" $tmp).Trim() -split ' ' |
| 70 | + [pscustomobject]@{ Png = $t.Png; Tmp = $tmp; W = [int]$wh[0]; H = [int]$wh[1] } |
| 71 | +} |
| 72 | + |
| 73 | +$maxW = ($trimmed | Measure-Object -Property W -Maximum).Maximum |
| 74 | +$maxH = ($trimmed | Measure-Object -Property H -Maximum).Maximum |
| 75 | +Write-Host "Normalizing banners to ${maxW}x${maxH}" |
| 76 | + |
| 77 | +$trimmed | ForEach-Object -ThrottleLimit 4 -Parallel { |
| 78 | + $ErrorActionPreference = 'Stop' |
| 79 | + $d = $_ |
| 80 | + & magick $d.Tmp -background none -gravity center ` |
| 81 | + -extent "$($using:maxW)x$($using:maxH)" +repage ` |
| 82 | + -define png:exclude-chunks=date,time $d.Png |
| 83 | + if ($LASTEXITCODE -ne 0) { throw "magick extent failed for $($d.Png)" } |
| 84 | + Remove-Item $d.Tmp |
| 85 | +} |
| 86 | + |
| 87 | +Write-Host "=== Done ===" |
0 commit comments