From 2fda71d8634f100a6d7dc4165a4bbad19530d628 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 14 Oct 2022 17:54:24 +0200 Subject: [PATCH 1/2] Modernized --- winget-detect.ps1 | 8 ++------ winget-install.ps1 | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/winget-detect.ps1 b/winget-detect.ps1 index da64005..0c79d49 100644 --- a/winget-detect.ps1 +++ b/winget-detect.ps1 @@ -7,7 +7,7 @@ $AppToDetect = "Notepad++.Notepad++" Function Get-WingetCmd { #Get WinGet Path (if admin context) - $ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" + $ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } if ($ResolveWingetPath) { #If multiple version, pick last one $WingetPath = $ResolveWingetPath[-1].Path @@ -18,11 +18,7 @@ Function Get-WingetCmd { if ($WingetCmd) { $Script:Winget = $WingetCmd.Source } - #Get Winget Location in System context (WinGet < 1.17) - elseif (Test-Path "$WingetPath\AppInstallerCLI.exe") { - $Script:Winget = "$WingetPath\AppInstallerCLI.exe" - } - #Get Winget Location in System context (WinGet > 1.17) + #Get Winget Location in System context elseif (Test-Path "$WingetPath\winget.exe") { $Script:Winget = "$WingetPath\winget.exe" } diff --git a/winget-install.ps1 b/winget-install.ps1 index b92e69b..ee3e3a4 100644 --- a/winget-install.ps1 +++ b/winget-install.ps1 @@ -99,9 +99,9 @@ function Write-Log ($LogMsg, $LogColor = "White") { #Get WinGet Location Function function Get-WingetCmd { #Get WinGet Path (if admin context) - $ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" + $ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } if ($ResolveWingetPath) { - #If multiple versions (when pre-release versions are installed), pick last one + #If multiple versions, pick last one $WingetPath = $ResolveWingetPath[-1].Path } #Get WinGet Location in User context @@ -114,7 +114,7 @@ function Get-WingetCmd { $Script:Winget = "$WingetPath\winget.exe" } else { - Write-Log "Winget not installed !" "Red" + Write-Log "Winget not installed or detected !" "Red" break } Write-Log "Using following Winget Cmd: $winget`n" From 9e2346811c5e8c532ab29c819abb8d974892dde9 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 14 Oct 2022 18:04:17 +0200 Subject: [PATCH 2/2] Environment #56 --- winget-detect.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winget-detect.ps1 b/winget-detect.ps1 index 0c79d49..4d19501 100644 --- a/winget-detect.ps1 +++ b/winget-detect.ps1 @@ -7,7 +7,7 @@ $AppToDetect = "Notepad++.Notepad++" Function Get-WingetCmd { #Get WinGet Path (if admin context) - $ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } + $ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } if ($ResolveWingetPath) { #If multiple version, pick last one $WingetPath = $ResolveWingetPath[-1].Path