mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Refactor: Centralize driver checkbox event handling
Moves the interdependent state logic for the driver-related checkboxes from the main UI script into a new, centralized function within the core module. This change simplifies the event handling by using a single handler for all related checkboxes, which improves code readability and maintainability. The new function is also called during initialization to ensure the UI reflects the correct state on startup.
This commit is contained in:
@@ -217,41 +217,6 @@ $window.Add_Loaded({
|
||||
}
|
||||
Update-CopyButtonState -State $script:uiState # Initial check
|
||||
|
||||
# General Browse Button Handlers (Keep existing logic)
|
||||
|
||||
# Driver Checkbox Conditional Logic
|
||||
$script:uiState.Controls.chkInstallDrivers.Add_Checked({
|
||||
$script:uiState.Controls.chkCopyDrivers.IsEnabled = $false
|
||||
$script:uiState.Controls.chkCompressDriversToWIM.IsEnabled = $false
|
||||
})
|
||||
$script:uiState.Controls.chkInstallDrivers.Add_Unchecked({
|
||||
# Only re-enable if the other checkboxes are not checked
|
||||
if (-not $script:uiState.Controls.chkCopyDrivers.IsChecked) {
|
||||
$script:uiState.Controls.chkCopyDrivers.IsEnabled = $true
|
||||
}
|
||||
if (-not $script:uiState.Controls.chkCompressDriversToWIM.IsChecked) {
|
||||
$script:uiState.Controls.chkCompressDriversToWIM.IsEnabled = $true
|
||||
}
|
||||
})
|
||||
$script:uiState.Controls.chkCopyDrivers.Add_Checked({
|
||||
$script:uiState.Controls.chkInstallDrivers.IsEnabled = $false
|
||||
})
|
||||
$script:uiState.Controls.chkCopyDrivers.Add_Unchecked({
|
||||
# Only re-enable if InstallDrivers is not checked
|
||||
if (-not $script:uiState.Controls.chkInstallDrivers.IsChecked) { $script:uiState.Controls.chkInstallDrivers.IsEnabled = $true }
|
||||
})
|
||||
$script:uiState.Controls.chkCompressDriversToWIM.Add_Checked({
|
||||
$script:uiState.Controls.chkInstallDrivers.IsEnabled = $false
|
||||
})
|
||||
$script:uiState.Controls.chkCompressDriversToWIM.Add_Unchecked({
|
||||
# Only re-enable if InstallDrivers is not checked
|
||||
if (-not $script:uiState.Controls.chkInstallDrivers.IsChecked) { $script:uiState.Controls.chkInstallDrivers.IsEnabled = $true }
|
||||
})
|
||||
# Set initial state based on defaults (assuming defaults are false)
|
||||
$script:uiState.Controls.chkInstallDrivers.IsEnabled = $true
|
||||
$script:uiState.Controls.chkCopyDrivers.IsEnabled = $true
|
||||
$script:uiState.Controls.chkCompressDriversToWIM.IsEnabled = $true
|
||||
|
||||
# AppsScriptVariables Event Handlers
|
||||
$script:uiState.Controls.chkDefineAppsScriptVariables.Add_Checked({
|
||||
$script:uiState.Controls.appsScriptVariablesPanel.Visibility = 'Visible'
|
||||
|
||||
@@ -583,6 +583,23 @@ function Register-EventHandlers {
|
||||
})
|
||||
|
||||
# Drivers Tab Event Handlers
|
||||
# Define a single handler for interdependent driver checkboxes
|
||||
$driverCheckboxHandler = {
|
||||
param($eventSource, $routedEventArgs)
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
if ($null -ne $window) {
|
||||
Update-DriverCheckboxStates -State $window.Tag
|
||||
}
|
||||
}
|
||||
|
||||
# Attach the handler to all relevant checkboxes
|
||||
$State.Controls.chkInstallDrivers.Add_Checked($driverCheckboxHandler)
|
||||
$State.Controls.chkInstallDrivers.Add_Unchecked($driverCheckboxHandler)
|
||||
$State.Controls.chkCopyDrivers.Add_Checked($driverCheckboxHandler)
|
||||
$State.Controls.chkCopyDrivers.Add_Unchecked($driverCheckboxHandler)
|
||||
$State.Controls.chkCompressDriversToWIM.Add_Checked($driverCheckboxHandler)
|
||||
$State.Controls.chkCompressDriversToWIM.Add_Unchecked($driverCheckboxHandler)
|
||||
|
||||
$State.Controls.btnBrowseDriversFolder.Add_Click({
|
||||
param($eventSource, $routedEventArgs)
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
|
||||
@@ -238,6 +238,10 @@ function Initialize-UIDefaults {
|
||||
$State.Controls.chkInstallDrivers.IsChecked = $State.Defaults.generalDefaults.InstallDrivers
|
||||
$State.Controls.chkCopyDrivers.IsChecked = $State.Defaults.generalDefaults.CopyDrivers
|
||||
$State.Controls.chkCopyPEDrivers.IsChecked = $State.Defaults.generalDefaults.CopyPEDrivers
|
||||
$State.Controls.chkCompressDriversToWIM.IsChecked = $State.Defaults.generalDefaults.CompressDownloadedDriversToWim
|
||||
|
||||
# Set initial state for driver checkbox interplay
|
||||
Update-DriverCheckboxStates -State $State
|
||||
|
||||
# Set initial state for InstallApps checkbox based on updates
|
||||
Update-InstallAppsState -State $State
|
||||
|
||||
@@ -108,66 +108,67 @@ function Get-GeneralDefaults {
|
||||
|
||||
return [PSCustomObject]@{
|
||||
# Build Tab Defaults
|
||||
CustomFFUNameTemplate = "{WindowsRelease}_{WindowsVersion}_{SKU}_{yyyy}-{MM}-{dd}_{HH}{mm}"
|
||||
FFUCaptureLocation = $ffuCapturePath
|
||||
ShareName = "FFUCaptureShare"
|
||||
Username = "ffu_user"
|
||||
BuildUSBDriveEnable = $false
|
||||
CompactOS = $true
|
||||
Optimize = $true
|
||||
AllowVHDXCaching = $false
|
||||
CreateCaptureMedia = $true
|
||||
CreateDeploymentMedia = $true
|
||||
AllowExternalHardDiskMedia = $false
|
||||
PromptExternalHardDiskMedia = $true
|
||||
SelectSpecificUSBDrives = $false
|
||||
CopyAutopilot = $false
|
||||
CopyUnattend = $false
|
||||
CopyPPKG = $false
|
||||
CleanupAppsISO = $true
|
||||
CleanupCaptureISO = $true
|
||||
CleanupDeployISO = $true
|
||||
CleanupDrivers = $false
|
||||
RemoveFFU = $false
|
||||
RemoveApps = $false
|
||||
RemoveUpdates = $false
|
||||
CustomFFUNameTemplate = "{WindowsRelease}_{WindowsVersion}_{SKU}_{yyyy}-{MM}-{dd}_{HH}{mm}"
|
||||
FFUCaptureLocation = $ffuCapturePath
|
||||
ShareName = "FFUCaptureShare"
|
||||
Username = "ffu_user"
|
||||
BuildUSBDriveEnable = $false
|
||||
CompactOS = $true
|
||||
Optimize = $true
|
||||
AllowVHDXCaching = $false
|
||||
CreateCaptureMedia = $true
|
||||
CreateDeploymentMedia = $true
|
||||
AllowExternalHardDiskMedia = $false
|
||||
PromptExternalHardDiskMedia = $true
|
||||
SelectSpecificUSBDrives = $false
|
||||
CopyAutopilot = $false
|
||||
CopyUnattend = $false
|
||||
CopyPPKG = $false
|
||||
CleanupAppsISO = $true
|
||||
CleanupCaptureISO = $true
|
||||
CleanupDeployISO = $true
|
||||
CleanupDrivers = $false
|
||||
RemoveFFU = $false
|
||||
RemoveApps = $false
|
||||
RemoveUpdates = $false
|
||||
# Hyper-V Settings Defaults
|
||||
VMHostIPAddress = ""
|
||||
DiskSizeGB = 30
|
||||
MemoryGB = 4
|
||||
Processors = 4
|
||||
VMLocation = $vmLocationPath
|
||||
VMNamePrefix = "_FFU"
|
||||
LogicalSectorSize = 512
|
||||
VMHostIPAddress = ""
|
||||
DiskSizeGB = 30
|
||||
MemoryGB = 4
|
||||
Processors = 4
|
||||
VMLocation = $vmLocationPath
|
||||
VMNamePrefix = "_FFU"
|
||||
LogicalSectorSize = 512
|
||||
# Updates Tab Defaults
|
||||
UpdateLatestCU = $true
|
||||
UpdateLatestNet = $true
|
||||
UpdateLatestDefender = $true
|
||||
UpdateEdge = $true
|
||||
UpdateOneDrive = $true
|
||||
UpdateLatestMSRT = $true
|
||||
UpdateLatestMicrocode = $false
|
||||
UpdatePreviewCU = $false
|
||||
UpdateLatestCU = $true
|
||||
UpdateLatestNet = $true
|
||||
UpdateLatestDefender = $true
|
||||
UpdateEdge = $true
|
||||
UpdateOneDrive = $true
|
||||
UpdateLatestMSRT = $true
|
||||
UpdateLatestMicrocode = $false
|
||||
UpdatePreviewCU = $false
|
||||
# Applications Tab Defaults
|
||||
InstallApps = $false
|
||||
ApplicationPath = $appsPath
|
||||
AppListJsonPath = $appListJsonPath
|
||||
InstallWingetApps = $false
|
||||
BringYourOwnApps = $false
|
||||
InstallApps = $false
|
||||
ApplicationPath = $appsPath
|
||||
AppListJsonPath = $appListJsonPath
|
||||
InstallWingetApps = $false
|
||||
BringYourOwnApps = $false
|
||||
# M365 Apps/Office Tab Defaults
|
||||
InstallOffice = $true
|
||||
OfficePath = $officePath
|
||||
CopyOfficeConfigXML = $false
|
||||
OfficeConfigXMLFilePath = ""
|
||||
InstallOffice = $true
|
||||
OfficePath = $officePath
|
||||
CopyOfficeConfigXML = $false
|
||||
OfficeConfigXMLFilePath = ""
|
||||
# Drivers Tab Defaults
|
||||
DriversFolder = $driversPath
|
||||
PEDriversFolder = $peDriversPath
|
||||
DriversJsonPath = $driversJsonPath
|
||||
DownloadDrivers = $false
|
||||
InstallDrivers = $false
|
||||
CopyDrivers = $false
|
||||
CopyPEDrivers = $false
|
||||
UpdateADK = $true
|
||||
DriversFolder = $driversPath
|
||||
PEDriversFolder = $peDriversPath
|
||||
DriversJsonPath = $driversJsonPath
|
||||
DownloadDrivers = $false
|
||||
InstallDrivers = $false
|
||||
CopyDrivers = $false
|
||||
CopyPEDrivers = $false
|
||||
UpdateADK = $true
|
||||
CompressDownloadedDriversToWim = $false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,9 +198,9 @@ function Update-InstallAppsState {
|
||||
|
||||
# Determine if any checkbox that forces "Install Apps" is checked
|
||||
$anyUpdateChecked = $State.Controls.chkUpdateLatestDefender.IsChecked -or `
|
||||
$State.Controls.chkUpdateEdge.IsChecked -or `
|
||||
$State.Controls.chkUpdateOneDrive.IsChecked -or `
|
||||
$State.Controls.chkUpdateLatestMSRT.IsChecked
|
||||
$State.Controls.chkUpdateEdge.IsChecked -or `
|
||||
$State.Controls.chkUpdateOneDrive.IsChecked -or `
|
||||
$State.Controls.chkUpdateLatestMSRT.IsChecked
|
||||
|
||||
$isForced = $anyUpdateChecked -or $installOfficeChk.IsChecked
|
||||
|
||||
@@ -225,6 +226,33 @@ function Update-InstallAppsState {
|
||||
}
|
||||
}
|
||||
|
||||
# Function to manage the enabled state of interdependent driver-related checkboxes
|
||||
function Update-DriverCheckboxStates {
|
||||
param([PSCustomObject]$State)
|
||||
|
||||
$installDriversChk = $State.Controls.chkInstallDrivers
|
||||
$copyDriversChk = $State.Controls.chkCopyDrivers
|
||||
$compressWimChk = $State.Controls.chkCompressDriversToWIM
|
||||
|
||||
# Default to enabled, then apply disabling rules
|
||||
$installDriversChk.IsEnabled = $true
|
||||
$copyDriversChk.IsEnabled = $true
|
||||
$compressWimChk.IsEnabled = $true
|
||||
|
||||
if ($installDriversChk.IsChecked) {
|
||||
$copyDriversChk.IsEnabled = $false
|
||||
$compressWimChk.IsEnabled = $false
|
||||
}
|
||||
|
||||
if ($copyDriversChk.IsChecked) {
|
||||
$installDriversChk.IsEnabled = $false
|
||||
}
|
||||
|
||||
if ($compressWimChk.IsChecked) {
|
||||
$installDriversChk.IsEnabled = $false
|
||||
}
|
||||
}
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# SECTION: Module Export
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user