Enhance the winget install check

This commit is contained in:
Manuel Thalmann 2024-08-07 03:34:12 +02:00
parent 3876ca99e0
commit 3d9db2c5c3
2 changed files with 12 additions and 1 deletions

View file

@ -64,7 +64,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

@ -58,6 +58,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.