summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/base/system.cpp')
-rw-r--r--rbutil/rbutilqt/base/system.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/rbutil/rbutilqt/base/system.cpp b/rbutil/rbutilqt/base/system.cpp
index c36c95b9a1..855d9e3b06 100644
--- a/rbutil/rbutilqt/base/system.cpp
+++ b/rbutil/rbutilqt/base/system.cpp
@@ -432,7 +432,7 @@ QMap<uint32_t, QString> System::listUsbDevices(void)
DWORD buffersize = 0;
QString description;
- // get device desriptor first
+ // get device descriptor first
// for some reason not doing so results in bad things (tm)
while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
SPDRP_DEVICEDESC, &data, (PBYTE)buffer, buffersize, &buffersize)) {
@@ -445,6 +445,11 @@ QMap<uint32_t, QString> System::listUsbDevices(void)
break;
}
}
+ if(!buffer) {
+ LOG_WARNING() << "Got no device description"
+ << "(SetupDiGetDeviceRegistryProperty), item" << i;
+ continue;
+ }
description = QString::fromWCharArray(buffer);
// now get the hardware id, which contains PID and VID.
@@ -460,18 +465,19 @@ QMap<uint32_t, QString> System::listUsbDevices(void)
}
}
- unsigned int vid, pid;
- // convert buffer text to upper case to avoid depending on the case of
- // the keys (W7 uses different casing than XP at least).
- int len = _tcslen(buffer);
- while(len--) buffer[len] = _totupper(buffer[len]);
- if(_stscanf(buffer, _TEXT("USB\\VID_%x&PID_%x"), &vid, &pid) == 2) {
- uint32_t id;
- id = vid << 16 | pid;
- usbids.insert(id, description);
- LOG_INFO("USB VID: %04x, PID: %04x", vid, pid);
+ if(buffer) {
+ // convert buffer text to upper case to avoid depending on the case of
+ // the keys (W7 uses different casing than XP at least).
+ QString data = QString::fromWCharArray(buffer);
+ QRegExp rex("USB\\\\VID_([0-9a-fA-F]{4})&PID_([0-9a-fA-F]{4}).*");
+ if(rex.indexIn(data) >= 0) {
+ uint32_t id;
+ id = rex.cap(1).toUInt(0, 16) << 16 | rex.cap(2).toUInt(0, 16);
+ usbids.insert(id, description);
+ LOG_INFO() << "USB:" << QString("0x%1").arg(id, 8, 16);
+ }
+ free(buffer);
}
- if(buffer) free(buffer);
}
SetupDiDestroyDeviceInfoList(deviceInfo);