Skip to content

Commit

Permalink
support for wildcards in HardwareIDs inside _Driver
Browse files Browse the repository at this point in the history
  • Loading branch information
jantari committed Dec 16, 2019
1 parent e4d7e51 commit f59ea57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 12 additions & 4 deletions private/Test-MachineSatisfiesDependency.ps1
Expand Up @@ -31,11 +31,18 @@
return -2
}

foreach ($HardwareID in $Dependency.HardwareID.'#cdata-section') {
if ($CachedHardwareTable['_PnPID'].HardwareID -notcontains "$HardwareID") {
continue
[bool]$HardwareFound = $false

foreach ($HardwareInMachine in $CachedHardwareTable['_PnPID'].HardwareID) {
foreach ($HardwareID in $Dependency.HardwareID.'#cdata-section') {
# Lenovo HardwareIDs can contain wildcards (*) so we have to compare with "-like"
if ($HardwareInMachine -like "$HardwareID") {
$HardwareFound = $true
}
}
}

if ($HardwareFound) {
if (@($Dependency.ChildNodes.SchemaInfo.Name) -contains 'Date') {
$LenovoDate = [DateTime]::new(0)
if ( [DateTime]::TryParseExact($Dependency.Date, 'yyyy-MM-dd', [CultureInfo]::InvariantCulture, 'None', [ref]$LenovoDate) ) {
Expand All @@ -47,7 +54,7 @@
Write-Verbose "Got unsupported date format from Lenovo: '$($Dependency.Date)' (expected yyyy-MM-dd)"
}
}

if (@($Dependency.ChildNodes.SchemaInfo.Name) -contains 'Version') {
$DriverVersion = ($CachedHardwareTable['_PnPID'].Where{ $_.HardwareID -eq "$HardwareID" } | Get-PnpDeviceProperty -KeyName 'DEVPKEY_Device_DriverVersion').Data
# Not all drivers tell us their versions via the OS API. I think later I can try to parse the INIs as an alternative, but it would get tricky
Expand All @@ -58,6 +65,7 @@
}
}
}

return -1
}
'_EmbeddedControllerVersion' {
Expand Down
10 changes: 7 additions & 3 deletions public/Get-LSUpdate.ps1
Expand Up @@ -112,7 +112,7 @@
if ($DebugLogFile) {
Add-Content -LiteralPath $DebugLogFile -Value "Parsing dependencies for package: $($packageXML.Package.id)`r`n"
}

$packageObject = [LenovoPackage]@{
'ID' = $packageXML.Package.id
'Category' = $packageURL.category
Expand All @@ -124,8 +124,12 @@
'URL' = $packageURL.location
'Extracter' = $packageXML.Package
'Installer' = [PackageInstallInfo]::new($packageXML.Package, $packageURL.category)
'IsApplicable' = Resolve-XMLDependencies -PackageID $packageXML.Package.id -XML $packageXML.Package.Dependencies -FailUnsupportedDependencies:$FailUnsupportedDependencies -DebugLogFile $DebugLogFile
'IsInstalled' = Resolve-XMLDependencies -PackageID $packageXML.Package.id -XML $packageXML.Package.DetectInstall -FailUnsupportedDependencies:$FailUnsupportedDependencies -DebugLogFile $DebugLogFile
'IsApplicable' = Resolve-XMLDependencies -PackageID $packageXML.Package.id -XMLIN $packageXML.Package.Dependencies -FailUnsupportedDependencies:$FailUnsupportedDependencies -DebugLogFile $DebugLogFile
'IsInstalled' = if ($packageXML.Package.DetectInstall) {
Resolve-XMLDependencies -PackageID $packageXML.Package.id -XMLIN $packageXML.Package.DetectInstall -FailUnsupportedDependencies:$FailUnsupportedDependencies -DebugLogFile $DebugLogFile
} else {
0
}
}

if ($All -or ($packageObject.IsApplicable -and $packageObject.IsInstalled -eq $false)) {
Expand Down

1 comment on commit f59ea57

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PSScriptAnalyzer results as of this commit:

  • 2 Warning
See details
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Line     : 1
Column   : 10
Message  : Function 'New-WebClient' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.

RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Line     : 1
Column   : 10
Message  : Function 'Set-BIOSUpdateRegistryFlag' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.

Please sign in to comment.