diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2010-07-25 19:25:38 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2010-07-25 19:25:38 +0000 |
commit | 803a0edb58e46e2031358b09ac340b38f58a87b5 (patch) | |
tree | 9154c8be0aaf7b50f9e1ad3e64c8e8bb9925f4bb | |
parent | d904597524f0dfeee537149f11c4472dc5f4d36e (diff) |
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
-rw-r--r-- | rbutil/rbutilqt/base/system.cpp | 24 |
1 files 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<uint32_t, QString> 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<uint32_t, QString> 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<uint32_t, QString> 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); |