From 73df1c08719960c7002e521ce7466d1cc9e93ca6 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 6 Feb 2019 20:18:44 +0100 Subject: setupapi: Add DrvInfoDetailData.IsCompatible() to simplify HID detection Signed-off-by: Simon Rozman --- setupapi/types_windows.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'setupapi/types_windows.go') diff --git a/setupapi/types_windows.go b/setupapi/types_windows.go index 2dfcb70..db2f8ce 100644 --- a/setupapi/types_windows.go +++ b/setupapi/types_windows.go @@ -6,6 +6,7 @@ package setupapi import ( + "strings" "syscall" "unsafe" @@ -447,6 +448,21 @@ type DrvInfoDetailData struct { CompatIDs []string } +// IsCompatible method tests if given hardware ID matches the driver or is listed on the compatible ID list. +func (DriverInfoDetailData DrvInfoDetailData) IsCompatible(hwid string) bool { + hwidLC := strings.ToLower(hwid) + if strings.ToLower(DriverInfoDetailData.HardwareID) == hwidLC { + return true + } + for i := range DriverInfoDetailData.CompatIDs { + if strings.ToLower(DriverInfoDetailData.CompatIDs[i]) == hwidLC { + return true + } + } + + return false +} + // DICD flags control SetupDiCreateDeviceInfo type DICD uint32 -- cgit v1.2.3-59-g8ed1b