Enhance the winget install check

This commit is contained in:
Manuel Thalmann 2024-08-07 03:34:12 +02:00
parent 8ae54f48e8
commit 9b1654c828
2 changed files with 12 additions and 1 deletions

View file

@ -64,7 +64,7 @@ $null = New-Module {
Install-Module -AcceptLicense -Force PSWindowsUpdate; Install-Module -AcceptLicense -Force PSWindowsUpdate;
}; };
if (-not (Test-Command winget)) { if (-not (Test-Winget)) {
. "$PSScriptRoot/../Software/winget/Manage.ps1"; . "$PSScriptRoot/../Software/winget/Manage.ps1";
continue; continue;
} }

View file

@ -58,6 +58,17 @@ function Test-Command {
[bool] (Get-Command $Name -ErrorAction SilentlyContinue); [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 .SYNOPSIS
Checks whether a package with the specified name is installed. Checks whether a package with the specified name is installed.