From 803a0edb58e46e2031358b09ac340b38f58a87b5 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 25 Jul 2010 19:25:38 +0000 Subject: Fix USB ID retrieval on Windows 7. The device string containing the USB IDs differs in casing on Windows 7 so always convert to upper case before scanning the string. Use DEVICEDESC instead of LOCATION_INFORMATION for the user visible device string as the latter doesn't show anything useful to the user on W7, at least for the devices I've tried. Unfortunately DEVICEDESC is less descriptive than the previously used. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27561 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/base/system.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/rbutil/rbutilqt/base/system.cpp b/rbutil/rbutilqt/base/system.cpp index 61a5b95cde..229becc40c 100644 --- a/rbutil/rbutilqt/base/system.cpp +++ b/rbutil/rbutilqt/base/system.cpp @@ -336,20 +336,7 @@ QMap System::listUsbDevices(void) // get device desriptor first // for some reason not doing so results in bad things (tm) while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, - SPDRP_DEVICEDESC,&data, (PBYTE)buffer, buffersize, &buffersize)) { - if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - if(buffer) free(buffer); - // double buffer size to avoid problems as per KB888609 - buffer = (LPTSTR)malloc(buffersize * 2); - } - else { - break; - } - } - - // now get the hardware id, which contains PID and VID. - while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, - SPDRP_LOCATION_INFORMATION,&data, (PBYTE)buffer, buffersize, &buffersize)) { + SPDRP_DEVICEDESC, &data, (PBYTE)buffer, buffersize, &buffersize)) { if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { if(buffer) free(buffer); // double buffer size to avoid problems as per KB888609 @@ -361,8 +348,9 @@ QMap System::listUsbDevices(void) } description = QString::fromWCharArray(buffer); + // now get the hardware id, which contains PID and VID. while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, - SPDRP_HARDWAREID,&data, (PBYTE)buffer, buffersize, &buffersize)) { + SPDRP_HARDWAREID, &data, (PBYTE)buffer, buffersize, &buffersize)) { if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { if(buffer) free(buffer); // double buffer size to avoid problems as per KB888609 @@ -374,7 +362,11 @@ QMap System::listUsbDevices(void) } unsigned int vid, pid; - if(_stscanf(buffer, _TEXT("USB\\Vid_%x&Pid_%x"), &vid, &pid) == 2) { + // 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); -- cgit v1.2.3