From f93404376258b94885cbac0c9a619cc2c076021c Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 7 Aug 2024 03:34:12 +0200 Subject: [PATCH] Enhance the `winget` install check --- scripts/Windows/OS/Install.ps1 | 2 +- scripts/Windows/Scripts/SoftwareManagement.ps1 | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 38333fabe..be1328ad7 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -65,7 +65,7 @@ $null = New-Module { Install-Module -AcceptLicense -Force PSWindowsUpdate; }; - if (-not (Test-Command winget)) { + if (-not (Test-Winget)) { . "$PSScriptRoot/../Software/winget/Manage.ps1"; continue; } diff --git a/scripts/Windows/Scripts/SoftwareManagement.ps1 b/scripts/Windows/Scripts/SoftwareManagement.ps1 index 2d01d2bef..369a3570f 100644 --- a/scripts/Windows/Scripts/SoftwareManagement.ps1 +++ b/scripts/Windows/Scripts/SoftwareManagement.ps1 @@ -57,6 +57,17 @@ function Test-Command { [bool] (Get-Command $Name -ErrorAction SilentlyContinue); } +<# + .SYNOPSIS + Checks whether `winget` is working properly. +#> +function Test-Winget { + (Test-Command winget) -and -not ( + [System.Linq.Enumerable]::Any( + [string[]](winget source update winget), + [System.Func[string,bool]]{ param($line) $line -eq "Cancelled"; })); +} + <# .SYNOPSIS Checks whether a package with the specified name is installed.