From 152309163738a8091f6e7f35a409042535ddd7a0 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Sat, 28 Jun 2025 00:51:22 -0700 Subject: [PATCH] Feat: Add WIM compression for existing driver folders Implements logic to compress previously downloaded driver folders into WIM files if the compression option is enabled. This ensures consistency in the driver store when re-running the download process. Refactors the parallel task processing to rely on a standardized boolean 'Success' property from all driver download tasks. This simplifies the result handling logic and makes it more reliable than parsing status strings. --- .../FFU.Common/FFU.Common.Parallel.psm1 | 21 ++++++-------- .../FFUUI.Core/FFUUI.Core.Drivers.Dell.psm1 | 27 ++++++++++++++++++ .../FFUUI.Core/FFUUI.Core.Drivers.HP.psm1 | 8 ++++++ .../FFUUI.Core/FFUUI.Core.Drivers.Lenovo.psm1 | 27 ++++++++++++++++++ .../FFUUI.Core.Drivers.Microsoft.psm1 | 28 +++++++++++++++++++ 5 files changed, 99 insertions(+), 12 deletions(-) diff --git a/FFUDevelopment/FFU.Common/FFU.Common.Parallel.psm1 b/FFUDevelopment/FFU.Common/FFU.Common.Parallel.psm1 index 61a6fa4..c62ce96 100644 --- a/FFUDevelopment/FFU.Common/FFU.Common.Parallel.psm1 +++ b/FFUDevelopment/FFU.Common/FFU.Common.Parallel.psm1 @@ -218,22 +218,19 @@ function Invoke-ParallelProcessing { elseif ($taskResult.PSObject.Properties.Name -contains 'Identifier') { $taskSpecificIdentifier = $taskResult.Identifier } $resultStatus = $taskResult.Status + # Simplified success check. All driver tasks should now return a 'Success' property. if ($taskResult.PSObject.Properties.Name -contains 'Success') { - # Dell, Microsoft, Lenovo $resultCode = if ($taskResult.Success) { 0 } else { 1 } } - elseif ($taskResult.Status -like 'Completed*') { - # HP success - $resultCode = 0 - } - elseif ($taskResult.Status -like 'Error*') { - # HP error - $resultCode = 1 - } else { - # Default for HP if status is unexpected, or if 'Success' property is missing but status isn't 'Completed*' or 'Error*' - WriteLog "Unexpected status or missing 'Success' property from task for '$taskSpecificIdentifier': $($taskResult.Status)" - $resultCode = 1 # Assume error + # Fallback for any task that *still* doesn't return 'Success'. This is now the exceptional case. + WriteLog "Warning: Task for '$taskSpecificIdentifier' did not return a 'Success' property. Inferring from status: '$($taskResult.Status)'" + if ($taskResult.Status -like 'Completed*' -or $taskResult.Status -like 'Already downloaded*') { + $resultCode = 0 # Treat as success + } + else { + $resultCode = 1 # Treat as error + } } } elseif ($make -in ('Microsoft', 'Dell', 'HP', 'Lenovo')) { diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Dell.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Dell.psm1 index a615da5..3d67561 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Dell.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Dell.psm1 @@ -186,6 +186,33 @@ function Save-DellDriversTask { if (-not $existingDriver.PSObject.Properties['Model']) { $existingDriver | Add-Member -MemberType NoteProperty -Name 'Model' -Value $modelName } + + # Special handling for existing folders that need compression + if ($CompressToWim -and $existingDriver.Status -eq 'Already downloaded') { + $wimFilePath = Join-Path -Path $makeDriversPath -ChildPath "$($modelName).wim" + $sourceFolderPath = Join-Path -Path $makeDriversPath -ChildPath $modelName + WriteLog "Attempting compression of existing folder '$sourceFolderPath' to '$wimFilePath'." + if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $modelName -Status "Compressing existing..." } + try { + Compress-DriverFolderToWim -SourceFolderPath $sourceFolderPath -DestinationWimPath $wimFilePath -WimName $modelName -WimDescription "Drivers for $modelName" -ErrorAction Stop + $existingDriver.Status = "Already downloaded & Compressed" + $existingDriver.DriverPath = Join-Path -Path $make -ChildPath "$($modelName).wim" + $existingDriver.Success = $true + WriteLog "Successfully compressed existing drivers for $modelName to $wimFilePath." + } + catch { + WriteLog "Error compressing existing drivers for $($modelName): $($_.Exception.Message)" + $existingDriver.Status = "Already downloaded (Compression failed)" + $existingDriver.Success = $false + } + if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $modelName -Status $existingDriver.Status } + } + + # Ensure the Success property exists on the object being returned. + if (-not $existingDriver.PSObject.Properties.Name -contains 'Success') { + $existingDriver | Add-Member -MemberType NoteProperty -Name 'Success' -Value $true + } + return $existingDriver } diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.HP.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.HP.psm1 index 043d6c9..5ba4bd3 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.HP.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.HP.psm1 @@ -141,14 +141,22 @@ function Save-HPDriversTask { Compress-DriverFolderToWim -SourceFolderPath $sourceFolderPath -DestinationWimPath $wimFilePath -WimName $identifier -WimDescription "Drivers for $identifier" -ErrorAction Stop $existingDriver.Status = "Already downloaded & Compressed" $existingDriver.DriverPath = Join-Path -Path $make -ChildPath "$($sanitizedModelName).wim" + $existingDriver.Success = $true WriteLog "Successfully compressed existing drivers for $identifier to $wimFilePath." } catch { WriteLog "Error compressing existing drivers for $($identifier): $($_.Exception.Message)" $existingDriver.Status = "Already downloaded (Compression failed)" + $existingDriver.Success = $false } if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $identifier -Status $existingDriver.Status } } + + # Ensure the Success property exists on the object being returned. + if (-not $existingDriver.PSObject.Properties.Name -contains 'Success') { + $existingDriver | Add-Member -MemberType NoteProperty -Name 'Success' -Value $true + } + return $existingDriver } diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Lenovo.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Lenovo.psm1 index 283698a..c81a3bf 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Lenovo.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Lenovo.psm1 @@ -104,6 +104,33 @@ function Save-LenovoDriversTask { # We need to return 'Identifier' for Lenovo's logic. $existingDriver | Add-Member -MemberType NoteProperty -Name 'Identifier' -Value $identifier -Force $existingDriver.PSObject.Properties.Remove('Model') + + # Special handling for existing folders that need compression + if ($CompressToWim -and $existingDriver.Status -eq 'Already downloaded') { + $wimFilePath = Join-Path -Path $makeDriversPath -ChildPath "$($sanitizedIdentifier).wim" + $sourceFolderPath = Join-Path -Path $makeDriversPath -ChildPath $sanitizedIdentifier + WriteLog "Attempting compression of existing folder '$sourceFolderPath' to '$wimFilePath'." + if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $identifier -Status "Compressing existing..." } + try { + Compress-DriverFolderToWim -SourceFolderPath $sourceFolderPath -DestinationWimPath $wimFilePath -WimName $identifier -WimDescription "Drivers for $identifier" -ErrorAction Stop + $existingDriver.Status = "Already downloaded & Compressed" + $existingDriver.DriverPath = Join-Path -Path $make -ChildPath "$($sanitizedIdentifier).wim" + $existingDriver.Success = $true + WriteLog "Successfully compressed existing drivers for $identifier to $wimFilePath." + } + catch { + WriteLog "Error compressing existing drivers for $($identifier): $($_.Exception.Message)" + $existingDriver.Status = "Already downloaded (Compression failed)" + $existingDriver.Success = $false + } + if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $identifier -Status $existingDriver.Status } + } + + # Ensure the Success property exists on the object being returned. + if (-not $existingDriver.PSObject.Properties.Name -contains 'Success') { + $existingDriver | Add-Member -MemberType NoteProperty -Name 'Success' -Value $true + } + return $existingDriver } diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Microsoft.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Microsoft.psm1 index d46abbc..6c29263 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Microsoft.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Drivers.Microsoft.psm1 @@ -109,6 +109,34 @@ function Save-MicrosoftDriversTask { if (-not $existingDriver.PSObject.Properties['Model']) { $existingDriver | Add-Member -MemberType NoteProperty -Name 'Model' -Value $modelName } + + # Special handling for existing folders that need compression + if ($CompressToWim -and $existingDriver.Status -eq 'Already downloaded') { + $makeDriversPath = Join-Path -Path $DriversFolder -ChildPath $make + $wimFilePath = Join-Path -Path $makeDriversPath -ChildPath "$($modelName).wim" + $sourceFolderPath = Join-Path -Path $makeDriversPath -ChildPath $modelName + WriteLog "Attempting compression of existing folder '$sourceFolderPath' to '$wimFilePath'." + if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $modelName -Status "Compressing existing..." } + try { + Compress-DriverFolderToWim -SourceFolderPath $sourceFolderPath -DestinationWimPath $wimFilePath -WimName $modelName -WimDescription "Drivers for $modelName" -ErrorAction Stop + $existingDriver.Status = "Already downloaded & Compressed" + $existingDriver.DriverPath = Join-Path -Path $make -ChildPath "$($modelName).wim" + $existingDriver.Success = $true + WriteLog "Successfully compressed existing drivers for $modelName to $wimFilePath." + } + catch { + WriteLog "Error compressing existing drivers for $($modelName): $($_.Exception.Message)" + $existingDriver.Status = "Already downloaded (Compression failed)" + $existingDriver.Success = $false + } + if ($null -ne $ProgressQueue) { Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $modelName -Status $existingDriver.Status } + } + + # Ensure the Success property exists on the object being returned. + if (-not $existingDriver.PSObject.Properties.Name -contains 'Success') { + $existingDriver | Add-Member -MemberType NoteProperty -Name 'Success' -Value $true + } + return $existingDriver }