From 039b5aa10cdf83c9d2184f3f2a97a90a2f6ba7aa Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Fri, 23 Aug 2024 00:36:06 +0300 Subject: [PATCH] Improve 'Invoke-WPFPresets.ps1' Public Function as well as Simple Optimizations --- functions/public/Invoke-WPFButton.ps1 | 4 ++-- functions/public/Invoke-WPFPresets.ps1 | 31 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/functions/public/Invoke-WPFButton.ps1 b/functions/public/Invoke-WPFButton.ps1 index ac5b2f8cdb..94901b8eda 100644 --- a/functions/public/Invoke-WPFButton.ps1 +++ b/functions/public/Invoke-WPFButton.ps1 @@ -26,8 +26,8 @@ function Invoke-WPFButton { "WPFInstallUpgrade" {Invoke-WPFInstallUpgrade} "WPFstandard" {Invoke-WPFPresets "Standard"} "WPFminimal" {Invoke-WPFPresets "Minimal"} - "WPFclear" {Invoke-WPFPresets -preset $null -imported $true} - "WPFclearWinget" {Invoke-WPFPresets -preset $null -imported $true -CheckBox "WPFInstall"} + "WPFclear" {Invoke-WPFPresets -imported $true -checkboxfilterpattern "WPFTweak*"} + "WPFclearWinget" {Invoke-WPFPresets -imported $true -checkboxfilterpattern "WPFInstall*"} "WPFtweaksbutton" {Invoke-WPFtweaksbutton} "WPFOOSUbutton" {Invoke-WPFOOSU} "WPFAddUltPerf" {Invoke-WPFUltimatePerformance -State "Enable"} diff --git a/functions/public/Invoke-WPFPresets.ps1 b/functions/public/Invoke-WPFPresets.ps1 index 1595a8f103..4d018af2cd 100644 --- a/functions/public/Invoke-WPFPresets.ps1 +++ b/functions/public/Invoke-WPFPresets.ps1 @@ -10,29 +10,36 @@ function Invoke-WPFPresets { .PARAMETER imported If the preset is imported from a file, defaults to false - .PARAMETER checkbox - The checkbox to set the options to, defaults to 'WPFTweaks' + .PARAMETER checkboxfilterpattern + The Pattern to use when filtering through CheckBoxes, defaults to "**" #> - param( - $preset, - [bool]$imported = $false + param ( + [Parameter(position=0)] + [string]$preset, + + [Parameter(position=1)] + [bool]$imported = $false, + + [Parameter(position=2)] + [string]$checkboxfilterpattern = "**" ) - if($imported -eq $true) { + if ($imported -eq $true) { $CheckBoxesToCheck = $preset } else { $CheckBoxesToCheck = $sync.configs.preset.$preset } - $CheckBoxes = $sync.GetEnumerator() | Where-Object { $_.Value -is [System.Windows.Controls.CheckBox] -and $_.Name -notlike "WPFToggle*" } - Write-Debug "Getting checkboxes to set $($CheckBoxes.Count)" + $CheckBoxes = ($sync.GetEnumerator()).where{ $_.Value -is [System.Windows.Controls.CheckBox] -and $_.Name -notlike "WPFToggle*" -and $_.Name -like "$checkboxfilterpattern"} + Write-Debug "Getting checkboxes to set, number of checkboxes: $($CheckBoxes.Count)" - $CheckBoxesToCheck | ForEach-Object { - if ($_ -ne $null) { - Write-Debug $_ - } + if ($CheckBoxesToCheck -ne $null) { + $debugMsg = "CheckBoxes to Check are: " + $CheckBoxesToCheck | ForEach-Object { $debugMsg += "$_, " } + $debugMsg = $debugMsg -replace (',\s*$', '') + Write-Debug "$debugMsg" } foreach ($CheckBox in $CheckBoxes) {