From 4ce997d016650735768315cf6a192e21c77fb6a4 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Mon, 25 Nov 2024 11:23:03 +0100 Subject: [PATCH] replace builtin install method with web request to app installer --- util/winget.psm1 | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/util/winget.psm1 b/util/winget.psm1 index 84a4410..b5a8c84 100644 --- a/util/winget.psm1 +++ b/util/winget.psm1 @@ -1,12 +1,18 @@ function InstallWinget { - # Reference: https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget-on-windows-sandbox - $progressPreference = 'silentlyContinue' - Write-Host "Installing WinGet PowerShell module from PSGallery..." - Install-PackageProvider -Name NuGet -Force | Out-Null - Install-Module -Name Microsoft.WinGet.Client -Force -Repository PSGallery | Out-Null - Write-Host "Using Repair-WinGetPackageManager cmdlet to bootstrap WinGet..." - Repair-WinGetPackageManager + $download = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest' + $setup = "$env:TMP\winget_setup.msixbundle" + + if (-not (Test-Path $setup)) + { + $releases = Invoke-RestMethod $download + $assets = $releases | Select-Object -ExpandProperty "assets" + $installer = $assets | Where-Object "name" -Match "msixbundle" + $url = $installer | Select-Object -ExpandProperty "browser_download_url" + Invoke-RestMethod $url -OutFile $setup + } + + Add-AppxPackage -Path $setup } function WingetInstall