92 lines
7.6 KiB
PowerShell
92 lines
7.6 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[ValidateSet('Development','Store')][string]$Channel = 'Development',
|
|
[string]$IdentityFile,
|
|
[string]$AppDirectory,
|
|
[switch]$SignDevelopment,
|
|
[string]$SdkBin
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
. (Join-Path $PSScriptRoot 'hash-file.ps1')
|
|
$projectRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
|
|
if (-not $IdentityFile) { $IdentityFile = Join-Path $projectRoot $(if ($Channel -eq 'Store') { 'store\identity.store.json' } else { 'store\identity.dev.json' }) }
|
|
$identity = Get-Content -LiteralPath $IdentityFile -Raw | ConvertFrom-Json
|
|
foreach ($field in 'Name','Publisher','PublisherDisplayName','DisplayName','Version') {
|
|
if ([string]::IsNullOrWhiteSpace($identity.$field)) { throw "Store-Identität fehlt: $field. Werte aus Partner Center > Produktidentität in $IdentityFile eintragen." }
|
|
}
|
|
if ($identity.Name -notmatch '^[A-Za-z0-9.-]{3,50}$') { throw 'Ungültiger Package Identity Name.' }
|
|
if ($identity.Version -notmatch '^\d+\.\d+\.\d+\.0$') { throw 'MSIX-Version muss vier Zahlen enthalten; Store-Pakete enden auf .0.' }
|
|
foreach ($part in $identity.Version.Split('.')) { if ([int]$part -gt 65535) { throw 'Versionssegment zu groß.' } }
|
|
if ($Channel -eq 'Store' -and ($identity.Name -match 'Development|PLACEHOLDER' -or $identity.Publisher -eq 'CN=FileBow Development')) { throw 'Entwicklungsidentität darf nicht für den Store verwendet werden.' }
|
|
if ($Channel -eq 'Store' -and $SignDevelopment) { throw 'Store-Pakete erhalten keine Entwicklungssignatur.' }
|
|
if (-not $SdkBin) {
|
|
$candidates = @("$env:USERPROFILE\.nuget\packages\microsoft.windows.sdk.buildtools\10.0.26100.8249\bin\10.0.26100.0\x64")
|
|
$candidates += @(Get-ChildItem 'C:\Program Files (x86)\Windows Kits\10\bin' -Directory -ErrorAction SilentlyContinue | Sort-Object Name -Descending | ForEach-Object { Join-Path $_.FullName 'x64' })
|
|
$SdkBin = $candidates | Where-Object { Test-Path (Join-Path $_ 'makeappx.exe') } | Select-Object -First 1
|
|
}
|
|
if (-not $SdkBin) { throw 'Windows SDK BuildTools fehlt. Zuerst dotnet restore native/FileBow.Windows.csproj ausführen.' }
|
|
$appPath = if (-not $AppDirectory) { Join-Path $projectRoot 'out\FileBow-win32-x64' } elseif ([IO.Path]::IsPathRooted($AppDirectory)) { [IO.Path]::GetFullPath($AppDirectory) } else { [IO.Path]::GetFullPath((Join-Path $projectRoot $AppDirectory)) }
|
|
if (-not (Test-Path "$appPath\FileBow.exe")) { throw 'Zuerst pnpm build ausführen.' }
|
|
$appMetadata = Get-Content -LiteralPath (Join-Path $appPath 'resources\app\package.json') -Raw | ConvertFrom-Json
|
|
if ("$($appMetadata.version).0" -ne $identity.Version) { throw 'App version and MSIX identity version do not match. Rebuild the app before packaging.' }
|
|
$stage = [IO.Path]::GetFullPath((Join-Path $projectRoot "build\msix-$Channel-$([Guid]::NewGuid().ToString('N').Substring(0,8))"))
|
|
$expectedParent = [IO.Path]::GetFullPath((Join-Path $projectRoot 'build'))
|
|
if ([IO.Path]::GetDirectoryName($stage) -ne $expectedParent) { throw 'Unerwarteter Staging-Pfad.' }
|
|
New-Item -ItemType Directory -Path $stage | Out-Null
|
|
Copy-Item -LiteralPath $appPath -Destination (Join-Path $stage 'app') -Recurse
|
|
Copy-Item -LiteralPath (Join-Path $projectRoot 'store\Assets') -Destination (Join-Path $stage 'Assets') -Recurse
|
|
function XmlEscape([string]$value) { return [System.Security.SecurityElement]::Escape($value) }
|
|
$name = XmlEscape $identity.Name; $publisher = XmlEscape $identity.Publisher
|
|
$display = XmlEscape $identity.DisplayName; $publisherDisplay = XmlEscape $identity.PublisherDisplayName
|
|
$manifest = @"
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
|
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
|
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
|
|
xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10"
|
|
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
|
|
IgnorableNamespaces="uap desktop uap10 rescap">
|
|
<Identity Name="$name" Publisher="$publisher" Version="$($identity.Version)" ProcessorArchitecture="x64" />
|
|
<Properties><DisplayName>$display</DisplayName><PublisherDisplayName>$publisherDisplay</PublisherDisplayName><Logo>Assets\StoreLogo.png</Logo><Description>Convert, compress and edit files.</Description></Properties>
|
|
<Dependencies><TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.19041.0" MaxVersionTested="10.0.26100.0" /></Dependencies>
|
|
<Resources><Resource Language="en-us" /></Resources>
|
|
<Applications>
|
|
<Application Id="App" Executable="app\FileBow.exe" EntryPoint="Windows.FullTrustApplication" uap10:RuntimeBehavior="packagedClassicApp" uap10:TrustLevel="mediumIL">
|
|
<uap:VisualElements DisplayName="$display" Description="Convert and edit files" BackgroundColor="#14161B" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
|
|
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" Square71x71Logo="Assets\Square71x71Logo.png" Square310x310Logo="Assets\Square310x310Logo.png" />
|
|
</uap:VisualElements>
|
|
<Extensions>
|
|
<desktop:Extension Category="windows.startupTask" Executable="app\FileBow.exe" EntryPoint="Windows.FullTrustApplication" uap10:Parameters="--hidden">
|
|
<desktop:StartupTask TaskId="FileBowStartup" Enabled="false" DisplayName="$display" />
|
|
</desktop:Extension>
|
|
</Extensions>
|
|
</Application>
|
|
</Applications>
|
|
<Capabilities><rescap:Capability Name="runFullTrust" /></Capabilities>
|
|
</Package>
|
|
"@
|
|
[IO.File]::WriteAllText((Join-Path $stage 'AppxManifest.xml'), $manifest, [Text.UTF8Encoding]::new($false))
|
|
$outputDir = Join-Path $projectRoot 'out\msix'
|
|
New-Item -ItemType Directory -Force -Path $outputDir | Out-Null
|
|
$package = Join-Path $outputDir "FileBow_$($identity.Version)_x64_$Channel.msix"
|
|
$packLog = Join-Path $projectRoot "build\makeappx-$Channel.log"
|
|
& (Join-Path $SdkBin 'makeappx.exe') pack /d $stage /p $package /o /h SHA256 *> $packLog
|
|
if ($LASTEXITCODE -ne 0) { throw 'MakeAppx-Validierung fehlgeschlagen.' }
|
|
$certificatePath = $null
|
|
if ($SignDevelopment) {
|
|
# Load Windows modules explicitly when the parent shell supplies a different PSModulePath.
|
|
Import-Module (Join-Path $PSHOME 'Modules\Microsoft.PowerShell.Security\Microsoft.PowerShell.Security.psd1') -ErrorAction Stop
|
|
Import-Module (Join-Path $env:WINDIR 'System32\WindowsPowerShell\v1.0\Modules\PKI\PKI.psd1') -ErrorAction Stop
|
|
$certificate = Get-ChildItem Cert:\CurrentUser\My | Where-Object { $_.Subject -eq $identity.Publisher -and $_.FriendlyName -eq 'FileBow local development' -and $_.HasPrivateKey -and $_.NotAfter -gt (Get-Date).AddDays(7) } | Select-Object -First 1
|
|
if (-not $certificate) {
|
|
$certificate = New-SelfSignedCertificate -Type Custom -Subject $identity.Publisher -FriendlyName 'FileBow local development' -CertStoreLocation Cert:\CurrentUser\My -KeyUsage DigitalSignature -KeyExportPolicy NonExportable -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.3','2.5.29.19={text}') -NotAfter (Get-Date).AddYears(1)
|
|
}
|
|
& (Join-Path $SdkBin 'signtool.exe') sign /fd SHA256 /sha1 $certificate.Thumbprint /s My $package
|
|
if ($LASTEXITCODE -ne 0) { throw 'Signieren fehlgeschlagen.' }
|
|
$certificatePath = Join-Path $outputDir 'FileBow-Development.cer'
|
|
Export-Certificate -Cert $certificate -FilePath $certificatePath -Force | Out-Null
|
|
}
|
|
$record = @{ Channel=$Channel; Package=$package; AppDirectory=$appPath; Stage=$stage; Identity=$identity; Signed=[bool]$SignDevelopment; Certificate=$certificatePath; SHA256=(Get-FileBowSha256 $package); BuiltAt=(Get-Date).ToUniversalTime().ToString('o') }
|
|
$record | ConvertTo-Json -Depth 5 | Set-Content (Join-Path $outputDir "build-$Channel.json") -Encoding utf8
|
|
Write-Output $package
|