Files
winutil/functions/public/Invoke-WPFUnInstall.ps1
T

68 lines
3.0 KiB
PowerShell
Raw Normal View History

+2
2023-05-09 13:14:27 -05:00
function Invoke-WPFUnInstall {
2025-03-01 20:50:12 +01:00
param(
[Parameter(Mandatory=$false)]
[PSObject[]]$PackagesToUninstall = $($sync.selectedApps | Foreach-Object { $sync.configs.applicationsHashtable.$_ })
)
+2
2023-05-09 13:14:27 -05:00
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Uninstalls the selected programs
+2
2023-05-09 13:14:27 -05:00
#>
if($sync.ProcessRunning) {
2024-01-15 11:32:19 -06:00
$msg = "[Invoke-WPFUnInstall] Install process is currently running"
+2
2023-05-09 13:14:27 -05:00
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
return
}
2025-03-01 20:50:12 +01:00
if ($PackagesToUninstall.Count -eq 0) {
2024-06-28 16:55:35 +02:00
$WarningMsg = "Please select the program(s) to uninstall"
+2
2023-05-09 13:14:27 -05:00
[System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
return
}
$ButtonType = [System.Windows.MessageBoxButton]::YesNo
$MessageboxTitle = "Are you sure?"
2025-03-01 20:50:12 +01:00
$Messageboxbody = ("This will uninstall the following applications: `n $($PackagesToUninstall | Select-Object Name, Description| Out-String)")
+2
2023-05-09 13:14:27 -05:00
$MessageIcon = [System.Windows.MessageBoxImage]::Information
$confirm = [System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $MessageIcon)
if($confirm -eq "No") {return}
+2
2023-05-09 13:14:27 -05:00
$ManagerPreference = $sync["ManagerPreference"]
2025-06-01 17:40:37 +02:00
Invoke-WPFRunspace -ArgumentList @(("PackagesToUninstall", $PackagesToUninstall),("ManagerPreference", $ManagerPreference)) -DebugPreference $DebugPreference -ScriptBlock {
param($PackagesToUninstall, $ManagerPreference, $DebugPreference)
2025-06-01 17:40:37 +02:00
$packagesSorted = Get-WinUtilSelectedPackages -PackageList $PackagesToUninstall -Preference $ManagerPreference
$packagesWinget = $packagesSorted[[PackageManagers]::Winget]
$packagesChoco = $packagesSorted[[PackageManagers]::Choco]
try {
+2
2023-05-09 13:14:27 -05:00
$sync.ProcessRunning = $true
Show-WPFInstallAppBusy -text "Uninstalling apps..."
+2
2023-05-09 13:14:27 -05:00
# Uninstall all selected programs in new window
if($packagesWinget.Count -gt 0) {
Install-WinUtilProgramWinget -Action Uninstall -Programs $packagesWinget
+26
2024-06-04 20:27:27 -07:00
}
if($packagesChoco.Count -gt 0) {
Install-WinUtilProgramChoco -Action Uninstall -Programs $packagesChoco
+26
2024-06-04 20:27:27 -07:00
}
Hide-WPFInstallAppBusy
+2
2023-05-09 13:14:27 -05:00
Write-Host "==========================================="
2023-10-19 17:12:55 -05:00
Write-Host "-- Uninstalls have finished ---"
+2
2023-05-09 13:14:27 -05:00
Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
} catch {
+2
2023-05-09 13:14:27 -05:00
Write-Host "==========================================="
+26
2024-06-04 20:27:27 -07:00
Write-Host "Error: $_"
+2
2023-05-09 13:14:27 -05:00
Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -overlay "warning" })
+2
2023-05-09 13:14:27 -05:00
}
$sync.ProcessRunning = $False
+2
2023-05-09 13:14:27 -05:00
}
2024-06-28 16:55:35 +02:00
}