Files
winutil/functions/private/Get-WinUtilCheckBoxes.ps1
T

84 lines
2.6 KiB
PowerShell
Raw Normal View History

+3
2023-03-07 12:28:00 -08:00
Function Get-WinUtilCheckBoxes {
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Finds all checkboxes that are checked on the specific tab and inputs them into a script.
+3
2023-03-07 12:28:00 -08:00
2023-10-19 17:12:55 -05:00
.PARAMETER unCheck
Whether to uncheck the checkboxes that are checked. Defaults to true
+3
2023-03-07 12:28:00 -08:00
2023-10-19 17:12:55 -05:00
.OUTPUTS
A List containing the name of each checked checkbox
.EXAMPLE
+3
2023-03-07 12:28:00 -08:00
Get-WinUtilCheckBoxes "WPFInstall"
#>
Param(
2024-01-15 11:32:19 -06:00
[boolean]$unCheck = $false
+3
2023-03-07 12:28:00 -08:00
)
2024-01-15 11:32:19 -06:00
$Output = @{
Install = @()
WPFTweaks = @()
WPFFeature = @()
WPFInstall = @()
+3
2023-03-07 12:28:00 -08:00
}
2023-10-19 17:12:55 -05:00
2024-01-15 11:32:19 -06:00
$CheckBoxes = $sync.GetEnumerator() | Where-Object { $_.Value -is [System.Windows.Controls.CheckBox] }
+26
2024-06-04 20:27:27 -07:00
# First check and add WPFTweaksRestorePoint if checked
$RestorePoint = $CheckBoxes | Where-Object { $_.Key -eq 'WPFTweaksRestorePoint' -and $_.Value.IsChecked -eq $true }
if ($RestorePoint) {
$Output["WPFTweaks"] = @('WPFTweaksRestorePoint')
Write-Debug "Adding WPFTweaksRestorePoint as first in WPFTweaks"
if ($unCheck) {
$RestorePoint.Value.IsChecked = $false
}
}
2024-01-15 11:32:19 -06:00
foreach ($CheckBox in $CheckBoxes) {
+26
2024-06-04 20:27:27 -07:00
if ($CheckBox.Key -eq 'WPFTweaksRestorePoint') { continue } # Skip since it's already handled
2024-01-15 11:32:19 -06:00
$group = if ($CheckBox.Key.StartsWith("WPFInstall")) { "Install" }
elseif ($CheckBox.Key.StartsWith("WPFTweaks")) { "WPFTweaks" }
elseif ($CheckBox.Key.StartsWith("WPFFeature")) { "WPFFeature" }
if ($group) {
if ($CheckBox.Value.IsChecked -eq $true) {
$feature = switch ($group) {
"Install" {
# Get the winget value
+26
2024-06-04 20:27:27 -07:00
[PsCustomObject]@{
winget="$($sync.configs.applications.$($CheckBox.Name).winget)";
choco="$($sync.configs.applications.$($CheckBox.Name).choco)";
2024-01-15 11:32:19 -06:00
}
+26
2024-06-04 20:27:27 -07:00
2024-01-15 11:32:19 -06:00
}
default {
$CheckBox.Name
}
}
2023-10-19 17:12:55 -05:00
2024-01-15 11:32:19 -06:00
if (-not $Output.ContainsKey($group)) {
$Output[$group] = @()
}
if ($group -eq "Install") {
$Output["WPFInstall"] += $CheckBox.Name
Write-Debug "Adding: $($CheckBox.Name) under: WPFInstall"
+2
2023-05-09 13:14:27 -05:00
}
2024-01-15 11:32:19 -06:00
Write-Debug "Adding: $($feature) under: $($group)"
$Output[$group] += $feature
2023-10-19 17:12:55 -05:00
+26
2024-06-04 20:27:27 -07:00
if ($unCheck) {
2024-01-15 11:32:19 -06:00
$CheckBox.Value.IsChecked = $false
+3
2023-03-07 12:28:00 -08:00
}
}
}
}
2024-01-15 11:32:19 -06:00
return $Output
+3
2023-03-07 12:28:00 -08:00
}