From d21418ef1edb2e90ad80a79d31123c156c06dc32 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Mon, 15 Jul 2024 21:06:19 +0200 Subject: [PATCH] undo programwinget function rework --- .../private/Install-WinUtilProgramWinget.ps1 | 85 ++++++++----------- 1 file changed, 37 insertions(+), 48 deletions(-) diff --git a/functions/private/Install-WinUtilProgramWinget.ps1 b/functions/private/Install-WinUtilProgramWinget.ps1 index 699b67e4..08d1d611 100644 --- a/functions/private/Install-WinUtilProgramWinget.ps1 +++ b/functions/private/Install-WinUtilProgramWinget.ps1 @@ -40,58 +40,47 @@ Function Install-WinUtilProgramWinget { # This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers. Write-Host "Starting install of $($Program.winget) with winget." try { - $status = (Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru -NoNewWindow).ExitCode - switch ($status) { - 0 { - Write-Host "$($Program.winget) installed successfully." - continue - } - -1978335189 { - Write-Host "$($Program.winget) No applicable update found" - continue - } - default { - Write-Host "Attempt with User scope" - $status = (Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru -NoNewWindow).ExitCode - switch ($status) { - 0 { - Write-Host "$($Program.winget) installed successfully with User scope." - continue - } - -1978335189 { - Write-Host "$($Program.winget) No applicable update found" - continue - } - default { - Write-Host "Attempt with User prompt" - $userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $($Program.winget) installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User Credential Prompt", [System.Windows.MessageBoxButton]::YesNo) - if ($userChoice -eq 'Yes') { - $getcreds = Get-Credential - $process = Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Credential $getcreds -PassThru -NoNewWindow - Wait-Process -Id $process.Id - $status = $process.ExitCode - switch ($status) { - 0 { - Write-Host "$($Program.winget) installed successfully with User prompt." - continue - } - -1978335189 { - Write-Host "$($Program.winget) No applicable update found" - continue - } - } - } else { - Write-Host "Skipping installation with specific user credentials." - } - } - } - } + $status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru -NoNewWindow).ExitCode + if($status -eq 0) { + Write-Host "$($Program.winget) installed successfully." + continue + } + if ($status -eq -1978335189) { + Write-Host "$($Program.winget) No applicable update found" + continue + } + Write-Host "Attempt with User scope" + $status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru -NoNewWindow).ExitCode + if($status -eq 0) { + Write-Host "$($Program.winget) installed successfully with User scope." + continue + } + if ($status -eq -1978335189) { + Write-Host "$($Program.winget) No applicable update found" + continue + } + Write-Host "Attempt with User prompt" + $userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $($Program.winget) installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User Credential Prompt", [System.Windows.MessageBoxButton]::YesNo) + if ($userChoice -eq 'Yes') { + $getcreds = Get-Credential + $process = Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Credential $getcreds -PassThru -NoNewWindow + Wait-Process -Id $process.Id + $status = $process.ExitCode + } else { + Write-Host "Skipping installation with specific user credentials." + } + if($status -eq 0) { + Write-Host "$($Program.winget) installed successfully with User prompt." + continue + } + if ($status -eq -1978335189) { + Write-Host "$($Program.winget) No applicable update found" + continue } } catch { - Write-Host "Failed to install $($Program.winget) with winget" + Write-Host "Failed to install $($Program.winget). With winget" $failedPackages += $Program } - } elseif($manage -eq "Uninstalling") { # Uninstall package via ID using winget directly.