Updated formatting

This commit is contained in:
rbalsleyMSFT
2025-06-05 16:31:44 -07:00
parent 00a27fc4a8
commit 1b5fa5129c
2 changed files with 186 additions and 162 deletions
+48 -24
View File
@@ -146,11 +146,15 @@ function Set-UIValue {
$itemValue = $null
if ($item -is [System.Windows.Controls.ComboBoxItem]) {
$itemValue = $item.Content
} elseif ($item -is [pscustomobject] -and $item.PSObject.Properties['Value']) {
}
elseif ($item -is [pscustomobject] -and $item.PSObject.Properties['Value']) {
$itemValue = $item.Value
} elseif ($item -is [pscustomobject] -and $item.PSObject.Properties['Display']) { # Assuming 'Display' might be used if 'Value' isn't
}
elseif ($item -is [pscustomobject] -and $item.PSObject.Properties['Display']) {
# Assuming 'Display' might be used if 'Value' isn't
$itemValue = $item.Display
} else {
}
else {
$itemValue = $item # For simple string items or direct object comparison
}
@@ -164,10 +168,12 @@ function Set-UIValue {
if ($null -ne $itemToSelect) {
$control.SelectedItem = $itemToSelect
WriteLog "LoadConfig: Successfully set '$ControlName.SelectedItem' by finding matching item for value '$finalValue'."
} elseif ($control.IsEditable -and ($finalValue -is [string] -or $finalValue -is [int] -or $finalValue -is [long])) {
}
elseif ($control.IsEditable -and ($finalValue -is [string] -or $finalValue -is [int] -or $finalValue -is [long])) {
$control.Text = $finalValue.ToString()
WriteLog "LoadConfig: Set '$ControlName.Text' to '$($finalValue.ToString())' as SelectedItem match failed (editable ComboBox)."
} else {
}
else {
$itemsString = ""
try {
# Safer way to get item strings
@@ -176,10 +182,12 @@ function Set-UIValue {
if ($null -ne $cbItem) { $itemStrings += $cbItem.ToString() } else { $itemStrings += "[NULL_ITEM]" }
}
$itemsString = $itemStrings -join "; "
} catch { $itemsString = "Error retrieving item strings." }
}
catch { $itemsString = "Error retrieving item strings." }
WriteLog "LoadConfig Warning: Could not find or set item matching value '$finalValue' for '$ControlName.SelectedItem'. Current items: [$itemsString]"
}
} else {
}
else {
# For other properties or controls
$control.$PropertyName = $finalValue
WriteLog "LoadConfig: Successfully set '$ControlName.$PropertyName' to '$finalValue'."
@@ -594,7 +602,8 @@ function Get-UIConfig {
$vars[$item.Key] = $item.Value
}
if ($vars.Count -gt 0) { $vars } else { $null }
} else { $null }
}
else { $null }
BuildUSBDrive = $window.FindName('chkBuildUSBDriveEnable').IsChecked
CleanupAppsISO = $window.FindName('chkCleanupAppsISO').IsChecked
CleanupCaptureISO = $window.FindName('chkCleanupCaptureISO').IsChecked
@@ -629,7 +638,8 @@ function Get-UIConfig {
Memory = [int64]$window.FindName('txtMemory').Text * 1GB
Model = if ($window.FindName('chkDownloadDrivers').IsChecked) {
$selectedModels = $script:lstDriverModels.Items | Where-Object { $_.IsSelected }
if ($selectedModels.Count -ge 1) { # If one or more models are selected
if ($selectedModels.Count -ge 1) {
# If one or more models are selected
$selectedModels[0].Model # Use the 'Model' property (display name) of the first selected one
}
else {
@@ -1110,7 +1120,8 @@ function Invoke-ListViewSort {
elseif ($property -eq "Value") {
$secondarySortPropertyName = "Key"
}
else { # Default secondary sort for IsSelected or other properties
else {
# Default secondary sort for IsSelected or other properties
$secondarySortPropertyName = "Key"
}
}
@@ -1367,7 +1378,8 @@ function Add-SelectableGridViewColumn {
$headerChk = Get-Variable -Name $headerCheckboxNameFromTag -Scope Script -ValueOnly -ErrorAction SilentlyContinue
if ($null -ne $headerChk) {
Update-SelectAllHeaderCheckBoxState -ListView $targetListView -HeaderCheckBox $headerChk
} else {
}
else {
WriteLog "Add-SelectableGridViewColumn: Error - Could not retrieve script variable for header checkbox named '$headerCheckboxNameFromTag' for ListView '$listViewNameFromTag'."
}
})
@@ -1394,7 +1406,8 @@ function Update-SelectAllHeaderCheckBoxState {
if ($null -ne $ListView.ItemsSource) {
$collectionToInspect = @($ListView.ItemsSource)
}
elseif ($ListView.HasItems) { # Check if Items collection has items and ItemsSource is null
elseif ($ListView.HasItems) {
# Check if Items collection has items and ItemsSource is null
$collectionToInspect = @($ListView.Items)
}
@@ -1407,7 +1420,8 @@ function Update-SelectAllHeaderCheckBoxState {
$selectedCount = ($collectionToInspect | Where-Object { $_.IsSelected }).Count
$totalItemCount = $collectionToInspect.Count # Get the total count from the collection being inspected
if ($totalItemCount -eq 0) { # Handle empty list case specifically
if ($totalItemCount -eq 0) {
# Handle empty list case specifically
$HeaderCheckBox.IsChecked = $false
}
elseif ($selectedCount -eq $totalItemCount) {
@@ -2351,7 +2365,7 @@ $window.Add_Loaded({
# New logic for AppsScriptVariables
$script:chkDefineAppsScriptVariables.Visibility = 'Visible'
})
$script:chkInstallApps.Add_Unchecked({
$script:chkInstallApps.Add_Unchecked({
$script:chkInstallWingetApps.IsChecked = $false # Uncheck children when parent is unchecked
$script:chkBringYourOwnApps.IsChecked = $false
$script:chkInstallWingetApps.Visibility = 'Collapsed'
@@ -2800,7 +2814,8 @@ $script:chkInstallApps.Add_Unchecked({
$script:lstAppsScriptVariables.ItemsSource = $script:appsScriptVariablesDataList.ToArray()
# Update the header checkbox state
if ($null -ne $script:chkSelectAllAppsScriptVariables) { # Check if variable exists
if ($null -ne $script:chkSelectAllAppsScriptVariables) {
# Check if variable exists
Update-SelectAllHeaderCheckBoxState -ListView $script:lstAppsScriptVariables -HeaderCheckBox $script:chkSelectAllAppsScriptVariables
}
})
@@ -3238,7 +3253,8 @@ $btnLoadConfig.Add_Click({
if (($configContent.PSObject.Properties.Match('AppsScriptVariables')).Count -gt 0) {
$appsScriptVarsKeyExists = $true
}
} catch { WriteLog "ERROR: Exception while trying to Match key 'AppsScriptVariables'. Error: $($_.Exception.Message)" }
}
catch { WriteLog "ERROR: Exception while trying to Match key 'AppsScriptVariables'. Error: $($_.Exception.Message)" }
}
$lstAppsScriptVars = $window.FindName('lstAppsScriptVariables')
@@ -3258,12 +3274,14 @@ $btnLoadConfig.Add_Click({
$chkDefineAppsScriptVars.IsChecked = $true
$appsScriptVarsPanel.Visibility = 'Visible'
WriteLog "LoadConfig: Loaded AppsScriptVariables and checked 'Define Apps Script Variables'."
} else {
}
else {
$chkDefineAppsScriptVars.IsChecked = $false
$appsScriptVarsPanel.Visibility = 'Collapsed'
WriteLog "LoadConfig: AppsScriptVariables key was present but empty. Unchecked 'Define Apps Script Variables'."
}
} elseif ($appsScriptVarsKeyExists -and $null -ne $configContent.AppsScriptVariables -and $configContent.AppsScriptVariables -is [hashtable]) {
}
elseif ($appsScriptVarsKeyExists -and $null -ne $configContent.AppsScriptVariables -and $configContent.AppsScriptVariables -is [hashtable]) {
# Handle if it's already a hashtable (e.g., from older config or direct creation)
WriteLog "LoadConfig: Processing AppsScriptVariables (Hashtable) from config."
$loadedVars = $configContent.AppsScriptVariables
@@ -3276,12 +3294,14 @@ $btnLoadConfig.Add_Click({
$chkDefineAppsScriptVars.IsChecked = $true
$appsScriptVarsPanel.Visibility = 'Visible'
WriteLog "LoadConfig: Loaded AppsScriptVariables (Hashtable) and checked 'Define Apps Script Variables'."
} else {
}
else {
$chkDefineAppsScriptVars.IsChecked = $false
$appsScriptVarsPanel.Visibility = 'Collapsed'
WriteLog "LoadConfig: AppsScriptVariables (Hashtable) key was present but empty. Unchecked 'Define Apps Script Variables'."
}
} else {
}
else {
$chkDefineAppsScriptVars.IsChecked = $false
$appsScriptVarsPanel.Visibility = 'Collapsed'
WriteLog "LoadConfig Info: Key 'AppsScriptVariables' not found, is null, or not a PSCustomObject/Hashtable. Unchecked 'Define Apps Script Variables'."
@@ -3300,7 +3320,8 @@ $btnLoadConfig.Add_Click({
if (($configContent.PSObject.Properties.Match('USBDriveList')).Count -gt 0) {
$usbDriveListKeyExists = $true
}
} catch {
}
catch {
WriteLog "ERROR: Exception while trying to Match key 'USBDriveList' on configContent.PSObject.Properties. Error: $($_.Exception.Message)"
}
}
@@ -3333,7 +3354,8 @@ $btnLoadConfig.Add_Click({
if ($propertyExists -and ($propertyValue -eq $item.SerialNumber)) {
WriteLog "LoadConfig: Selecting USB Drive Model '$($item.Model)' with Serial '$($item.SerialNumber)'."
$item.IsSelected = $true
} else {
}
else {
if (-not $propertyExists -and ($null -ne $configContent.USBDriveList)) {
WriteLog "LoadConfig: Property '$($propertyName)' not found on USBDriveList for item Model '$($item.Model)'."
}
@@ -3346,7 +3368,8 @@ $btnLoadConfig.Add_Click({
$allSelected = $script:lstUSBDrives.Items.Count -gt 0 -and -not ($script:lstUSBDrives.Items | Where-Object { -not $_.IsSelected })
$script:chkSelectAllUSBDrives.IsChecked = $allSelected
WriteLog "LoadConfig: USBDriveList processing complete."
} else {
}
else {
WriteLog "LoadConfig Info: Key 'USBDriveList' not found or is null in configuration file. Skipping USB drive selection."
}
@@ -3359,7 +3382,8 @@ $btnLoadConfig.Add_Click({
$shouldAutoCheckSpecificDrives = $true
}
}
elseif ($configContent.USBDriveList -is [hashtable]) { # Fallback for older configs
elseif ($configContent.USBDriveList -is [hashtable]) {
# Fallback for older configs
if ($configContent.USBDriveList.Keys.Count -gt 0) {
$shouldAutoCheckSpecificDrives = $true
}