mirror of
https://git.zx2c4.com/wireguard-go
synced 2024-11-15 01:05:15 +01:00
setupapi: Add SP_DRVINFO_DATA.IsNewer() method to simplify comparison
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
3c29434a79
commit
069016bbc4
@ -177,6 +177,28 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !driverData.IsNewer(windows.Filetime{}, 0) {
|
||||||
|
t.Error("Driver should have non-zero date and version")
|
||||||
|
}
|
||||||
|
if !driverData.IsNewer(windows.Filetime{HighDateTime: driverData.DriverDate.HighDateTime}, 0) {
|
||||||
|
t.Error("Driver should have non-zero date and version")
|
||||||
|
}
|
||||||
|
if driverData.IsNewer(windows.Filetime{HighDateTime: driverData.DriverDate.HighDateTime + 1}, 0) {
|
||||||
|
t.Error("Driver should report newer version on high-date-time")
|
||||||
|
}
|
||||||
|
if !driverData.IsNewer(windows.Filetime{HighDateTime: driverData.DriverDate.HighDateTime, LowDateTime: driverData.DriverDate.LowDateTime}, 0) {
|
||||||
|
t.Error("Driver should have non-zero version")
|
||||||
|
}
|
||||||
|
if driverData.IsNewer(windows.Filetime{HighDateTime: driverData.DriverDate.HighDateTime, LowDateTime: driverData.DriverDate.LowDateTime + 1}, 0) {
|
||||||
|
t.Error("Driver should report newer version on low-date-time")
|
||||||
|
}
|
||||||
|
if driverData.IsNewer(windows.Filetime{HighDateTime: driverData.DriverDate.HighDateTime, LowDateTime: driverData.DriverDate.LowDateTime}, driverData.DriverVersion) {
|
||||||
|
t.Error("Driver should not be newer than itself")
|
||||||
|
}
|
||||||
|
if driverData.IsNewer(windows.Filetime{HighDateTime: driverData.DriverDate.HighDateTime, LowDateTime: driverData.DriverDate.LowDateTime}, driverData.DriverVersion+1) {
|
||||||
|
t.Error("Driver should report newer version on version")
|
||||||
|
}
|
||||||
|
|
||||||
err = devInfoList.SetSelectedDriver(deviceData, driverData)
|
err = devInfoList.SetSelectedDriver(deviceData, driverData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error calling SetupDiSetSelectedDriver: %s", err.Error())
|
t.Errorf("Error calling SetupDiSetSelectedDriver: %s", err.Error())
|
||||||
|
@ -321,6 +321,32 @@ func (data SP_DRVINFO_DATA) ToGo() *DrvInfoData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNewer method returns true if SP_DRVINFO_DATA date and version is newer than supplied parameters.
|
||||||
|
func (data SP_DRVINFO_DATA) IsNewer(DriverDate windows.Filetime, DriverVersion uint64) bool {
|
||||||
|
if data.DriverDate.HighDateTime > DriverDate.HighDateTime {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if data.DriverDate.HighDateTime < DriverDate.HighDateTime {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.DriverDate.LowDateTime > DriverDate.LowDateTime {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if data.DriverDate.LowDateTime < DriverDate.LowDateTime {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.DriverVersion > DriverVersion {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if data.DriverVersion < DriverVersion {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// DrvInfoData is driver information structure (member of a driver info list that may be associated with a particular device instance, or (globally) with a device information set)
|
// DrvInfoData is driver information structure (member of a driver info list that may be associated with a particular device instance, or (globally) with a device information set)
|
||||||
type DrvInfoData struct {
|
type DrvInfoData struct {
|
||||||
DriverType uint32
|
DriverType uint32
|
||||||
|
Loading…
Reference in New Issue
Block a user