From c8042c6a75386d86c22b97e2284979171272099e Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Thu, 29 May 2025 13:26:03 -0700 Subject: [PATCH] Add Drivers.json path configuration to UI and core logic - Introduced a new TextBox and Button in the UI for specifying the Drivers.json file path. - Updated the UI layout to accommodate the new Drivers.json path input. - Enhanced the core logic to set a default path for Drivers.json based on the Drivers folder. - Implemented functionality to browse and select the Drivers.json file, allowing users to create or select an existing file. --- FFUDevelopment/BuildFFUVM_UI.ps1 | 36 +++++++++++++- FFUDevelopment/BuildFFUVM_UI.xaml | 59 ++++++++++++++--------- FFUDevelopment/FFUUI.Core/FFUUI.Core.psm1 | 1 + 3 files changed, 73 insertions(+), 23 deletions(-) diff --git a/FFUDevelopment/BuildFFUVM_UI.ps1 b/FFUDevelopment/BuildFFUVM_UI.ps1 index c7a2015..6fe8871 100644 --- a/FFUDevelopment/BuildFFUVM_UI.ps1 +++ b/FFUDevelopment/BuildFFUVM_UI.ps1 @@ -614,7 +614,7 @@ function Get-UIConfig { Disksize = [int64]$window.FindName('txtDiskSize').Text * 1GB # Renamed from DiskSize DownloadDrivers = $window.FindName('chkDownloadDrivers').IsChecked # UI Only parameter DriversFolder = $window.FindName('txtDriversFolder').Text - DriversJsonPath = "$($window.FindName('txtDriversFolder').Text)\Drivers.json" # Parameter from Sample_default.json, derived + DriversJsonPath = $script:txtDriversJsonPath.Text # Read from the new TextBox FFUCaptureLocation = $window.FindName('txtFFUCaptureLocation').Text FFUDevelopmentPath = $window.FindName('txtFFUDevPath').Text FFUPrefix = $window.FindName('txtVMNamePrefix').Text @@ -1810,6 +1810,9 @@ $window.Add_Loaded({ # Drivers tab defaults from General Defaults $window.FindName('txtDriversFolder').Text = $script:generalDefaults.DriversFolder $window.FindName('txtPEDriversFolder').Text = $script:generalDefaults.PEDriversFolder + $script:txtDriversJsonPath = $window.FindName('txtDriversJsonPath') # Assign new TextBox + $script:txtDriversJsonPath.Text = $script:generalDefaults.DriversJsonPath # Set default text + $script:btnBrowseDriversJsonPath = $window.FindName('btnBrowseDriversJsonPath') # Assign new Button $window.FindName('chkDownloadDrivers').IsChecked = $script:generalDefaults.DownloadDrivers $window.FindName('chkInstallDrivers').IsChecked = $script:generalDefaults.InstallDrivers $window.FindName('chkCopyDrivers').IsChecked = $script:generalDefaults.CopyDrivers @@ -2608,6 +2611,36 @@ $script:chkInstallApps.Add_Unchecked({ $selectedPath = Show-ModernFolderPicker -Title "Select PE Drivers Folder" if ($selectedPath) { $window.FindName('txtPEDriversFolder').Text = $selectedPath } }) + $script:btnBrowseDriversJsonPath.Add_Click({ + $sfd = New-Object System.Windows.Forms.SaveFileDialog + $sfd.Filter = "JSON files (*.json)|*.json|All files (*.*)|*.*" + $sfd.Title = "Select or Create Drivers.json File" + $sfd.FileName = "Drivers.json" + $sfd.CheckFileExists = $false # Allow creating a new file or selecting existing + + # Set initial directory based on current TextBox value or DriversFolder default + $currentDriversJsonPath = $script:txtDriversJsonPath.Text + $initialDirectory = $null + if (-not [string]::IsNullOrWhiteSpace($currentDriversJsonPath) -and (Split-Path -Path $currentDriversJsonPath -IsValid)) { + $initialDirectory = Split-Path -Path $currentDriversJsonPath -Parent + if (-not (Test-Path -Path $initialDirectory -PathType Container)) { + # If parent of current path doesn't exist, fall back + $initialDirectory = $script:generalDefaults.DriversFolder + } + } + else { + $initialDirectory = $script:generalDefaults.DriversFolder + } + # Ensure the fallback directory exists, otherwise use FFUDevelopmentPath + if (-not (Test-Path -Path $initialDirectory -PathType Container)) { + $initialDirectory = $window.FindName('txtFFUDevPath').Text # Fallback to FFU Dev Path + } + $sfd.InitialDirectory = $initialDirectory + + if ($sfd.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { + $script:txtDriversJsonPath.Text = $sfd.FileName + } + }) # Driver Checkbox Conditional Logic $script:chkInstallDrivers.Add_Checked({ @@ -3098,6 +3131,7 @@ $btnLoadConfig.Add_Click({ # WriteLog "LoadConfig Info: 'Model' key ('$($configContent.Model)') from config is not directly mapped to a single UI input. Set 'Make' and use 'Get Models'." Set-UIValue -ControlName 'txtDriversFolder' -PropertyName 'Text' -ConfigObject $configContent -ConfigKey 'DriversFolder' -WindowInstance $window Set-UIValue -ControlName 'txtPEDriversFolder' -PropertyName 'Text' -ConfigObject $configContent -ConfigKey 'PEDriversFolder' -WindowInstance $window + Set-UIValue -ControlName 'txtDriversJsonPath' -PropertyName 'Text' -ConfigObject $configContent -ConfigKey 'DriversJsonPath' -WindowInstance $window # Load DriversJsonPath Set-UIValue -ControlName 'chkCopyPEDrivers' -PropertyName 'IsChecked' -ConfigObject $configContent -ConfigKey 'CopyPEDrivers' -WindowInstance $window Set-UIValue -ControlName 'chkCompressDriversToWIM' -PropertyName 'IsChecked' -ConfigObject $configContent -ConfigKey 'CompressDownloadedDriversToWim' -WindowInstance $window diff --git a/FFUDevelopment/BuildFFUVM_UI.xaml b/FFUDevelopment/BuildFFUVM_UI.xaml index 5c04bc4..45802d5 100644 --- a/FFUDevelopment/BuildFFUVM_UI.xaml +++ b/FFUDevelopment/BuildFFUVM_UI.xaml @@ -679,6 +679,8 @@ + + @@ -695,9 +697,9 @@ - + - + @@ -730,23 +732,36 @@ - - + + + + + + + + + +