Skip to content

Commit

Permalink
Merge pull request #60 from KnifMelti/KnifDev
Browse files Browse the repository at this point in the history
Modernized
  • Loading branch information
Romanitho authored Oct 14, 2022
2 parents 7b52dcf + 9e23468 commit b1d9eda
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 2 additions & 6 deletions winget-detect.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$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
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions winget-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit b1d9eda

Please sign in to comment.