Enhance the winget install check

This commit is contained in:
Manuel Thalmann 2024-08-07 03:34:12 +02:00
parent 0b28364280
commit 7177fa97ca
2 changed files with 12 additions and 1 deletions

View file

@ -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;
}

View file

@ -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.