Repository navigation
Expand file tree
/
Copy pathbuild.ps1
More file actions
87 lines (73 loc) · 3.73 KB
/
Copy pathbuild.ps1
File metadata and controls
87 lines (73 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#requires -Version 5
<#
Builds CoderStyle.exe with the C# compiler that ships with the .NET
Framework, so nothing has to be installed to build or to run it.
Every asset is embedded as a manifest resource:
css -> assets/dream-skin.css
inject -> assets/renderer-inject.js
appicon -> assets/app.ico
theme.<id> -> assets/themes/<id>/theme.json
art.<id>.<ext> -> assets/themes/<id>/<image>
assets/app.ico is additionally linked as the Win32 icon resource, which is
what Explorer, the taskbar and shortcuts read. Without it the exe has no icon
at all and Windows falls back to a blank default.
#>
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$csc = 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe'
if (-not (Test-Path -LiteralPath $csc)) { throw "csc.exe not found: $csc" }
$dist = Join-Path $root 'dist'
$null = New-Item -ItemType Directory -Force -Path $dist
$out = Join-Path $dist 'CoderStyle.exe'
# The pre-rename binary is still sitting in dist and would keep launching, and
# an old tray icon fighting the new one over the same debug port is a confusing
# way to find that out.
$stale = Join-Path $dist 'CodexSkinStudio.exe'
if (Test-Path -LiteralPath $stale) { Remove-Item -LiteralPath $stale -Force }
$icon = Join-Path $root 'assets\app.ico'
if (-not (Test-Path -LiteralPath $icon)) { & (Join-Path $root 'tools\make-icon.ps1') }
$resources = @(
"/resource:$(Join-Path $root 'assets\dream-skin.css'),css"
"/resource:$(Join-Path $root 'assets\renderer-inject.js'),inject"
"/resource:$icon,appicon"
)
foreach ($dir in Get-ChildItem -LiteralPath (Join-Path $root 'assets\themes') -Directory) {
$manifest = Join-Path $dir.FullName 'theme.json'
if (-not (Test-Path -LiteralPath $manifest)) { continue }
$cfg = Get-Content -LiteralPath $manifest -Raw -Encoding UTF8 | ConvertFrom-Json
$id = if ($cfg.id) { $cfg.id } else { $dir.Name }
$image = Join-Path $dir.FullName $cfg.image
if (-not (Test-Path -LiteralPath $image)) { throw "theme '$id' references a missing image: $($cfg.image)" }
$ext = [System.IO.Path]::GetExtension($cfg.image).TrimStart('.')
$resources += "/resource:$manifest,theme.$id"
$resources += "/resource:$image,art.$id.$ext"
Write-Host "embedded theme: $id ($($cfg.name))"
}
$refs = @(
'/r:System.dll'
'/r:System.Core.dll'
'/r:System.Drawing.dll'
'/r:System.Windows.Forms.dll'
'/r:System.Web.Extensions.dll'
'/r:Microsoft.CSharp.dll'
)
$sources = Get-ChildItem -LiteralPath (Join-Path $root 'src') -Filter *.cs | ForEach-Object { $_.FullName }
$manifestFile = Join-Path $root 'assets\app.manifest'
if (-not (Test-Path -LiteralPath $manifestFile)) { throw "missing manifest: $manifestFile" }
# /target:winexe is what keeps a console window from ever appearing.
# /win32icon is what gives the exe, its shortcuts and the taskbar an icon.
# /win32manifest is what declares DPI awareness. Without it Windows treats the
# process as unaware, lies to it about every metric, and bitmap-stretches the
# whole window on a scaled display.
$cscArgs = @('/nologo', '/target:winexe', '/platform:x64', '/optimize+',
"/win32icon:$icon", "/win32manifest:$manifestFile", "/out:$out") + $refs + $resources + $sources
& $csc $cscArgs
if ($LASTEXITCODE -ne 0) { throw "compile failed ($LASTEXITCODE)" }
# An exe missing its icon resource looks identical to a working build until it
# reaches Explorer, so confirm the resource landed rather than assuming it.
Add-Type -AssemblyName System.Drawing
$probe = [System.Drawing.Icon]::ExtractAssociatedIcon($out)
if ($null -eq $probe) { throw "built exe has no associated icon" }
$probe.Dispose()
$size = (Get-Item -LiteralPath $out).Length
Write-Host ("built {0} ({1:N0} KB)" -f $out, ($size / 1KB))