mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-08-09 17:41:14 +10:00
Fix AppX detection and add package restore support (#4842)
* Fix installed AppX package detection * Add AppX package restore workflow * Add AppX operation progress feedback * Fix AppX operation launch race * Handle AppX workflow failures
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
function Get-WinUtilInstalledAPPX {
|
||||
<#
|
||||
|
||||
.SYNOPSIS
|
||||
Gets the names of AppX packages installed for all users
|
||||
|
||||
#>
|
||||
|
||||
# AppX module auto-loading can leave PowerShell 7 dependent on a temporary Windows PowerShell
|
||||
# compatibility proxy. Run the query in Windows PowerShell 5.1 so it remains available after
|
||||
# those temporary proxy files are removed.
|
||||
$ps5Command = {
|
||||
Get-AppxPackage -AllUsers -ErrorAction Stop | Select-Object -ExpandProperty Name
|
||||
}
|
||||
|
||||
$packageOutput = powershell.exe -NoProfile -NonInteractive -Command $ps5Command 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
$failureDetails = ($packageOutput | Out-String).Trim()
|
||||
Write-WinUtilLog -Level "ERROR" -Component "AppX" -Message "Failed to get installed AppX packages: $failureDetails"
|
||||
return @()
|
||||
}
|
||||
|
||||
return @($packageOutput)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
function Install-WinUtilAPPX {
|
||||
<#
|
||||
|
||||
.SYNOPSIS
|
||||
Registers a local AppX package or installs it from the Microsoft Store
|
||||
|
||||
.PARAMETER Name
|
||||
The AppX package name to install
|
||||
|
||||
.PARAMETER StoreId
|
||||
The optional Microsoft Store product ID used when no local manifest is available
|
||||
|
||||
#>
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Name,
|
||||
|
||||
[string]$StoreId
|
||||
)
|
||||
|
||||
Write-WinUtilLog -Component "AppX" -Message "Installing AppX package: $Name"
|
||||
|
||||
# AppX and DISM cmdlets are more reliable in Windows PowerShell 5.1. Query both installed and
|
||||
# provisioned package metadata because either can expose a local manifest that can be registered.
|
||||
$ps5Command = {
|
||||
$packageName = $args[0]
|
||||
$manifestPaths = [System.Collections.Generic.List[string]]::new()
|
||||
|
||||
Get-AppxPackage -AllUsers -Name $packageName -ErrorAction SilentlyContinue |
|
||||
Sort-Object -Property Version -Descending |
|
||||
ForEach-Object {
|
||||
if (-not [string]::IsNullOrWhiteSpace($_.InstallLocation)) {
|
||||
$manifestPaths.Add((Join-Path $_.InstallLocation "AppxManifest.xml"))
|
||||
}
|
||||
}
|
||||
|
||||
Get-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue |
|
||||
Where-Object DisplayName -EQ $packageName |
|
||||
ForEach-Object {
|
||||
if (-not [string]::IsNullOrWhiteSpace($_.InstallLocation)) {
|
||||
$manifestPaths.Add((Join-Path $_.InstallLocation "AppxManifest.xml"))
|
||||
}
|
||||
}
|
||||
|
||||
$manifestPath = $manifestPaths |
|
||||
Select-Object -Unique |
|
||||
Where-Object { Test-Path -LiteralPath $_ } |
|
||||
Select-Object -First 1
|
||||
|
||||
if ($null -ne $manifestPath) {
|
||||
Add-AppxPackage -Register $manifestPath -DisableDevelopmentMode -ErrorAction Stop
|
||||
Write-Output $manifestPath
|
||||
}
|
||||
}
|
||||
|
||||
$manifestOutput = powershell.exe -NoProfile -NonInteractive -Command $ps5Command -args $Name 2>&1
|
||||
if ($LASTEXITCODE -eq 0 -and $null -ne $manifestOutput) {
|
||||
$manifestPath = ($manifestOutput | Select-Object -Last 1).ToString().Trim()
|
||||
if (-not [string]::IsNullOrWhiteSpace($manifestPath)) {
|
||||
Write-WinUtilLog -Component "AppX" -Message "Registered local AppX manifest for $Name`: $manifestPath"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
$failureDetails = ($manifestOutput | Out-String).Trim()
|
||||
Write-WinUtilLog -Level "WARN" -Component "AppX" -Message "Local AppX registration failed for $Name`: $failureDetails"
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($StoreId)) {
|
||||
$errorMessage = "Unable to install $Name because no local manifest or Microsoft Store ID is available."
|
||||
Write-WinUtilLog -Level "ERROR" -Component "AppX" -Message $errorMessage
|
||||
throw $errorMessage
|
||||
}
|
||||
|
||||
Write-WinUtilLog -Component "AppX" -Message "No usable local manifest found for $Name. Installing Microsoft Store product $StoreId."
|
||||
Install-WinUtilWinget
|
||||
Install-WinUtilProgramWinget -Action Install -Programs @("msstore:$StoreId")
|
||||
}
|
||||
@@ -53,8 +53,9 @@ function Remove-WinUtilProvisionedAPPX {
|
||||
$removalOutput = powershell.exe -NoProfile -NonInteractive -Command $ps5Command -args $PackageList 2>&1
|
||||
if ($LASTEXITCODE -ne 0 -or $null -ne $removalOutput) {
|
||||
$failureDetails = ($removalOutput | Out-String).Trim()
|
||||
Write-WinUtilLog -Level "ERROR" -Component "AppX" -Message "AppX provisioned package removal failed: $failureDetails"
|
||||
return
|
||||
$errorMessage = "AppX provisioned package removal failed: $failureDetails"
|
||||
Write-WinUtilLog -Level "ERROR" -Component "AppX" -Message $errorMessage
|
||||
throw $errorMessage
|
||||
}
|
||||
|
||||
Write-WinUtilLog -Component "AppX" -Message "AppX provisioned package removal completed."
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
function Set-WinUtilTweaksProgressIndicator {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Shows, updates, or hides the window-level progress indicator used by the
|
||||
Tweaks and Undo workflows. It lives outside the TabControl, so unlike the
|
||||
Install tab's progress bar it stays visible no matter which tab is active.
|
||||
Shows, updates, or hides the window-level progress indicator used by long-running
|
||||
workflows such as Tweaks, Undo, and AppX management. It lives outside the TabControl,
|
||||
so unlike the Install tab's progress bar it stays visible no matter which tab is active.
|
||||
.PARAMETER Visible
|
||||
Whether the indicator should be shown or hidden.
|
||||
.PARAMETER Label
|
||||
|
||||
Reference in New Issue
Block a user