mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-06-28 09:04:47 -05:00
Choco Logic Refactor and Add Checkbox to prefer Chocolatey over Winget (#2596)
* First Selector and Logic * Extend Functionality * Switch to PreferChocolatey Checkbox * Persist Choco Preference across program restarts * Change Logging, Fix interactivity and optimize uninstall * Implement "Get-Installed" (quick-and-dirty) * Code Formatting * Rename File/Function, Refactor Choco Install, Add Status Indicator * Add documentation --------- Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
@ -28,38 +28,51 @@ function Invoke-WPFUnInstall {
|
||||
$confirm = [System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $MessageIcon)
|
||||
|
||||
if($confirm -eq "No") {return}
|
||||
$ChocoPreference = $($sync.WPFpreferChocolatey.IsChecked)
|
||||
|
||||
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $DebugPreference)
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall, $ChocoPreference -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $ChocoPreference, $DebugPreference)
|
||||
if ($PackagesToInstall.count -eq 1) {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
|
||||
} else {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
|
||||
}
|
||||
$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"
|
||||
$packagesWinget = [System.Collections.ArrayList]::new()
|
||||
$packagesChoco = [System.Collections.ArrayList]::new()
|
||||
|
||||
foreach ($package in $PackagesToInstall) {
|
||||
if ($ChocoPreference) {
|
||||
if ($package.choco -eq "na") {
|
||||
$packagesWinget.add($package.winget)
|
||||
Write-Host "Queueing $($package.winget) for Winget uninstall"
|
||||
} else {
|
||||
$packagesWinget.add($($package.winget))
|
||||
Write-Host "Queueing $($package.winget) for Winget Uninstall"
|
||||
$null = $packagesChoco.add($package.choco)
|
||||
Write-Host "Queueing $($package.choco) for Chocolatey uninstall"
|
||||
}
|
||||
}
|
||||
return $packagesWinget, $packagesChoco
|
||||
else {
|
||||
if ($package.winget -eq "na") {
|
||||
$packagesChoco.add($package.choco)
|
||||
Write-Host "Queueing $($package.choco) for Chocolatey uninstall"
|
||||
} else {
|
||||
$null = $packagesWinget.add($($package.winget))
|
||||
Write-Host "Queueing $($package.winget) for Winget uninstall"
|
||||
}
|
||||
}
|
||||
}
|
||||
return $packagesWinget, $packagesChoco
|
||||
}.Invoke($PackagesToInstall)
|
||||
|
||||
try {
|
||||
$sync.ProcessRunning = $true
|
||||
|
||||
# Install all selected programs in new window
|
||||
if($packagesWinget.Count -gt 0) {
|
||||
Invoke-WinUtilWingetProgram -Action Uninstall -Programs $packagesWinget
|
||||
Install-WinUtilProgramWinget -Action Uninstall -Programs $packagesWinget
|
||||
}
|
||||
if($packagesChoco.Count -gt 0) {
|
||||
Install-WinUtilProgramChoco -ProgramsToInstall $packagesChoco -Manage "Uninstalling"
|
||||
Install-WinUtilProgramChoco -Action Uninstall -Programs $packagesChoco
|
||||
}
|
||||
|
||||
Write-Host "==========================================="
|
||||
|
Reference in New Issue
Block a user