|
| 1 | +[CmdletBinding()] |
| 2 | +Param( |
| 3 | + [Parameter(Mandatory=$true, ValueFromPipeline=$true, |
| 4 | + HelpMessage="Path to the .appx/.msix to validate")] |
| 5 | + [string] |
| 6 | + $Path, |
| 7 | + |
| 8 | + [Parameter(HelpMessage="Path to Windows Kit")] |
| 9 | + [ValidateScript({Test-Path $_ -Type Leaf})] |
| 10 | + [string] |
| 11 | + $WindowsKitPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0" |
| 12 | +) |
| 13 | + |
| 14 | +$ErrorActionPreference = "Stop" |
| 15 | + |
| 16 | +If ($null -Eq (Get-Item $WindowsKitPath -EA:SilentlyContinue)) { |
| 17 | + Write-Error "Could not find a windows SDK at at `"$WindowsKitPath`".`nMake sure that WindowsKitPath points to a valid SDK." |
| 18 | + Exit 1 |
| 19 | +} |
| 20 | + |
| 21 | +$makeAppx = "$WindowsKitPath\x86\MakeAppx.exe" |
| 22 | +$makePri = "$WindowsKitPath\x86\MakePri.exe" |
| 23 | + |
| 24 | +Function Expand-ApplicationPackage { |
| 25 | + Param( |
| 26 | + [Parameter(Mandatory, ValueFromPipeline)] |
| 27 | + [string] |
| 28 | + $Path |
| 29 | + ) |
| 30 | + |
| 31 | + $sentinelFile = New-TemporaryFile |
| 32 | + $directory = New-Item -Type Directory "$($sentinelFile.FullName)_Package" |
| 33 | + Remove-Item $sentinelFile -Force -EA:Ignore |
| 34 | + |
| 35 | + & $makeAppx unpack /p $Path /d $directory /nv /o |
| 36 | + |
| 37 | + If ($LastExitCode -Ne 0) { |
| 38 | + Throw "Failed to expand AppX" |
| 39 | + } |
| 40 | + |
| 41 | + $directory |
| 42 | +} |
| 43 | + |
| 44 | +Write-Verbose "Expanding $Path" |
| 45 | +$AppxPackageRoot = Expand-ApplicationPackage $Path |
| 46 | +$AppxPackageRootPath = $AppxPackageRoot.FullName |
| 47 | + |
| 48 | +Write-Verbose "Expanded to $AppxPackageRootPath" |
| 49 | + |
| 50 | +Try { |
| 51 | + & $makePri dump /if "$AppxPackageRootPath\resources.pri" /of "$AppxPackageRootPath\resources.pri.xml" /o |
| 52 | + If ($LastExitCode -Ne 0) { |
| 53 | + Throw "Failed to dump PRI" |
| 54 | + } |
| 55 | + |
| 56 | + $Manifest = [xml](Get-Content "$AppxPackageRootPath\AppxManifest.xml") |
| 57 | + $PRIFile = [xml](Get-Content "$AppxPackageRootPath\resources.pri.xml") |
| 58 | + |
| 59 | + ### Check the activatable class entries for a few DLLs we need. |
| 60 | + $inProcServers = $Manifest.Package.Extensions.Extension.InProcessServer.Path |
| 61 | + $RequiredInProcServers = ("TerminalApp.dll", "TerminalControl.dll", "TerminalConnection.dll") |
| 62 | + |
| 63 | + Write-Verbose "InProc Servers: $inProcServers" |
| 64 | + |
| 65 | + ForEach ($req in $RequiredInProcServers) { |
| 66 | + If ($req -NotIn $inProcServers) { |
| 67 | + Throw "Failed to find $req in InProcServer list $inProcServers" |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + ### Check that we have an App.xbf (which is a proxy for our resources having been merged) |
| 72 | + $resourceXpath = '/PriInfo/ResourceMap/ResourceMapSubtree[@name="Files"]/NamedResource[@name="App.xbf"]' |
| 73 | + $AppXbf = $PRIFile.SelectSingleNode($resourceXpath) |
| 74 | + If ($null -eq $AppXbf) { |
| 75 | + Throw "Failed to find App.xbf (TerminalApp project) in resources.pri" |
| 76 | + } |
| 77 | +} Finally { |
| 78 | + Remove-Item -Recurse -Force $AppxPackageRootPath |
| 79 | +} |
0 commit comments