diff --git a/FFUDevelopment/BuildFFUVM_UI.ps1 b/FFUDevelopment/BuildFFUVM_UI.ps1 index 8baa557..9e7e6df 100644 --- a/FFUDevelopment/BuildFFUVM_UI.ps1 +++ b/FFUDevelopment/BuildFFUVM_UI.ps1 @@ -218,85 +218,6 @@ $window.Add_Loaded({ Update-CopyButtonState -State $script:uiState # Initial check # General Browse Button Handlers (Keep existing logic) - $script:uiState.Controls.btnBrowseFFUDevPath.Add_Click({ - $selectedPath = Show-ModernFolderPicker -Title "Select FFU Development Path" - if ($selectedPath) { - $script:uiState.Controls.txtFFUDevPath.Text = $selectedPath - } - }) - $script:uiState.Controls.btnBrowseFFUCaptureLocation.Add_Click({ - $selectedPath = Show-ModernFolderPicker -Title "Select FFU Capture Location" - if ($selectedPath) { - $script:uiState.Controls.txtFFUCaptureLocation.Text = $selectedPath - } - }) - $script:uiState.Controls.btnBrowseOfficePath.Add_Click({ - $selectedPath = Show-ModernFolderPicker -Title "Select Office Path" - if ($selectedPath) { - $script:uiState.Controls.txtOfficePath.Text = $selectedPath - } - }) - $script:uiState.Controls.btnBrowseDriversFolder.Add_Click({ - $selectedPath = Show-ModernFolderPicker -Title "Select Drivers Folder" - if ($selectedPath) { - $script:uiState.Controls.txtDriversFolder.Text = $selectedPath - } - }) - $script:uiState.Controls.btnBrowsePEDriversFolder.Add_Click({ - $selectedPath = Show-ModernFolderPicker -Title "Select PE Drivers Folder" - if ($selectedPath) { - $script:uiState.Controls.txtPEDriversFolder.Text = $selectedPath - } - }) - $script:uiState.Controls.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 - - $currentDriversJsonPath = $script:uiState.Controls.txtDriversJsonPath.Text - $dialogInitialDirectory = $null # Initialize to null - - if (-not [string]::IsNullOrWhiteSpace($currentDriversJsonPath)) { - WriteLog "Attempting to determine InitialDirectory for Drivers.json SaveFileDialog from txtDriversJsonPath: '$currentDriversJsonPath'" - try { - # Attempt to get the parent directory of the path in the textbox - $parentDir = Split-Path -Path $currentDriversJsonPath -Parent -ErrorAction Stop - - # Check if the parent directory is not null/empty and actually exists as a directory - if (-not ([string]::IsNullOrEmpty($parentDir)) -and (Test-Path -Path $parentDir -PathType Container)) { - $dialogInitialDirectory = $parentDir - WriteLog "Set InitialDirectory for SaveFileDialog to '$parentDir' based on parent of txtDriversJsonPath." - } - else { - # Parent directory is invalid or doesn't exist - WriteLog "Parent directory '$parentDir' from txtDriversJsonPath ('$currentDriversJsonPath') is not a valid existing directory. SaveFileDialog will use default InitialDirectory." - # $dialogInitialDirectory remains $null, so dialog uses its default - } - } - catch { - # Error occurred trying to split the path (e.g., path is malformed) - WriteLog "Error splitting path from txtDriversJsonPath ('$currentDriversJsonPath'): $($_.Exception.Message). SaveFileDialog will use default InitialDirectory." - # $dialogInitialDirectory remains $null - } - } - else { - # TextBox is empty, dialog will use its default initial directory - WriteLog "txtDriversJsonPath is empty. SaveFileDialog will use default InitialDirectory." - # $dialogInitialDirectory remains $null - } - - $sfd.InitialDirectory = $dialogInitialDirectory # Set to $null if no valid directory was found, dialog will use its default - - if ($sfd.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { - $script:uiState.Controls.txtDriversJsonPath.Text = $sfd.FileName - WriteLog "User selected or created Drivers.json at: $($sfd.FileName)" - } - else { - WriteLog "User cancelled SaveFileDialog for Drivers.json." - } - }) # Driver Checkbox Conditional Logic $script:uiState.Controls.chkInstallDrivers.Add_Checked({ diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 index 6f5b81c..53688d0 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 @@ -3,6 +3,26 @@ function Register-EventHandlers { WriteLog "Registering UI event handlers..." # Build Tab Event Handlers + $State.Controls.btnBrowseFFUDevPath.Add_Click({ + param($eventSource, $routedEventArgs) + $window = [System.Windows.Window]::GetWindow($eventSource) + $localState = $window.Tag + $selectedPath = Show-ModernFolderPicker -Title "Select FFU Development Path" + if ($selectedPath) { + $localState.Controls.txtFFUDevPath.Text = $selectedPath + } + }) + + $State.Controls.btnBrowseFFUCaptureLocation.Add_Click({ + param($eventSource, $routedEventArgs) + $window = [System.Windows.Window]::GetWindow($eventSource) + $localState = $window.Tag + $selectedPath = Show-ModernFolderPicker -Title "Select FFU Capture Location" + if ($selectedPath) { + $localState.Controls.txtFFUCaptureLocation.Text = $selectedPath + } + }) + # Build USB Drive Settings Event Handlers $State.Controls.chkBuildUSBDriveEnable.Add_Checked({ param($eventSource, $routedEventArgs) @@ -514,6 +534,16 @@ function Register-EventHandlers { }) # M365 Apps/Office tab Event + $State.Controls.btnBrowseOfficePath.Add_Click({ + param($eventSource, $routedEventArgs) + $window = [System.Windows.Window]::GetWindow($eventSource) + $localState = $window.Tag + $selectedPath = Show-ModernFolderPicker -Title "Select Office Path" + if ($selectedPath) { + $localState.Controls.txtOfficePath.Text = $selectedPath + } + }) + $State.Controls.chkInstallOffice.Add_Checked({ param($eventSource, $routedEventArgs) $window = [System.Windows.Window]::GetWindow($eventSource) @@ -553,6 +583,80 @@ function Register-EventHandlers { }) # Drivers Tab Event Handlers + $State.Controls.btnBrowseDriversFolder.Add_Click({ + param($eventSource, $routedEventArgs) + $window = [System.Windows.Window]::GetWindow($eventSource) + $localState = $window.Tag + $selectedPath = Show-ModernFolderPicker -Title "Select Drivers Folder" + if ($selectedPath) { + $localState.Controls.txtDriversFolder.Text = $selectedPath + } + }) + + $State.Controls.btnBrowsePEDriversFolder.Add_Click({ + param($eventSource, $routedEventArgs) + $window = [System.Windows.Window]::GetWindow($eventSource) + $localState = $window.Tag + $selectedPath = Show-ModernFolderPicker -Title "Select PE Drivers Folder" + if ($selectedPath) { + $localState.Controls.txtPEDriversFolder.Text = $selectedPath + } + }) + + $State.Controls.btnBrowseDriversJsonPath.Add_Click({ + param($eventSource, $routedEventArgs) + $window = [System.Windows.Window]::GetWindow($eventSource) + $localState = $window.Tag + + $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 + + $currentDriversJsonPath = $localState.Controls.txtDriversJsonPath.Text + $dialogInitialDirectory = $null # Initialize to null + + if (-not [string]::IsNullOrWhiteSpace($currentDriversJsonPath)) { + WriteLog "Attempting to determine InitialDirectory for Drivers.json SaveFileDialog from txtDriversJsonPath: '$currentDriversJsonPath'" + try { + # Attempt to get the parent directory of the path in the textbox + $parentDir = Split-Path -Path $currentDriversJsonPath -Parent -ErrorAction Stop + + # Check if the parent directory is not null/empty and actually exists as a directory + if (-not ([string]::IsNullOrEmpty($parentDir)) -and (Test-Path -Path $parentDir -PathType Container)) { + $dialogInitialDirectory = $parentDir + WriteLog "Set InitialDirectory for SaveFileDialog to '$parentDir' based on parent of txtDriversJsonPath." + } + else { + # Parent directory is invalid or doesn't exist + WriteLog "Parent directory '$parentDir' from txtDriversJsonPath ('$currentDriversJsonPath') is not a valid existing directory. SaveFileDialog will use default InitialDirectory." + # $dialogInitialDirectory remains $null, so dialog uses its default + } + } + catch { + # Error occurred trying to split the path (e.g., path is malformed) + WriteLog "Error splitting path from txtDriversJsonPath ('$currentDriversJsonPath'): $($_.Exception.Message). SaveFileDialog will use default InitialDirectory." + # $dialogInitialDirectory remains $null + } + } + else { + # TextBox is empty, dialog will use its default initial directory + WriteLog "txtDriversJsonPath is empty. SaveFileDialog will use default InitialDirectory." + # $dialogInitialDirectory remains $null + } + + $sfd.InitialDirectory = $dialogInitialDirectory # Set to $null if no valid directory was found, dialog will use its default + + if ($sfd.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { + $localState.Controls.txtDriversJsonPath.Text = $sfd.FileName + WriteLog "User selected or created Drivers.json at: $($sfd.FileName)" + } + else { + WriteLog "User cancelled SaveFileDialog for Drivers.json." + } + }) + $State.Controls.chkDownloadDrivers.Add_Checked({ param($eventSource, $routedEventArgs) $window = [System.Windows.Window]::GetWindow($eventSource)