Refactor Dell driver catalog download logic

Moves the logic for downloading and preparing the Dell driver catalog from the main build scripts directly into the specific Dell driver download task.

This change encapsulates all Dell-specific logic within the `Save-DellDriversTask` function, making it self-sufficient. Each parallel task now manages its own dependency on the catalog file, which simplifies the main script's responsibilities.

Also includes minor code style formatting.
This commit is contained in:
rbalsleyMSFT
2025-06-17 16:02:34 -07:00
parent df96d14643
commit ab0b92ad5c
4 changed files with 105 additions and 175 deletions
+2 -40
View File
@@ -1910,7 +1910,8 @@ function Get-WindowsESD {
}
elseif ($WindowsRelease -eq 11) {
'https://go.microsoft.com/fwlink/?LinkId=2156292'
} else {
}
else {
throw "Downloading Windows $WindowsRelease is not supported. Please use the -ISOPath parameter to specify the path to the Windows $WindowsRelease ISO file."
}
@@ -3956,44 +3957,6 @@ if ($driversJsonPath -and (Test-Path $driversJsonPath) -and ($InstallDrivers -or
else {
WriteLog "Found $($driversToProcess.Count) driver entries to process from $driversJsonPath."
$dellCatalogXmlPathForJob = $null
if ($driversToProcess | Where-Object { $_.Make -eq 'Dell' }) {
WriteLog "Dell drivers found in JSON, ensuring Dell Catalog XML is available..."
$dellDriversFolderScript = Join-Path -Path $DriversFolder -ChildPath "Dell"
$catalogBaseNameScript = if ($WindowsRelease -le 11) { "CatalogPC" } else { "Catalog" }
$dellCabFileScript = Join-Path -Path $dellDriversFolderScript -ChildPath "$($catalogBaseNameScript).cab"
$dellCatalogXmlPathForJob = Join-Path -Path $dellDriversFolderScript -ChildPath "$($catalogBaseNameScript).xml"
$catalogUrlScript = if ($WindowsRelease -le 11) { "http://downloads.dell.com/catalog/CatalogPC.cab" } else { "https://downloads.dell.com/catalog/Catalog.cab" }
$downloadDellCatalogScript = $true
if (Test-Path -Path $dellCatalogXmlPathForJob -PathType Leaf) {
if (((Get-Date) - (Get-Item $dellCatalogXmlPathForJob).LastWriteTime).TotalDays -lt 7) {
WriteLog "Using existing Dell Catalog XML (less than 7 days old): $dellCatalogXmlPathForJob"
$downloadDellCatalogScript = $false
}
else { WriteLog "Existing Dell Catalog XML '$dellCatalogXmlPathForJob' is older than 7 days." }
}
else { WriteLog "Dell Catalog XML '$dellCatalogXmlPathForJob' not found." }
if ($downloadDellCatalogScript) {
WriteLog "Dell Catalog XML '$dellCatalogXmlPathForJob' needs to be downloaded/updated."
try {
if (-not (Test-Path -Path $dellDriversFolderScript -PathType Container)) { New-Item -Path $dellDriversFolderScript -ItemType Directory -Force | Out-Null }
if (Test-Path $dellCabFileScript) { Remove-Item $dellCabFileScript -Force -ErrorAction SilentlyContinue }
if (Test-Path $dellCatalogXmlPathForJob) { Remove-Item $dellCatalogXmlPathForJob -Force -ErrorAction SilentlyContinue }
Start-BitsTransferWithRetry -Source $catalogUrlScript -Destination $dellCabFileScript
Invoke-Process -FilePath "Expand.exe" -ArgumentList """$dellCabFileScript"" ""$dellCatalogXmlPathForJob""" | Out-Null
Remove-Item -Path $dellCabFileScript -Force -ErrorAction SilentlyContinue
WriteLog "Dell Catalog XML prepared at $dellCatalogXmlPathForJob"
}
catch {
WriteLog "Failed to prepare Dell Catalog XML: $($_.Exception.Message). Dell driver downloads may fail."
$dellCatalogXmlPathForJob = $null
}
}
}
$taskArguments = @{
DriversFolder = $DriversFolder
WindowsRelease = $WindowsRelease
@@ -4002,7 +3965,6 @@ if ($driversJsonPath -and (Test-Path $driversJsonPath) -and ($InstallDrivers -or
Headers = $Headers
UserAgent = $UserAgent
CompressToWim = $CompressDownloadedDriversToWim
DellCatalogXmlPath = $dellCatalogXmlPathForJob
}
WriteLog "Starting parallel driver processing using Invoke-ParallelProcessing..."
-61
View File
@@ -220,66 +220,6 @@ $window.Add_Loaded({
$localUserAgent = $coreStaticVars.UserAgent
$compressDrivers = $script:uiState.Controls.chkCompressDriversToWIM.IsChecked
# --- Dell Catalog Handling (once, if Dell drivers are selected) ---
$dellCatalogXmlPath = $null # This will be the path passed to the background task
if ($selectedDrivers | Where-Object { $_.Make -eq 'Dell' }) {
$script:uiState.Controls.txtStatus.Text = "Checking Dell Catalog..."
WriteLog "Dell drivers selected. Preparing Dell catalog..."
$dellDriversFolderUi = Join-Path -Path $localDriversFolder -ChildPath "Dell"
$catalogBaseName = if ($localWindowsRelease -le 11) { "CatalogPC" } else { "Catalog" }
$dellCabFileUi = Join-Path -Path $dellDriversFolderUi -ChildPath "$($catalogBaseName).cab"
# This $dellCatalogXmlPath is the one we ensure exists and is up-to-date for the Save-DellDriversTask
$dellCatalogXmlPath = Join-Path -Path $dellDriversFolderUi -ChildPath "$($catalogBaseName).xml"
$catalogUrl = if ($localWindowsRelease -le 11) { "http://downloads.dell.com/catalog/CatalogPC.cab" } else { "https://downloads.dell.com/catalog/Catalog.cab" }
$downloadDellCatalog = $true
if (Test-Path -Path $dellCatalogXmlPath -PathType Leaf) {
if (((Get-Date) - (Get-Item $dellCatalogXmlPath).LastWriteTime).TotalDays -lt 7) {
WriteLog "Using existing Dell Catalog XML (less than 7 days old) for download task: $dellCatalogXmlPath"
$downloadDellCatalog = $false
$script:uiState.Controls.txtStatus.Text = "Dell Catalog ready."
}
else {
WriteLog "Existing Dell Catalog XML '$dellCatalogXmlPath' is older than 7 days."
}
}
else {
WriteLog "Dell Catalog XML '$dellCatalogXmlPath' not found."
}
if ($downloadDellCatalog) {
WriteLog "Dell Catalog XML '$dellCatalogXmlPath' needs to be downloaded/updated for driver download task."
$script:uiState.Controls.txtStatus.Text = "Downloading Dell Catalog..."
try {
# Ensure Dell drivers folder exists
if (-not (Test-Path -Path $dellDriversFolderUi -PathType Container)) {
WriteLog "Creating Dell drivers folder: $dellDriversFolderUi"
New-Item -Path $dellDriversFolderUi -ItemType Directory -Force | Out-Null
}
if (Test-Path $dellCabFileUi) { Remove-Item $dellCabFileUi -Force -ErrorAction SilentlyContinue }
if (Test-Path $dellCatalogXmlPath) { Remove-Item $dellCatalogXmlPath -Force -ErrorAction SilentlyContinue }
# Using Start-BitsTransferWithRetry and Invoke-Process (available from FFUUI.Core.psm1)
Start-BitsTransferWithRetry -Source $catalogUrl -Destination $dellCabFileUi
WriteLog "Dell Catalog CAB downloaded to $dellCabFileUi"
Invoke-Process -FilePath "Expand.exe" -ArgumentList """$dellCabFileUi"" ""$dellCatalogXmlPath""" | Out-Null
WriteLog "Dell Catalog XML extracted to $dellCatalogXmlPath"
Remove-Item -Path $dellCabFileUi -Force -ErrorAction SilentlyContinue
WriteLog "Dell Catalog CAB file $dellCabFileUi deleted."
$script:uiState.Controls.txtStatus.Text = "Dell Catalog ready."
}
catch {
$errMsg = "Failed to download/extract Dell Catalog for driver download task: $($_.Exception.Message)"
WriteLog $errMsg; [System.Windows.MessageBox]::Show($errMsg, "Dell Catalog Error", "OK", "Error")
$dellCatalogXmlPath = $null # Ensure it's null if failed, Save-DellDriversTask will handle this
$script:uiState.Controls.txtStatus.Text = "Dell Catalog download failed. Dell drivers may not download."
}
}
}
# --- End Dell Catalog Handling ---
$script:uiState.Controls.txtStatus.Text = "Processing all selected drivers..."
WriteLog "Processing all selected drivers: $($selectedDrivers.Model -join ', ')"
@@ -291,7 +231,6 @@ $window.Add_Loaded({
Headers = $localHeaders
UserAgent = $localUserAgent
CompressToWim = $compressDrivers
DellCatalogXmlPath = $dellCatalogXmlPath
}
Invoke-ParallelProcessing -ItemsToProcess $selectedDrivers `
@@ -173,12 +173,10 @@ function Invoke-ParallelProcessing {
-CompressToWim $localJobArgs['CompressToWim']
}
'Dell' {
# DellCatalogXmlPath might be null if catalog prep failed; Save-DellDriversTask should handle this.
$taskResult = Save-DellDriversTask -DriverItemData $currentItem `
-DriversFolder $localJobArgs['DriversFolder'] `
-WindowsArch $localJobArgs['WindowsArch'] `
-WindowsRelease $localJobArgs['WindowsRelease'] `
-DellCatalogXmlPath $localJobArgs['DellCatalogXmlPath'] `
-ProgressQueue $localProgressQueue `
-CompressToWim $localJobArgs['CompressToWim']
}
@@ -160,13 +160,10 @@ function Save-DellDriversTask {
[string]$WindowsArch,
[Parameter(Mandatory = $true)]
[int]$WindowsRelease,
[Parameter(Mandatory = $true)]
[string]$DellCatalogXmlPath, # Path to the *existing* central XML catalog file
[Parameter()] # Made optional
[System.Collections.Concurrent.ConcurrentQueue[hashtable]]$ProgressQueue = $null, # Default to null
[Parameter()]
[bool]$CompressToWim = $false # New parameter for compression
# REMOVED: UI-related parameters, Catalog download/extract params
)
$modelName = $DriverItemData.Model
@@ -181,6 +178,42 @@ function Save-DellDriversTask {
$modelPath = Join-Path -Path $makeDriversPath -ChildPath $modelName
try {
# --- Dell Catalog Handling ---
$dellDriversFolder = Join-Path -Path $DriversFolder -ChildPath "Dell"
$catalogBaseName = if ($WindowsRelease -le 11) { "CatalogPC" } else { "Catalog" }
$dellCabFile = Join-Path -Path $dellDriversFolder -ChildPath "$($catalogBaseName).cab"
$dellCatalogXML = Join-Path -Path $dellDriversFolder -ChildPath "$($catalogBaseName).xml"
$catalogUrl = if ($WindowsRelease -le 11) { "http://downloads.dell.com/catalog/CatalogPC.cab" } else { "https://downloads.dell.com/catalog/Catalog.cab" }
$downloadCatalog = $true
if (Test-Path -Path $dellCatalogXML -PathType Leaf) {
if (((Get-Date) - (Get-Item $dellCatalogXML).LastWriteTime).TotalDays -lt 7) {
WriteLog "Using existing Dell Catalog XML (less than 7 days old): $dellCatalogXML"
$downloadCatalog = $false
}
else { WriteLog "Existing Dell Catalog XML is older than 7 days: $dellCatalogXML" }
}
else { WriteLog "Dell Catalog XML not found: $dellCatalogXML" }
if ($downloadCatalog) {
WriteLog "Downloading and extracting Dell Catalog for task..."
if (-not (Test-Path -Path $dellDriversFolder -PathType Container)) {
New-Item -Path $dellDriversFolder -ItemType Directory -Force | Out-Null
}
try {
$request = [System.Net.WebRequest]::Create($catalogUrl); $request.Method = 'HEAD'; $response = $request.GetResponse(); $response.Close()
}
catch { throw "Dell Catalog URL '$catalogUrl' not accessible: $($_.Exception.Message)" }
if (Test-Path -Path $dellCabFile) { Remove-Item -Path $dellCabFile -Force -ErrorAction SilentlyContinue }
if (Test-Path -Path $dellCatalogXML) { Remove-Item -Path $dellCatalogXML -Force -ErrorAction SilentlyContinue }
Start-BitsTransferWithRetry -Source $catalogUrl -Destination $dellCabFile
Invoke-Process -FilePath "Expand.exe" -ArgumentList """$dellCabFile"" ""$dellCatalogXML""" | Out-Null
Remove-Item -Path $dellCabFile -Force -ErrorAction SilentlyContinue
}
# --- End Dell Catalog Handling ---
# 1. Check if drivers already exist for this model (final destination)
if (Test-Path -Path $modelPath -PathType Container) {
$folderSize = (Get-ChildItem -Path $modelPath -Recurse | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
@@ -195,19 +228,17 @@ function Save-DellDriversTask {
}
}
# 2. REMOVED: Download and Extract Catalog - This is now done centrally in the UI script
# 3. Parse the *EXISTING* XML and Find Drivers for *this specific model*
$status = "Finding drivers..."
if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $modelName -Status $status }
# Check if the provided XML path exists
if (-not (Test-Path -Path $DellCatalogXmlPath -PathType Leaf)) {
throw "Dell Catalog XML file not found at specified path: $DellCatalogXmlPath"
if (-not (Test-Path -Path $dellCatalogXML -PathType Leaf)) {
throw "Dell Catalog XML file not found at specified path: $dellCatalogXML"
}
WriteLog "Parsing existing Dell Catalog XML for model '$modelName' from: $DellCatalogXmlPath"
[xml]$xmlContent = Get-Content -Path $DellCatalogXmlPath
WriteLog "Parsing existing Dell Catalog XML for model '$modelName' from: $dellCatalogXML"
[xml]$xmlContent = Get-Content -Path $dellCatalogXML
# Check if manifest and baseLocation exist before accessing
if ($null -eq $xmlContent.manifest -or $null -eq $xmlContent.manifest.baseLocation) {
throw "Invalid Dell Catalog XML format: Missing 'manifest' or 'baseLocation' element in '$DellCatalogXmlPath'."
@@ -219,7 +250,7 @@ function Save-DellDriversTask {
$softwareComponents = @($xmlContent.Manifest.SoftwareComponent | Where-Object { $_.ComponentType.value -eq "DRVR" })
$modelSpecificDriversFound = $false
WriteLog "Searching $($softwareComponents.Count) DRVR components in '$DellCatalogXmlPath' for model '$modelName'..."
WriteLog "Searching $($softwareComponents.Count) DRVR components in '$dellCatalogXML' for model '$modelName'..."
foreach ($component in $softwareComponents) {
# Check if SupportedSystems and Brand exist
@@ -303,7 +334,7 @@ function Save-DellDriversTask {
if (-not $modelSpecificDriversFound) {
$status = "No drivers found for OS"
WriteLog "No drivers found for model '$modelName' matching Windows Release '$WindowsRelease' and Arch '$WindowsArch' in '$DellCatalogXmlPath'."
WriteLog "No drivers found for model '$modelName' matching Windows Release '$WindowsRelease' and Arch '$WindowsArch' in '$dellCatalogXML'."
if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $modelName -Status $status }
# Consider this success as the process completed, just no drivers to download
return [PSCustomObject]@{ Model = $modelName; Status = $status; Success = $true }