setupapi: Merge SP_DRVINFO_DATA and DrvInfoData
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
0525f6b112
commit
b662896cf4
|
@ -109,47 +109,47 @@ func (deviceInfoSet DevInfo) CancelDriverInfoSearch() error {
|
|||
return SetupDiCancelDriverInfoSearch(deviceInfoSet)
|
||||
}
|
||||
|
||||
//sys setupDiEnumDriverInfo(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverType SPDIT, memberIndex uint32, driverInfoData *SP_DRVINFO_DATA) (err error) = setupapi.SetupDiEnumDriverInfoW
|
||||
//sys setupDiEnumDriverInfo(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverType SPDIT, memberIndex uint32, driverInfoData *DrvInfoData) (err error) = setupapi.SetupDiEnumDriverInfoW
|
||||
|
||||
// SetupDiEnumDriverInfo function enumerates the members of a driver list.
|
||||
func SetupDiEnumDriverInfo(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverType SPDIT, memberIndex int) (*SP_DRVINFO_DATA, error) {
|
||||
data := &SP_DRVINFO_DATA{}
|
||||
data.Size = uint32(unsafe.Sizeof(*data))
|
||||
func SetupDiEnumDriverInfo(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverType SPDIT, memberIndex int) (*DrvInfoData, error) {
|
||||
data := &DrvInfoData{}
|
||||
data.size = uint32(unsafe.Sizeof(*data))
|
||||
|
||||
return data, setupDiEnumDriverInfo(deviceInfoSet, deviceInfoData, driverType, uint32(memberIndex), data)
|
||||
}
|
||||
|
||||
// EnumDriverInfo method enumerates the members of a driver list.
|
||||
func (deviceInfoSet DevInfo) EnumDriverInfo(deviceInfoData *DevInfoData, driverType SPDIT, memberIndex int) (*SP_DRVINFO_DATA, error) {
|
||||
func (deviceInfoSet DevInfo) EnumDriverInfo(deviceInfoData *DevInfoData, driverType SPDIT, memberIndex int) (*DrvInfoData, error) {
|
||||
return SetupDiEnumDriverInfo(deviceInfoSet, deviceInfoData, driverType, memberIndex)
|
||||
}
|
||||
|
||||
//sys setupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *SP_DRVINFO_DATA) (err error) = setupapi.SetupDiGetSelectedDriverW
|
||||
//sys setupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (err error) = setupapi.SetupDiGetSelectedDriverW
|
||||
|
||||
// SetupDiGetSelectedDriver function retrieves the selected driver for a device information set or a particular device information element.
|
||||
func SetupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData) (*SP_DRVINFO_DATA, error) {
|
||||
data := &SP_DRVINFO_DATA{}
|
||||
data.Size = uint32(unsafe.Sizeof(*data))
|
||||
func SetupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData) (*DrvInfoData, error) {
|
||||
data := &DrvInfoData{}
|
||||
data.size = uint32(unsafe.Sizeof(*data))
|
||||
|
||||
return data, setupDiGetSelectedDriver(deviceInfoSet, deviceInfoData, data)
|
||||
}
|
||||
|
||||
// GetSelectedDriver method retrieves the selected driver for a device information set or a particular device information element.
|
||||
func (deviceInfoSet DevInfo) GetSelectedDriver(deviceInfoData *DevInfoData) (*SP_DRVINFO_DATA, error) {
|
||||
func (deviceInfoSet DevInfo) GetSelectedDriver(deviceInfoData *DevInfoData) (*DrvInfoData, error) {
|
||||
return SetupDiGetSelectedDriver(deviceInfoSet, deviceInfoData)
|
||||
}
|
||||
|
||||
//sys SetupDiSetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *SP_DRVINFO_DATA) (err error) = setupapi.SetupDiSetSelectedDriverW
|
||||
//sys SetupDiSetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (err error) = setupapi.SetupDiSetSelectedDriverW
|
||||
|
||||
// SetSelectedDriver method sets, or resets, the selected driver for a device information element or the selected class driver for a device information set.
|
||||
func (deviceInfoSet DevInfo) SetSelectedDriver(deviceInfoData *DevInfoData, driverInfoData *SP_DRVINFO_DATA) error {
|
||||
func (deviceInfoSet DevInfo) SetSelectedDriver(deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) error {
|
||||
return SetupDiSetSelectedDriver(deviceInfoSet, deviceInfoData, driverInfoData)
|
||||
}
|
||||
|
||||
//sys setupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *SP_DRVINFO_DATA, driverInfoDetailData *_SP_DRVINFO_DETAIL_DATA, driverInfoDetailDataSize uint32, requiredSize *uint32) (err error) = setupapi.SetupDiGetDriverInfoDetailW
|
||||
//sys setupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData, driverInfoDetailData *_SP_DRVINFO_DETAIL_DATA, driverInfoDetailDataSize uint32, requiredSize *uint32) (err error) = setupapi.SetupDiGetDriverInfoDetailW
|
||||
|
||||
// SetupDiGetDriverInfoDetail function retrieves driver information detail for a device information set or a particular device information element in the device information set.
|
||||
func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *SP_DRVINFO_DATA) (driverInfoDetailData *DrvInfoDetailData, err error) {
|
||||
func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (driverInfoDetailData *DrvInfoDetailData, err error) {
|
||||
const bufCapacity = 0x800
|
||||
buf := [bufCapacity]byte{}
|
||||
var bufLen uint32
|
||||
|
@ -179,7 +179,7 @@ func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa
|
|||
}
|
||||
|
||||
// GetDriverInfoDetail method retrieves driver information detail for a device information set or a particular device information element in the device information set.
|
||||
func (deviceInfoSet DevInfo) GetDriverInfoDetail(deviceInfoData *DevInfoData, driverInfoData *SP_DRVINFO_DATA) (*DrvInfoDetailData, error) {
|
||||
func (deviceInfoSet DevInfo) GetDriverInfoDetail(deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (*DrvInfoDetailData, error) {
|
||||
return SetupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData)
|
||||
}
|
||||
|
||||
|
|
|
@ -166,7 +166,7 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
|
|||
}
|
||||
defer devInfoList.DestroyDriverInfoList(deviceData, driverType)
|
||||
|
||||
var selectedDriverData *SP_DRVINFO_DATA
|
||||
var selectedDriverData *DrvInfoData
|
||||
for j := 0; true; j++ {
|
||||
driverData, err := devInfoList.EnumDriverInfo(deviceData, driverType, j)
|
||||
if err != nil {
|
||||
|
@ -176,10 +176,6 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
|
||||
if driverData2, err2 := driverData.toGo().toWindows(); err2 != nil || *driverData2 != *driverData {
|
||||
t.Error("Error converting between SP_DRVINFO_DATA and DrvInfoData")
|
||||
}
|
||||
|
||||
if driverData.DriverType == 0 {
|
||||
continue
|
||||
}
|
||||
|
@ -238,6 +234,20 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
|
|||
t.Error("SetupDiGetSelectedDriver should return driver selected with SetupDiSetSelectedDriver")
|
||||
}
|
||||
}
|
||||
|
||||
data := &DrvInfoData{}
|
||||
data.SetDescription("foobar")
|
||||
if data.GetDescription() != "foobar" {
|
||||
t.Error("DrvInfoData.(Get|Set)Description() differ")
|
||||
}
|
||||
data.SetMfgName("foobar")
|
||||
if data.GetMfgName() != "foobar" {
|
||||
t.Error("DrvInfoData.(Get|Set)MfgName() differ")
|
||||
}
|
||||
data.SetProviderName("foobar")
|
||||
if data.GetProviderName() != "foobar" {
|
||||
t.Error("DrvInfoData.(Get|Set)ProviderName() differ")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupDiGetClassDevsEx(t *testing.T) {
|
||||
|
|
|
@ -291,30 +291,59 @@ type RemoveDeviceParams struct {
|
|||
HwProfile uint32
|
||||
}
|
||||
|
||||
type SP_DRVINFO_DATA struct {
|
||||
Size uint32
|
||||
// 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 {
|
||||
size uint32
|
||||
DriverType uint32
|
||||
_ uintptr
|
||||
Description [LINE_LEN]uint16
|
||||
MfgName [LINE_LEN]uint16
|
||||
ProviderName [LINE_LEN]uint16
|
||||
description [LINE_LEN]uint16
|
||||
mfgName [LINE_LEN]uint16
|
||||
providerName [LINE_LEN]uint16
|
||||
DriverDate windows.Filetime
|
||||
DriverVersion uint64
|
||||
}
|
||||
|
||||
func (data *SP_DRVINFO_DATA) toGo() *DrvInfoData {
|
||||
return &DrvInfoData{
|
||||
DriverType: data.DriverType,
|
||||
Description: windows.UTF16ToString(data.Description[:]),
|
||||
MfgName: windows.UTF16ToString(data.MfgName[:]),
|
||||
ProviderName: windows.UTF16ToString(data.ProviderName[:]),
|
||||
DriverDate: data.DriverDate,
|
||||
DriverVersion: data.DriverVersion,
|
||||
}
|
||||
func (data *DrvInfoData) GetDescription() string {
|
||||
return windows.UTF16ToString(data.description[:])
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (data *DrvInfoData) SetDescription(description string) error {
|
||||
str, err := syscall.UTF16FromString(description)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copy(data.description[:], str)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (data *DrvInfoData) GetMfgName() string {
|
||||
return windows.UTF16ToString(data.mfgName[:])
|
||||
}
|
||||
|
||||
func (data *DrvInfoData) SetMfgName(mfgName string) error {
|
||||
str, err := syscall.UTF16FromString(mfgName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copy(data.mfgName[:], str)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (data *DrvInfoData) GetProviderName() string {
|
||||
return windows.UTF16ToString(data.providerName[:])
|
||||
}
|
||||
|
||||
func (data *DrvInfoData) SetProviderName(providerName string) error {
|
||||
str, err := syscall.UTF16FromString(providerName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copy(data.providerName[:], str)
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsNewer method returns true if DrvInfoData date and version is newer than supplied parameters.
|
||||
func (data *DrvInfoData) IsNewer(driverDate windows.Filetime, driverVersion uint64) bool {
|
||||
if data.DriverDate.HighDateTime > driverDate.HighDateTime {
|
||||
return true
|
||||
}
|
||||
|
@ -339,45 +368,6 @@ func (data *SP_DRVINFO_DATA) IsNewer(driverDate windows.Filetime, driverVersion
|
|||
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)
|
||||
type DrvInfoData struct {
|
||||
DriverType uint32
|
||||
Description string
|
||||
MfgName string
|
||||
ProviderName string
|
||||
DriverDate windows.Filetime
|
||||
DriverVersion uint64
|
||||
}
|
||||
|
||||
func (driverInfoData *DrvInfoData) toWindows() (data *SP_DRVINFO_DATA, err error) {
|
||||
data = &SP_DRVINFO_DATA{
|
||||
DriverType: driverInfoData.DriverType,
|
||||
DriverDate: driverInfoData.DriverDate,
|
||||
DriverVersion: driverInfoData.DriverVersion,
|
||||
}
|
||||
data.Size = uint32(unsafe.Sizeof(*data))
|
||||
|
||||
DescriptionUTF16, err := syscall.UTF16FromString(driverInfoData.Description)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
copy(data.Description[:], DescriptionUTF16)
|
||||
|
||||
MfgNameUTF16, err := syscall.UTF16FromString(driverInfoData.MfgName)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
copy(data.MfgName[:], MfgNameUTF16)
|
||||
|
||||
ProviderNameUTF16, err := syscall.UTF16FromString(driverInfoData.ProviderName)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
copy(data.ProviderName[:], ProviderNameUTF16)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type _SP_DRVINFO_DETAIL_DATA struct {
|
||||
Size uint32
|
||||
InfDate windows.Filetime
|
||||
|
|
|
@ -151,7 +151,7 @@ func SetupDiCancelDriverInfoSearch(deviceInfoSet DevInfo) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func setupDiEnumDriverInfo(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverType SPDIT, memberIndex uint32, driverInfoData *SP_DRVINFO_DATA) (err error) {
|
||||
func setupDiEnumDriverInfo(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverType SPDIT, memberIndex uint32, driverInfoData *DrvInfoData) (err error) {
|
||||
r1, _, e1 := syscall.Syscall6(procSetupDiEnumDriverInfoW.Addr(), 5, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(driverType), uintptr(memberIndex), uintptr(unsafe.Pointer(driverInfoData)), 0)
|
||||
if r1 == 0 {
|
||||
if e1 != 0 {
|
||||
|
@ -163,7 +163,7 @@ func setupDiEnumDriverInfo(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, d
|
|||
return
|
||||
}
|
||||
|
||||
func setupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *SP_DRVINFO_DATA) (err error) {
|
||||
func setupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (err error) {
|
||||
r1, _, e1 := syscall.Syscall(procSetupDiGetSelectedDriverW.Addr(), 3, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(driverInfoData)))
|
||||
if r1 == 0 {
|
||||
if e1 != 0 {
|
||||
|
@ -175,7 +175,7 @@ func setupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData
|
|||
return
|
||||
}
|
||||
|
||||
func SetupDiSetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *SP_DRVINFO_DATA) (err error) {
|
||||
func SetupDiSetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (err error) {
|
||||
r1, _, e1 := syscall.Syscall(procSetupDiSetSelectedDriverW.Addr(), 3, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(driverInfoData)))
|
||||
if r1 == 0 {
|
||||
if e1 != 0 {
|
||||
|
@ -187,7 +187,7 @@ func SetupDiSetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData
|
|||
return
|
||||
}
|
||||
|
||||
func setupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *SP_DRVINFO_DATA, driverInfoDetailData *_SP_DRVINFO_DETAIL_DATA, driverInfoDetailDataSize uint32, requiredSize *uint32) (err error) {
|
||||
func setupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData, driverInfoDetailData *_SP_DRVINFO_DETAIL_DATA, driverInfoDetailDataSize uint32, requiredSize *uint32) (err error) {
|
||||
r1, _, e1 := syscall.Syscall6(procSetupDiGetDriverInfoDetailW.Addr(), 6, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(driverInfoData)), uintptr(unsafe.Pointer(driverInfoDetailData)), uintptr(driverInfoDetailDataSize), uintptr(unsafe.Pointer(requiredSize)))
|
||||
if r1 == 0 {
|
||||
if e1 != 0 {
|
||||
|
|
Loading…
Reference in a new issue