From cc02facb11ad570aa0dadb1e0d5825bbc9431ee3 Mon Sep 17 00:00:00 2001 From: Martin Wiethan <47688561+Marterich@users.noreply.github.com> Date: Fri, 10 May 2024 06:13:57 +0200 Subject: [PATCH] Only install choco if needed (#1943) --- functions/private/Install-WinUtilWinget.ps1 | 2 ++ functions/public/Invoke-WPFFixesWinget.ps1 | 3 ++- functions/public/Invoke-WPFGetIso.ps1 | 2 ++ scripts/main.ps1 | 4 ++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/functions/private/Install-WinUtilWinget.ps1 b/functions/private/Install-WinUtilWinget.ps1 index 093a5c35..601d3c30 100644 --- a/functions/private/Install-WinUtilWinget.ps1 +++ b/functions/private/Install-WinUtilWinget.ps1 @@ -53,6 +53,8 @@ function Install-WinUtilWinget { Write-Host "Failure detected while installing via GitHub method. Continuing with Chocolatey method as fallback." -ForegroundColor Red # In case install fails via GitHub method. Try { + # Install Choco if not already present + Install-WinUtilChoco Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget-cli" Write-Host "Winget Installed" -ForegroundColor Green Write-Output "Refreshing Environment Variables...`n" diff --git a/functions/public/Invoke-WPFFixesWinget.ps1 b/functions/public/Invoke-WPFFixesWinget.ps1 index 5dd53a6b..96b5bb7f 100644 --- a/functions/public/Invoke-WPFFixesWinget.ps1 +++ b/functions/public/Invoke-WPFFixesWinget.ps1 @@ -7,7 +7,8 @@ function Invoke-WPFFixesWinget { .DESCRIPTION BravoNorris for the fantastic idea of a button to reinstall winget #> - + # Install Choco if not already present + Install-WinUtilChoco Start-Process -FilePath "choco" -ArgumentList "install winget -y --force" -NoNewWindow -Wait } \ No newline at end of file diff --git a/functions/public/Invoke-WPFGetIso.ps1 b/functions/public/Invoke-WPFGetIso.ps1 index 1b448a4f..483c494a 100644 --- a/functions/public/Invoke-WPFGetIso.ps1 +++ b/functions/public/Invoke-WPFGetIso.ps1 @@ -41,6 +41,8 @@ function Invoke-WPFGetIso { # you consent to downloading it, no need to show extra dialogs [System.Windows.MessageBox]::Show("oscdimge.exe is not found on the system, winutil will now attempt do download and install it using choco. This might take a long time.") # the step below needs choco to download oscdimg + # Install Choco if not already present + Install-WinUtilChoco $chocoFound = [bool] (Get-Command -ErrorAction Ignore -Type Application choco) Write-Host "choco on system: $chocoFound" if (!$chocoFound) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 38007969..cc9aaa35 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -145,8 +145,8 @@ Invoke-WPFRunspace -ScriptBlock { # Print the logo Invoke-WPFFormVariables -# Check if Chocolatey is installed -Install-WinUtilChoco +# Install Winget if not already present +Install-WinUtilWinget # Set the titlebar $sync["Form"].title = $sync["Form"].title + " " + $sync.version