mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Refactor: Pre-process Dell catalog before parallel downloads
Moves the Dell catalog download and preparation logic from the individual driver download task to the parent function. This prevents a race condition where multiple parallel tasks would attempt to download and extract the same catalog file simultaneously. The catalog is now prepared once before any driver downloads begin, improving efficiency and reliability. Additionally, comments out manual garbage collection calls in the VM build UI.
This commit is contained in:
@@ -178,41 +178,10 @@ function Save-DellDriversTask {
|
||||
$modelPath = Join-Path -Path $makeDriversPath -ChildPath $modelName
|
||||
|
||||
try {
|
||||
# --- Dell Catalog Handling ---
|
||||
# Define paths for Dell catalog. The catalog is assumed to be prepared by the calling function.
|
||||
$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) {
|
||||
@@ -567,7 +536,6 @@ function Save-DellDriversTask {
|
||||
# Ensure return object is created even on error
|
||||
return [PSCustomObject]@{ Model = $modelName; Status = $status; Success = $success }
|
||||
}
|
||||
# REMOVED: Finally block that cleaned up temp catalog files
|
||||
|
||||
# Enqueue the final status (success or error) before returning
|
||||
if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $modelName -Status $status }
|
||||
|
||||
@@ -568,6 +568,52 @@ function Invoke-DownloadSelectedDrivers {
|
||||
$State.Controls.txtStatus.Text = "Processing all selected drivers..."
|
||||
WriteLog "Processing all selected drivers: $($selectedDrivers.Model -join ', ')"
|
||||
|
||||
# Pre-process Dell Catalog if needed, so it's not done in parallel
|
||||
if ($selectedDrivers | Where-Object { $_.Make -eq 'Dell' }) {
|
||||
WriteLog "Dell drivers selected. Ensuring Dell Catalog is up-to-date..."
|
||||
try {
|
||||
$dellDriversFolder = Join-Path -Path $localDriversFolder -ChildPath "Dell"
|
||||
$catalogBaseName = if ($localWindowsRelease -le 11) { "CatalogPC" } else { "Catalog" }
|
||||
$dellCabFile = Join-Path -Path $dellDriversFolder -ChildPath "$($catalogBaseName).cab"
|
||||
$dellCatalogXML = Join-Path -Path $dellDriversFolder -ChildPath "$($catalogBaseName).xml"
|
||||
$catalogUrl = if ($localWindowsRelease -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).CreationTime).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 driver download process..."
|
||||
if (-not (Test-Path -Path $dellDriversFolder -PathType Container)) {
|
||||
New-Item -Path $dellDriversFolder -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
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
|
||||
WriteLog "Dell Catalog prepared successfully."
|
||||
}
|
||||
}
|
||||
catch {
|
||||
$errorMessage = "Failed to prepare Dell Catalog: $($_.Exception.Message)"
|
||||
WriteLog $errorMessage
|
||||
[System.Windows.MessageBox]::Show($errorMessage, "Dell Catalog Error", "OK", "Error")
|
||||
$Button.IsEnabled = $true
|
||||
$State.Controls.pbOverallProgress.Visibility = 'Collapsed'
|
||||
$State.Controls.txtStatus.Text = "Driver download cancelled due to Dell Catalog error."
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
$taskArguments = @{
|
||||
DriversFolder = $localDriversFolder
|
||||
WindowsRelease = $localWindowsRelease
|
||||
|
||||
Reference in New Issue
Block a user