Simplifies driver folder discovery logic

Removes hardcoded manufacturer name list and treats all immediate child folders under the Drivers path as potential manufacturer containers. This supports both known vendors (Dell, HP, Lenovo, Microsoft) and unknown/custom manufacturers without requiring code changes.

Adds support for manufacturer folders that directly contain installable driver content (no model subfolders), enabling flatter folder structures when appropriate.

Improves code readability by consolidating the folder processing logic into a single loop that checks for model subfolders first, then falls back to treating the manufacturer folder itself as a driver source if it contains installable content.
This commit is contained in:
rbalsleyMSFT
2025-11-18 23:48:07 -08:00
parent fc4a71f7e1
commit a1d08b6fa4
+25 -28
View File
@@ -1149,13 +1149,12 @@ if ($null -eq $DriverSourcePath) {
If (Test-Path -Path $DriversPath) {
WriteLog "Searching for driver WIMs and folders in $DriversPath"
# Get all WIM files
$WimFiles = Get-ChildItem -Path $DriversPath -Filter *.wim -Recurse
# Collect all WIM-based driver sources anywhere under Drivers
$wimFiles = Get-ChildItem -Path $DriversPath -Filter *.wim -File -Recurse -ErrorAction SilentlyContinue
# Build folder list that surfaces Manufacturer\Model entries
$DriverFolders = Get-ChildItem -Path $DriversPath -Directory
# Treat each immediate child folder as a manufacturer container (supports known and unknown vendors)
$manufacturerFolders = Get-ChildItem -Path $DriversPath -Directory -ErrorAction SilentlyContinue
$driversRootFullPath = (Get-Item -Path $DriversPath).FullName.TrimEnd('\')
$manufacturerFolderNames = @('dell','hp','lenovo','microsoft')
$relativePathResolver = {
param(
[string]$candidatePath,
@@ -1168,7 +1167,7 @@ if ($null -eq $DriverSourcePath) {
if ([string]::IsNullOrWhiteSpace($relativeSegment)) {
return Split-Path -Path $normalizedPath -Leaf
}
return $relativeSegment
return $relativePath = $relativeSegment
}
return $normalizedPath
}
@@ -1179,7 +1178,7 @@ if ($null -eq $DriverSourcePath) {
# Create a combined list
$DriverSources = @()
foreach ($wimFile in $WimFiles) {
foreach ($wimFile in $wimFiles) {
$relativePath = & $relativePathResolver -candidatePath $wimFile.FullName -rootPath $driversRootFullPath
$DriverSources += [PSCustomObject]@{
Type = 'WIM'
@@ -1187,15 +1186,26 @@ if ($null -eq $DriverSourcePath) {
RelativePath = $relativePath
}
}
foreach ($driverFolder in $DriverFolders) {
$parentIsRoot = $driverFolder.Parent.FullName -eq $driversRootFullPath
$folderNameLower = $driverFolder.Name.ToLowerInvariant()
$isManufacturerFolder = $parentIsRoot -and ($manufacturerFolderNames -contains $folderNameLower)
foreach ($manufacturerFolder in $manufacturerFolders) {
$modelFolders = Get-ChildItem -Path $manufacturerFolder.FullName -Directory -ErrorAction SilentlyContinue
if ($isManufacturerFolder) {
# Only manufacturer folders (Dell/HP/Lenovo/Microsoft) should surface child model folders.
$childModelFolders = Get-ChildItem -Path $driverFolder.FullName -Directory -ErrorAction SilentlyContinue
foreach ($modelFolder in $childModelFolders) {
if ($null -eq $modelFolders -or $modelFolders.Count -eq 0) {
if (Test-DriverFolderHasInstallableContent -Path $manufacturerFolder.FullName) {
$relativePath = & $relativePathResolver -candidatePath $manufacturerFolder.FullName -rootPath $driversRootFullPath
$DriverSources += [PSCustomObject]@{
Type = 'Folder'
Path = $manufacturerFolder.FullName
RelativePath = $relativePath
}
WriteLog "Using manufacturer folder '$($manufacturerFolder.FullName)' as a driver source because it contains installable content."
}
else {
WriteLog "Skipping '$($manufacturerFolder.FullName)' because it has no model folders with installable content."
}
continue
}
foreach ($modelFolder in $modelFolders) {
if (-not (Test-DriverFolderHasInstallableContent -Path $modelFolder.FullName)) {
WriteLog "Skipping driver folder '$($modelFolder.FullName)' because no installable files were found."
continue
@@ -1207,19 +1217,6 @@ if ($null -eq $DriverSourcePath) {
RelativePath = $relativePath
}
}
continue
}
if (-not (Test-DriverFolderHasInstallableContent -Path $driverFolder.FullName)) {
WriteLog "Skipping driver folder '$($driverFolder.FullName)' because no installable files were found."
continue
}
$relativePath = & $relativePathResolver -candidatePath $driverFolder.FullName -rootPath $driversRootFullPath
$DriverSources += [PSCustomObject]@{
Type = 'Folder'
Path = $driverFolder.FullName
RelativePath = $relativePath
}
}
$DriverSourcesCount = $DriverSources.Count