-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-msix.ps1
More file actions
188 lines (164 loc) · 7.81 KB
/
Copy pathbuild-msix.ps1
File metadata and controls
188 lines (164 loc) · 7.81 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# .\build-msix.ps1 [-Version "0.2.0.0"] [-Platform "x64"] [-Configuration "Release"] [-SkipSign]
param(
[string]$Version = "0.2.0.0",
[string]$Platform = "x64",
[string]$Configuration = "Release",
[switch]$SkipSign
)
$ErrorActionPreference = "Stop"
$Root = $PSScriptRoot
$Proj = Join-Path $Root "Buzzr\Buzzr.csproj"
$Out = Join-Path $Root "release"
$CertDir = Join-Path $Root ".certs"
$CertPath = Join-Path $CertDir "Buzzr.pfx"
$CertPw = "Buzzr-Dev"
$CertSubject = "CN=dev.highest.buzzr"
function Step($msg) { Write-Host "`n>> $msg" -ForegroundColor Cyan }
function Ok($msg) { Write-Host " $msg" -ForegroundColor Green }
function Warn($msg) { Write-Host " $msg" -ForegroundColor Yellow }
Step "Preparing release directory"
if (Test-Path $Out) { Remove-Item $Out -Recurse -Force }
New-Item -ItemType Directory -Path $Out -Force | Out-Null
if (-not $SkipSign) {
Step "Code signing certificate"
if (-not (Test-Path $CertDir)) { New-Item -ItemType Directory -Path $CertDir -Force | Out-Null }
if (Test-Path $CertPath) {
Ok "Exists: $CertPath"
} else {
Warn "Creating self-signed cert..."
$cert = New-SelfSignedCertificate `
-Type Custom -Subject $CertSubject -KeyUsage DigitalSignature `
-FriendlyName "Buzzr Development" `
-CertStoreLocation "Cert:\CurrentUser\My" `
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")
$pw = ConvertTo-SecureString -String $CertPw -Force -AsPlainText
Export-PfxCertificate -Cert "Cert:\CurrentUser\My\$($cert.Thumbprint)" -FilePath $CertPath -Password $pw | Out-Null
Ok "Created: $CertPath"
try {
$pfx = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($CertPath, $CertPw)
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store(
[System.Security.Cryptography.X509Certificates.StoreName]::TrustedPeople,
[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine)
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$store.Add($pfx)
$store.Close()
Ok "Added to Trusted People store"
} catch {
Warn "Couldn't trust cert locally (run as Admin)"
}
}
}
Step "Building Go sidecar"
$sidecarDir = Join-Path $Root "sidecar"
$sidecarExe = Join-Path $sidecarDir "buzzr-sidecar.exe"
$savedCC = $env:CC
$savedCGO = $env:CGO_ENABLED
try {
$env:CC = "E:\Programs\msys64\ucrt64\bin\gcc.exe"
$env:CGO_ENABLED = "1"
Push-Location $sidecarDir
& go build -tags goolm -ldflags "-s -w" -o buzzr-sidecar.exe .
Pop-Location
if ($LASTEXITCODE -ne 0) {
Warn "Sidecar build failed (continuing without it)"
} elseif (Test-Path $sidecarExe) {
$sidecarSize = (Get-Item $sidecarExe).Length / 1MB
Ok "Built buzzr-sidecar.exe ($([math]::Round($sidecarSize, 1)) MB)"
}
} finally {
$env:CC = $savedCC
$env:CGO_ENABLED = $savedCGO
}
Step "Building native taskbar badge DLL"
$nativeDir = Join-Path $Root "Buzzr\Native"
$nativeDll = Join-Path $nativeDir "taskbar_badge.dll"
$gccPath = "E:\Programs\msys64\ucrt64\bin\gcc.exe"
Push-Location $nativeDir
& $gccPath -shared -O2 -o taskbar_badge.dll taskbar_badge.c -lole32 -luuid -lgdi32 -luser32 -lm
Pop-Location
if ($LASTEXITCODE -ne 0) {
Warn "Native DLL build failed (badge notifications will be disabled)"
} elseif (Test-Path $nativeDll) {
$dllSize = (Get-Item $nativeDll).Length / 1KB
Ok "Built taskbar_badge.dll ($([math]::Round($dllSize, 1)) KB)"
}
Step "Visual assets"
$assetsDir = Join-Path $Root "Buzzr\Assets"
if (-not (Test-Path $assetsDir)) { New-Item -ItemType Directory -Path $assetsDir -Force | Out-Null }
$png = [Convert]::FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIHWNgYPj/HwADBwF/OMBo3AAAAABJRU5ErkJggg==")
@("Square44x44Logo.png","Square71x71Logo.png","Square150x150Logo.png","Square310x310Logo.png",
"Wide310x150Logo.png","SplashScreen.png","StoreLogo.png","LockScreenLogo.png") | ForEach-Object {
$p = Join-Path $assetsDir $_
if (-not (Test-Path $p)) { [IO.File]::WriteAllBytes($p, $png); Ok "Created: $_" }
}
Step "Building MSIX ($Platform $Configuration)"
$msixPub = Join-Path $Out "msix-publish"
& dotnet publish $Proj --configuration $Configuration --runtime "win-$Platform" --self-contained true --output $msixPub `
/p:Platform=$Platform /p:WindowsPackageType=MSIX /p:AppxPackageDir="$Out\msix\" `
/p:AppxBundle=Never /p:AppxPackageSigningEnabled=false /p:GenerateAppxPackageOnBuild=true /p:Version=$Version
if ($LASTEXITCODE -ne 0) { Write-Host "MSIX build failed" -ForegroundColor Red; exit 1 }
$msixFile = Get-ChildItem -Path $Out -Filter "*.msix" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
if ($msixFile) { Ok "Built: $($msixFile.FullName)" }
else { Warn "MSIX not found in output" }
if ($msixFile -and -not $SkipSign) {
Step "Signing MSIX"
$signtool = $null
$sdkRoot = "${env:ProgramFiles(x86)}\Windows Kits\10\bin"
if (Test-Path $sdkRoot) {
Get-ChildItem $sdkRoot -Directory | Sort-Object Name -Descending | ForEach-Object {
if (-not $signtool) {
$c = Join-Path $_.FullName "x64\signtool.exe"
if (Test-Path $c) { $signtool = $c }
}
}
}
# also check NuGet cache for signtool
if (-not $signtool) {
$nugetPath = Join-Path $env:USERPROFILE ".nuget\packages\microsoft.windows.sdk.buildtools"
if (Test-Path $nugetPath) {
$signtool = Get-ChildItem $nugetPath -Recurse -Filter "signtool.exe" |
Where-Object { $_.FullName -like "*x64*" } |
Sort-Object FullName -Descending |
Select-Object -First 1 -ExpandProperty FullName
}
}
if ($signtool) {
& $signtool sign /fd SHA256 /a /f $CertPath /p $CertPw $msixFile.FullName
if ($LASTEXITCODE -eq 0) { Ok "Signed" } else { Warn "Signing failed ($LASTEXITCODE)" }
} else {
Warn "signtool.exe not found (install Windows SDK or restore NuGet packages)"
}
$final = Join-Path $Out "Buzzr-$Version-$Platform.msix"
Copy-Item $msixFile.FullName $final -Force
Ok "Output: $final"
}
# bundle installer (msix + cert + install script)
if ($msixFile -and (Test-Path $CertPath)) {
Step "Creating installer bundle"
$bundleDir = Join-Path $Out "Buzzr-$Version-$Platform-installer"
New-Item -ItemType Directory -Path $bundleDir -Force | Out-Null
Copy-Item (Join-Path $Out "Buzzr-$Version-$Platform.msix") $bundleDir -ErrorAction SilentlyContinue
if (-not (Test-Path (Join-Path $bundleDir "*.msix"))) {
Copy-Item $msixFile.FullName (Join-Path $bundleDir "Buzzr-$Version-$Platform.msix")
}
Copy-Item $CertPath $bundleDir
Copy-Item (Join-Path $Root "install.ps1") $bundleDir
$bundleZip = Join-Path $Out "Buzzr-$Version-$Platform-installer.zip"
Compress-Archive -Path "$bundleDir\*" -DestinationPath $bundleZip -Force
Remove-Item $bundleDir -Recurse -Force
Ok "Installer: $bundleZip"
}
Step "Building portable zip ($Platform $Configuration)"
$portDir = Join-Path $Out "portable"
& dotnet publish $Proj --configuration $Configuration --runtime "win-$Platform" --self-contained true --output $portDir `
/p:Platform=$Platform /p:WindowsPackageType=None /p:PublishSingleFile=false /p:Version=$Version
if ($LASTEXITCODE -ne 0) { Write-Host "Portable build failed" -ForegroundColor Red; exit 1 }
$zip = Join-Path $Out "Buzzr-$Version-$Platform-portable.zip"
Compress-Archive -Path "$portDir\*" -DestinationPath $zip -Force
Ok "Output: $zip"
Step "Done"
Write-Host ""
Get-ChildItem $Out -File | ForEach-Object {
Write-Host " $($_.Name) ($([math]::Round($_.Length / 1MB, 2)) MB)" -ForegroundColor White
}
Write-Host "`nOutput: $Out" -ForegroundColor Cyan