Add .NET fallback on Expand-Archive fail

The `Expand-Archive` cmdlet fails in localized Windows Sandbox environments (e.g., de-DE) because the `Microsoft.PowerShell.Archive` module cannot find its localization resources (`ArchiveResources.psd1`) in the minimal OS image.
pull/13/head
Jean-Luc Tcharnetsky 2025-12-18 16:15:56 +01:00 committed by ThioJoe
parent c33a3c70b7
commit dce2153228
No known key found for this signature in database
GPG Key ID: 2E328FE64CC3898C
1 changed files with 12 additions and 4 deletions

View File

@ -126,7 +126,16 @@ if ($depsZipUrl) {
# Remove existing Dependencies folder and expand the zip # Remove existing Dependencies folder and expand the zip
if (Test-Path $topDepsFolder) { Remove-Item -Path $topDepsFolder -Recurse -Force } if (Test-Path $topDepsFolder) { Remove-Item -Path $topDepsFolder -Recurse -Force }
Expand-Archive -LiteralPath $depsZipPath -DestinationPath $topDepsFolder -Force # Use Expand-Archive cmdlet by default because it's safe for constrained language mode. Fall back to .NET assembly if it fails.
try {
Expand-Archive -LiteralPath $depsZipPath -DestinationPath $topDepsFolder -Force -ErrorAction Stop
}
catch {
Write-Warning "Standard extraction failed, attempting .NET fallback. The error was: $($_.Exception.Message)"
# Fallback using .NET System.IO.Compression (Fixes issues in non-EN Windows Sandbox)
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($depsZipPath, $topDepsFolder)
}
} }
else { Write-Warning "No $depsZipName found in $latestTag, skipping dependency download."; } else { Write-Warning "No $depsZipName found in $latestTag, skipping dependency download."; }
@ -156,4 +165,3 @@ if ($removeMsStoreAsSource.IsPresent) {
# Automatically accept source agreements to avoid prompts. Mostly applies to msstore. # Automatically accept source agreements to avoid prompts. Mostly applies to msstore.
winget list --accept-source-agreements | Out-Null winget list --accept-source-agreements | Out-Null
} }