Files
FFU/FFUDevelopment/FFU.Common/FFU.Common.Drivers.psm1
T
rbalsleyMSFT 9282b4231e Add FFU.Common and FFUUI.Core module manifests and shared UI functions
- Created module manifest for FFU.Common with initial version 0.0.1.
- Created module manifest for FFUUI.Core with initial version 0.0.1.
- Implemented shared UI functions in FFUUI.Shared.psm1, including:
  - Update-ListViewItemStatus: Updates the status of items in a ListView.
  - Update-OverallProgress: Updates a progress bar and status label.
  - Invoke-ProgressUpdate: Enqueues progress updates to the UI thread.
  - Add-SortableColumn: Adds sortable columns to a ListView.
  - Add-SelectableGridViewColumn: Adds a selectable column with a "Select All" checkbox.
  - Update-SelectAllHeaderCheckBoxState: Updates the state of the header checkbox.
  - Invoke-ListViewSort: Sorts ListView items based on specified properties.
  - Show-ModernFolderPicker: Displays a modern folder picker dialog.
2025-06-11 20:50:51 -07:00

92 lines
3.9 KiB
PowerShell

# FFU Common Drivers Module
# Contains shared functions related to driver handling.
#Requires -Modules Dism
# # Import the common core module for logging and process invocation
# Import-Module "$PSScriptRoot\FFU.Common.Core.psm1"
# --------------------------------------------------------------------------
# SECTION: Driver Compression Function
# --------------------------------------------------------------------------
function Compress-DriverFolderToWim {
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory = $true)]
[ValidateScript({ Test-Path -Path $_ -PathType Container })]
[string]$SourceFolderPath,
[Parameter(Mandatory = $true)]
[string]$DestinationWimPath,
[Parameter()]
[string]$WimName, # Optional, defaults to folder name
[Parameter()]
[string]$WimDescription # Optional, defaults to folder name
)
WriteLog "Starting compression of folder '$SourceFolderPath' to '$DestinationWimPath'."
# Default WIM Name and Description to the source folder name if not provided
$sourceFolderName = Split-Path -Path $SourceFolderPath -Leaf
if ([string]::IsNullOrWhiteSpace($WimName)) {
$WimName = $sourceFolderName
WriteLog "WIM Name not provided, defaulting to source folder name: '$WimName'."
}
if ([string]::IsNullOrWhiteSpace($WimDescription)) {
$WimDescription = $sourceFolderName
WriteLog "WIM Description not provided, defaulting to source folder name: '$WimDescription'."
}
# Ensure destination directory exists
$destinationDir = Split-Path -Path $DestinationWimPath -Parent
if (-not (Test-Path -Path $destinationDir -PathType Container)) {
WriteLog "Creating destination directory: $destinationDir"
try {
New-Item -Path $destinationDir -ItemType Directory -Force -ErrorAction Stop | Out-Null
}
catch {
WriteLog "Failed to create destination directory '$destinationDir': $($_.Exception.Message)"
return $false # Indicate failure
}
}
if ($PSCmdlet.ShouldProcess("Folder '$SourceFolderPath'", "Compress to WIM '$DestinationWimPath'")) {
try {
# Construct arguments for dism.exe
$dismArgs = "/Capture-Image /ImageFile:`"$DestinationWimPath`" /CaptureDir:`"$SourceFolderPath`" /Name:`"$WimName`" /Description:`"$WimDescription`" /Compress:Max /CheckIntegrity /Quiet"
WriteLog "Executing dism.exe via Invoke-Process with arguments:"
WriteLog "dism.exe $dismArgs"
# Call Invoke-Process (assumed to be available from FFUUI.Core.psm1 or another imported module)
# Invoke-Process is expected to throw an exception for non-zero exit codes.
Invoke-Process -FilePath "dism.exe" -ArgumentList $dismArgs -Wait $true
WriteLog "Successfully compressed '$SourceFolderPath' to '$DestinationWimPath' using dism.exe."
return $true # Indicate success
}
catch {
WriteLog "Failed to compress folder '$SourceFolderPath' to WIM '$DestinationWimPath' using dism.exe."
WriteLog "Error details: $($_.Exception.Message)"
# Check if the error message contains details about the DISM log (dism.exe output might be in the exception)
if ($_.Exception.Message -match 'DISM log file can be found at (.*)') {
$dismLogPath = $matches[1].Trim()
WriteLog "Check the DISM log for more details: $dismLogPath"
}
return $false # Indicate failure
}
}
else {
WriteLog "Compression operation skipped due to -WhatIf."
return $false # Indicate skipped operation
}
}
# --------------------------------------------------------------------------
# SECTION: Module Export
# --------------------------------------------------------------------------
Export-ModuleMember -Function Compress-DriverFolderToWim