From c842584cfe2b2368bff57dba281d6715793a682f Mon Sep 17 00:00:00 2001 From: Chris Titus Date: Wed, 7 Feb 2024 18:11:40 -0600 Subject: [PATCH] revert winget --- functions/private/Install-WinUtilChoco.ps1 | 2 +- .../private/Install-WinUtilProgramWinget.ps1 | 4 +-- functions/private/Install-WinUtilWinget.ps1 | 18 ++++--------- functions/public/Invoke-WPFGetInstalled.ps1 | 2 +- functions/public/Invoke-WPFInstall.ps1 | 2 +- functions/public/Invoke-WPFInstallUpgrade.ps1 | 2 +- winutil.ps1 | 26 +++++++------------ 7 files changed, 20 insertions(+), 36 deletions(-) diff --git a/functions/private/Install-WinUtilChoco.ps1 b/functions/private/Install-WinUtilChoco.ps1 index b96fc0e5..83e7160d 100644 --- a/functions/private/Install-WinUtilChoco.ps1 +++ b/functions/private/Install-WinUtilChoco.ps1 @@ -10,7 +10,7 @@ function Install-WinUtilChoco { try { Write-Host "Checking if Chocolatey is Installed..." - if((Test-WinUtilPackageManager -choco)){ + if((Get-Command -Name choco -ErrorAction Ignore)) { Write-Host "Chocolatey Already Installed" return } diff --git a/functions/private/Install-WinUtilProgramWinget.ps1 b/functions/private/Install-WinUtilProgramWinget.ps1 index 8c7647ed..1d535aa8 100644 --- a/functions/private/Install-WinUtilProgramWinget.ps1 +++ b/functions/private/Install-WinUtilProgramWinget.ps1 @@ -30,7 +30,7 @@ Function Install-WinUtilProgramWinget { Write-Progress -Activity "$manage Applications" -Status "$manage $Program $($x + 1) of $count" -PercentComplete $($x/$count*100) if($manage -eq "Installing"){ - Start-Process -FilePath winget -ArgumentList "install -e --accept-source-agreements --accept-package-agreements --ignore-security-hash --disable-interactivity --silent $Program" -NoNewWindow -Wait + Start-Process -FilePath winget -ArgumentList "install -e --accept-source-agreements --accept-package-agreements --scope=machine --silent $Program" -NoNewWindow -Wait } if($manage -eq "Uninstalling"){ Start-Process -FilePath winget -ArgumentList "uninstall -e --purge --force --silent $Program" -NoNewWindow -Wait @@ -41,4 +41,4 @@ Function Install-WinUtilProgramWinget { Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed -} +} \ No newline at end of file diff --git a/functions/private/Install-WinUtilWinget.ps1 b/functions/private/Install-WinUtilWinget.ps1 index 16877293..a334bb61 100644 --- a/functions/private/Install-WinUtilWinget.ps1 +++ b/functions/private/Install-WinUtilWinget.ps1 @@ -22,7 +22,6 @@ function Install-WinUtilWinget { if (Test-WinUtilPackageManager -winget) { # Checks if winget executable exists and if the Windows Version is 1809 or higher Write-Host "Winget Already Installed" - Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "winget settings --enable InstallerHashOverride" -Wait -NoNewWindow return } @@ -40,19 +39,12 @@ function Install-WinUtilWinget { return } - Write-Host "Running Alternative Installers and Direct Installing" - # Checks if winget is installed via Chocolatey - - Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget --force" -Wait -NoNewWindow - if (Test-WinUtilPackageManager -winget) { - # Checks if winget executable exists and if the Windows Version is 1809 or higher - Write-Host "Winget Installed via Chocolatey" - return - } else { - Write-Host "- Failed to install Winget via Chocolatey" - } + Write-Host "Running Alternative Installer and Direct Installing" + Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget" + + Write-Host "Winget Installed" } Catch{ throw [WingetFailedInstall]::new('Failed to install') } -} +} \ No newline at end of file diff --git a/functions/public/Invoke-WPFGetInstalled.ps1 b/functions/public/Invoke-WPFGetInstalled.ps1 index 7c250eab..b3df6a8d 100644 --- a/functions/public/Invoke-WPFGetInstalled.ps1 +++ b/functions/public/Invoke-WPFGetInstalled.ps1 @@ -16,7 +16,7 @@ function Invoke-WPFGetInstalled { return } - if(!(Test-WinUtilPackageManager -winget) -and $checkbox -eq "winget"){ + if(!(Get-Command -Name winget -ErrorAction SilentlyContinue) -and $checkbox -eq "winget"){ Write-Host "===========================================" Write-Host "-- Winget is not installed ---" Write-Host "===========================================" diff --git a/functions/public/Invoke-WPFInstall.ps1 b/functions/public/Invoke-WPFInstall.ps1 index 69ee6a72..29ebe7b4 100644 --- a/functions/public/Invoke-WPFInstall.ps1 +++ b/functions/public/Invoke-WPFInstall.ps1 @@ -35,7 +35,7 @@ function Invoke-WPFInstall { } Catch { Write-Host "===========================================" - Write-Host "-- Winget failed to install ---" + Write-Host "Error: $_" Write-Host "===========================================" } Start-Sleep -Seconds 5 diff --git a/functions/public/Invoke-WPFInstallUpgrade.ps1 b/functions/public/Invoke-WPFInstallUpgrade.ps1 index 8cf026a7..82184e80 100644 --- a/functions/public/Invoke-WPFInstallUpgrade.ps1 +++ b/functions/public/Invoke-WPFInstallUpgrade.ps1 @@ -5,7 +5,7 @@ function Invoke-WPFInstallUpgrade { Invokes the function that upgrades all installed programs using winget #> - if(!(Test-WinUtilPackageManager -winget)){ + if(!(Get-Command -Name winget -ErrorAction SilentlyContinue)){ Write-Host "===========================================" Write-Host "-- Winget is not installed ---" Write-Host "===========================================" diff --git a/winutil.ps1 b/winutil.ps1 index fad841d2..3e750be9 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -495,7 +495,7 @@ function Install-WinUtilChoco { try { Write-Host "Checking if Chocolatey is Installed..." - if((Test-WinUtilPackageManager -choco)){ + if((Get-Command -Name choco -ErrorAction Ignore)) { Write-Host "Chocolatey Already Installed" return } @@ -544,7 +544,7 @@ Function Install-WinUtilProgramWinget { Write-Progress -Activity "$manage Applications" -Status "$manage $Program $($x + 1) of $count" -PercentComplete $($x/$count*100) if($manage -eq "Installing"){ - Start-Process -FilePath winget -ArgumentList "install -e --accept-source-agreements --accept-package-agreements --ignore-security-hash --disable-interactivity --silent $Program" -NoNewWindow -Wait + Start-Process -FilePath winget -ArgumentList "install -e --accept-source-agreements --accept-package-agreements --scope=machine --silent $Program" -NoNewWindow -Wait } if($manage -eq "Uninstalling"){ Start-Process -FilePath winget -ArgumentList "uninstall -e --purge --force --silent $Program" -NoNewWindow -Wait @@ -580,7 +580,6 @@ function Install-WinUtilWinget { if (Test-WinUtilPackageManager -winget) { # Checks if winget executable exists and if the Windows Version is 1809 or higher Write-Host "Winget Already Installed" - Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "winget settings --enable InstallerHashOverride" -Wait -NoNewWindow return } @@ -598,17 +597,10 @@ function Install-WinUtilWinget { return } - Write-Host "Running Alternative Installers and Direct Installing" - # Checks if winget is installed via Chocolatey - - Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget --force" -Wait -NoNewWindow - if (Test-WinUtilPackageManager -winget) { - # Checks if winget executable exists and if the Windows Version is 1809 or higher - Write-Host "Winget Installed via Chocolatey" - return - } else { - Write-Host "- Failed to install Winget via Chocolatey" - } + Write-Host "Running Alternative Installer and Direct Installing" + Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget" + + Write-Host "Winget Installed" } Catch{ throw [WingetFailedInstall]::new('Failed to install') @@ -2883,7 +2875,7 @@ function Invoke-WPFGetInstalled { return } - if(!(Test-WinUtilPackageManager -winget) -and $checkbox -eq "winget"){ + if(!(Get-Command -Name winget -ErrorAction SilentlyContinue) -and $checkbox -eq "winget"){ Write-Host "===========================================" Write-Host "-- Winget is not installed ---" Write-Host "===========================================" @@ -3217,7 +3209,7 @@ function Invoke-WPFInstall { } Catch { Write-Host "===========================================" - Write-Host "-- Winget failed to install ---" + Write-Host "Error: $_" Write-Host "===========================================" } Start-Sleep -Seconds 5 @@ -3231,7 +3223,7 @@ function Invoke-WPFInstallUpgrade { Invokes the function that upgrades all installed programs using winget #> - if(!(Test-WinUtilPackageManager -winget)){ + if(!(Get-Command -Name winget -ErrorAction SilentlyContinue)){ Write-Host "===========================================" Write-Host "-- Winget is not installed ---" Write-Host "==========================================="