Fixes DeviceNamingMode UI state tracking and defaults

Updates the FFU UI core to better track the loaded `DeviceNamingMode` configuration.
Introduces flags to detect explicit user changes versus default states.
Ensures that if the user does not explicitly set the device naming mode, it defaults gracefully and preserves legacy script behaviors.
Updates documentation to reflect the actual behavior of not writing the `DeviceNamingMode` key unless modified.
This commit is contained in:
rbalsleyMSFT
2026-04-15 13:04:12 -07:00
parent 0607cf5386
commit 24f10b89b0
7 changed files with 102 additions and 18 deletions
+5 -2
View File
@@ -46,7 +46,8 @@ $script:uiState = [PSCustomObject]@{
logStreamReader = $null;
pollTimer = $null;
currentBuildProcess = $null;
lastConfigFilePath = $null
lastConfigFilePath = $null;
loadedDeviceNamingMode = $null
};
Flags = @{
installAppsForcedByUpdates = $false;
@@ -56,7 +57,9 @@ $script:uiState = [PSCustomObject]@{
lastSortAscending = $true;
isBuilding = $false;
isCleanupRunning = $false;
isFluentSupported = $false
isFluentSupported = $false;
deviceNamingModeWasExplicitlyChanged = $false;
suppressDeviceNamingChangeTracking = $false
};
Defaults = @{};
LogFilePath = "$FFUDevelopmentPath\FFUDevelopment_UI.log"
@@ -36,7 +36,7 @@ function Get-UIConfig {
UseDriversAsPEDrivers = $State.Controls.chkUseDriversAsPEDrivers.IsChecked
CopyPPKG = $State.Controls.chkCopyPPKG.IsChecked
CopyUnattend = $State.Controls.chkCopyUnattend.IsChecked
DeviceNamingMode = Get-SelectedDeviceNamingMode -State $State
DeviceNamingMode = Get-ConfiguredDeviceNamingMode -State $State
DeviceNameTemplate = $State.Controls.txtDeviceNameTemplate.Text
DeviceNamePrefixesPath = $State.Controls.txtDeviceNamePrefixesPath.Text
DeviceNamePrefixes = @(Get-DeviceNamePrefixes -State $State)
@@ -480,17 +480,20 @@ function Update-UIFromConfig {
$State.Controls.txtDeviceNamePrefixesPath.Text = Get-DefaultDeviceNamePrefixesPath -FFUDevelopmentPath $State.Controls.txtFFUDevPath.Text
}
$deviceNamingMode = 'None'
$loadedDeviceNamingMode = $null
if ($ConfigContent.PSObject.Properties.Name -contains 'DeviceNamingMode') {
$deviceNamingMode = [string]$ConfigContent.DeviceNamingMode
$candidateDeviceNamingMode = [string]$ConfigContent.DeviceNamingMode
if ($candidateDeviceNamingMode -in @('Legacy', 'None', 'Prompt', 'Template', 'Prefixes')) {
$loadedDeviceNamingMode = $candidateDeviceNamingMode
}
}
if ($deviceNamingMode -eq 'Legacy') {
$deviceNamingMode = 'Prompt'
$displayDeviceNamingMode = if ($loadedDeviceNamingMode -in @('Prompt', 'Template', 'Prefixes')) {
$loadedDeviceNamingMode
}
if ($deviceNamingMode -notin @('None', 'Prompt', 'Template', 'Prefixes')) {
$deviceNamingMode = 'None'
else {
'None'
}
Set-DeviceNamingMode -State $State -Mode $deviceNamingMode
Set-DeviceNamingModeState -State $State -DisplayMode $displayDeviceNamingMode -LoadedMode $loadedDeviceNamingMode
Import-DeviceNamePrefixesFromConfiguredPath -State $State
Update-DeviceNamingControls -State $State
@@ -58,6 +58,55 @@ function Set-DeviceNamingMode {
$State.Controls.rbDeviceNamingPrefixes.IsChecked = $Mode -eq 'Prefixes'
}
function Set-DeviceNamingModeState {
param(
[PSCustomObject]$State,
[ValidateSet('None', 'Prompt', 'Template', 'Prefixes')]
[string]$DisplayMode,
[AllowNull()]
[string]$LoadedMode
)
if ($null -eq $State.Flags) {
$State.Flags = @{}
}
if ($null -eq $State.Data) {
$State.Data = @{}
}
$previousSuppressionState = $true -eq $State.Flags.suppressDeviceNamingChangeTracking
$State.Flags.suppressDeviceNamingChangeTracking = $true
try {
Set-DeviceNamingMode -State $State -Mode $DisplayMode
}
finally {
$State.Flags.suppressDeviceNamingChangeTracking = $previousSuppressionState
}
$State.Data.loadedDeviceNamingMode = if ([string]::IsNullOrWhiteSpace($LoadedMode)) {
$null
}
else {
$LoadedMode.Trim()
}
$State.Flags.deviceNamingModeWasExplicitlyChanged = $false
}
function Get-ConfiguredDeviceNamingMode {
param([PSCustomObject]$State)
if (($null -ne $State.Flags) -and ($true -eq $State.Flags.deviceNamingModeWasExplicitlyChanged)) {
return Get-SelectedDeviceNamingMode -State $State
}
if (($null -ne $State.Data) -and -not [string]::IsNullOrWhiteSpace([string]$State.Data.loadedDeviceNamingMode)) {
return [string]$State.Data.loadedDeviceNamingMode
}
return $null
}
function Get-DeviceNamePrefixes {
param([PSCustomObject]$State)
@@ -467,17 +516,32 @@ function Register-EventHandlers {
$State.Controls.rbDeviceNamingNone.Add_Checked({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
Update-DeviceNamingControls -State $window.Tag
$localState = $window.Tag
if (-not ($true -eq $localState.Flags.suppressDeviceNamingChangeTracking)) {
$localState.Flags.deviceNamingModeWasExplicitlyChanged = $true
$localState.Data.loadedDeviceNamingMode = $null
}
Update-DeviceNamingControls -State $localState
})
$State.Controls.rbDeviceNamingPrompt.Add_Checked({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
Update-DeviceNamingControls -State $window.Tag
$localState = $window.Tag
if (-not ($true -eq $localState.Flags.suppressDeviceNamingChangeTracking)) {
$localState.Flags.deviceNamingModeWasExplicitlyChanged = $true
$localState.Data.loadedDeviceNamingMode = $null
}
Update-DeviceNamingControls -State $localState
})
$State.Controls.rbDeviceNamingTemplate.Add_Checked({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
Update-DeviceNamingControls -State $window.Tag
$localState = $window.Tag
if (-not ($true -eq $localState.Flags.suppressDeviceNamingChangeTracking)) {
$localState.Flags.deviceNamingModeWasExplicitlyChanged = $true
$localState.Data.loadedDeviceNamingMode = $null
}
Update-DeviceNamingControls -State $localState
})
$State.Controls.txtDeviceNameTemplate.Add_TextChanged({
param($eventSource, $textChangedEventArgs)
@@ -489,7 +553,12 @@ function Register-EventHandlers {
$State.Controls.rbDeviceNamingPrefixes.Add_Checked({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
Update-DeviceNamingControls -State $window.Tag
$localState = $window.Tag
if (-not ($true -eq $localState.Flags.suppressDeviceNamingChangeTracking)) {
$localState.Flags.deviceNamingModeWasExplicitlyChanged = $true
$localState.Data.loadedDeviceNamingMode = $null
}
Update-DeviceNamingControls -State $localState
})
$State.Controls.btnBrowseDeviceNamePrefixesPath.Add_Click({
param($eventSource, $routedEventArgs)
@@ -400,7 +400,13 @@ function Initialize-UIDefaults {
$State.Controls.chkCopyAutopilot.IsChecked = $State.Defaults.generalDefaults.CopyAutopilot
$State.Controls.chkCopyUnattend.IsChecked = $State.Defaults.generalDefaults.CopyUnattend
$State.Controls.chkCopyPPKG.IsChecked = $State.Defaults.generalDefaults.CopyPPKG
Set-DeviceNamingMode -State $State -Mode $State.Defaults.generalDefaults.DeviceNamingMode
$defaultDeviceNamingMode = if ($State.Defaults.generalDefaults.DeviceNamingMode -in @('None', 'Prompt', 'Template', 'Prefixes')) {
$State.Defaults.generalDefaults.DeviceNamingMode
}
else {
'None'
}
Set-DeviceNamingModeState -State $State -DisplayMode $defaultDeviceNamingMode -LoadedMode $null
$State.Controls.txtDeviceNameTemplate.Text = $State.Defaults.generalDefaults.DeviceNameTemplate
$State.Controls.txtDeviceNamePrefixesPath.Text = $State.Defaults.generalDefaults.DeviceNamePrefixesPath
$State.Controls.txtDeviceNamePrefixes.Text = ($State.Defaults.generalDefaults.DeviceNamePrefixes -join [System.Environment]::NewLine)
Binary file not shown.