winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

Execute-AppxRecipe.ps1 (1814B)


      1 # Copyright (c) Microsoft Corporation.
      2 # Licensed under the MIT License.
      3 [CmdletBinding()]
      4 param(
      5     [Parameter(Mandatory=$true,Position=0)]
      6     [string]$AppxRecipePath,
      7 
      8     [string]$LayoutPath,
      9 
     10     [switch]$Force
     11 )
     12 
     13 [xml]$Local:recipe = Get-Content $AppxRecipePath
     14 
     15 if ([System.String]::IsNullOrEmpty($LayoutPath))
     16 {
     17     $LayoutPath = $Local:recipe.Project.PropertyGroup.LayoutDir
     18 }
     19 
     20 $Local:namespace = @{
     21     ns = "http://schemas.microsoft.com/developer/msbuild/2003"
     22 }
     23 
     24 $Local:manifestElement = Select-Xml -Xml $Local:recipe -Namespace $Local:namespace -XPath "//ns:AppXManifest" | Select-Object -ExpandProperty Node
     25 $Local:packageFileElements = Select-Xml -Xml $Local:recipe -Namespace $Local:namespace -XPath "//ns:AppxPackagedFile" | Select-Object -ExpandProperty Node
     26 
     27 $Local:allItems = $Local:packageFileElements + $Local:manifestElement
     28 
     29 $Local:progressActivity = "Copying files to $LayoutPath"
     30 Write-Progress -Activity $Local:progressActivity
     31 
     32 if ($Force) {
     33     $null = New-Item -Path $LayoutPath -ItemType Directory -Force
     34 } else {
     35     New-Item -Path $LayoutPath -ItemType Directory -ErrorAction Inquire
     36 }
     37 
     38 [Int32]$Local:filesCopied = 0
     39 
     40 $Local:allItems | ForEach-Object -Process {
     41     $Local:sourcePath = $_.Include
     42     $Local:destinationPath = Join-Path $LayoutPath $_.PackagePath
     43     Write-Verbose "$Local:sourcePath => $Local:destinationPath"
     44     $null = New-Item -Path ([System.IO.Path]::GetDirectoryName($Local:destinationPath)) -ItemType Directory -Force
     45     Copy-Item -Path $Local:sourcePath -Destination $Local:destinationPath
     46     $Local:filesCopied += 1
     47     Write-Progress -Activity $Local:progressActivity -PercentComplete (($Local:filesCopied * 100) / $Local:allItems.Count)
     48 }
     49 
     50 Write-Progress -Activity $Local:progressActivity -Completed