From 7177fa97cae34b4e07e360208aee5bf170ac84e6 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 38333fab..be1328ad 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 2d01d2be..369a3570 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.