From dec704305f6c5ca860712f701575fa5117af0f0e Mon Sep 17 00:00:00 2001 From: Martin Wiethan <47688561+Marterich@users.noreply.github.com> Date: Fri, 22 Mar 2024 00:02:36 +0100 Subject: [PATCH] Handle preview versions of winget (#1682) * Update close-old-issues.yaml * Compile Winutil * Update close-old-issues.yaml * Update close-old-issues.yaml * Update close-old-issues.yaml * Added compatibility with preview versions of Winget * Update winutil.ps1 * Update Test-WinUtilPackageManager.ps1 * Document Formatting --------- Co-authored-by: Chris Titus Co-authored-by: ChrisTitusTech Co-authored-by: Chris Titus --- .../private/Test-WinUtilPackageManager.ps1 | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/functions/private/Test-WinUtilPackageManager.ps1 b/functions/private/Test-WinUtilPackageManager.ps1 index 0bd4c89c..acd9224b 100644 --- a/functions/private/Test-WinUtilPackageManager.ps1 +++ b/functions/private/Test-WinUtilPackageManager.ps1 @@ -20,11 +20,17 @@ function Test-WinUtilPackageManager { # Install Winget if not detected $wingetExists = Get-Command -Name winget -ErrorAction SilentlyContinue if ($wingetExists) { - $wingetVersion = [System.Version]::Parse((winget --version).Trim('v')) + $wingetversionfull = (winget --version) + $wingetversiontrim = $wingetversionfull.Trim('v') + if ($wingetversiontrim.EndsWith("-preview")) { + $wingetversiontrim = $wingetversiontrim.Trim('-preview') + $wingetpreview = $true + } + $wingetVersion = [System.Version]::Parse($wingetversiontrim) $minimumWingetVersion = [System.Version]::new(1,2,10691) # Win 11 23H2 comes with bad winget v1.2.10691 $wingetOutdated = $wingetVersion -le $minimumWingetVersion - Write-Host "Winget v$wingetVersion" + Write-Host "Winget $wingetVersionfull" } if (!$wingetExists -or $wingetOutdated) { @@ -37,17 +43,21 @@ function Test-WinUtilPackageManager { if ($winget) { if ($wingetExists -and !$wingetOutdated) { - Write-Host "- Winget up-to-date" + if (!$wingetpreview) { + Write-Host "- Winget up-to-date" + } else { + Write-Host "- Winget preview version detected. Unexptected problems may occur" -ForegroundColor Yellow + } return $true } } - if($choco){ - if ((Get-Command -Name choco -ErrorAction Ignore) -and ($chocoVersion = (Get-Item "$env:ChocolateyInstall\choco.exe" -ErrorAction Ignore).VersionInfo.ProductVersion)){ + if ($choco) { + if ((Get-Command -Name choco -ErrorAction Ignore) -and ($chocoVersion = (Get-Item "$env:ChocolateyInstall\choco.exe" -ErrorAction Ignore).VersionInfo.ProductVersion)) { Write-Host "Chocolatey v$chocoVersion" return $true } } return $false -} \ No newline at end of file +}