From 579030eeb936041654e7b2ec6e5e9a45ce747013 Mon Sep 17 00:00:00 2001 From: Marterich <47688561+Marterich@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:50:52 +0200 Subject: [PATCH] Implement "Get-Installed" (quick-and-dirty) --- .../private/Invoke-WinUtilCurrentSystem.ps1 | 10 ++++++++++ functions/public/Invoke-WPFGetInstalled.ps1 | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/functions/private/Invoke-WinUtilCurrentSystem.ps1 b/functions/private/Invoke-WinUtilCurrentSystem.ps1 index 505942b5..b8d1e377 100644 --- a/functions/private/Invoke-WinUtilCurrentSystem.ps1 +++ b/functions/private/Invoke-WinUtilCurrentSystem.ps1 @@ -13,6 +13,16 @@ Function Invoke-WinUtilCurrentSystem { param( $CheckBox ) + if ($CheckBox -eq "choco"){ + $apps = (choco list | Select-String -Pattern "^\S+").Matches.Value + $filter = Get-WinUtilVariables -Type Checkbox | Where-Object {$psitem -like "WPFInstall*"} + $sync.GetEnumerator() | Where-Object {$psitem.Key -in $filter} | ForEach-Object { + $dependencies = @($sync.configs.applications.$($psitem.Key).choco -split ";") + if ($dependencies -in $apps) { + Write-Output $psitem.name + } + } + } if ($checkbox -eq "winget") { diff --git a/functions/public/Invoke-WPFGetInstalled.ps1 b/functions/public/Invoke-WPFGetInstalled.ps1 index df03b808..c27fd13c 100644 --- a/functions/public/Invoke-WPFGetInstalled.ps1 +++ b/functions/public/Invoke-WPFGetInstalled.ps1 @@ -16,14 +16,12 @@ function Invoke-WPFGetInstalled { return } - if(((Test-WinUtilPackageManager -winget) -eq "not-installed") -and $checkbox -eq "winget") { + if(($sync.WPFpreferChocolatey.IsChecked -eq $false) -and ((Test-WinUtilPackageManager -winget) -eq "not-installed") -and $checkbox -eq "winget") { return } - if ($sync.WPFpreferChocolatey.IsChecked) { - Write-Host "The Function `"Get Installed`" is only supported for Winget at the moment" -ForegroundColor Red - } - Invoke-WPFRunspace -ArgumentList $checkbox -DebugPreference $DebugPreference -ScriptBlock { - param($checkbox, $DebugPreference) + $preferChoco = $sync.WPFpreferChocolatey.IsChecked + Invoke-WPFRunspace -ArgumentList $checkbox, $preferChoco -DebugPreference $DebugPreference -ScriptBlock { + param($checkbox, $preferChoco, $DebugPreference) $sync.ProcessRunning = $true $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" }) @@ -34,8 +32,12 @@ function Invoke-WPFGetInstalled { if($checkbox -eq "tweaks") { Write-Host "Getting Installed Tweaks..." } - - $Checkboxes = Invoke-WinUtilCurrentSystem -CheckBox $checkbox + if ($preferChoco -and $checkbox -eq "winget") { + $Checkboxes = Invoke-WinUtilCurrentSystem -CheckBox "choco" + } + else{ + $Checkboxes = Invoke-WinUtilCurrentSystem -CheckBox $checkbox + } $sync.form.Dispatcher.invoke({ foreach($checkbox in $Checkboxes) {