function Invoke-WPFInstall { <# .SYNOPSIS Installs the selected programs using winget, if one or more of the selected programs are already installed on the system, winget will try and perform an upgrade if there's a newer version to install. #> $PackagesToInstall = $sync.selectedApps | Foreach-Object { $sync.configs.applicationsHashtable.$_ } if($sync.ProcessRunning) { $msg = "[Invoke-WPFInstall] An Install process is currently running." [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) return } if ($PackagesToInstall.Count -eq 0) { $WarningMsg = "Please select the program(s) to install or upgrade." [System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) return } $ManagerPreference = $sync.preferences.packagemanager $handle = Invoke-WPFRunspace -ParameterList @(("PackagesToInstall", $PackagesToInstall),("ManagerPreference", $ManagerPreference)) -ScriptBlock { param($PackagesToInstall, $ManagerPreference) $packagesSorted = Get-WinUtilSelectedPackages -PackageList $PackagesToInstall -Preference $ManagerPreference $packagesWinget = $packagesSorted[[PackageManagers]::Winget] $packagesChoco = $packagesSorted[[PackageManagers]::Choco] try { $sync.ProcessRunning = $true if($packagesWinget.Count -gt 0 -and $packagesWinget -ne "0") { Show-WPFInstallAppBusy -text "Installing apps..." Install-WinUtilWinget Install-WinUtilProgramWinget -Action Install -Programs $packagesWinget } if($packagesChoco.Count -gt 0) { Install-WinUtilChoco Install-WinUtilProgramChoco -Action Install -Programs $packagesChoco } Hide-WPFInstallAppBusy Write-Host "===========================================" Write-Host "-- Installs have finished ---" Write-Host "===========================================" Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" } } catch { Write-Host "===========================================" Write-Host "Error: $_" Write-Host "===========================================" Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Error" -overlay "warning" } } $sync.ProcessRunning = $False } }