diff options
Diffstat (limited to 'rbutil/rbutilqt/base/system.cpp')
-rw-r--r-- | rbutil/rbutilqt/base/system.cpp | 30 |
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) | |||
432 | DWORD buffersize = 0; | 432 | DWORD buffersize = 0; |
433 | QString description; | 433 | QString description; |
434 | 434 | ||
435 | // get device desriptor first | 435 | // get device descriptor first |
436 | // for some reason not doing so results in bad things (tm) | 436 | // for some reason not doing so results in bad things (tm) |
437 | while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, | 437 | while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, |
438 | SPDRP_DEVICEDESC, &data, (PBYTE)buffer, buffersize, &buffersize)) { | 438 | SPDRP_DEVICEDESC, &data, (PBYTE)buffer, buffersize, &buffersize)) { |
@@ -445,6 +445,11 @@ QMap<uint32_t, QString> System::listUsbDevices(void) | |||
445 | break; | 445 | break; |
446 | } | 446 | } |
447 | } | 447 | } |
448 | if(!buffer) { | ||
449 | LOG_WARNING() << "Got no device description" | ||
450 | << "(SetupDiGetDeviceRegistryProperty), item" << i; | ||
451 | continue; | ||
452 | } | ||
448 | description = QString::fromWCharArray(buffer); | 453 | description = QString::fromWCharArray(buffer); |
449 | 454 | ||
450 | // now get the hardware id, which contains PID and VID. | 455 | // now get the hardware id, which contains PID and VID. |
@@ -460,18 +465,19 @@ QMap<uint32_t, QString> System::listUsbDevices(void) | |||
460 | } | 465 | } |
461 | } | 466 | } |
462 | 467 | ||
463 | unsigned int vid, pid; | 468 | if(buffer) { |
464 | // convert buffer text to upper case to avoid depending on the case of | 469 | // convert buffer text to upper case to avoid depending on the case of |
465 | // the keys (W7 uses different casing than XP at least). | 470 | // the keys (W7 uses different casing than XP at least). |
466 | int len = _tcslen(buffer); | 471 | QString data = QString::fromWCharArray(buffer); |
467 | while(len--) buffer[len] = _totupper(buffer[len]); | 472 | QRegExp rex("USB\\\\VID_([0-9a-fA-F]{4})&PID_([0-9a-fA-F]{4}).*"); |
468 | if(_stscanf(buffer, _TEXT("USB\\VID_%x&PID_%x"), &vid, &pid) == 2) { | 473 | if(rex.indexIn(data) >= 0) { |
469 | uint32_t id; | 474 | uint32_t id; |
470 | id = vid << 16 | pid; | 475 | id = rex.cap(1).toUInt(0, 16) << 16 | rex.cap(2).toUInt(0, 16); |
471 | usbids.insert(id, description); | 476 | usbids.insert(id, description); |
472 | LOG_INFO("USB VID: %04x, PID: %04x", vid, pid); | 477 | LOG_INFO() << "USB:" << QString("0x%1").arg(id, 8, 16); |
478 | } | ||
479 | free(buffer); | ||
473 | } | 480 | } |
474 | if(buffer) free(buffer); | ||
475 | } | 481 | } |
476 | SetupDiDestroyDeviceInfoList(deviceInfo); | 482 | SetupDiDestroyDeviceInfoList(deviceInfo); |
477 | 483 | ||