mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Improves driver matching to select the most specific rule
Refines the driver selection logic to correctly handle overlapping or wildcard-based rules in the driver mapping file. Previously, the script would use the first rule that matched the system manufacturer and model. This could lead to a less specific rule being chosen if it appeared before a more specific one. The logic now finds all matching rules and selects the one with the most specific model name, ensuring a more accurate driver package is applied.
This commit is contained in:
@@ -436,16 +436,26 @@ if (Test-Path -Path $driverMappingPath -PathType Leaf) {
|
|||||||
# Load and parse the mapping file
|
# Load and parse the mapping file
|
||||||
$driverMappings = Get-Content -Path $driverMappingPath -Raw | ConvertFrom-Json
|
$driverMappings = Get-Content -Path $driverMappingPath -Raw | ConvertFrom-Json
|
||||||
|
|
||||||
# Find a matching rule
|
# Find all matching rules and select the most specific one
|
||||||
$matchedRule = $null
|
$matchingRules = @()
|
||||||
foreach ($rule in $driverMappings) {
|
foreach ($rule in $driverMappings) {
|
||||||
# Use -like for wildcard matching
|
# Use -like for wildcard matching
|
||||||
if ($systemManufacturer -like "$($rule.Manufacturer)*" -and $systemModel -like "$($rule.Model)*") {
|
if ($systemManufacturer -like "$($rule.Manufacturer)*" -and $systemModel -like "$($rule.Model)*") {
|
||||||
$matchedRule = $rule
|
$matchingRules += $rule
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Select the best match
|
||||||
|
$matchedRule = $null
|
||||||
|
if ($matchingRules.Count -gt 0) {
|
||||||
|
WriteLog "Found $($matchingRules.Count) potential driver mapping rule(s)."
|
||||||
|
foreach ($rule in $matchingRules) {
|
||||||
|
WriteLog " - Potential Match: Manufacturer='$($rule.Manufacturer)', Model='$($rule.Model)', Path='$($rule.DriverPath)'"
|
||||||
|
}
|
||||||
|
# Sort by model name length, descending, to find the most specific match
|
||||||
|
$matchedRule = $matchingRules | Sort-Object -Property @{Expression = { $_.Model.Length } } -Descending | Select-Object -First 1
|
||||||
|
}
|
||||||
|
|
||||||
if ($null -ne $matchedRule) {
|
if ($null -ne $matchedRule) {
|
||||||
WriteLog "Automatic match found: Manufacturer='$($matchedRule.Manufacturer)', Model='$($matchedRule.Model)'"
|
WriteLog "Automatic match found: Manufacturer='$($matchedRule.Manufacturer)', Model='$($matchedRule.Model)'"
|
||||||
$potentialDriverPath = Join-Path -Path $DriversPath -ChildPath $matchedRule.DriverPath
|
$potentialDriverPath = Join-Path -Path $DriversPath -ChildPath $matchedRule.DriverPath
|
||||||
|
|||||||
Reference in New Issue
Block a user