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

78 lines
2.3 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 Group
The group of checkboxes to check
+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] }
foreach ($CheckBox in $CheckBoxes) {
$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
$wingetValue = $sync.configs.applications.$($CheckBox.Name).winget
if (-not [string]::IsNullOrWhiteSpace($wingetValue) -and $wingetValue -ne "na") {
$wingetValue -split ";"
} else {
$sync.configs.applications.$($CheckBox.Name).choco
}
}
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
2024-01-15 11:32:19 -06:00
if ($uncheck -eq $true) {
$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
}