From 8095a09a7a4b854db991d646cbf130a28107b61e Mon Sep 17 00:00:00 2001 From: Jean-Luc Tcharnetsky <88255067+Jean-LucTch@users.noreply.github.com> Date: Thu, 18 Dec 2025 16:15:56 +0100 Subject: [PATCH] replace Expand-Archive with .NET ZipFile for Sandbox stability 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. Changes: - Replaced `Expand-Archive` with `[System.IO.Compression.ZipFile]::ExtractToDirectory` - Added `Add-Type -AssemblyName System.IO.Compression.FileSystem` to ensure .NET zip support - Added a safety check to ensure the Downloads directory exists --- Installer Scripts/Install-Winget.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Installer Scripts/Install-Winget.ps1 b/Installer Scripts/Install-Winget.ps1 index 1bafd78..bfa4ad2 100644 --- a/Installer Scripts/Install-Winget.ps1 +++ b/Installer Scripts/Install-Winget.ps1 @@ -81,6 +81,7 @@ function Install-WingetDependencies { $ProgressPreference = 'SilentlyContinue' $downloadPath = Join-Path $env:USERPROFILE "Downloads" +if (!(Test-Path $downloadPath)) { New-Item -ItemType Directory -Path $downloadPath } $latestRelease = Get-LatestRelease if (-not $latestRelease) { Write-Error "Could not retrieve the latest release. Exiting."; return; } @@ -125,8 +126,10 @@ if ($depsZipUrl) { # Remove existing Dependencies folder and expand the zip if (Test-Path $topDepsFolder) { Remove-Item -Path $topDepsFolder -Recurse -Force } - - Expand-Archive -LiteralPath $depsZipPath -DestinationPath $topDepsFolder -Force + + # Replaces Expand archives with .NET System.IO.Compression + 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."; } @@ -156,4 +159,3 @@ if ($removeMsStoreAsSource.IsPresent) { # Automatically accept source agreements to avoid prompts. Mostly applies to msstore. winget list --accept-source-agreements | Out-Null } -