From 665f31d91af7070a0fedb180854267834d74bffe Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Thu, 9 May 2024 22:31:27 +0200 Subject: [PATCH] Added ability to import drivers * Added ability to import drivers Added the ability to import drivers from the active installation to the MicroWin image. * Merge branch 'test-2024-04-20-2' into CW-MicroWin-240420 * Update inputXML.xaml Removed warning because of a fluke * Update Invoke-WPFMicrowin.ps1 Use the driver injection directory if it is specified and if the directory exists * Merge branch 'test-2024-04-20-2' into CW-MicroWin-240420 * Merge branch 'test-2024-04-20-2' into CW-MicroWin-240420 --- functions/public/Invoke-WPFMicrowin.ps1 | 46 +++++++++++++++++++++++-- xaml/inputXML.xaml | 1 + 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/functions/public/Invoke-WPFMicrowin.ps1 b/functions/public/Invoke-WPFMicrowin.ps1 index 89d15872..564a836a 100644 --- a/functions/public/Invoke-WPFMicrowin.ps1 +++ b/functions/public/Invoke-WPFMicrowin.ps1 @@ -53,6 +53,7 @@ public class PowerManagement { $keepEdge = $sync.WPFMicrowinKeepEdge.IsChecked $copyToUSB = $sync.WPFMicrowinCopyToUsb.IsChecked $injectDrivers = $sync.MicrowinInjectDrivers.IsChecked + $importDrivers = $sync.MicrowinImportDrivers.IsChecked $mountDir = $sync.MicrowinMountDir.Text $scratchDir = $sync.MicrowinScratchDir.Text @@ -111,13 +112,54 @@ public class PowerManagement { return } + if ($importDrivers) + { + Write-Host "Exporting drivers from active installation..." + if (Test-Path "$env:TEMP\DRV_EXPORT") + { + Remove-Item "$env:TEMP\DRV_EXPORT" -Recurse -Force + } + if (($injectDrivers -and (Test-Path $sync.MicrowinDriverLocation.Text))) + { + Write-Host "Using specified driver source..." + dism /english /online /export-driver /destination="$($sync.MicrowinDriverLocation.Text)" | Out-Host + if ($?) + { + # Don't add exported drivers yet, that is run later + Write-Host "Drivers have been exported successfully." + } + else + { + Write-Host "Failed to export drivers." + } + } + else + { + New-Item -Path "$env:TEMP\DRV_EXPORT" -ItemType Directory -Force + dism /english /online /export-driver /destination="$env:TEMP\DRV_EXPORT" | Out-Host + if ($?) + { + Write-Host "Adding exported drivers..." + dism /english /image="$scratchDir" /add-driver /driver="$env:TEMP\DRV_EXPORT" /recurse | Out-Host + } + else + { + Write-Host "Failed to export drivers. Continuing without importing them..." + } + if (Test-Path "$env:TEMP\DRV_EXPORT") + { + Remove-Item "$env:TEMP\DRV_EXPORT" -Recurse -Force + } + } + } + if ($injectDrivers) { $driverPath = $sync.MicrowinDriverLocation.Text if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - Add-WindowsDriver -Path "$scratchDir" -Recurse -Driver "$driverPath" + dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host } else { @@ -335,7 +377,7 @@ public class PowerManagement { if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - Add-WindowsDriver -Path "$scratchDir" -Driver "$driverPath" -Recurse + dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host } else { diff --git a/xaml/inputXML.xaml b/xaml/inputXML.xaml index 9fee01b4..ba3475fb 100644 --- a/xaml/inputXML.xaml +++ b/xaml/inputXML.xaml @@ -843,6 +843,7 @@ Foreground="{LabelboxForegroundColor}" ToolTip="Path to unpacked drivers all sys and inf files for devices that need drivers" /> +