Refactor architecture handling for app downloads

Clarifies the distinction between the application architecture to be downloaded and the target Windows architecture for installer pruning.

Renames the `SelectedWindowsArch` parameter to `WindowsArch` and introduces a new `ApplicationArch` parameter. This makes the download and subsequent installer selection logic more explicit and easier to understand, especially for MS Store apps where multiple installers might be available.
This commit is contained in:
rbalsleyMSFT
2025-08-22 18:47:43 -07:00
parent 3f892493c0
commit 3e34bd6bff
3 changed files with 16 additions and 16 deletions
@@ -163,7 +163,7 @@ function Invoke-ParallelProcessing {
AppsPath = $localJobArgs['AppsPath'] AppsPath = $localJobArgs['AppsPath']
OrchestrationPath = $localJobArgs['OrchestrationPath'] OrchestrationPath = $localJobArgs['OrchestrationPath']
ProgressQueue = $localProgressQueue ProgressQueue = $localProgressQueue
SelectedWindowsArch = $localJobArgs['SelectedWindowsArch'] WindowsArch = $localJobArgs['WindowsArch']
} }
$taskResult = Start-WingetAppDownloadTask @wingetTaskArgs $taskResult = Start-WingetAppDownloadTask @wingetTaskArgs
if ($null -ne $taskResult) { if ($null -ne $taskResult) {
@@ -20,11 +20,11 @@ function Get-Application {
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$AppsPath, [string]$AppsPath,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$ApplicationArch,
[string]$WindowsArch, [string]$WindowsArch,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$OrchestrationPath, [string]$OrchestrationPath,
[switch]$SkipWin32Json, [switch]$SkipWin32Json
[string]$SelectedWindowsArch
) )
# Block Company Portal from winget source # Block Company Portal from winget source
@@ -89,8 +89,8 @@ function Get-Application {
return 1 # Return error code return 1 # Return error code
} }
# Determine architectures to download # Determine architectures to download (ApplicationArch controls download set; WindowsArch (optional) used later for pruning store installers)
$architecturesToDownload = if ($WindowsArch -eq 'x86 x64') { @('x86', 'x64') } else { @($WindowsArch) } $architecturesToDownload = if ($ApplicationArch -eq 'x86 x64') { @('x86', 'x64') } else { @($ApplicationArch) }
$overallResult = 0 $overallResult = 0
# For msstore, we don't specify architecture, so we only need to loop once. # For msstore, we don't specify architecture, so we only need to loop once.
@@ -253,11 +253,11 @@ function Get-Application {
} }
} }
# Clean up multiple versions honoring SelectedWindowsArch (keep only one installer) # Clean up multiple versions honoring WindowsArch (pruning target; keep only one installer)
WriteLog "$AppName has completed downloading. Evaluating installer set for pruning." WriteLog "$AppName has completed downloading. Evaluating installer set for pruning."
$packages = Get-ChildItem -Path "$appFolderPath\*" -Exclude "Dependencies\*", "*.xml", "*.yaml" -File -ErrorAction Stop $packages = Get-ChildItem -Path "$appFolderPath\*" -Exclude "Dependencies\*", "*.xml", "*.yaml" -File -ErrorAction Stop
if ($packages.Count -gt 1 -and $SelectedWindowsArch) { if ($packages.Count -gt 1 -and $WindowsArch) {
WriteLog "SelectedWindowsArch provided for pruning: $SelectedWindowsArch" WriteLog "WindowsArch pruning target provided: $WindowsArch"
# Detect universal bundles (contain x86,x64,arm64 in name) # Detect universal bundles (contain x86,x64,arm64 in name)
$universalCandidates = $packages | Where-Object { $universalCandidates = $packages | Where-Object {
$base = $_.BaseName $base = $_.BaseName
@@ -280,11 +280,11 @@ function Get-Application {
$candidateSet = $universalCandidates $candidateSet = $universalCandidates
} }
else { else {
$archToken = switch -Regex ($SelectedWindowsArch.ToLower()) { $archToken = switch -Regex ($WindowsArch.ToLower()) {
'^x64$' { 'x64' ; break } '^x64$' { 'x64' ; break }
'^x86$' { 'x86' ; break } '^x86$' { 'x86' ; break }
'^arm64$' { 'arm64' ; break } '^arm64$' { 'arm64' ; break }
default { $SelectedWindowsArch.ToLower() } default { $WindowsArch.ToLower() }
} }
$archMatches = $packages | Where-Object { $_.BaseName -match "(?i)$archToken" } $archMatches = $packages | Where-Object { $_.BaseName -match "(?i)$archToken" }
if ($archMatches) { if ($archMatches) {
@@ -313,7 +313,7 @@ function Get-Application {
} }
} }
elseif ($packages.Count -gt 1) { elseif ($packages.Count -gt 1) {
WriteLog "Multiple installers present but no SelectedWindowsArch supplied. Using original latest-version logic." WriteLog "Multiple installers present but no WindowsArch pruning target supplied. Using original latest-version logic."
$latestPackage = $packages | Sort-Object { (Get-AuthenticodeSignature $_.FullName).SignerCertificate.NotBefore } -Descending | Select-Object -First 1 $latestPackage = $packages | Sort-Object { (Get-AuthenticodeSignature $_.FullName).SignerCertificate.NotBefore } -Descending | Select-Object -First 1
WriteLog "Retaining latest by signature date: $($latestPackage.Name)" WriteLog "Retaining latest by signature date: $($latestPackage.Name)"
foreach ($package in $packages) { foreach ($package in $packages) {
@@ -389,7 +389,7 @@ function Get-Apps {
foreach ($wingetApp in $wingetApps) { foreach ($wingetApp in $wingetApps) {
try { try {
$appArch = if ($wingetApp.PSObject.Properties['architecture']) { $wingetApp.architecture } else { $WindowsArch } $appArch = if ($wingetApp.PSObject.Properties['architecture']) { $wingetApp.architecture } else { $WindowsArch }
Get-Application -AppName $wingetApp.Name -AppId $wingetApp.Id -Source 'winget' -AppsPath $AppsPath -WindowsArch $appArch -OrchestrationPath $OrchestrationPath Get-Application -AppName $wingetApp.Name -AppId $wingetApp.Id -Source 'winget' -AppsPath $AppsPath -ApplicationArch $appArch -OrchestrationPath $OrchestrationPath
} }
catch { catch {
WriteLog "Error occurred while processing $($wingetApp.Name): $_" WriteLog "Error occurred while processing $($wingetApp.Name): $_"
@@ -407,7 +407,7 @@ function Get-Apps {
foreach ($storeApp in $StoreApps) { foreach ($storeApp in $StoreApps) {
try { try {
$appArch = if ($storeApp.PSObject.Properties['architecture']) { $storeApp.architecture } else { $WindowsArch } $appArch = if ($storeApp.PSObject.Properties['architecture']) { $storeApp.architecture } else { $WindowsArch }
Get-Application -AppName $storeApp.Name -AppId $storeApp.Id -Source 'msstore' -AppsPath $AppsPath -WindowsArch $appArch -OrchestrationPath $OrchestrationPath -SelectedWindowsArch $WindowsArch Get-Application -AppName $storeApp.Name -AppId $storeApp.Id -Source 'msstore' -AppsPath $AppsPath -ApplicationArch $appArch -WindowsArch $WindowsArch -OrchestrationPath $OrchestrationPath
} }
catch { catch {
WriteLog "Error occurred while processing $($storeApp.Name): $_" WriteLog "Error occurred while processing $($storeApp.Name): $_"
@@ -386,7 +386,7 @@ function Start-WingetAppDownloadTask {
[string]$OrchestrationPath, [string]$OrchestrationPath,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[System.Collections.Concurrent.ConcurrentQueue[hashtable]]$ProgressQueue, # Add queue parameter [System.Collections.Concurrent.ConcurrentQueue[hashtable]]$ProgressQueue, # Add queue parameter
[string]$SelectedWindowsArch [string]$WindowsArch
) )
$appName = $ApplicationItemData.Name $appName = $ApplicationItemData.Name
@@ -596,7 +596,7 @@ function Start-WingetAppDownloadTask {
try { try {
# Call Get-Application # Call Get-Application
$resultCode = Get-Application -AppName $appName -AppId $appId -Source $source -AppsPath $AppsPath -WindowsArch $ApplicationItemData.Architecture -OrchestrationPath $OrchestrationPath -SkipWin32Json -SelectedWindowsArch $SelectedWindowsArch -ErrorAction Stop $resultCode = Get-Application -AppName $appName -AppId $appId -Source $source -AppsPath $AppsPath -ApplicationArch $ApplicationItemData.Architecture -WindowsArch $WindowsArch -OrchestrationPath $OrchestrationPath -SkipWin32Json -ErrorAction Stop
# Determine status based on result code # Determine status based on result code
switch ($resultCode) { switch ($resultCode) {
@@ -718,7 +718,7 @@ function Invoke-WingetDownload {
AppsPath = $localAppsPath AppsPath = $localAppsPath
AppListJsonPath = $localAppListJsonPath AppListJsonPath = $localAppListJsonPath
OrchestrationPath = $localOrchestrationPath OrchestrationPath = $localOrchestrationPath
SelectedWindowsArch = $localWindowsArch WindowsArch = $localWindowsArch
} }
# Select only necessary properties before passing to Invoke-ParallelProcessing # Select only necessary properties before passing to Invoke-ParallelProcessing