restructure "Install-WinUtilProgramWinget"

This commit is contained in:
MyDrift 2024-07-15 20:14:39 +02:00
parent 508a7cb777
commit 2d253d0e46

View File

@ -40,47 +40,58 @@ Function Install-WinUtilProgramWinget {
# This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers. # 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." Write-Host "Starting install of $($Program.winget) with winget."
try { try {
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru -NoNewWindow).ExitCode $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) { switch ($status) {
Write-Host "$($Program.winget) installed successfully." 0 {
continue Write-Host "$($Program.winget) installed successfully."
} continue
if ($status -eq -1978335189) { }
Write-Host "$($Program.winget) No applicable update found" -1978335189 {
continue 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 default {
if($status -eq 0) { Write-Host "Attempt with User scope"
Write-Host "$($Program.winget) installed successfully 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
continue switch ($status) {
} 0 {
if ($status -eq -1978335189) { Write-Host "$($Program.winget) installed successfully with User scope."
Write-Host "$($Program.winget) No applicable update found" continue
continue }
} -1978335189 {
Write-Host "Attempt with User prompt" Write-Host "$($Program.winget) No applicable update found"
$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) continue
if ($userChoice -eq 'Yes') { }
$getcreds = Get-Credential default {
$process = Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Credential $getcreds -PassThru -NoNewWindow Write-Host "Attempt with User prompt"
Wait-Process -Id $process.Id $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)
$status = $process.ExitCode if ($userChoice -eq 'Yes') {
} else { $getcreds = Get-Credential
Write-Host "Skipping installation with specific user credentials." $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
if($status -eq 0) { $status = $process.ExitCode
Write-Host "$($Program.winget) installed successfully with User prompt." switch ($status) {
continue 0 {
} Write-Host "$($Program.winget) installed successfully with User prompt."
if ($status -eq -1978335189) { continue
Write-Host "$($Program.winget) No applicable update found" }
continue -1978335189 {
Write-Host "$($Program.winget) No applicable update found"
continue
}
}
} else {
Write-Host "Skipping installation with specific user credentials."
}
}
}
}
} }
} catch { } catch {
Write-Host "Failed to install $($Program.winget). With winget" Write-Host "Failed to install $($Program.winget) with winget"
$failedPackages += $Program $failedPackages += $Program
} }
} }
elseif($manage -eq "Uninstalling") { elseif($manage -eq "Uninstalling") {
# Uninstall package via ID using winget directly. # Uninstall package via ID using winget directly.