mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-05-10 00:02:09 +00:00
60 lines
2.6 KiB
PowerShell
60 lines
2.6 KiB
PowerShell
function Invoke-WPFInstall {
|
|
param (
|
|
[Parameter(Mandatory=$false)]
|
|
[PSObject[]]$PackagesToInstall = $($sync.selectedApps | Foreach-Object { $sync.configs.applicationsHashtable.$_ })
|
|
)
|
|
<#
|
|
|
|
.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.
|
|
|
|
#>
|
|
|
|
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["ManagerPreference"]
|
|
|
|
Invoke-WPFRunspace -ParameterList @(("PackagesToInstall", $PackagesToInstall),("ManagerPreference", $ManagerPreference)) -DebugPreference $DebugPreference -ScriptBlock {
|
|
param($PackagesToInstall, $ManagerPreference, $DebugPreference)
|
|
|
|
$packagesSorted = Get-WinUtilSelectedPackages -PackageList $PackagesToInstall -Preference $ManagerPreference
|
|
|
|
$packagesWinget = $packagesSorted[[PackageManagers]::Winget]
|
|
$packagesChoco = $packagesSorted[[PackageManagers]::Choco]
|
|
|
|
try {
|
|
$sync.ProcessRunning = $true
|
|
$errorPackages = @()
|
|
if($packagesWinget.Count -gt 0) {
|
|
Install-WinUtilWinget
|
|
Install-WinUtilProgramWinget -Action Install -Programs $packagesWinget
|
|
|
|
}
|
|
if($packagesChoco.Count -gt 0) {
|
|
Install-WinUtilChoco
|
|
Install-WinUtilProgramChoco -Action Install -Programs $packagesChoco
|
|
}
|
|
Write-Host "==========================================="
|
|
Write-Host "-- Installs have finished ---"
|
|
Write-Host "==========================================="
|
|
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
|
|
} catch {
|
|
Write-Host "==========================================="
|
|
Write-Host "Error: $_"
|
|
Write-Host "==========================================="
|
|
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -overlay "warning" })
|
|
}
|
|
$sync.ProcessRunning = $False
|
|
}
|
|
}
|