From da2c8a1ca514233c01f5c89954f6d84f189b889c Mon Sep 17 00:00:00 2001 From: Kian Date: Fri, 10 May 2024 18:17:12 -0500 Subject: [PATCH] fix uninstall --- functions/public/Invoke-WPFUnInstall.ps1 | 32 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/functions/public/Invoke-WPFUnInstall.ps1 b/functions/public/Invoke-WPFUnInstall.ps1 index 4292aeb3..facd7155 100644 --- a/functions/public/Invoke-WPFUnInstall.ps1 +++ b/functions/public/Invoke-WPFUnInstall.ps1 @@ -12,9 +12,9 @@ function Invoke-WPFUnInstall { return } - $WingetInstall = (Get-WinUtilCheckBoxes)["Install"] + $PackagesToInstall = (Get-WinUtilCheckBoxes)["Install"] - if ($wingetinstall.Count -eq 0) { + if ($PackagesToInstall.Count -eq 0) { $WarningMsg = "Please select the program(s) to install" [System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) return @@ -22,21 +22,39 @@ function Invoke-WPFUnInstall { $ButtonType = [System.Windows.MessageBoxButton]::YesNo $MessageboxTitle = "Are you sure?" - $Messageboxbody = ("This will uninstall the following applications: `n $WingetInstall") + $Messageboxbody = ("This will uninstall the following applications: `n $($PackagesToInstall | Format-Table | Out-String)") $MessageIcon = [System.Windows.MessageBoxImage]::Information $confirm = [System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $MessageIcon) if($confirm -eq "No"){return} - Invoke-WPFRunspace -ArgumentList $WingetInstall -DebugPreference $DebugPreference -ScriptBlock { - param($WingetInstall, $DebugPreference) - + Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock { + param($PackagesToInstall, $DebugPreference) + $packagesWinget, $packagesChoco = { + $packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new() + $packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new() + foreach ($package in $PackagesToInstall) { + if ($package.winget -eq "na") { + $packagesChoco.add($package) + Write-Host "Queueing $($package.choco) for Chocolatey Uninstall" + } else { + $packagesWinget.add($package) + Write-Host "Queueing $($package.winget) for Winget Uninstall" + } + } + return $packagesWinget, $packagesChoco + }.Invoke($PackagesToInstall) try{ $sync.ProcessRunning = $true # Install all selected programs in new window - Install-WinUtilProgramWinget -ProgramsToInstall $WingetInstall -Manage "Uninstalling" + if($packagesWinget.Count -gt 0){ + Install-WinUtilProgramWinget -ProgramsToInstall $PackagesToInstall -Manage "Uninstalling" + } + if($packagesChoco.Count -gt 0){ + Install-WinUtilProgramChoco -ProgramsToInstall $PackagesToInstall -Manage "Uninstalling" + } $ButtonType = [System.Windows.MessageBoxButton]::OK $MessageboxTitle = "Uninstalls are Finished "