Files
winutil/functions/public/Invoke-WPFPresets.ps1
Eren 3fb5c04693 Fix import/export functionality (#4131)
* fix: cast selections to string to prevent PSCustomObject type issues

* fix(presets): clear existing selections before importing to replace state instead of merging

* refactor(impex): warn user when exporting empty selections or importing empty config
2026-03-02 13:02:48 -06:00

51 lines
1.5 KiB
PowerShell

function Invoke-WPFPresets {
<#
.SYNOPSIS
Sets the checkboxes in winutil to the given preset
.PARAMETER preset
The preset to set the checkboxes to
.PARAMETER imported
If the preset is imported from a file, defaults to false
.PARAMETER checkboxfilterpattern
The Pattern to use when filtering through CheckBoxes, defaults to "**"
#>
param (
[Parameter(position=0)]
[Array]$preset = $null,
[Parameter(position=1)]
[bool]$imported = $false,
[Parameter(position=2)]
[string]$checkboxfilterpattern = "**"
)
if ($imported -eq $true) {
$CheckBoxesToCheck = $preset
} else {
$CheckBoxesToCheck = $sync.configs.preset.$preset
}
# clear out the filtered pattern so applying a preset replaces the current
# state rather than merging with it
switch ($checkboxfilterpattern) {
"WPFTweak*" { $sync.selectedTweaks = [System.Collections.Generic.List[string]]::new() }
"WPFInstall*" { $sync.selectedApps = [System.Collections.Generic.List[string]]::new() }
"WPFeatures" { $sync.selectedFeatures = [System.Collections.Generic.List[string]]::new() }
"WPFToggle" { $sync.selectedToggles = [System.Collections.Generic.List[string]]::new() }
default {}
}
if ($preset) {
Update-WinUtilSelections -flatJson $CheckBoxesToCheck
}
Reset-WPFCheckBoxes -doToggles $false -checkboxfilterpattern $checkboxfilterpattern
}