From ee32ec6a53cbeb6b80d595686b85d65014da0766 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 9 Nov 2026 05:23:34 -0700 Subject: [PATCH] feat(packaging): Windows MSI, portable and symbols zips (M8) WiX v5 installer in the Craft family's install policy: per-user by default, everyone on request, upgrades in place. Registers .anicraft (default app) and offers Open with for .fla/.xfl; Start menu, App Paths, Launch on Finish. sign.ps1 signs with a PFX or Azure Trusted Signing and warns without secrets. --- .gitattributes | 5 + .gitignore | 2 + packaging/.shellcheckrc | 3 + packaging/check-icons.sh | 45 +++ packaging/env.sh | 83 +++++ packaging/windows/INSTALLATION.md | 34 ++ packaging/windows/README.md | 4 + packaging/windows/anicraft.en-us.wxl | 11 + packaging/windows/anicraft.wxs | 103 ++++++ packaging/windows/check-icons.ps1 | 51 +++ packaging/windows/check-install-policy.ps1 | 370 +++++++++++++++++++++ packaging/windows/install-policy.json | 83 +++++ packaging/windows/install-policy.wxi | 71 ++++ packaging/windows/package.ps1 | 217 ++++++++++++ packaging/windows/sign.ps1 | 110 ++++++ packaging/windows/symbols.txt | 22 ++ packaging/windows/test-install-policy.ps1 | 54 +++ 17 files changed, 1268 insertions(+) create mode 100644 packaging/.shellcheckrc create mode 100644 packaging/check-icons.sh create mode 100644 packaging/env.sh create mode 100644 packaging/windows/INSTALLATION.md create mode 100644 packaging/windows/README.md create mode 100644 packaging/windows/anicraft.en-us.wxl create mode 100644 packaging/windows/anicraft.wxs create mode 100644 packaging/windows/check-icons.ps1 create mode 100644 packaging/windows/check-install-policy.ps1 create mode 100644 packaging/windows/install-policy.json create mode 100644 packaging/windows/install-policy.wxi create mode 100644 packaging/windows/package.ps1 create mode 100644 packaging/windows/sign.ps1 create mode 100644 packaging/windows/symbols.txt create mode 100644 packaging/windows/test-install-policy.ps1 diff --git a/.gitattributes b/.gitattributes index ca4ca149..4e745c27 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,3 +10,8 @@ scripts/git-hooks/* text eol=lf *.wav binary *.ogg binary *.mp3 binary +# packaging scripts run on Linux and macOS runners; the DMG layout files are binary +*.sh text eol=lf +*.tiff binary +*.DS_Store binary +*.ico binary diff --git a/.gitignore b/.gitignore index a711a09f..5ea1a17b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # build output /target/ +# release packages (packaging/*/package.*) +/dist/ # sample plug-ins built by examples/plugins/build.sh (sources are committed, binaries never) /examples/plugins/dist/ /examples/plugins/target/ diff --git a/packaging/.shellcheckrc b/packaging/.shellcheckrc new file mode 100644 index 00000000..36c19d06 --- /dev/null +++ b/packaging/.shellcheckrc @@ -0,0 +1,3 @@ +# shellcheck config for the packaging scripts (CI: .github/workflows/packaging-lint.yml). +source-path=SCRIPTDIR +external-sources=true diff --git a/packaging/check-icons.sh b/packaging/check-icons.sh new file mode 100644 index 00000000..f724e017 --- /dev/null +++ b/packaging/check-icons.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Check that every icon file the packaging uses exists and has the size it claims, without +# building anything. packaging-lint runs it (storytold/craft-common-actions). +# +# bash packaging/check-icons.sh +set -euo pipefail +# shellcheck source=env.sh +. "$(dirname "${BASH_SOURCE[0]}")/env.sh" +ICONS="$ROOT/assets/app-icon" +failed=0 +need() { + if [[ ! -s "$1" ]]; then + echo "error: missing icon $1" >&2 + failed=1 + fi + return 0 +} + +# PNG width and height are big-endian at bytes 16..23 of the IHDR chunk. +png_size() { + od -An -tu1 -j16 -N8 "$1" | awk '{ printf "%dx%d", $1*16777216 + $2*65536 + $3*256 + $4, $5*16777216 + $6*65536 + $7*256 + $8 }' + return 0 +} + +# Windows: the .ico build.rs embeds and the MSI's shortcut and Add/Remove Programs icon. +need "$ICONS/anicraft.ico" +# macOS: package.sh makes AniCraft.icns from the tile on Apple's grid. +need "$ICONS/anicraft-padded-1024.png" +# Linux: hicolor theme icons (desktop entry, AppStream, MIME type, AppImage, Flatpak). +for s in 16 24 32 48 64 128 256 512; do + png="$ICONS/hicolor/${s}x${s}/apps/$APP_ID.png" + need "$png" + if [[ -s "$png" ]] && [[ "$(png_size "$png")" != "${s}x${s}" ]]; then + echo "error: $png is $(png_size "$png"), expected ${s}x${s}" >&2 + failed=1 + fi +done +need "$ICONS/hicolor/scalable/apps/$APP_ID.svg" +if [[ -s "$ICONS/anicraft-padded-1024.png" ]] && [[ "$(png_size "$ICONS/anicraft-padded-1024.png")" != "1024x1024" ]]; then + echo "error: anicraft-padded-1024.png is not 1024x1024" >&2 + failed=1 +fi + +if [[ "$failed" != 0 ]]; then exit 1; fi +echo "app icons ok" diff --git a/packaging/env.sh b/packaging/env.sh new file mode 100644 index 00000000..8d4c9927 --- /dev/null +++ b/packaging/env.sh @@ -0,0 +1,83 @@ +# shellcheck shell=bash +# Shared setup for the packaging scripts. Source it: `. "$(dirname "$0")/../env.sh"`. +# The family's shared release workflow (storytold/craft-common-actions) sources it too: it reads +# VERSION and finds the ANICRAFT_ prefix in the VERSION line below. +# +# Exports: +# ROOT workspace root +# VERSION [workspace.package] version from Cargo.toml (override: ANICRAFT_VERSION) +# DIST output directory for release artifacts (default: $ROOT/dist/release) +# ANICRAFT_BUILD_SHA git commit of the build (Info.plist, logs) +# ANICRAFT_BUILD_DATE UTC build date, YYYY-MM-DD (AppStream release date) +# CARGO_TARGET_DIR cargo's target dir (default: $ROOT/target) + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +export ROOT + +# The version lives in exactly one place: `[workspace.package] version` in the root Cargo.toml. +workspace_version() { + awk ' + /^\[/ { in_pkg = ($0 == "[workspace.package]") ; next } + in_pkg && $1 == "version" { gsub(/[" \r]/, "", $3); print $3; exit } + ' "$ROOT/Cargo.toml" + return 0 +} + +VERSION="${ANICRAFT_VERSION:-$(workspace_version)}" +if [[ -z "$VERSION" ]]; then + echo "error: could not read [workspace.package] version from $ROOT/Cargo.toml" >&2 + exit 1 +fi +export VERSION + +DIST="${DIST:-$ROOT/dist/release}" +mkdir -p "$DIST" +export DIST + +if [[ -z "${ANICRAFT_BUILD_SHA:-}" ]]; then + ANICRAFT_BUILD_SHA="$(git -C "$ROOT" rev-parse HEAD 2>/dev/null || true)" +fi +export ANICRAFT_BUILD_SHA +export ANICRAFT_BUILD_DATE="${ANICRAFT_BUILD_DATE:-$(date -u +%Y-%m-%d)}" +export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/target}" + +# The app id, used for the desktop entry, AppStream, MIME package, icons, the macOS bundle id and +# the window's Wayland app_id / X11 class (src/platform.rs). One value everywhere. +export APP_ID=ai.storyteller.anicraft + +# Emit a GitHub Actions warning (plain stderr outside Actions). +warn() { + if [[ -n "${GITHUB_ACTIONS:-}" ]]; then echo "::warning::$*"; else echo "warning: $*" >&2; fi + return 0 +} + +# Copy the licence, notice and readme files into a package directory, plus the licences of the +# craft-fonts fonts the build embedded. +copy_docs() { + local dest="$1" f + for f in README.md LICENSE-MIT LICENSE-APACHE NOTICE ATTRIBUTION.md; do + if [[ -f "$ROOT/$f" ]]; then cp "$ROOT/$f" "$dest/"; fi + done + copy_font_licences "$dest" + return 0 +} + +# Builds made with craft-fonts (CRAFT_FONTS_DIR, every official release) embed its OFL-1.1 fonts: +# ship each font's licence as OFL-.txt. Does nothing without CRAFT_FONTS_DIR. +copy_font_licences() { + local dest="$1" lic family + if [[ -z "${CRAFT_FONTS_DIR:-}" ]]; then return 0; fi + for lic in "$CRAFT_FONTS_DIR"/fonts/*/OFL.txt; do + [[ -f "$lic" ]] || continue + family="$(basename "$(dirname "$lic")")" + cp "$lic" "$dest/OFL-$family.txt" + done + return 0 +} + +# Portable SHA-256 of a file (prints just the hash). +sha256() { + local file="$1" + if command -v sha256sum >/dev/null; then sha256sum "$file" | cut -d' ' -f1; else shasum -a 256 "$file" | cut -d' ' -f1; fi + return 0 +} diff --git a/packaging/windows/INSTALLATION.md b/packaging/windows/INSTALLATION.md new file mode 100644 index 00000000..b2f4c7f8 --- /dev/null +++ b/packaging/windows/INSTALLATION.md @@ -0,0 +1,34 @@ +# Windows installation policy checks + +New installations default to the current account under `Programs\ArtCraft\`. +The first setup page offers installation for everyone. Scope is selected before duplicate +checks and directory costing. An update uses the existing context's remembered exact folder; +`INSTALLFOLDER` supplied explicitly is never replaced. It is a secure MSI property so the +chosen folder reaches the elevated installer. Silent machine updates pass `ALLUSERS=1`. +A cross-context copy is refused; changing context means uninstalling the old copy first. + +App registration follows the selected context. Existing optional shortcuts and file-handler +choices stay app-owned. Uninstalling removes the program files and registrations only: +preferences, plug-ins and crash-recovery copies in `%APPDATA%\AniCraft` belong to the user and +stay. + +## Repeatable metadata tests + +On Windows with WiX 5.0.2 and its matching UI/Util extensions: + +```powershell +./packaging/windows/test-install-policy.ps1 -OutputDirectory ./target/install-policy-tests +``` + +The script builds x64, x86 and arm64 packages with deliberately non-executable payloads. It +uses the actual package source and compiled database. A safe Windows Installer session checks +24 scope/registration/maintenance cases, remembered and explicit custom folders, sequencing, +upgrade identity and the original registration inventory recorded in `install-policy.json`. +The release packaging script runs the compiled checker before signing. Packaging CI runs the +small fixture builds without compiling the Rust application. + +Never install or distribute the `NOT-INSTALLABLE.msi` fixtures as an app. Passing these checks +does not prove real installation, elevation, legacy-version upgrades, registry writes, optional +shortcut/menu behaviour, cancellation, rollback or uninstall. Those still require the real +payload in an authorised clean Windows test environment. Cross-architecture metadata is not +execution evidence on those architectures. diff --git a/packaging/windows/README.md b/packaging/windows/README.md new file mode 100644 index 00000000..de083b1c --- /dev/null +++ b/packaging/windows/README.md @@ -0,0 +1,4 @@ +# Windows packaging + +`package.ps1` builds the MSI, the portable zip and the debug symbols (see `docs/release.md`). +See [installation policy checks](INSTALLATION.md) for the installer scope and path gates. diff --git a/packaging/windows/anicraft.en-us.wxl b/packaging/windows/anicraft.en-us.wxl new file mode 100644 index 00000000..b9a057d8 --- /dev/null +++ b/packaging/windows/anicraft.en-us.wxl @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/packaging/windows/anicraft.wxs b/packaging/windows/anicraft.wxs new file mode 100644 index 00000000..e40c60cf --- /dev/null +++ b/packaging/windows/anicraft.wxs @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packaging/windows/check-icons.ps1 b/packaging/windows/check-icons.ps1 new file mode 100644 index 00000000..62239399 --- /dev/null +++ b/packaging/windows/check-icons.ps1 @@ -0,0 +1,51 @@ +<# +.SYNOPSIS + Check the MSI's icon references without building or installing AniCraft. + +.DESCRIPTION + ICE50 requires advertised shortcut icon identifiers to have the target file's extension. + Windows Installer uses those identifiers as cached file names; an identifier without the + extension can show a generic icon even when the ICO and the app are fine. Also checks that + the ICO the build embeds exists. Runs in packaging-lint (Linux pwsh) and in package.ps1. +#> +param( + [string] $WxsPath = (Join-Path $PSScriptRoot 'anicraft.wxs') +) +$ErrorActionPreference = 'Stop' +$Root = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path +$Ico = Join-Path (Join-Path (Join-Path $Root 'assets') 'app-icon') 'anicraft.ico' +if (-not (Test-Path -LiteralPath $Ico)) { throw "The app icon $Ico is missing." } + +[xml] $Wxs = Get-Content -LiteralPath $WxsPath -Raw +$Ns = [Xml.XmlNamespaceManager]::new($Wxs.NameTable) +$Ns.AddNamespace('w', 'http://wixtoolset.org/schemas/v4/wxs') +$Icons = @{} +foreach ($icon in $Wxs.SelectNodes('//w:Icon', $Ns)) { + $Icons[$icon.GetAttribute('Id')] = $icon +} + +foreach ($shortcut in $Wxs.SelectNodes('//w:File/w:Shortcut[@Advertise="yes"]', $Ns)) { + $id = $shortcut.GetAttribute('Id') + $iconId = $shortcut.GetAttribute('Icon') + if (-not $Icons.ContainsKey($iconId)) { + throw "Advertised shortcut '$id' references missing icon '$iconId'." + } + $iconExtension = [IO.Path]::GetExtension($iconId) + if ($iconExtension -notin '.exe', '.ico') { + throw "Advertised shortcut '$id' icon '$iconId' must have an .exe or .ico extension (ICE50)." + } + $file = $shortcut.ParentNode + $fileName = if ($file.HasAttribute('Name')) { $file.GetAttribute('Name') } else { $file.GetAttribute('Source') } + # Source paths use Windows separators even when this check runs on Linux in packaging-lint. + $fileName = ($fileName -split '[\\/]')[-1] + $targetExtension = [IO.Path]::GetExtension($fileName) + if ($iconExtension -ne $targetExtension) { + throw "Advertised shortcut '$id' icon '$iconId' must match target '$fileName' extension '$targetExtension' (ICE50)." + } +} + +$arpIcon = $Wxs.SelectSingleNode('//w:Property[@Id="ARPPRODUCTICON"]', $Ns) +if ($arpIcon -and -not $Icons.ContainsKey($arpIcon.GetAttribute('Value'))) { + throw "ARPPRODUCTICON references missing icon '$($arpIcon.GetAttribute('Value'))'." +} +Write-Output 'Windows icon references ok' diff --git a/packaging/windows/check-install-policy.ps1 b/packaging/windows/check-install-policy.ps1 new file mode 100644 index 00000000..5463c008 --- /dev/null +++ b/packaging/windows/check-install-policy.ps1 @@ -0,0 +1,370 @@ +<# +.SYNOPSIS + Check the compiled installation policy without installing any product. +.DESCRIPTION + Uses Windows Installer's safe session (OpenPackage option 1). Only property-setting custom + actions are exercised. No AppSearch, install, repair, removal or file-writing action runs. +#> +param([Parameter(Mandatory = $true)] [string] $MsiPath) +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version Latest +$policy = Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'install-policy.json') | ConvertFrom-Json +function Read-Rows($Database, [string] $Sql, [int] $Columns) { + $view = $Database.OpenView($Sql) + try { + [void]$view.Execute() + while ($null -ne ($record = $view.Fetch())) { + try { + $values = @(for ($i = 1; $i -le $Columns; $i++) { + $record.GetType().InvokeMember('StringData', 'GetProperty', $null, $record, @($i)) + }) + ,$values + } finally { [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($record) } + } + } finally { + [void]$view.Close() + [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($view) + } +} +function Set-SessionProperty($Session, [string] $Name, [string] $Value) { + [void]$Session.GetType().InvokeMember('Property', 'SetProperty', $null, $Session, @($Name, $Value)) +} +function Get-SessionProperty($Session, [string] $Name) { + $Session.GetType().InvokeMember('Property', 'GetProperty', $null, $Session, @($Name)) +} +function Get-PackageTemplate($Database) { + # Summary information property 7 is the platform: "Intel;1033", "x64;1033" or "Arm64;1033". + $summary = $Database.GetType().InvokeMember('SummaryInformation', 'GetProperty', $null, $Database, @(0)) + try { [string]$summary.GetType().InvokeMember('Property', 'GetProperty', $null, $summary, @(7)) } + finally { [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($summary) } +} +$installer = $null; $database = $null; $session = $null +try { + $installer = New-Object -ComObject WindowsInstaller.Installer + $file = (Resolve-Path -LiteralPath $MsiPath).Path + $database = $installer.OpenDatabase($file, 0) + $session = $installer.OpenPackage($file, 1) + $properties = @{} + foreach ($row in (Read-Rows $database 'SELECT `Property`, `Value` FROM `Property`' 2)) { $properties[$row[0]] = $row[1] } + $secureProperties = @($properties['SecureCustomProperties'] -split ';') + if ('INSTALLFOLDER' -notin $secureProperties) { + throw 'The selected installation folder must survive elevation (secure INSTALLFOLDER).' + } + if ($policy.mode -eq 'perUser') { + if ($properties.ContainsKey('ALLUSERS')) { throw 'Launcher must remain per-user; machine self-update is not part of this change.' } + if ($properties['UpgradeCode'].Trim('{}') -ne $policy.upgradeCode) { throw 'Launcher upgrade identity changed.' } + $dirs = @{} + foreach ($row in (Read-Rows $database 'SELECT `Directory`, `Directory_Parent`, `DefaultDir` FROM `Directory`' 3)) { $dirs[$row[0]] = @($row[1],$row[2]) } + if ($dirs['INSTALLFOLDER'][0] -ne 'CraftSuiteFolder' -or $dirs['CraftSuiteFolder'][1] -ne 'ArtCraft' -or + $dirs['CraftSuiteFolder'][0] -ne 'LocalProgramsFolder' -or $dirs['LocalProgramsFolder'][0] -ne 'LocalAppDataFolder') { + throw 'Launcher new-install folder must be under the per-user ArtCraft suite root.' + } + foreach ($explicit in @('', 'F:\Chosen exact launcher')) { + Set-SessionProperty $session 'PREVIOUSINSTALLFOLDER' 'E:\Existing exact launcher' + Set-SessionProperty $session 'INSTALLFOLDER' $explicit + $row = @(Read-Rows $database 'SELECT `Condition` FROM `InstallUISequence` WHERE `Action` = ''CraftRestoreLauncherFolder''' 1)[0] + if ($session.EvaluateCondition($row[0]) -eq 1) { + if ($session.DoAction('CraftRestoreLauncherFolder') -ne 1) { throw 'Launcher restore action failed.' } + } + $expected = if ($explicit) { $explicit } else { 'E:\Existing exact launcher' } + if ((Get-SessionProperty $session 'INSTALLFOLDER') -ne $expected) { throw 'Launcher custom or existing path was lost.' } + } + $rows = @(Read-Rows $database 'SELECT `Root`, `Key`, `Name`, `Value` FROM `Registry`' 4) + if (@($rows | Where-Object { $_[0] -ne '1' }).Count) { throw 'Launcher registration must stay under the current account.' } + foreach ($entry in $policy.registry) { + if (@($rows | Where-Object { $_[0] -eq $entry[0] -and $_[1] -eq $entry[1] -and $_[2] -eq $entry[2] -and $_[3] -eq $entry[3] }).Count -ne 1) { + throw 'Launcher registration or shortcut preference changed unexpectedly.' + } + } + Write-Output 'PASS ArtCraft Launcher: per-user scope, suite folder, remembered/custom paths and existing registration. No installation performed.' + return + } + if ($properties['ALLUSERS'] -ne '2' -or $properties['MSIINSTALLPERUSER'] -ne '1') { + throw 'Policy regression: new packages must default to the per-user dual-scope context.' + } + if ($properties['UpgradeCode'].Trim('{}') -ne $policy.upgradeCode) { throw 'The existing upgrade identity must not change.' } + $directories = @{} + foreach ($row in (Read-Rows $database 'SELECT `Directory`, `Directory_Parent`, `DefaultDir` FROM `Directory`' 3)) { + $directories[$row[0]] = @($row[1], $row[2]) + } + if ($directories['INSTALLFOLDER'][0] -ne 'CraftSuiteFolder' -or + $directories['CraftSuiteFolder'][1] -ne 'ArtCraft') { throw 'Expected the app under the ArtCraft suite folder.' } + $programs = $directories['CraftSuiteFolder'][0] + if ($programs -eq 'ProgramFiles6432Folder') { $programs = $directories[$programs][0] } + if ($programs -notin 'ProgramFilesFolder', 'ProgramFiles64Folder') { + throw 'Use Windows Installer native folder redirection, not a hard-coded profile path.' + } + $guards = @(Read-Rows $database 'SELECT `Condition`, `Description` FROM `LaunchCondition`' 2 | + Where-Object { $_[0] -match 'CRAFT_(USER|MACHINE)_DIR' }) + if ($guards.Count -ne 2) { throw 'Expected both duplicate-installation guards.' } + $cases = 0 + foreach ($scope in @('', '2', '1')) { + foreach ($user in @('', 'D:\Existing user app')) { + foreach ($machine in @('', 'E:\Existing machine app')) { + foreach ($installed in @('', '1')) { + Set-SessionProperty $session 'ALLUSERS' $scope + Set-SessionProperty $session 'Installed' $installed + Set-SessionProperty $session 'CRAFT_USER_DIR' $user + Set-SessionProperty $session 'CRAFT_MACHINE_DIR' $machine + $allowed = $true + foreach ($guard in $guards) { + $value = $session.EvaluateCondition($guard[0]) + if ($value -notin 0, 1) { throw 'Invalid duplicate guard.' } + if ($value -eq 0) { $allowed = $false } + } + $opposite = if ($scope -eq '1') { $user } else { $machine } + $expected = [bool]$installed -or -not [bool]$opposite + if ($allowed -ne $expected) { throw "Scope regression: ALLUSERS='$scope', user=$([bool]$user), machine=$([bool]$machine), maintenance=$([bool]$installed)." } + $cases++ + } + } + } + } + # Execute the actual authored type-51 actions in a safe session, not copied resolver logic. + foreach ($scope in @('', '2', '1')) { + foreach ($explicit in @('', 'F:\Chosen exact app')) { + Set-SessionProperty $session 'ALLUSERS' $scope + Set-SessionProperty $session 'INSTALLFOLDER' $explicit + Set-SessionProperty $session 'CRAFT_USER_DIR' 'D:\Existing user app' + Set-SessionProperty $session 'CRAFT_MACHINE_DIR' 'E:\Existing machine app' + $action = if ($scope -eq '1') { 'CraftRestoreMachineFolder' } else { 'CraftRestoreUserFolder' } + # Evaluate the compiled condition, so the test exercises it instead of calling the action directly. + $restore = @(Read-Rows $database ('SELECT `Condition` FROM `InstallExecuteSequence` WHERE `Action` = ''{0}''' -f $action) 1)[0] + $selected = $session.EvaluateCondition($restore[0]) -eq 1 + if ($selected -eq [bool]$explicit) { throw "$action must run only when no folder was supplied (condition: $($restore[0]))." } + if ($selected -and $session.DoAction($action) -ne 1) { throw 'Remembered-folder property action failed.' } + $expected = if ($explicit) { $explicit } elseif ($scope -eq '1') { 'E:\Existing machine app' } else { 'D:\Existing user app' } + if ((Get-SessionProperty $session 'INSTALLFOLDER') -ne $expected) { throw 'Custom or remembered folder was not preserved.' } + } + } + $ui = @{} + foreach ($row in (Read-Rows $database 'SELECT `Action`, `Sequence` FROM `InstallUISequence`' 2)) { $ui[$row[0]] = [int]$row[1] } + if (-not ($ui['AppSearch'] -lt $ui['CraftPreferMachineScope'] -and + $ui['CraftPreferMachineScope'] -lt $ui['CraftScopeDlg'] -and + $ui['CraftScopeDlg'] -lt $ui['FindRelatedProducts'] -and + $ui['FindRelatedProducts'] -lt $ui['LaunchConditions'] -and + $ui['CraftScopeDlg'] -lt $ui['CraftRestoreUserFolder'] -and $ui['CraftRestoreUserFolder'] -lt $ui['CostInitialize'] -and + $ui['CraftScopeDlg'] -lt $ui['CraftRestoreMachineFolder'] -and $ui['CraftRestoreMachineFolder'] -lt $ui['CostInitialize'])) { + throw 'Scope must be chosen after AppSearch and before FindRelatedProducts, launch checks and costing.' + } + # Windows Installer resolves Program Files for the context it started in, before the wizard's scope choice. + # The wizard therefore sets the new-install folder itself, and only in the wizard. + $defaults = @(Read-Rows $database 'SELECT `Action`, `Sequence`, `Condition` FROM `InstallUISequence`' 3 | Where-Object { $_[0] -like 'CraftDefault*' }) + if ($defaults.Count -lt 2) { throw 'The wizard must set the new-install folder after the scope page; Program Files is resolved before the choice.' } + foreach ($row in $defaults) { + if (-not ($ui['CraftScopeDlg'] -lt [int]$row[1] -and [int]$row[1] -lt $ui['CostInitialize'])) { throw "$($row[0]) must run after the scope page and before costing." } + } + if (@(Read-Rows $database 'SELECT `Action` FROM `InstallExecuteSequence`' 1 | Where-Object { $_[0] -like 'CraftDefault*' }).Count) { + throw 'Silent installs must not use the wizard-only default folder actions.' + } + # The machine default comes from the environment of the package architecture, not from a folder name. + # x86 packages use Program Files (x86) on 64-bit Windows; x64 and Arm64 packages use the 64-bit root. + $machineRoot = if ((Get-PackageTemplate $database) -match '^Intel') { + if (Get-SessionProperty $session 'VersionNT64') { ${env:ProgramFiles(x86)} } else { $env:ProgramFiles } + } elseif ($env:ProgramW6432) { $env:ProgramW6432 } else { $env:ProgramFiles } + $machineFolder = (Join-Path $machineRoot "ArtCraft\$($policy.name)") + '\' + foreach ($scope in @('1', '')) { + Set-SessionProperty $session 'ALLUSERS' $scope + Set-SessionProperty $session 'INSTALLFOLDER' '' + Set-SessionProperty $session 'CRAFT_MACHINE_DIR' '' + Set-SessionProperty $session 'CRAFT_USER_DIR' '' + foreach ($row in @($defaults | Sort-Object { [int]$_[1] })) { + if ($session.EvaluateCondition($row[2]) -eq 1 -and $session.DoAction($row[0]) -ne 1) { throw "$($row[0]) failed." } + } + $folder = Get-SessionProperty $session 'INSTALLFOLDER' + $wanted = if ($scope -eq '1') { $machineFolder } else { (Join-Path $env:LOCALAPPDATA "Programs\ArtCraft\$($policy.name)") + '\' } + if ($folder -ine $wanted) { throw "Wizard default folder for ALLUSERS='$scope' is '$folder', expected '$wanted'." } + } + # Replay the wizard's compiled folder actions in sequence order, as the full UI runs them. A remembered + # folder must win over the new-install default, and a folder the user typed must survive both. + $uiFolderActions = @(Read-Rows $database 'SELECT `Action`, `Sequence`, `Condition` FROM `InstallUISequence`' 3 | + Where-Object { $_[0] -match '^Craft(Restore|Default)' } | Sort-Object { [int]$_[1] }) + $userDefault = (Join-Path $env:LOCALAPPDATA "Programs\ArtCraft\$($policy.name)") + '\' + foreach ($case in @( + @('1', 'D:\Remembered user app', 'E:\Remembered machine app', '', 'E:\Remembered machine app'), + @('', 'D:\Remembered user app', 'E:\Remembered machine app', '', 'D:\Remembered user app'), + @('1', '', '', '', $machineFolder), + @('', '', '', '', $userDefault), + @('1', 'D:\Remembered user app', 'E:\Remembered machine app', 'F:\Chosen exact app', 'F:\Chosen exact app'))) { + Set-SessionProperty $session 'Installed' '' + Set-SessionProperty $session 'ALLUSERS' $case[0] + Set-SessionProperty $session 'CRAFT_USER_DIR' $case[1] + Set-SessionProperty $session 'CRAFT_MACHINE_DIR' $case[2] + Set-SessionProperty $session 'INSTALLFOLDER' $case[3] + foreach ($row in $uiFolderActions) { + if ($session.EvaluateCondition($row[2]) -eq 1 -and $session.DoAction($row[0]) -ne 1) { throw "$($row[0]) failed." } + } + $folder = Get-SessionProperty $session 'INSTALLFOLDER' + if ($folder -ine $case[4]) { throw "Full-UI folder for ALLUSERS='$($case[0])' is '$folder', expected '$($case[4])'." } + } + $execute = @{} + foreach ($row in (Read-Rows $database 'SELECT `Action`, `Sequence` FROM `InstallExecuteSequence`' 2)) { $execute[$row[0]] = [int]$row[1] } + foreach ($action in @('CraftRestoreUserFolder','CraftRestoreMachineFolder')) { + if (-not ($execute['AppSearch'] -lt $execute[$action] -and $execute[$action] -lt $execute['CostInitialize'])) { + throw 'Silent updates must restore the folder before directory costing.' + } + } + foreach ($resolver in @('CraftUFromLegacyExe','CraftMFromLegacyExe')) { + if (-not ($execute['AppSearch'] -lt $execute[$resolver] -and $execute[$resolver] -lt $execute['LaunchConditions'])) { + throw 'Both legacy folder resolvers must run after AppSearch and before the launch checks.' + } + } + # AppSearch itself never runs in this safe session, so check the compiled searches and then run the + # property actions that turn the search results into the remembered folder, once per scope. + $appSearch = @{} + foreach ($row in (Read-Rows $database 'SELECT `Property`, `Signature_` FROM `AppSearch`' 2)) { $appSearch[$row[0]] = $row[1] } + $locators = @{} + foreach ($row in (Read-Rows $database 'SELECT `Signature_`, `Root`, `Key`, `Name`, `Type` FROM `RegLocator`' 5)) { $locators[$row[0]] = $row } + $appPaths = '^Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\[^\\]+\.exe$' + # Suffix, how to match the key, key, value name, locator type (2 = raw value, 1 = file; the 64-bit flag is masked off). + $searchContract = @( + @('DIR', 'exact', "Software\$($policy.name)", 'InstallDir', '2'), + @('FOLDER', 'exact', "Software\$($policy.name)", 'InstallFolder', '2'), + @('PATH', 'regex', $appPaths, 'Path', '2'), + @('EXEFOLDER', 'regex', $appPaths, '', '1'), + @('EXE', 'regex', $appPaths, '', '1')) + $resolverCases = @( + @{ name = 'every record, DIR wins'; dir = 'D:\Dir\'; folder = 'D:\Folder\'; path = 'D:\Path\'; exeFolder = 'D:\Exe\'; exe = 'D:\Exe\app.exe'; existing = ''; expected = 'D:\Dir\' }, + @{ name = 'FOLDER wins without DIR'; dir = ''; folder = 'D:\Folder\'; path = 'D:\Path\'; exeFolder = 'D:\Exe\'; exe = 'D:\Exe\app.exe'; existing = ''; expected = 'D:\Folder\' }, + @{ name = 'PATH wins without DIR, FOLDER'; dir = ''; folder = ''; path = 'D:\Path\'; exeFolder = 'D:\Exe\'; exe = 'D:\Exe\app.exe'; existing = ''; expected = 'D:\Path\' }, + @{ name = 'legacy exe folder is last'; dir = ''; folder = ''; path = ''; exeFolder = 'D:\Exe\'; exe = 'D:\Exe\app.exe'; existing = ''; expected = 'D:\Exe\' }, + @{ name = 'legacy folder needs the exe'; dir = ''; folder = ''; path = ''; exeFolder = 'D:\Exe\'; exe = ''; existing = ''; expected = '' }, + @{ name = 'a preset folder is kept'; dir = 'D:\Dir\'; folder = 'D:\Folder\'; path = 'D:\Path\'; exeFolder = 'D:\Exe\'; exe = 'D:\Exe\app.exe'; existing = 'P:\Preset\'; expected = 'P:\Preset\' }) + foreach ($scopeSpec in @(@('U', '1', 'CRAFT_USER_DIR'), @('M', '2', 'CRAFT_MACHINE_DIR'))) { + $letter = $scopeSpec[0]; $target = $scopeSpec[2] + foreach ($item in $searchContract) { + $property = "CRAFT_${letter}_$($item[0])" + $locator = if ($appSearch.ContainsKey($property)) { $locators[$appSearch[$property]] } else { $null } + $keyOk = $null -ne $locator -and $(if ($item[1] -eq 'exact') { $locator[2] -eq $item[2] } else { $locator[2] -match $item[2] }) + if (-not $keyOk -or $locator[1] -ne $scopeSpec[1] -or $locator[3] -ne $item[3] -or ([int]$locator[4] -band 3) -ne [int]$item[4]) { + throw "Compiled search for $property is missing or points at the wrong registry location." + } + } + $chain = @(Read-Rows $database 'SELECT `Action`, `Sequence`, `Condition` FROM `InstallExecuteSequence`' 3 | + Where-Object { $_[0] -match "^Craft${letter}From" } | Sort-Object { [int]$_[1] }) + $order = @($chain | ForEach-Object { $_[0] }) -join ',' + if ($order -ne "Craft${letter}FromDIR,Craft${letter}FromFOLDER,Craft${letter}FromPATH,Craft${letter}FromLegacyExe") { + throw "Remembered-folder resolvers for scope $letter run in the wrong order: $order" + } + foreach ($case in $resolverCases) { + Set-SessionProperty $session $target $case.existing + Set-SessionProperty $session "CRAFT_${letter}_DIR" $case.dir + Set-SessionProperty $session "CRAFT_${letter}_FOLDER" $case.folder + Set-SessionProperty $session "CRAFT_${letter}_PATH" $case.path + Set-SessionProperty $session "CRAFT_${letter}_EXEFOLDER" $case.exeFolder + Set-SessionProperty $session "CRAFT_${letter}_EXE" $case.exe + foreach ($row in $chain) { + if ($session.EvaluateCondition($row[2]) -eq 1 -and $session.DoAction($row[0]) -ne 1) { throw "$($row[0]) failed." } + } + $got = Get-SessionProperty $session $target + if ($got -ne $case.expected) { throw "Resolver chain for scope $letter, case '$($case.name)': got '$got', expected '$($case.expected)'." } + } + } + # Switching the first-page choice must reset BOTH properties, including a back-and-forth change. + $events = @(Read-Rows $database 'SELECT `Event`, `Argument`, `Condition`, `Ordering` FROM `ControlEvent` WHERE `Dialog_` = ''CraftScopeDlg'' AND `Control_` = ''Next'' ORDER BY `Ordering`' 4) + # Model the full-UI upgrade entry with an existing machine-wide copy. Run + # the actual preference action, then the compiled Next events before discovery. + Set-SessionProperty $session 'ALLUSERS' '2' + Set-SessionProperty $session 'CRAFT_SCOPE' 'user' + Set-SessionProperty $session 'CRAFT_USER_DIR' '' + Set-SessionProperty $session 'CRAFT_MACHINE_DIR' 'E:\Existing machine app' + $preference = @(Read-Rows $database 'SELECT `Condition` FROM `InstallUISequence` WHERE `Action` = ''CraftPreferMachineScope''' 1)[0] + if ($session.EvaluateCondition($preference[0]) -ne 1 -or $session.DoAction('CraftPreferMachineScope') -ne 1 -or + (Get-SessionProperty $session 'CRAFT_SCOPE') -ne 'machine') { + throw 'Full-UI machine upgrades must initially select the existing machine context.' + } + foreach ($choice in @('machine','user','machine','user')) { + Set-SessionProperty $session 'CRAFT_SCOPE' $choice + foreach ($event in $events) { + if ($event[0] -notmatch '^\[([^\]]+)\]$') { continue } + $property = $Matches[1] + if ($session.EvaluateCondition($event[2]) -eq 1) { + Set-SessionProperty $session $property $(if ($event[1] -eq '{}') { '' } else { $event[1] }) + } + } + $allUsers = Get-SessionProperty $session 'ALLUSERS' + $perUser = Get-SessionProperty $session 'MSIINSTALLPERUSER' + if (($choice -eq 'machine' -and ($allUsers -ne '1' -or $perUser)) -or + ($choice -eq 'user' -and ($allUsers -or $perUser -ne '1'))) { + throw 'Scope selector does not reset the requested installation context.' + } + } + $actions = @(Read-Rows $database 'SELECT `Action`, `Source`, `Target`, `Type` FROM `CustomAction`' 4) + $savedOptions = @($actions | Where-Object { $_[0] -match '^CraftLoadOption[0-9]+M$' }) + foreach ($option in $savedOptions) { + if ([int]$option[3] -ne 51) { throw 'Saved-option test may run only property-setting actions.' } + $number = [regex]::Match($option[0], '[0-9]+').Value + foreach ($scope in @('2','1')) { + Set-SessionProperty $session 'ALLUSERS' $scope + Set-SessionProperty $session "CRAFT_OPTION_${number}_M" 'saved-machine-choice' + Set-SessionProperty $session "CRAFT_OPTION_${number}_U" 'saved-user-choice' + Set-SessionProperty $session $option[1] '' + $action = "CraftLoadOption$number" + $(if ($scope -eq '1') { 'M' } else { 'U' }) + if ($session.DoAction($action) -ne 1) { throw 'Saved-option property action failed.' } + $expected = if ($scope -eq '1') { 'saved-machine-choice' } else { 'saved-user-choice' } + if ((Get-SessionProperty $session $option[1]) -ne $expected) { throw 'Saved installer choices leaked across contexts.' } + } + } + # Follow the compiled control conditions, not the source's intended appearance. + $controls = @(Read-Rows $database 'SELECT `Dialog_`, `Control`, `Type`, `Attributes`, `Text` FROM `Control`' 5) + $conditions = @() + if (@(Read-Rows $database 'SELECT `Name` FROM `_Tables` WHERE `Name` = ''ControlCondition''' 1).Count) { + $conditions = @(Read-Rows $database 'SELECT `Dialog_`, `Control_`, `Action`, `Condition` FROM `ControlCondition`' 4) + } + function Test-ControlVisible($Control) { + $visible = ([int]$Control[3] -band 1) -ne 0 + foreach ($condition in $conditions) { + if ($condition[0] -eq $Control[0] -and $condition[1] -eq $Control[1] -and $session.EvaluateCondition($condition[3]) -eq 1) { + if ($condition[2] -eq 'Show') { $visible = $true } + if ($condition[2] -eq 'Hide') { $visible = $false } + } + } + return $visible + } + foreach ($button in @($controls | Where-Object { $_[0] -in 'InstallWelcome','InstallMaintenance','DesktopShortcutDlg' -and ([int]$_[3] -band 8388608) -ne 0 })) { + $plain = @($controls | Where-Object { $_[0] -eq $button[0] -and $_[1] -eq ($button[1] + 'User') }) + if ($plain.Count -ne 1 -or ([int]$plain[0][3] -band 8388608)) { throw 'Scope-aware buttons need an unshielded per-user counterpart.' } + foreach ($scope in @('', '2', '1')) { + Set-SessionProperty $session 'ALLUSERS' $scope + if ((Test-ControlVisible $button) -ne ($scope -eq '1') -or (Test-ControlVisible $plain[0]) -ne ($scope -ne '1')) { + throw 'The elevation shield must follow the selected scope.' + } + } + $dialog = $button[0]; $shieldId = $button[1]; $plainId = $plain[0][1] + $shieldEvents = @(Read-Rows $database "SELECT ``Event``, ``Argument``, ``Condition``, ``Ordering`` FROM ``ControlEvent`` WHERE ``Dialog_`` = '$dialog' AND ``Control_`` = '$shieldId' ORDER BY ``Ordering``" 4 | ForEach-Object { $_ -join '|' }) + $plainEvents = @(Read-Rows $database "SELECT ``Event``, ``Argument``, ``Condition``, ``Ordering`` FROM ``ControlEvent`` WHERE ``Dialog_`` = '$dialog' AND ``Control_`` = '$plainId' ORDER BY ``Ordering``" 4 | ForEach-Object { $_ -join '|' }) + if (($shieldEvents -join "`n") -ne ($plainEvents -join "`n")) { throw 'Per-user and machine buttons must perform the same operation.' } + } + foreach ($scope in @('', '2', '1')) { + Set-SessionProperty $session 'ALLUSERS' $scope + foreach ($text in @($controls | Where-Object { $_[4] -like '*for all users*' })) { + if ((Test-ControlVisible $text) -ne ($scope -eq '1')) { throw 'The welcome-page scope text must follow the selected scope.' } + } + } + if ($policy.id -in 'deckcraft','filmcraft','soundcraft') { + foreach ($route in @(@('WelcomeDlg','Next','InstallDirDlg'),@('InstallDirDlg','Back','WelcomeDlg'))) { + $dialog = $route[0]; $control = $route[1] + $routes = @(Read-Rows $database "SELECT ``Argument``, ``Condition`` FROM ``ControlEvent`` WHERE ``Dialog_`` = '$dialog' AND ``Control_`` = '$control' AND ``Event`` = 'NewDialog' ORDER BY ``Ordering``" 2) + Set-SessionProperty $session 'Installed' '' + $destination = '' + foreach ($event in $routes) { if ($session.EvaluateCondition($event[1]) -eq 1) { $destination = $event[0] } } + if ($destination -ne $route[2]) { throw 'Skipping the licence page must work in both navigation directions.' } + } + } + $registry = @(Read-Rows $database 'SELECT `Root`, `Key`, `Name`, `Value` FROM `Registry`' 4) + if (@($registry | Where-Object { $_[0] -in '1', '2' }).Count) { throw 'Registration must follow the selected context, not force HKCU or HKLM.' } + if (@($registry | Where-Object { $_[0] -eq '0' -and $_[1] -match '^Software\\Classes(\\|$)' }).Count) { + throw 'HKCR keys must be relative to Classes.' + } + foreach ($entry in $policy.registry) { + $found = @($registry | Where-Object { $_[0] -eq $entry[0] -and $_[1] -eq $entry[1] -and $_[2] -eq $entry[2] -and $_[3] -eq $entry[3] }) + if ($found.Count -ne 1) { throw "Lost or changed registration: $($entry[1]) / $($entry[2])" } + } + $installDir = @($registry | Where-Object { $_[0] -eq '-1' -and $_[1] -eq "Software\$($policy.name)" -and $_[2] -eq 'InstallDir' -and $_[3] -eq '[INSTALLFOLDER]' }) + if ($installDir.Count -ne 1) { throw 'A context-sensitive installation-folder record is required.' } + Write-Output "PASS $($policy.name): $cases scope cases, folder preservation, action sequencing and registry contract. No installation performed." +} finally { + foreach ($com in @($session, $database, $installer)) { + if ($null -ne $com) { [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($com) } + } +} diff --git a/packaging/windows/install-policy.json b/packaging/windows/install-policy.json new file mode 100644 index 00000000..7f65d551 --- /dev/null +++ b/packaging/windows/install-policy.json @@ -0,0 +1,83 @@ +{ + "id": "anicraft", + "name": "AniCraft", + "upgradeCode": "95D4D208-47EF-42CD-9127-28D9A7BA88A2", + "sources": [ + "anicraft.wxs" + ], + "icon": "assets/app-icon/anicraft.ico", + "localization": [ + "anicraft.en-us.wxl" + ], + "extensions": [ + "UI", + "Util" + ], + "payloads": [ + "anicraft-cli.exe", + "anicraft.exe" + ], + "registry": [ + [ + "-1", + "Software\\Classes\\Anicraft.Import\\shell\\open\\command", + "", + "\"[#AnicraftExe]\" \"%1\"" + ], + [ + "-1", + "Software\\Classes\\.fla\\OpenWithProgids", + "Anicraft.Import", + "" + ], + [ + "-1", + "Software\\Classes\\.xfl\\OpenWithProgids", + "Anicraft.Import", + "" + ], + [ + "-1", + "Software\\Classes\\Applications\\anicraft.exe", + "FriendlyAppName", + "AniCraft" + ], + [ + "-1", + "Software\\Classes\\Applications\\anicraft.exe\\shell\\open\\command", + "", + "\"[#AnicraftExe]\" \"%1\"" + ], + [ + "-1", + "Software\\Classes\\Applications\\anicraft.exe\\SupportedTypes", + ".anicraft", + "" + ], + [ + "-1", + "Software\\Classes\\Applications\\anicraft.exe\\SupportedTypes", + ".fla", + "" + ], + [ + "-1", + "Software\\Classes\\Applications\\anicraft.exe\\SupportedTypes", + ".xfl", + "" + ], + [ + "-1", + "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\anicraft.exe", + "", + "[#AnicraftExe]" + ], + [ + "-1", + "Software\\AniCraft", + "InstallDir", + "[INSTALLFOLDER]" + ] + ], + "mode": "dualScope" +} diff --git a/packaging/windows/install-policy.wxi b/packaging/windows/install-policy.wxi new file mode 100644 index 00000000..97229e43 --- /dev/null +++ b/packaging/windows/install-policy.wxi @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packaging/windows/package.ps1 b/packaging/windows/package.ps1 new file mode 100644 index 00000000..d2eb2000 --- /dev/null +++ b/packaging/windows/package.ps1 @@ -0,0 +1,217 @@ +<# +.SYNOPSIS + Build, sign and package AniCraft for Windows. + +.DESCRIPTION + Produces, in $env:DIST (default: dist/release): + anicraft--windows-.msi installer (WiX v5, per-user by default, everyone optional) + anicraft--windows--portable.zip anicraft.exe + anicraft-cli.exe + notices + anicraft--windows--symbols.zip anicraft.pdb + anicraft_cli.pdb (optional, for profilers) + + The installer registers .anicraft (AniCraft is its default app) and offers AniCraft under + "Open with" for .fla and .xfl. The binaries link the C runtime statically (+crt-static), so + neither the MSI nor the portable zip needs the Visual C++ redistributable. Signing is + delegated to sign.ps1, which warns and leaves files unsigned when no signing secrets are set. + + Needs: Rust (MSVC toolchain + the target), the Windows SDK (rc.exe, signtool.exe), + and WiX v5: dotnet tool install --global wix --version 5.0.2 + wix extension add -g WixToolset.UI.wixext/5.0.2 WixToolset.Util.wixext/5.0.2 + +.EXAMPLE + pwsh packaging/windows/package.ps1 -Arch x64 + pwsh packaging/windows/package.ps1 -Arch x64 -SkipBuild + pwsh packaging/windows/package.ps1 -Arch arm64 # cross-compiled; needs the MSVC ARM64 build tools +#> +param( + [ValidateSet('x64', 'x86', 'arm64')] [string] $Arch = 'x64', + [switch] $SkipBuild +) +$ErrorActionPreference = 'Stop' +$Root = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path +$AppId = 'ai.storyteller.anicraft' + +function Invoke-Native([string] $What, [scriptblock] $Block) { + Write-Output "==> $What" + & $Block + if ($LASTEXITCODE -ne 0) { throw "$What failed with exit code $LASTEXITCODE" } +} + +# The version lives in one place: [workspace.package] version in the root Cargo.toml. +# ANICRAFT_VERSION (set by the shared release workflow from packaging/env.sh) overrides it. +$Version = $env:ANICRAFT_VERSION +if (-not $Version) { + $inPkg = $false + foreach ($line in Get-Content (Join-Path $Root 'Cargo.toml')) { + if ($line -match '^\s*\[') { $inPkg = ($line.Trim() -eq '[workspace.package]'); continue } + if ($inPkg -and $line -match '^\s*version\s*=\s*"([^"]+)"') { $Version = $Matches[1]; break } + } +} +if (-not $Version) { throw 'could not read [workspace.package] version from Cargo.toml' } +# MSI ProductVersion is numeric (major.minor.build); pre-release tags are dropped there. +$MsiVersion = ($Version -split '-')[0] + +$Target = switch ($Arch) { 'x64' { 'x86_64-pc-windows-msvc' } 'x86' { 'i686-pc-windows-msvc' } 'arm64' { 'aarch64-pc-windows-msvc' } } +$Dist = if ($env:DIST) { $env:DIST } else { Join-Path $Root 'dist\release' } +$TargetDir = if ($env:CARGO_TARGET_DIR) { $env:CARGO_TARGET_DIR } else { Join-Path $Root 'target' } +New-Item -ItemType Directory -Force -Path $Dist | Out-Null + +Write-Output "AniCraft $Version for Windows $Arch ($Target)" + +if (-not $SkipBuild) { + # Static CRT: no VC++ redistributable needed. Scoped to the target so host build scripts and + # proc-macros are unaffected. + $flagVar = 'CARGO_TARGET_' + ($Target.ToUpper() -replace '-', '_') + '_RUSTFLAGS' + [Environment]::SetEnvironmentVariable($flagVar, '-C target-feature=+crt-static') + # Fail the build (rather than warn) if build.rs can't embed the icon and version resource. + $env:ANICRAFT_REQUIRE_WINRES = '1' + Invoke-Native "cargo build ($Target)" { cargo build --release --locked -p anicraft -p anicraft-cli --target $Target } +} + +$Bin = Join-Path $TargetDir "$Target\release" + +# Check both binaries' PE headers before packaging. Machine (COFF header) must match -Arch, so an +# x64 build can never ship labelled arm64. Subsystem (optional header): 2 = Windows GUI, 3 = console. +# The app must be GUI (no console window opens with it); the CLI must stay console so its output +# reaches the terminal. +function Get-PeHeader([string] $Path) { + $bytes = [System.IO.File]::ReadAllBytes($Path) + $pe = [BitConverter]::ToInt32($bytes, 0x3C) + return @{ Machine = [BitConverter]::ToUInt16($bytes, $pe + 4); Subsystem = [BitConverter]::ToUInt16($bytes, $pe + 0x5C) } +} +$Machine = switch ($Arch) { 'x64' { 0x8664 } 'x86' { 0x14C } 'arm64' { 0xAA64 } } +foreach ($check in @(@('anicraft.exe', 2), @('anicraft-cli.exe', 3))) { + $h = Get-PeHeader (Join-Path $Bin $check[0]) + if ($h.Machine -ne $Machine) { throw "$($check[0]) is for machine 0x$('{0:X}' -f $h.Machine), expected 0x$('{0:X}' -f $Machine) ($Arch)" } + if ($h.Subsystem -ne $check[1]) { throw "$($check[0]) has PE subsystem $($h.Subsystem), expected $($check[1])" } + Write-Output "ok $($check[0]): $Arch, PE subsystem $($h.Subsystem)" +} +$Stage = Join-Path $TargetDir "windows-package\$Arch" +Remove-Item -Recurse -Force $Stage -ErrorAction SilentlyContinue +New-Item -ItemType Directory -Force -Path $Stage | Out-Null +Copy-Item (Join-Path $Bin 'anicraft.exe'), (Join-Path $Bin 'anicraft-cli.exe') $Stage + +& (Join-Path $PSScriptRoot 'sign.ps1') (Join-Path $Stage 'anicraft.exe') (Join-Path $Stage 'anicraft-cli.exe') + +# ---- notices ----------------------------------------------------------------------------------- +# Installed next to the app: our licences, the dependencies' notices and the OFL licences of the +# craft-fonts typefaces the build embedded (every official release builds with CRAFT_FONTS_DIR). +$Docs = Join-Path $Stage 'notices' +New-Item -ItemType Directory -Force -Path $Docs | Out-Null +foreach ($f in 'README.md', 'LICENSE-MIT', 'LICENSE-APACHE', 'NOTICE', 'ATTRIBUTION.md') { + Copy-Item -LiteralPath (Join-Path $Root $f) -Destination $Docs +} +if ($env:CRAFT_FONTS_DIR) { + foreach ($ofl in Get-ChildItem -Path (Join-Path $env:CRAFT_FONTS_DIR 'fonts\*\OFL.txt') -File -ErrorAction SilentlyContinue) { + Copy-Item -LiteralPath $ofl.FullName -Destination (Join-Path $Docs "OFL-$($ofl.Directory.Name).txt") + } +} + +# ---- MSI --------------------------------------------------------------------------------------- +# The setup wizard's art, drawn here from the app icon so the MSI shows AniCraft rather than +# WiX's stock bitmaps: a 493x58 banner across the top of the inner pages (the page title is drawn +# over its left side, so that stays white) and a 493x312 backdrop for the Welcome and Finish pages +# (their text sits on the right; the left 164 px are ours). Both must be 24-bit BMPs. The colours +# are the icon's (assets/app-icon/README.md): Paper and the AniCraft yellow. +function New-InstallerArt([string] $IconPng, [string] $BannerOut, [string] $DialogOut) { + Add-Type -AssemblyName System.Drawing + $paper = [System.Drawing.ColorTranslator]::FromHtml('#f2f1ee') + $accent = [System.Drawing.ColorTranslator]::FromHtml('#dac604') + $icon = [System.Drawing.Image]::FromFile($IconPng) + try { + foreach ($spec in @(@($BannerOut, 493, 58), @($DialogOut, 493, 312))) { + $bmp = New-Object System.Drawing.Bitmap $spec[1], $spec[2], ([System.Drawing.Imaging.PixelFormat]::Format24bppRgb) + $g = [System.Drawing.Graphics]::FromImage($bmp) + try { + $g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic + $g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias + $g.Clear([System.Drawing.Color]::White) + if ($spec[2] -eq 58) { + $g.DrawImage($icon, 493 - 46 - 8, 6, 46, 46) + } else { + $panel = New-Object System.Drawing.SolidBrush $paper + $stripe = New-Object System.Drawing.SolidBrush $accent + $g.FillRectangle($panel, 0, 0, 164, 312) + $g.FillRectangle($stripe, 160, 0, 4, 312) + $g.DrawImage($icon, 18, 64, 124, 124) + $panel.Dispose(); $stripe.Dispose() + } + } finally { $g.Dispose() } + $bmp.Save($spec[0], [System.Drawing.Imaging.ImageFormat]::Bmp) + $bmp.Dispose() + } + } finally { $icon.Dispose() } +} +$Banner = Join-Path $Stage 'installer-banner.bmp' +$Dialog = Join-Path $Stage 'installer-dialog.bmp' +New-InstallerArt (Join-Path $Root "assets\app-icon\hicolor\256x256\apps\$AppId.png") $Banner $Dialog + +$Msi = Join-Path $Dist "anicraft-$Version-windows-$Arch.msi" +& (Join-Path $PSScriptRoot 'check-icons.ps1') +Invoke-Native 'wix build' { + wix build (Join-Path $PSScriptRoot 'anicraft.wxs') -arch $Arch ` + -ext WixToolset.UI.wixext -ext WixToolset.Util.wixext ` + -culture en-US -loc (Join-Path $PSScriptRoot 'anicraft.en-us.wxl') ` + -d "Version=$MsiVersion" -d "DisplayVersion=$Version" -d "BinDir=$Stage" -d "IconPath=$(Join-Path $Root 'assets\app-icon\anicraft.ico')" ` + -d "BannerBmp=$Banner" -d "DialogBmp=$Dialog" -d "DocsDir=$Docs" ` + -o $Msi +} +Invoke-Native 'MSI shortcut icon validation (ICE50)' { + wix msi validate $Msi -ice ICE50 -intermediateFolder (Join-Path $Stage 'msi-validation') +} +# Inspect the compiled tables and evaluate the scope and duplicate guards with Windows Installer. +# ICE validation alone cannot catch a well-formed condition with its meaning reversed. +& (Join-Path $PSScriptRoot 'check-install-policy.ps1') -MsiPath $Msi +# wix writes its debug symbols (.wixpdb) next to the MSI; keep them out of the release assets. +Remove-Item -Force -ErrorAction SilentlyContinue ([IO.Path]::ChangeExtension($Msi, '.wixpdb')) +& (Join-Path $PSScriptRoot 'sign.ps1') $Msi + +# ---- portable zip ------------------------------------------------------------------------------ +# The exes and notices at the archive's root (`\*`, not the folder itself), so they come +# out side by side wherever it is extracted. Settings still live in %APPDATA%\AniCraft. +$Portable = Join-Path $TargetDir "windows-package\anicraft-$Version-windows-$Arch-portable" +Remove-Item -Recurse -Force $Portable -ErrorAction SilentlyContinue +New-Item -ItemType Directory -Force -Path $Portable | Out-Null +Copy-Item (Join-Path $Stage '*.exe') $Portable +Copy-Item (Join-Path $Docs '*') $Portable +$Zip = Join-Path $Dist "anicraft-$Version-windows-$Arch-portable.zip" +Remove-Item -Force $Zip -ErrorAction SilentlyContinue +Compress-Archive -Path (Join-Path $Portable '*') -DestinationPath $Zip +$Check = Join-Path $TargetDir 'windows-package\portable-zip-check' +Remove-Item -Recurse -Force $Check -ErrorAction SilentlyContinue +Expand-Archive -Path $Zip -DestinationPath $Check -Force +foreach ($f in 'anicraft.exe', 'anicraft-cli.exe', 'NOTICE') { + if (-not (Test-Path (Join-Path $Check $f))) { throw "the portable zip has no $f at its root: $Zip" } +} +Remove-Item -Recurse -Force $Check -ErrorAction SilentlyContinue + +# ---- debug symbols ----------------------------------------------------------------------------- +# The MSVC linker writes a PDB beside each exe (anicraft.pdb, anicraft_cli.pdb). They ship as a +# separate, optional download so profilers show AniCraft's function names for the released +# binaries. Signing doesn't change the PDB signature an exe records, so they match the signed exes. +$Outputs = @($Msi, $Zip) +$Pdbs = @('anicraft.pdb', 'anicraft_cli.pdb' | ForEach-Object { Join-Path $Bin $_ }) +if (@($Pdbs | Where-Object { -not (Test-Path $_) }).Count -eq 0) { + $Symbols = Join-Path $TargetDir "windows-package\anicraft-$Version-windows-$Arch-symbols" + Remove-Item -Recurse -Force $Symbols -ErrorAction SilentlyContinue + New-Item -ItemType Directory -Force -Path $Symbols | Out-Null + Copy-Item $Pdbs $Symbols + Copy-Item (Join-Path $PSScriptRoot 'symbols.txt') $Symbols + $SymbolsZip = Join-Path $Dist "anicraft-$Version-windows-$Arch-symbols.zip" + Remove-Item -Force $SymbolsZip -ErrorAction SilentlyContinue + Compress-Archive -Path (Join-Path $Symbols '*') -DestinationPath $SymbolsZip + $Outputs += $SymbolsZip +} elseif ($env:GITHUB_ACTIONS) { + Write-Output "::warning::no PDBs in $Bin, so there is no symbols zip" +} else { + Write-Warning "no PDBs in $Bin, so there is no symbols zip" +} + +# Smoke-test the CLI when this machine can run it. An ARM64 build made on an x64 runner can't run +# here; .github/workflows/windows-arm64.yml installs and runs it on ARM64 instead. +$HostArch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant() +if ($Arch -ne 'arm64' -or $HostArch -eq 'arm64') { + Invoke-Native 'anicraft-cli --version' { & (Join-Path $Stage 'anicraft-cli.exe') --version } +} else { + Write-Output "skipping anicraft-cli --version: an $Arch build doesn't run on this $HostArch machine" +} +Get-Item $Outputs | Format-Table Name, Length diff --git a/packaging/windows/sign.ps1 b/packaging/windows/sign.ps1 new file mode 100644 index 00000000..44c48dd1 --- /dev/null +++ b/packaging/windows/sign.ps1 @@ -0,0 +1,110 @@ +<# +.SYNOPSIS + Authenticode-sign files with signtool, using whichever signing material is configured. + +.DESCRIPTION + Tries, in order: + 1. A code-signing certificate file: WINDOWS_CERTIFICATE (base64 .pfx), WINDOWS_CERTIFICATE_PASSWORD + 2. Azure Trusted Signing: AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, + AZURE_SIGNING_ENDPOINT (e.g. https://eus.codesigning.azure.net), + AZURE_SIGNING_ACCOUNT, AZURE_CERT_PROFILE + With neither, it prints a warning and leaves the files unsigned (exit code 0), so test builds + still produce installers. + + This is the one place to adapt when the signing setup changes (an HSM/cloud key, a different + timestamp server, ...). Optional overrides: WINDOWS_TIMESTAMP_URL, SIGNTOOL (path to signtool.exe). + +.EXAMPLE + pwsh packaging/windows/sign.ps1 dist/anicraft.exe dist/Photocraft.msi +#> +param( + [Parameter(Mandatory = $true, ValueFromRemainingArguments = $true)] + [string[]] $Files +) +$ErrorActionPreference = 'Stop' + +# Azure Trusted Signing loads this NuGet package's dlib into signtool, beside the signing secrets, +# so the package is pinned to a reviewed version and SHA-256 and refused on any mismatch (#2936). +# Upgrading is a deliberate change to both values: download +# https://www.nuget.org/api/v2/package/Microsoft.Trusted.Signing.Client/ and record +# (Get-FileHash -Algorithm SHA256 ).Hash. +$TrustedSigningClient = @{ + Version = '1.0.95' + Sha256 = '3BFCF1E0A3CB42AF1692F0A8ED45C15DE070C2DE86F28A59B2795D904D8A920F' +} + +function Write-Warn([string] $Message) { + if ($env:GITHUB_ACTIONS) { Write-Output "::warning::$Message" } else { Write-Warning $Message } +} + +function Find-SignTool { + if ($env:SIGNTOOL) { return $env:SIGNTOOL } + $onPath = Get-Command signtool.exe -ErrorAction SilentlyContinue + if ($onPath) { return $onPath.Source } + $kits = Join-Path ${env:ProgramFiles(x86)} 'Windows Kits\10\bin' + $found = Get-ChildItem -Path $kits -Recurse -Filter signtool.exe -ErrorAction SilentlyContinue | + Where-Object { $_.FullName -match '\\x64\\signtool\.exe$' } | + Sort-Object FullName -Descending | Select-Object -First 1 + if (-not $found) { throw 'signtool.exe not found (install the Windows SDK)' } + return $found.FullName +} + +function Invoke-SignTool([string[]] $Arguments) { + & $script:SignTool @Arguments + if ($LASTEXITCODE -ne 0) { throw "signtool $($Arguments[0]) failed with exit code $LASTEXITCODE" } +} + +$Files = $Files | ForEach-Object { (Resolve-Path $_).Path } +$haveCert = [bool]$env:WINDOWS_CERTIFICATE +$azureVars = 'AZURE_TENANT_ID', 'AZURE_CLIENT_ID', 'AZURE_CLIENT_SECRET', 'AZURE_SIGNING_ENDPOINT', 'AZURE_SIGNING_ACCOUNT', 'AZURE_CERT_PROFILE' +$haveAzure = -not ($azureVars | Where-Object { -not [Environment]::GetEnvironmentVariable($_) }) + +if (-not $haveCert -and -not $haveAzure) { + Write-Warn "Windows signing secrets not set (WINDOWS_CERTIFICATE or AZURE_*): leaving unsigned: $($Files -join ', ')" + exit 0 +} + +$script:SignTool = Find-SignTool +$common = @('sign', '/v', '/fd', 'SHA256', '/td', 'SHA256', '/d', 'AniCraft', '/du', 'https://github.com/storytold/AniCraft') +$tmp = Join-Path ([IO.Path]::GetTempPath()) "anicraft-sign-$PID" +New-Item -ItemType Directory -Force -Path $tmp | Out-Null + +try { + if ($haveCert) { + Write-Output "Signing with WINDOWS_CERTIFICATE: $($Files -join ', ')" + $pfx = Join-Path $tmp 'cert.pfx' + [IO.File]::WriteAllBytes($pfx, [Convert]::FromBase64String($env:WINDOWS_CERTIFICATE)) + $ts = if ($env:WINDOWS_TIMESTAMP_URL) { $env:WINDOWS_TIMESTAMP_URL } else { 'http://timestamp.digicert.com' } + $signArgs = $common + @('/tr', $ts, '/f', $pfx) + if ($env:WINDOWS_CERTIFICATE_PASSWORD) { $signArgs += @('/p', $env:WINDOWS_CERTIFICATE_PASSWORD) } + Invoke-SignTool ($signArgs + $Files) + } + else { + Write-Output "Signing with Azure Trusted Signing ($env:AZURE_SIGNING_ACCOUNT / $env:AZURE_CERT_PROFILE): $($Files -join ', ')" + # The dlib authenticates with DefaultAzureCredential, which reads AZURE_TENANT_ID, + # AZURE_CLIENT_ID and AZURE_CLIENT_SECRET from the environment. + $pkg = Join-Path $tmp 'trusted-signing.zip' + $version = $TrustedSigningClient.Version + Invoke-WebRequest -Uri "https://www.nuget.org/api/v2/package/Microsoft.Trusted.Signing.Client/$version" -OutFile $pkg + $sha256 = (Get-FileHash -Algorithm SHA256 -Path $pkg).Hash + if ($sha256 -ne $TrustedSigningClient.Sha256) { + throw "Microsoft.Trusted.Signing.Client $version has SHA-256 $sha256, expected $($TrustedSigningClient.Sha256): refusing to load it" + } + Expand-Archive -Path $pkg -DestinationPath (Join-Path $tmp 'client') -Force + $dlib = Get-ChildItem -Path (Join-Path $tmp 'client') -Recurse -Filter Azure.CodeSigning.Dlib.dll | + Where-Object { $_.FullName -match '\\x64\\' } | Select-Object -First 1 + if (-not $dlib) { throw 'Azure.CodeSigning.Dlib.dll not found in Microsoft.Trusted.Signing.Client' } + $metadata = Join-Path $tmp 'metadata.json' + @{ + Endpoint = $env:AZURE_SIGNING_ENDPOINT + CodeSigningAccountName = $env:AZURE_SIGNING_ACCOUNT + CertificateProfileName = $env:AZURE_CERT_PROFILE + } | ConvertTo-Json | Set-Content -Path $metadata -Encoding utf8 + $ts = if ($env:WINDOWS_TIMESTAMP_URL) { $env:WINDOWS_TIMESTAMP_URL } else { 'http://timestamp.acs.microsoft.com' } + Invoke-SignTool ($common + @('/tr', $ts, '/dlib', $dlib.FullName, '/dmdf', $metadata) + $Files) + } + Invoke-SignTool (@('verify', '/pa', '/v') + $Files) +} +finally { + Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue +} diff --git a/packaging/windows/symbols.txt b/packaging/windows/symbols.txt new file mode 100644 index 00000000..db6d890a --- /dev/null +++ b/packaging/windows/symbols.txt @@ -0,0 +1,22 @@ +AniCraft debug symbols + +anicraft.pdb and anicraft_cli.pdb are the debug symbols of anicraft.exe and +anicraft-cli.exe from the release with the same version and architecture as this zip. They +were written by the same build as those exes, so they match only them: a PDB from a local build +of the same commit doesn't. + +They hold AniCraft's function names (release builds carry no source line tables), which is +what a profiler needs to show where the time goes. AniCraft doesn't need them to run. + +To use them, either copy both files next to anicraft.exe (the installer's folder, by default +%LOCALAPPDATA%\Programs\ArtCraft\AniCraft, or C:\Program Files\ArtCraft\AniCraft when +installed for everyone), or add this folder to the profiler's symbol path: + + Windows Performance Analyzer: Trace > Configure Symbol Paths, add this folder, then + Trace > Load Symbols. + Superluminal: Settings > Symbols, add this folder as a symbol location. + Visual Studio: Tools > Options > Debugging > Symbols, add this folder. + Any tool reading _NT_SYMBOL_PATH: set _NT_SYMBOL_PATH to this folder. + +When you share a profile in an AniCraft issue, say which version and architecture you ran +(Help > About). diff --git a/packaging/windows/test-install-policy.ps1 b/packaging/windows/test-install-policy.ps1 new file mode 100644 index 00000000..d455d19d --- /dev/null +++ b/packaging/windows/test-install-policy.ps1 @@ -0,0 +1,54 @@ +<# +.SYNOPSIS + Build non-executable installer metadata fixtures; never install them. +#> +param( + [Parameter(Mandatory = $true)] [string] $OutputDirectory, + [ValidateSet('x64','x86','arm64')] [string[]] $Architectures = @('x64','x86','arm64') +) +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version Latest +$root = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path +$policy = Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'install-policy.json') | ConvertFrom-Json +[void](New-Item -ItemType Directory -Force -Path $OutputDirectory) +$output = (Resolve-Path -LiteralPath $OutputDirectory).Path +Add-Type -AssemblyName System.Drawing +foreach ($arch in $Architectures) { + $stage = Join-Path $output $arch + [void](New-Item -ItemType Directory -Force -Path $stage) + foreach ($name in $policy.payloads) { + $destination = Join-Path $stage $name + [void](New-Item -ItemType Directory -Force -Path ([IO.Path]::GetDirectoryName($destination))) + Set-Content -LiteralPath $destination -Encoding Ascii -Value 'NON-EXECUTABLE MSI METADATA TEST FIXTURE' + } + foreach ($folder in @('docs','models','notices')) { + $path = Join-Path $stage $folder + [void](New-Item -ItemType Directory -Force -Path $path) + Set-Content -LiteralPath (Join-Path $path "$folder-fixture.txt") -Value 'Metadata test fixture, not a user file or model.' + } + foreach ($model in @('metadata-one.rten','metadata-two.rten')) { + Set-Content -LiteralPath (Join-Path (Join-Path $stage 'models') $model) -Encoding Ascii -Value 'NON-EXECUTABLE MODEL METADATA FIXTURE' + } + foreach ($spec in @(@('banner.bmp',493,58),@('dialog.bmp',493,312))) { + $bitmap = [Drawing.Bitmap]::new($spec[1],$spec[2],[Drawing.Imaging.PixelFormat]::Format24bppRgb) + try { $bitmap.Save((Join-Path $stage $spec[0]),[Drawing.Imaging.ImageFormat]::Bmp) } + finally { $bitmap.Dispose() } + } + Set-Content -LiteralPath (Join-Path $stage 'licence.rtf') -Encoding Ascii -Value '{\rtf1 Metadata test fixture.}' + $sources = @($policy.sources | ForEach-Object { Join-Path $PSScriptRoot $_ }) + $msi = Join-Path $stage "$($policy.id)-NOT-INSTALLABLE.msi" + $extensions = @($policy.extensions | ForEach-Object { '-ext'; "WixToolset.$_.wixext" }) + & wix build @sources -arch $arch @extensions ` + -culture en-US -d 'Version=0.0.1' -d 'DisplayVersion=0.0.1-metadata-test' ` + -d "BinDir=$stage" -d "IconPath=$(Join-Path $root $policy.icon)" ` + -d "DocsDir=$(Join-Path $stage 'docs')" -d "ModelsDir=$(Join-Path $stage 'models')" ` + -d "AppNoticesDir=$(Join-Path $stage 'notices')" -d 'HasCraftFontLicences=1' -d 'HasCli=1' ` + -d "BannerBmp=$(Join-Path $stage 'banner.bmp')" -d "DialogBmp=$(Join-Path $stage 'dialog.bmp')" ` + -d "UiBannerBmp=$(Join-Path $stage 'banner.bmp')" -d "UiDialogBmp=$(Join-Path $stage 'dialog.bmp')" ` + -d "LicenseRtf=$(Join-Path $stage 'licence.rtf')" -o $msi @($policy.localization | ForEach-Object { '-loc'; Join-Path $PSScriptRoot $_ }) + if ($LASTEXITCODE -ne 0) { throw "WiX validation failed for $arch (exit $LASTEXITCODE)." } + $shell = (Get-Process -Id $PID).Path + & $shell -NoProfile -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot 'check-install-policy.ps1') -MsiPath $msi + if ($LASTEXITCODE -ne 0) { throw "Compiled installer policy failed for $arch (exit $LASTEXITCODE)." } + Write-Output "PASS $arch metadata-only package. This is not an executable installer." +}