Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle preview versions of winget #1682

Merged
merged 13 commits into from
Mar 21, 2024
22 changes: 16 additions & 6 deletions functions/private/Test-WinUtilPackageManager.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}