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
+184 -160
View File
@@ -146,11 +146,15 @@ function Set-UIValue {
$itemValue = $null $itemValue = $null
if ($item -is [System.Windows.Controls.ComboBoxItem]) { if ($item -is [System.Windows.Controls.ComboBoxItem]) {
$itemValue = $item.Content $itemValue = $item.Content
} elseif ($item -is [pscustomobject] -and $item.PSObject.Properties['Value']) { }
elseif ($item -is [pscustomobject] -and $item.PSObject.Properties['Value']) {
$itemValue = $item.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 $itemValue = $item.Display
} else { }
else {
$itemValue = $item # For simple string items or direct object comparison $itemValue = $item # For simple string items or direct object comparison
} }
@@ -164,10 +168,12 @@ function Set-UIValue {
if ($null -ne $itemToSelect) { if ($null -ne $itemToSelect) {
$control.SelectedItem = $itemToSelect $control.SelectedItem = $itemToSelect
WriteLog "LoadConfig: Successfully set '$ControlName.SelectedItem' by finding matching item for value '$finalValue'." 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() $control.Text = $finalValue.ToString()
WriteLog "LoadConfig: Set '$ControlName.Text' to '$($finalValue.ToString())' as SelectedItem match failed (editable ComboBox)." WriteLog "LoadConfig: Set '$ControlName.Text' to '$($finalValue.ToString())' as SelectedItem match failed (editable ComboBox)."
} else { }
else {
$itemsString = "" $itemsString = ""
try { try {
# Safer way to get item strings # Safer way to get item strings
@@ -176,10 +182,12 @@ function Set-UIValue {
if ($null -ne $cbItem) { $itemStrings += $cbItem.ToString() } else { $itemStrings += "[NULL_ITEM]" } if ($null -ne $cbItem) { $itemStrings += $cbItem.ToString() } else { $itemStrings += "[NULL_ITEM]" }
} }
$itemsString = $itemStrings -join "; " $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]" 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 # For other properties or controls
$control.$PropertyName = $finalValue $control.$PropertyName = $finalValue
WriteLog "LoadConfig: Successfully set '$ControlName.$PropertyName' to '$finalValue'." WriteLog "LoadConfig: Successfully set '$ControlName.$PropertyName' to '$finalValue'."
@@ -584,99 +592,101 @@ $defaultFFUPrefix = "_FFU"
function Get-UIConfig { function Get-UIConfig {
# Create hash to store configuration # Create hash to store configuration
$config = [ordered]@{ $config = [ordered]@{
AllowExternalHardDiskMedia = $window.FindName('chkAllowExternalHardDiskMedia').IsChecked AllowExternalHardDiskMedia = $window.FindName('chkAllowExternalHardDiskMedia').IsChecked
AllowVHDXCaching = $window.FindName('chkAllowVHDXCaching').IsChecked AllowVHDXCaching = $window.FindName('chkAllowVHDXCaching').IsChecked
AppListPath = $window.FindName('txtAppListJsonPath').Text AppListPath = $window.FindName('txtAppListJsonPath').Text
AppsPath = $window.FindName('txtApplicationPath').Text AppsPath = $window.FindName('txtApplicationPath').Text
AppsScriptVariables = if ($window.FindName('chkDefineAppsScriptVariables').IsChecked) { AppsScriptVariables = if ($window.FindName('chkDefineAppsScriptVariables').IsChecked) {
$vars = @{} $vars = @{}
foreach ($item in $script:appsScriptVariablesDataList) { foreach ($item in $script:appsScriptVariablesDataList) {
$vars[$item.Key] = $item.Value $vars[$item.Key] = $item.Value
} }
if ($vars.Count -gt 0) { $vars } else { $null } if ($vars.Count -gt 0) { $vars } else { $null }
} else { $null } }
BuildUSBDrive = $window.FindName('chkBuildUSBDriveEnable').IsChecked else { $null }
CleanupAppsISO = $window.FindName('chkCleanupAppsISO').IsChecked BuildUSBDrive = $window.FindName('chkBuildUSBDriveEnable').IsChecked
CleanupCaptureISO = $window.FindName('chkCleanupCaptureISO').IsChecked CleanupAppsISO = $window.FindName('chkCleanupAppsISO').IsChecked
CleanupDeployISO = $window.FindName('chkCleanupDeployISO').IsChecked CleanupCaptureISO = $window.FindName('chkCleanupCaptureISO').IsChecked
CleanupDrivers = $window.FindName('chkCleanupDrivers').IsChecked CleanupDeployISO = $window.FindName('chkCleanupDeployISO').IsChecked
CompactOS = $window.FindName('chkCompactOS').IsChecked CleanupDrivers = $window.FindName('chkCleanupDrivers').IsChecked
CompactOS = $window.FindName('chkCompactOS').IsChecked
CompressDownloadedDriversToWim = $window.FindName('chkCompressDriversToWIM').IsChecked # Renamed from CompressDriversToWIM CompressDownloadedDriversToWim = $window.FindName('chkCompressDriversToWIM').IsChecked # Renamed from CompressDriversToWIM
CopyAutopilot = $window.FindName('chkCopyAutopilot').IsChecked CopyAutopilot = $window.FindName('chkCopyAutopilot').IsChecked
CopyDrivers = $window.FindName('chkCopyDrivers').IsChecked CopyDrivers = $window.FindName('chkCopyDrivers').IsChecked
CopyOfficeConfigXML = $window.FindName('chkCopyOfficeConfigXML').IsChecked # UI Only parameter CopyOfficeConfigXML = $window.FindName('chkCopyOfficeConfigXML').IsChecked # UI Only parameter
CopyPEDrivers = $window.FindName('chkCopyPEDrivers').IsChecked CopyPEDrivers = $window.FindName('chkCopyPEDrivers').IsChecked
CopyPPKG = $window.FindName('chkCopyPPKG').IsChecked CopyPPKG = $window.FindName('chkCopyPPKG').IsChecked
CopyUnattend = $window.FindName('chkCopyUnattend').IsChecked CopyUnattend = $window.FindName('chkCopyUnattend').IsChecked
CreateCaptureMedia = $window.FindName('chkCreateCaptureMedia').IsChecked CreateCaptureMedia = $window.FindName('chkCreateCaptureMedia').IsChecked
CreateDeploymentMedia = $window.FindName('chkCreateDeploymentMedia').IsChecked CreateDeploymentMedia = $window.FindName('chkCreateDeploymentMedia').IsChecked
CustomFFUNameTemplate = $window.FindName('txtCustomFFUNameTemplate').Text CustomFFUNameTemplate = $window.FindName('txtCustomFFUNameTemplate').Text
Disksize = [int64]$window.FindName('txtDiskSize').Text * 1GB # Renamed from DiskSize Disksize = [int64]$window.FindName('txtDiskSize').Text * 1GB # Renamed from DiskSize
DownloadDrivers = $window.FindName('chkDownloadDrivers').IsChecked # UI Only parameter DownloadDrivers = $window.FindName('chkDownloadDrivers').IsChecked # UI Only parameter
DriversFolder = $window.FindName('txtDriversFolder').Text DriversFolder = $window.FindName('txtDriversFolder').Text
DriversJsonPath = $script:txtDriversJsonPath.Text # Read from the new TextBox DriversJsonPath = $script:txtDriversJsonPath.Text # Read from the new TextBox
FFUCaptureLocation = $window.FindName('txtFFUCaptureLocation').Text FFUCaptureLocation = $window.FindName('txtFFUCaptureLocation').Text
FFUDevelopmentPath = $window.FindName('txtFFUDevPath').Text FFUDevelopmentPath = $window.FindName('txtFFUDevPath').Text
FFUPrefix = $window.FindName('txtVMNamePrefix').Text FFUPrefix = $window.FindName('txtVMNamePrefix').Text
InstallApps = $window.FindName('chkInstallApps').IsChecked InstallApps = $window.FindName('chkInstallApps').IsChecked
InstallDrivers = $window.FindName('chkInstallDrivers').IsChecked InstallDrivers = $window.FindName('chkInstallDrivers').IsChecked
InstallOffice = $window.FindName('chkInstallOffice').IsChecked InstallOffice = $window.FindName('chkInstallOffice').IsChecked
InstallWingetApps = $window.FindName('chkInstallWingetApps').IsChecked # UI Only parameter InstallWingetApps = $window.FindName('chkInstallWingetApps').IsChecked # UI Only parameter
ISOPath = $window.FindName('txtISOPath').Text ISOPath = $window.FindName('txtISOPath').Text
LogicalSectorSizeBytes = [int]$window.FindName('cmbLogicalSectorSize').SelectedItem.Content LogicalSectorSizeBytes = [int]$window.FindName('cmbLogicalSectorSize').SelectedItem.Content
Make = $window.FindName('cmbMake').SelectedItem Make = $window.FindName('cmbMake').SelectedItem
MediaType = $window.FindName('cmbMediaType').SelectedItem MediaType = $window.FindName('cmbMediaType').SelectedItem
Memory = [int64]$window.FindName('txtMemory').Text * 1GB Memory = [int64]$window.FindName('txtMemory').Text * 1GB
Model = if ($window.FindName('chkDownloadDrivers').IsChecked) { Model = if ($window.FindName('chkDownloadDrivers').IsChecked) {
$selectedModels = $script:lstDriverModels.Items | Where-Object { $_.IsSelected } $selectedModels = $script:lstDriverModels.Items | Where-Object { $_.IsSelected }
if ($selectedModels.Count -ge 1) { # If one or more models are selected if ($selectedModels.Count -ge 1) {
$selectedModels[0].Model # Use the 'Model' property (display name) of the first selected one # If one or more models are selected
} $selectedModels[0].Model # Use the 'Model' property (display name) of the first selected one
else { }
$null # No model selected in the list else {
} $null # No model selected in the list
} }
else { }
$null # Not downloading drivers via UI selection else {
} $null # Not downloading drivers via UI selection
OfficeConfigXMLFile = $window.FindName('txtOfficeConfigXMLFilePath').Text # UI Only }
OfficePath = $window.FindName('txtOfficePath').Text # UI Only parameter OfficeConfigXMLFile = $window.FindName('txtOfficeConfigXMLFilePath').Text # UI Only
Optimize = $window.FindName('chkOptimize').IsChecked OfficePath = $window.FindName('txtOfficePath').Text # UI Only parameter
OptionalFeatures = $window.FindName('txtOptionalFeatures').Text # Parameter from Sample_default.json Optimize = $window.FindName('chkOptimize').IsChecked
OrchestrationPath = "$($window.FindName('txtApplicationPath').Text)\Orchestration" # Parameter from Sample_default.json, derived OptionalFeatures = $window.FindName('txtOptionalFeatures').Text # Parameter from Sample_default.json
PEDriversFolder = $window.FindName('txtPEDriversFolder').Text OrchestrationPath = "$($window.FindName('txtApplicationPath').Text)\Orchestration" # Parameter from Sample_default.json, derived
Processors = [int]$window.FindName('txtProcessors').Text PEDriversFolder = $window.FindName('txtPEDriversFolder').Text
ProductKey = $window.FindName('txtProductKey').Text Processors = [int]$window.FindName('txtProcessors').Text
PromptExternalHardDiskMedia = $window.FindName('chkPromptExternalHardDiskMedia').IsChecked ProductKey = $window.FindName('txtProductKey').Text
RemoveApps = $window.FindName('chkRemoveApps').IsChecked PromptExternalHardDiskMedia = $window.FindName('chkPromptExternalHardDiskMedia').IsChecked
RemoveFFU = $window.FindName('chkRemoveFFU').IsChecked RemoveApps = $window.FindName('chkRemoveApps').IsChecked
RemoveUpdates = $window.FindName('chkRemoveUpdates').IsChecked RemoveFFU = $window.FindName('chkRemoveFFU').IsChecked
ShareName = $window.FindName('txtShareName').Text RemoveUpdates = $window.FindName('chkRemoveUpdates').IsChecked
UpdateADK = $script:chkUpdateADK.IsChecked ShareName = $window.FindName('txtShareName').Text
UpdateEdge = $window.FindName('chkUpdateEdge').IsChecked UpdateADK = $script:chkUpdateADK.IsChecked
UpdateLatestCU = $window.FindName('chkUpdateLatestCU').IsChecked UpdateEdge = $window.FindName('chkUpdateEdge').IsChecked
UpdateLatestDefender = $window.FindName('chkUpdateLatestDefender').IsChecked UpdateLatestCU = $window.FindName('chkUpdateLatestCU').IsChecked
UpdateLatestMicrocode = $script:chkUpdateLatestMicrocode.IsChecked UpdateLatestDefender = $window.FindName('chkUpdateLatestDefender').IsChecked
UpdateLatestMSRT = $window.FindName('chkUpdateLatestMSRT').IsChecked UpdateLatestMicrocode = $script:chkUpdateLatestMicrocode.IsChecked
UpdateLatestNet = $window.FindName('chkUpdateLatestNet').IsChecked UpdateLatestMSRT = $window.FindName('chkUpdateLatestMSRT').IsChecked
UpdateOneDrive = $window.FindName('chkUpdateOneDrive').IsChecked UpdateLatestNet = $window.FindName('chkUpdateLatestNet').IsChecked
UpdatePreviewCU = $window.FindName('chkUpdatePreviewCU').IsChecked UpdateOneDrive = $window.FindName('chkUpdateOneDrive').IsChecked
UserAppListPath = "$($window.FindName('txtApplicationPath').Text)\UserAppList.json" # Parameter from Sample_default.json, derived UpdatePreviewCU = $window.FindName('chkUpdatePreviewCU').IsChecked
USBDriveList = @{} UserAppListPath = "$($window.FindName('txtApplicationPath').Text)\UserAppList.json" # Parameter from Sample_default.json, derived
Username = $window.FindName('txtUsername').Text USBDriveList = @{}
VMHostIPAddress = $window.FindName('txtVMHostIPAddress').Text Username = $window.FindName('txtUsername').Text
VMLocation = $window.FindName('txtVMLocation').Text VMHostIPAddress = $window.FindName('txtVMHostIPAddress').Text
VMSwitchName = if ($window.FindName('cmbVMSwitchName').SelectedItem -eq 'Other') { VMLocation = $window.FindName('txtVMLocation').Text
VMSwitchName = if ($window.FindName('cmbVMSwitchName').SelectedItem -eq 'Other') {
$window.FindName('txtCustomVMSwitchName').Text $window.FindName('txtCustomVMSwitchName').Text
} }
else { else {
$window.FindName('cmbVMSwitchName').SelectedItem $window.FindName('cmbVMSwitchName').SelectedItem
} }
WindowsArch = $window.FindName('cmbWindowsArch').SelectedItem WindowsArch = $window.FindName('cmbWindowsArch').SelectedItem
WindowsLang = $window.FindName('cmbWindowsLang').SelectedItem WindowsLang = $window.FindName('cmbWindowsLang').SelectedItem
WindowsRelease = [int]$window.FindName('cmbWindowsRelease').SelectedItem.Value WindowsRelease = [int]$window.FindName('cmbWindowsRelease').SelectedItem.Value
WindowsSKU = $window.FindName('cmbWindowsSKU').SelectedItem WindowsSKU = $window.FindName('cmbWindowsSKU').SelectedItem
WindowsVersion = $window.FindName('cmbWindowsVersion').SelectedItem WindowsVersion = $window.FindName('cmbWindowsVersion').SelectedItem
} }
# Add selected USB drives to the config # Add selected USB drives to the config
@@ -1110,7 +1120,8 @@ function Invoke-ListViewSort {
elseif ($property -eq "Value") { elseif ($property -eq "Value") {
$secondarySortPropertyName = "Key" $secondarySortPropertyName = "Key"
} }
else { # Default secondary sort for IsSelected or other properties else {
# Default secondary sort for IsSelected or other properties
$secondarySortPropertyName = "Key" $secondarySortPropertyName = "Key"
} }
} }
@@ -1367,7 +1378,8 @@ function Add-SelectableGridViewColumn {
$headerChk = Get-Variable -Name $headerCheckboxNameFromTag -Scope Script -ValueOnly -ErrorAction SilentlyContinue $headerChk = Get-Variable -Name $headerCheckboxNameFromTag -Scope Script -ValueOnly -ErrorAction SilentlyContinue
if ($null -ne $headerChk) { if ($null -ne $headerChk) {
Update-SelectAllHeaderCheckBoxState -ListView $targetListView -HeaderCheckBox $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'." 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) { if ($null -ne $ListView.ItemsSource) {
$collectionToInspect = @($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) $collectionToInspect = @($ListView.Items)
} }
@@ -1407,7 +1420,8 @@ function Update-SelectAllHeaderCheckBoxState {
$selectedCount = ($collectionToInspect | Where-Object { $_.IsSelected }).Count $selectedCount = ($collectionToInspect | Where-Object { $_.IsSelected }).Count
$totalItemCount = $collectionToInspect.Count # Get the total count from the collection being inspected $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 $HeaderCheckBox.IsChecked = $false
} }
elseif ($selectedCount -eq $totalItemCount) { elseif ($selectedCount -eq $totalItemCount) {
@@ -2351,7 +2365,7 @@ $window.Add_Loaded({
# New logic for AppsScriptVariables # New logic for AppsScriptVariables
$script:chkDefineAppsScriptVariables.Visibility = 'Visible' $script:chkDefineAppsScriptVariables.Visibility = 'Visible'
}) })
$script:chkInstallApps.Add_Unchecked({ $script:chkInstallApps.Add_Unchecked({
$script:chkInstallWingetApps.IsChecked = $false # Uncheck children when parent is unchecked $script:chkInstallWingetApps.IsChecked = $false # Uncheck children when parent is unchecked
$script:chkBringYourOwnApps.IsChecked = $false $script:chkBringYourOwnApps.IsChecked = $false
$script:chkInstallWingetApps.Visibility = 'Collapsed' $script:chkInstallWingetApps.Visibility = 'Collapsed'
@@ -2751,68 +2765,69 @@ $script:chkInstallApps.Add_Unchecked({
# AppsScriptVariables Event Handlers # AppsScriptVariables Event Handlers
$script:chkDefineAppsScriptVariables.Add_Checked({ $script:chkDefineAppsScriptVariables.Add_Checked({
$script:appsScriptVariablesPanel.Visibility = 'Visible' $script:appsScriptVariablesPanel.Visibility = 'Visible'
}) })
$script:chkDefineAppsScriptVariables.Add_Unchecked({ $script:chkDefineAppsScriptVariables.Add_Unchecked({
$script:appsScriptVariablesPanel.Visibility = 'Collapsed' $script:appsScriptVariablesPanel.Visibility = 'Collapsed'
}) })
$script:btnAddAppsScriptVariable.Add_Click({ $script:btnAddAppsScriptVariable.Add_Click({
$key = $script:txtAppsScriptKey.Text.Trim() $key = $script:txtAppsScriptKey.Text.Trim()
$value = $script:txtAppsScriptValue.Text.Trim() $value = $script:txtAppsScriptValue.Text.Trim()
if ([string]::IsNullOrWhiteSpace($key)) { if ([string]::IsNullOrWhiteSpace($key)) {
[System.Windows.MessageBox]::Show("Apps Script Variable Key cannot be empty.", "Input Error", "OK", "Warning") [System.Windows.MessageBox]::Show("Apps Script Variable Key cannot be empty.", "Input Error", "OK", "Warning")
return return
} }
# Check for duplicate keys # Check for duplicate keys
$existingKey = $script:lstAppsScriptVariables.Items | Where-Object { $_.Key -eq $key } $existingKey = $script:lstAppsScriptVariables.Items | Where-Object { $_.Key -eq $key }
if ($existingKey) { if ($existingKey) {
[System.Windows.MessageBox]::Show("An Apps Script Variable with the key '$key' already exists.", "Duplicate Key", "OK", "Warning") [System.Windows.MessageBox]::Show("An Apps Script Variable with the key '$key' already exists.", "Duplicate Key", "OK", "Warning")
return return
} }
$newItem = [PSCustomObject]@{ $newItem = [PSCustomObject]@{
IsSelected = $false # Add IsSelected property IsSelected = $false # Add IsSelected property
Key = $key Key = $key
Value = $value Value = $value
} }
$script:appsScriptVariablesDataList.Add($newItem) $script:appsScriptVariablesDataList.Add($newItem)
$script:lstAppsScriptVariables.ItemsSource = $script:appsScriptVariablesDataList.ToArray() $script:lstAppsScriptVariables.ItemsSource = $script:appsScriptVariablesDataList.ToArray()
$script:txtAppsScriptKey.Clear() $script:txtAppsScriptKey.Clear()
$script:txtAppsScriptValue.Clear() $script:txtAppsScriptValue.Clear()
# Update the header checkbox state # Update the header checkbox state
if ($null -ne $script:chkSelectAllAppsScriptVariables) { if ($null -ne $script:chkSelectAllAppsScriptVariables) {
Update-SelectAllHeaderCheckBoxState -ListView $script:lstAppsScriptVariables -HeaderCheckBox $script:chkSelectAllAppsScriptVariables Update-SelectAllHeaderCheckBoxState -ListView $script:lstAppsScriptVariables -HeaderCheckBox $script:chkSelectAllAppsScriptVariables
} }
}) })
$script:btnRemoveSelectedAppsScriptVariables.Add_Click({ $script:btnRemoveSelectedAppsScriptVariables.Add_Click({
$itemsToRemove = @($script:appsScriptVariablesDataList | Where-Object { $_.IsSelected }) $itemsToRemove = @($script:appsScriptVariablesDataList | Where-Object { $_.IsSelected })
if ($itemsToRemove.Count -eq 0) { if ($itemsToRemove.Count -eq 0) {
[System.Windows.MessageBox]::Show("Please select one or more Apps Script Variables to remove.", "Selection Error", "OK", "Warning") [System.Windows.MessageBox]::Show("Please select one or more Apps Script Variables to remove.", "Selection Error", "OK", "Warning")
return return
} }
foreach ($itemToRemove in $itemsToRemove) { foreach ($itemToRemove in $itemsToRemove) {
$script:appsScriptVariablesDataList.Remove($itemToRemove) $script:appsScriptVariablesDataList.Remove($itemToRemove)
} }
$script:lstAppsScriptVariables.ItemsSource = $script:appsScriptVariablesDataList.ToArray() $script:lstAppsScriptVariables.ItemsSource = $script:appsScriptVariablesDataList.ToArray()
# Update the header checkbox state # Update the header checkbox state
if ($null -ne $script:chkSelectAllAppsScriptVariables) { # Check if variable exists if ($null -ne $script:chkSelectAllAppsScriptVariables) {
Update-SelectAllHeaderCheckBoxState -ListView $script:lstAppsScriptVariables -HeaderCheckBox $script:chkSelectAllAppsScriptVariables # Check if variable exists
} Update-SelectAllHeaderCheckBoxState -ListView $script:lstAppsScriptVariables -HeaderCheckBox $script:chkSelectAllAppsScriptVariables
}) }
})
$script:btnClearAppsScriptVariables.Add_Click({ $script:btnClearAppsScriptVariables.Add_Click({
$script:appsScriptVariablesDataList.Clear() $script:appsScriptVariablesDataList.Clear()
$script:lstAppsScriptVariables.ItemsSource = $script:appsScriptVariablesDataList.ToArray() $script:lstAppsScriptVariables.ItemsSource = $script:appsScriptVariablesDataList.ToArray()
# Update the header checkbox state # Update the header checkbox state
if ($null -ne $script:chkSelectAllAppsScriptVariables) { if ($null -ne $script:chkSelectAllAppsScriptVariables) {
Update-SelectAllHeaderCheckBoxState -ListView $script:lstAppsScriptVariables -HeaderCheckBox $script:chkSelectAllAppsScriptVariables Update-SelectAllHeaderCheckBoxState -ListView $script:lstAppsScriptVariables -HeaderCheckBox $script:chkSelectAllAppsScriptVariables
} }
}) })
# Initial state for chkDefineAppsScriptVariables based on chkInstallApps # Initial state for chkDefineAppsScriptVariables based on chkInstallApps
if ($script:chkInstallApps.IsChecked) { if ($script:chkInstallApps.IsChecked) {
@@ -3238,7 +3253,8 @@ $btnLoadConfig.Add_Click({
if (($configContent.PSObject.Properties.Match('AppsScriptVariables')).Count -gt 0) { if (($configContent.PSObject.Properties.Match('AppsScriptVariables')).Count -gt 0) {
$appsScriptVarsKeyExists = $true $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') $lstAppsScriptVars = $window.FindName('lstAppsScriptVariables')
@@ -3258,12 +3274,14 @@ $btnLoadConfig.Add_Click({
$chkDefineAppsScriptVars.IsChecked = $true $chkDefineAppsScriptVars.IsChecked = $true
$appsScriptVarsPanel.Visibility = 'Visible' $appsScriptVarsPanel.Visibility = 'Visible'
WriteLog "LoadConfig: Loaded AppsScriptVariables and checked 'Define Apps Script Variables'." WriteLog "LoadConfig: Loaded AppsScriptVariables and checked 'Define Apps Script Variables'."
} else { }
else {
$chkDefineAppsScriptVars.IsChecked = $false $chkDefineAppsScriptVars.IsChecked = $false
$appsScriptVarsPanel.Visibility = 'Collapsed' $appsScriptVarsPanel.Visibility = 'Collapsed'
WriteLog "LoadConfig: AppsScriptVariables key was present but empty. Unchecked 'Define Apps Script Variables'." 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) # Handle if it's already a hashtable (e.g., from older config or direct creation)
WriteLog "LoadConfig: Processing AppsScriptVariables (Hashtable) from config." WriteLog "LoadConfig: Processing AppsScriptVariables (Hashtable) from config."
$loadedVars = $configContent.AppsScriptVariables $loadedVars = $configContent.AppsScriptVariables
@@ -3276,12 +3294,14 @@ $btnLoadConfig.Add_Click({
$chkDefineAppsScriptVars.IsChecked = $true $chkDefineAppsScriptVars.IsChecked = $true
$appsScriptVarsPanel.Visibility = 'Visible' $appsScriptVarsPanel.Visibility = 'Visible'
WriteLog "LoadConfig: Loaded AppsScriptVariables (Hashtable) and checked 'Define Apps Script Variables'." WriteLog "LoadConfig: Loaded AppsScriptVariables (Hashtable) and checked 'Define Apps Script Variables'."
} else { }
else {
$chkDefineAppsScriptVars.IsChecked = $false $chkDefineAppsScriptVars.IsChecked = $false
$appsScriptVarsPanel.Visibility = 'Collapsed' $appsScriptVarsPanel.Visibility = 'Collapsed'
WriteLog "LoadConfig: AppsScriptVariables (Hashtable) key was present but empty. Unchecked 'Define Apps Script Variables'." WriteLog "LoadConfig: AppsScriptVariables (Hashtable) key was present but empty. Unchecked 'Define Apps Script Variables'."
} }
} else { }
else {
$chkDefineAppsScriptVars.IsChecked = $false $chkDefineAppsScriptVars.IsChecked = $false
$appsScriptVarsPanel.Visibility = 'Collapsed' $appsScriptVarsPanel.Visibility = 'Collapsed'
WriteLog "LoadConfig Info: Key 'AppsScriptVariables' not found, is null, or not a PSCustomObject/Hashtable. Unchecked 'Define Apps Script Variables'." WriteLog "LoadConfig Info: Key 'AppsScriptVariables' not found, is null, or not a PSCustomObject/Hashtable. Unchecked 'Define Apps Script Variables'."
@@ -3290,7 +3310,7 @@ $btnLoadConfig.Add_Click({
$lstAppsScriptVars.ItemsSource = $script:appsScriptVariablesDataList.ToArray() $lstAppsScriptVars.ItemsSource = $script:appsScriptVariablesDataList.ToArray()
# Update the header checkbox state # Update the header checkbox state
if ($null -ne $script:chkSelectAllAppsScriptVariables) { if ($null -ne $script:chkSelectAllAppsScriptVariables) {
Update-SelectAllHeaderCheckBoxState -ListView $lstAppsScriptVars -HeaderCheckBox $script:chkSelectAllAppsScriptVariables Update-SelectAllHeaderCheckBoxState -ListView $lstAppsScriptVars -HeaderCheckBox $script:chkSelectAllAppsScriptVariables
} }
# Update USB Drive selection if present in config # Update USB Drive selection if present in config
@@ -3300,7 +3320,8 @@ $btnLoadConfig.Add_Click({
if (($configContent.PSObject.Properties.Match('USBDriveList')).Count -gt 0) { if (($configContent.PSObject.Properties.Match('USBDriveList')).Count -gt 0) {
$usbDriveListKeyExists = $true $usbDriveListKeyExists = $true
} }
} catch { }
catch {
WriteLog "ERROR: Exception while trying to Match key 'USBDriveList' on configContent.PSObject.Properties. Error: $($_.Exception.Message)" 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)) { if ($propertyExists -and ($propertyValue -eq $item.SerialNumber)) {
WriteLog "LoadConfig: Selecting USB Drive Model '$($item.Model)' with Serial '$($item.SerialNumber)'." WriteLog "LoadConfig: Selecting USB Drive Model '$($item.Model)' with Serial '$($item.SerialNumber)'."
$item.IsSelected = $true $item.IsSelected = $true
} else { }
else {
if (-not $propertyExists -and ($null -ne $configContent.USBDriveList)) { if (-not $propertyExists -and ($null -ne $configContent.USBDriveList)) {
WriteLog "LoadConfig: Property '$($propertyName)' not found on USBDriveList for item Model '$($item.Model)'." 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 }) $allSelected = $script:lstUSBDrives.Items.Count -gt 0 -and -not ($script:lstUSBDrives.Items | Where-Object { -not $_.IsSelected })
$script:chkSelectAllUSBDrives.IsChecked = $allSelected $script:chkSelectAllUSBDrives.IsChecked = $allSelected
WriteLog "LoadConfig: USBDriveList processing complete." WriteLog "LoadConfig: USBDriveList processing complete."
} else { }
else {
WriteLog "LoadConfig Info: Key 'USBDriveList' not found or is null in configuration file. Skipping USB drive selection." 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 $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) { if ($configContent.USBDriveList.Keys.Count -gt 0) {
$shouldAutoCheckSpecificDrives = $true $shouldAutoCheckSpecificDrives = $true
} }
+2 -2
View File
@@ -584,7 +584,7 @@
<Button x:Name="btnCopyBYOApps" Content="Copy Apps" IsEnabled="False" Margin="0,0,10,0" Padding="10,5" ToolTip="Copy applications with a specified source path to the AppsPath\Win32 folder"/> <Button x:Name="btnCopyBYOApps" Content="Copy Apps" IsEnabled="False" Margin="0,0,10,0" Padding="10,5" ToolTip="Copy applications with a specified source path to the AppsPath\Win32 folder"/>
<Button x:Name="btnClearBYOApplications" Content="Clear List" Padding="10,5" ToolTip="Clear all applications from the list"/> <Button x:Name="btnClearBYOApplications" Content="Clear List" Padding="10,5" ToolTip="Clear all applications from the list"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<!-- AppsScriptVariables Section --> <!-- AppsScriptVariables Section -->
<CheckBox x:Name="chkDefineAppsScriptVariables" Content="Define Apps Script Variables" Margin="5" ToolTip="Enable to define key-value pairs for Apps Script Variables"/> <CheckBox x:Name="chkDefineAppsScriptVariables" Content="Define Apps Script Variables" Margin="5" ToolTip="Enable to define key-value pairs for Apps Script Variables"/>
@@ -597,7 +597,7 @@
<!-- Value Input --> <!-- Value Input -->
<TextBlock Text="Value:" Margin="0,0,0,5"/> <TextBlock Text="Value:" Margin="0,0,0,5"/>
<TextBox x:Name="txtAppsScriptValue" Margin="0,0,0,10" ToolTip="Enter the variable value"/> <TextBox x:Name="txtAppsScriptValue" Margin="0,0,0,10" ToolTip="Enter the variable value"/>
<!-- Add Variable Button --> <!-- Add Variable Button -->
<Button x:Name="btnAddAppsScriptVariable" Content="Add Variable" Width="120" HorizontalAlignment="Left" Margin="0,10,0,10" Padding="10,5" ToolTip="Add the key-value pair to the list"/> <Button x:Name="btnAddAppsScriptVariable" Content="Add Variable" Width="120" HorizontalAlignment="Left" Margin="0,10,0,10" Padding="10,5" ToolTip="Add the key-value pair to the list"/>