summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/detect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/detect.cpp')
-rw-r--r--rbutil/rbutilqt/detect.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/rbutil/rbutilqt/detect.cpp b/rbutil/rbutilqt/detect.cpp
index 16ab856ebc..18f4d23ba5 100644
--- a/rbutil/rbutilqt/detect.cpp
+++ b/rbutil/rbutilqt/detect.cpp
@@ -172,12 +172,17 @@ QString Detect::osVersionString(void)
172 return result; 172 return result;
173} 173}
174 174
175QList<uint32_t> Detect::listUsbIds(void)
176{
177 return listUsbDevices().keys();
178}
179
175/** @brief detect devices based on usb pid / vid. 180/** @brief detect devices based on usb pid / vid.
176 * @return list with usb VID / PID values. 181 * @return list with usb VID / PID values.
177 */ 182 */
178QList<uint32_t> Detect::listUsbIds(void) 183QMap<uint32_t, QString> Detect::listUsbDevices(void)
179{ 184{
180 QList<uint32_t> usbids; 185 QMap<uint32_t, QString> usbids;
181 // usb pid detection 186 // usb pid detection
182#if defined(Q_OS_LINUX) | defined(Q_OS_MACX) 187#if defined(Q_OS_LINUX) | defined(Q_OS_MACX)
183 usb_init(); 188 usb_init();
@@ -195,7 +200,8 @@ QList<uint32_t> Detect::listUsbIds(void)
195 while(u) { 200 while(u) {
196 uint32_t id; 201 uint32_t id;
197 id = u->descriptor.idVendor << 16 | u->descriptor.idProduct; 202 id = u->descriptor.idVendor << 16 | u->descriptor.idProduct;
198 if(id) usbids.append(id); 203 // FIXME: until description is empty for now.
204 if(id) usbids.insert(id, QString(""));
199 u = u->next; 205 u = u->next;
200 } 206 }
201 } 207 }
@@ -221,6 +227,7 @@ QList<uint32_t> Detect::listUsbIds(void)
221 DWORD data; 227 DWORD data;
222 LPTSTR buffer = NULL; 228 LPTSTR buffer = NULL;
223 DWORD buffersize = 0; 229 DWORD buffersize = 0;
230 QString description;
224 231
225 // get device desriptor first 232 // get device desriptor first
226 // for some reason not doing so results in bad things (tm) 233 // for some reason not doing so results in bad things (tm)
@@ -238,6 +245,19 @@ QList<uint32_t> Detect::listUsbIds(void)
238 245
239 // now get the hardware id, which contains PID and VID. 246 // now get the hardware id, which contains PID and VID.
240 while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, 247 while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
248 SPDRP_LOCATION_INFORMATION,&data, (PBYTE)buffer, buffersize, &buffersize)) {
249 if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
250 if(buffer) free(buffer);
251 // double buffer size to avoid problems as per KB888609
252 buffer = (LPTSTR)malloc(buffersize * 2);
253 }
254 else {
255 break;
256 }
257 }
258 description = QString::fromWCharArray(buffer);
259
260 while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
241 SPDRP_HARDWAREID,&data, (PBYTE)buffer, buffersize, &buffersize)) { 261 SPDRP_HARDWAREID,&data, (PBYTE)buffer, buffersize, &buffersize)) {
242 if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { 262 if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
243 if(buffer) free(buffer); 263 if(buffer) free(buffer);
@@ -248,6 +268,7 @@ QList<uint32_t> Detect::listUsbIds(void)
248 break; 268 break;
249 } 269 }
250 } 270 }
271 qDebug() << "SetupDiGetDeviceRegistryProperty" << description << QString::fromWCharArray(buffer);
251 272
252 unsigned int vid, pid, rev; 273 unsigned int vid, pid, rev;
253 if(_stscanf(buffer, _TEXT("USB\\Vid_%x&Pid_%x&Rev_%x"), &vid, &pid, &rev) != 3) { 274 if(_stscanf(buffer, _TEXT("USB\\Vid_%x&Pid_%x&Rev_%x"), &vid, &pid, &rev) != 3) {
@@ -256,7 +277,7 @@ QList<uint32_t> Detect::listUsbIds(void)
256 else { 277 else {
257 uint32_t id; 278 uint32_t id;
258 id = vid << 16 | pid; 279 id = vid << 16 | pid;
259 usbids.append(id); 280 usbids.insert(id, description);
260 qDebug("VID: %04x PID: %04x", vid, pid); 281 qDebug("VID: %04x PID: %04x", vid, pid);
261 } 282 }
262 if(buffer) free(buffer); 283 if(buffer) free(buffer);