Enhance USB drive selection logic in LoadConfig process

- Added functionality to automatically check "Select Specific USB Drives" if USBDriveList is present and not empty in the configuration.
- Implemented checks for both PSCustomObject and hashtable types for backward compatibility.
- Included logging for the auto-check condition to improve traceability during configuration loading.
This commit is contained in:
rbalsleyMSFT
2025-05-26 17:59:28 -07:00
parent d253a88daa
commit d05f9aa267
+24
View File
@@ -2836,6 +2836,30 @@ $btnLoadConfig.Add_Click({
} else {
WriteLog "LoadConfig Info: Key 'USBDriveList' not found or is null in configuration file. Skipping USB drive selection."
}
# If BuildUSBDrive is enabled and USBDriveList was present and not empty in the config,
# ensure "Select Specific USB Drives" is checked to show the list.
$shouldAutoCheckSpecificDrives = $false
if ($window.FindName('chkBuildUSBDriveEnable').IsChecked -and $usbDriveListKeyExists -and ($null -ne $configContent.USBDriveList)) {
if ($configContent.USBDriveList -is [System.Management.Automation.PSCustomObject]) {
if ($configContent.USBDriveList.PSObject.Properties.Count -gt 0) {
$shouldAutoCheckSpecificDrives = $true
}
}
elseif ($configContent.USBDriveList -is [hashtable]) { # Fallback for older configs
if ($configContent.USBDriveList.Keys.Count -gt 0) {
$shouldAutoCheckSpecificDrives = $true
}
}
}
if ($shouldAutoCheckSpecificDrives) {
WriteLog "LoadConfig: Auto-checking 'Select Specific USB Drives' due to pre-selected USB drives in config."
$window.FindName('chkSelectSpecificUSBDrives').IsChecked = $true
}
else {
WriteLog "LoadConfig: Condition to auto-check 'Select Specific USB Drives' was NOT met."
}
WriteLog "LoadConfig: Configuration loading process finished."
}
}