mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Add experimental VM networking opt-in for Hyper-V builds
The Hyper-V switch selection in the UI previously did not connect the build VM to the network during provisioning. Since internet-connected Sysprep and capture flows are still experimental, this introduces an explicit "Enable VM Networking" checkbox to the Hyper-V Settings page that defaults to off. - Adds the `-EnableVMNetworking` parameter to BuildFFUVM.ps1 to conditionally attach the Hyper-V network adapter during VM creation. - Persists the setting through FFU config files and blocks UI execution if enabled without a valid switch. - Refactors WPF event handlers in FFUUI.Core to fix dropdown scoping errors. - Updates documentation and the sample configuration file to reflect the new behavior.
This commit is contained in:
@@ -44,6 +44,7 @@ function Get-UIConfig {
|
||||
DownloadDrivers = $State.Controls.chkDownloadDrivers.IsChecked
|
||||
DriversFolder = $State.Controls.txtDriversFolder.Text
|
||||
DriversJsonPath = $State.Controls.txtDriversJsonPath.Text
|
||||
EnableVMNetworking = $State.Controls.chkEnableVMNetworking.IsChecked
|
||||
FFUCaptureLocation = $State.Controls.txtFFUCaptureLocation.Text
|
||||
FFUDevelopmentPath = $State.Controls.txtFFUDevPath.Text
|
||||
FFUPrefix = $State.Controls.txtVMNamePrefix.Text
|
||||
@@ -466,6 +467,7 @@ function Update-UIFromConfig {
|
||||
Set-UIValue -ControlName 'chkRemoveDownloadedESD' -PropertyName 'IsChecked' -ConfigObject $ConfigContent -ConfigKey 'RemoveDownloadedESD' -State $State
|
||||
|
||||
# Hyper-V Settings
|
||||
Set-UIValue -ControlName 'chkEnableVMNetworking' -PropertyName 'IsChecked' -ConfigObject $ConfigContent -ConfigKey 'EnableVMNetworking' -State $State
|
||||
Select-VMSwitchFromConfig -State $State -ConfigContent $ConfigContent
|
||||
Set-UIValue -ControlName 'txtDiskSize' -PropertyName 'Text' -ConfigObject $ConfigContent -ConfigKey 'Disksize' -TransformValue { param($val) $val / 1GB } -State $State
|
||||
Set-UIValue -ControlName 'txtMemory' -PropertyName 'Text' -ConfigObject $ConfigContent -ConfigKey 'Memory' -TransformValue { param($val) $val / 1GB } -State $State
|
||||
@@ -473,6 +475,10 @@ function Update-UIFromConfig {
|
||||
Set-UIValue -ControlName 'txtVMLocation' -PropertyName 'Text' -ConfigObject $ConfigContent -ConfigKey 'VMLocation' -State $State
|
||||
Set-UIValue -ControlName 'txtVMNamePrefix' -PropertyName 'Text' -ConfigObject $ConfigContent -ConfigKey 'FFUPrefix' -State $State
|
||||
Set-UIValue -ControlName 'cmbLogicalSectorSize' -PropertyName 'SelectedItem' -ConfigObject $ConfigContent -ConfigKey 'LogicalSectorSizeBytes' -TransformValue { param($val) $val.ToString() } -State $State
|
||||
$State.Controls.spVMNetworkingSettings.IsEnabled = $true -eq $State.Controls.chkEnableVMNetworking.IsChecked
|
||||
if (-not ($true -eq $State.Controls.chkEnableVMNetworking.IsChecked)) {
|
||||
$State.Controls.txtCustomVMSwitchName.Visibility = 'Collapsed'
|
||||
}
|
||||
|
||||
# Windows Settings
|
||||
Set-UIValue -ControlName 'txtISOPath' -PropertyName 'Text' -ConfigObject $ConfigContent -ConfigKey 'ISOPath' -State $State
|
||||
|
||||
@@ -5,6 +5,28 @@
|
||||
This module is dedicated to managing user interactions within the FFU Builder UI. It contains the Register-EventHandlers function, which connects UI controls defined in the XAML to their corresponding actions in the PowerShell backend. This includes handling button clicks, text input validation, checkbox state changes, and list view interactions across all tabs, effectively wiring up the application's front-end to its core logic.
|
||||
#>
|
||||
|
||||
function Update-VMNetworkingControls {
|
||||
param([PSCustomObject]$State)
|
||||
|
||||
$isVmNetworkingEnabled = $true -eq $State.Controls.chkEnableVMNetworking.IsChecked
|
||||
$State.Controls.spVMNetworkingSettings.IsEnabled = $isVmNetworkingEnabled
|
||||
|
||||
if (-not $isVmNetworkingEnabled) {
|
||||
$State.Controls.txtCustomVMSwitchName.Visibility = 'Collapsed'
|
||||
return
|
||||
}
|
||||
|
||||
if ($State.Controls.cmbVMSwitchName.SelectedItem -eq 'Other') {
|
||||
$State.Controls.txtCustomVMSwitchName.Visibility = 'Visible'
|
||||
if ([string]::IsNullOrWhiteSpace($State.Controls.txtCustomVMSwitchName.Text) -and $null -ne $State.Data.customVMSwitchName) {
|
||||
$State.Controls.txtCustomVMSwitchName.Text = $State.Data.customVMSwitchName
|
||||
}
|
||||
}
|
||||
else {
|
||||
$State.Controls.txtCustomVMSwitchName.Visibility = 'Collapsed'
|
||||
}
|
||||
}
|
||||
|
||||
function Register-EventHandlers {
|
||||
param([PSCustomObject]$State)
|
||||
WriteLog "Registering UI event handlers..."
|
||||
@@ -379,22 +401,27 @@ function Register-EventHandlers {
|
||||
})
|
||||
|
||||
# Hyper-V tab event handlers
|
||||
$State.Controls.chkEnableVMNetworking.Add_Checked({
|
||||
param($eventSource, $routedEventArgs)
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
$localState = $window.Tag
|
||||
Update-VMNetworkingControls -State $localState
|
||||
})
|
||||
|
||||
$State.Controls.chkEnableVMNetworking.Add_Unchecked({
|
||||
param($eventSource, $routedEventArgs)
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
$localState = $window.Tag
|
||||
Update-VMNetworkingControls -State $localState
|
||||
})
|
||||
|
||||
$State.Controls.cmbVMSwitchName.Add_SelectionChanged({
|
||||
param($eventSource, $selectionChangedEventArgs)
|
||||
# The state object is available via the parent window's Tag property
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
$localState = $window.Tag
|
||||
|
||||
$selectedItem = $eventSource.SelectedItem
|
||||
if ($selectedItem -eq 'Other') {
|
||||
$localState.Controls.txtCustomVMSwitchName.Visibility = 'Visible'
|
||||
if ([string]::IsNullOrWhiteSpace($localState.Controls.txtCustomVMSwitchName.Text) -and $null -ne $localState.Data.customVMSwitchName) {
|
||||
$localState.Controls.txtCustomVMSwitchName.Text = $localState.Data.customVMSwitchName
|
||||
}
|
||||
}
|
||||
else {
|
||||
$localState.Controls.txtCustomVMSwitchName.Visibility = 'Collapsed'
|
||||
}
|
||||
Update-VMNetworkingControls -State $localState
|
||||
})
|
||||
|
||||
# Persist custom VM switch name when user edits it while 'Other' is selected
|
||||
|
||||
@@ -205,6 +205,8 @@ function Initialize-UIControls {
|
||||
$State.Controls.txtStatus = $window.FindName('txtStatus')
|
||||
$State.Controls.pbOverallProgress = $window.FindName('progressBar')
|
||||
$State.Controls.txtOverallStatus = $window.FindName('txtStatus')
|
||||
$State.Controls.chkEnableVMNetworking = $window.FindName('chkEnableVMNetworking')
|
||||
$State.Controls.spVMNetworkingSettings = $window.FindName('spVMNetworkingSettings')
|
||||
$State.Controls.cmbVMSwitchName = $window.FindName('cmbVMSwitchName')
|
||||
$State.Controls.txtCustomVMSwitchName = $window.FindName('txtCustomVMSwitchName')
|
||||
$State.Controls.txtFFUDevPath = $window.FindName('txtFFUDevPath')
|
||||
@@ -345,7 +347,6 @@ function Initialize-VMSwitchData {
|
||||
$State.Controls.cmbVMSwitchName.Items.Add('Other') | Out-Null
|
||||
if ($State.Controls.cmbVMSwitchName.Items.Count -gt 1) {
|
||||
$State.Controls.cmbVMSwitchName.SelectedIndex = 0
|
||||
$firstSwitch = $State.Controls.cmbVMSwitchName.SelectedItem
|
||||
$State.Controls.txtCustomVMSwitchName.Visibility = 'Collapsed'
|
||||
}
|
||||
else {
|
||||
@@ -398,7 +399,9 @@ function Initialize-UIDefaults {
|
||||
Update-BitsPrioritySetting -State $State
|
||||
|
||||
# Hyper-V Settings defaults from General Defaults
|
||||
$State.Controls.chkEnableVMNetworking.IsChecked = $State.Defaults.generalDefaults.EnableVMNetworking
|
||||
Initialize-VMSwitchData -State $State
|
||||
$State.Controls.spVMNetworkingSettings.IsEnabled = $true -eq $State.Controls.chkEnableVMNetworking.IsChecked
|
||||
$State.Controls.txtDiskSize.Text = $State.Defaults.generalDefaults.DiskSizeGB
|
||||
$State.Controls.txtMemory.Text = $State.Defaults.generalDefaults.MemoryGB
|
||||
$State.Controls.txtProcessors.Text = $State.Defaults.generalDefaults.Processors
|
||||
|
||||
@@ -140,6 +140,7 @@ function Get-GeneralDefaults {
|
||||
RemoveUpdates = $false
|
||||
RemoveDownloadedESD = $true
|
||||
# Hyper-V Settings Defaults
|
||||
EnableVMNetworking = $false
|
||||
DiskSizeGB = 50
|
||||
MemoryGB = 4
|
||||
Processors = 4
|
||||
|
||||
Reference in New Issue
Block a user