summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rbutil/rbutilqt/autodetection.cpp88
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro5
2 files changed, 89 insertions, 4 deletions
diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp
index 9b547bdb88..def1d12ef7 100644
--- a/rbutil/rbutilqt/autodetection.cpp
+++ b/rbutil/rbutilqt/autodetection.cpp
@@ -24,6 +24,15 @@
24#include <mntent.h> 24#include <mntent.h>
25#include <usb.h> 25#include <usb.h>
26#endif 26#endif
27#if defined(Q_OS_WIN32)
28#if defined(UNICODE)
29#define _UNICODE
30#endif
31#include <stdio.h>
32#include <tchar.h>
33#include <windows.h>
34#include <setupapi.h>
35#endif
27 36
28Autodetection::Autodetection(QObject* parent): QObject(parent) 37Autodetection::Autodetection(QObject* parent): QObject(parent)
29{ 38{
@@ -207,7 +216,7 @@ QString Autodetection::resolveMountPoint(QString device)
207 */ 216 */
208bool Autodetection::detectUsb() 217bool Autodetection::detectUsb()
209{ 218{
210 // autodetection only uses the buildin device settings only 219 // autodetection uses the buildin device settings only
211 QSettings dev(":/ini/rbutil.ini", QSettings::IniFormat, this); 220 QSettings dev(":/ini/rbutil.ini", QSettings::IniFormat, this);
212 221
213 // get a list of ID -> target name 222 // get a list of ID -> target name
@@ -269,5 +278,82 @@ bool Autodetection::detectUsb()
269 b = b->next; 278 b = b->next;
270 } 279 }
271#endif 280#endif
281
282#if defined(Q_OS_WIN32)
283 HDEVINFO deviceInfo;
284 SP_DEVINFO_DATA infoData;
285 DWORD i;
286
287 // Iterate over all devices
288 // by doing it this way it's unneccessary to use GUIDs which might be not
289 // present in current MinGW. It also seemed to be more reliably than using
290 // a GUID.
291 // See KB259695 for an example.
292 deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
293
294 infoData.cbSize = sizeof(SP_DEVINFO_DATA);
295
296 for(i = 0; SetupDiEnumDeviceInfo(deviceInfo, i, &infoData); i++) {
297 DWORD data;
298 LPTSTR buffer = NULL;
299 DWORD buffersize = 0;
300
301 // get device desriptor first
302 // for some reason not doing so results in bad things (tm)
303 while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
304 SPDRP_DEVICEDESC,&data, (PBYTE)buffer, buffersize, &buffersize)) {
305 if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
306 if(buffer) free(buffer);
307 // double buffer size to avoid problems as per KB888609
308 buffer = (LPTSTR)malloc(buffersize * 2);
309 }
310 else {
311 break;
312 }
313 }
314
315 // now get the hardware id, which contains PID and VID.
316 while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
317 SPDRP_HARDWAREID,&data, (PBYTE)buffer, buffersize, &buffersize)) {
318 if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
319 if(buffer) free(buffer);
320 // double buffer size to avoid problems as per KB888609
321 buffer = (LPTSTR)malloc(buffersize * 2);
322 }
323 else {
324 break;
325 }
326 }
327
328 unsigned int vid, pid, rev;
329 if(_stscanf(buffer, _TEXT("USB\\Vid_%x&Pid_%x&Rev_%x"), &vid, &pid, &rev) != 3) {
330 qDebug() << "Error getting USB ID -- possibly no USB device";
331 }
332 else {
333 uint32_t id;
334 id = vid << 16 | pid;
335 qDebug("VID: %04x PID: %04x", vid, pid);
336 if(usbids.contains(id)) {
337 m_device = usbids.value(id);
338 if(buffer) free(buffer);
339 SetupDiDestroyDeviceInfoList(deviceInfo);
340 qDebug() << "detectUsb: Got" << m_device;
341 return true;
342 }
343 if(usberror.contains(id)) {
344 m_errdev = usberror.value(id);
345 // we detected something, so return true
346 if(buffer) free(buffer);
347 SetupDiDestroyDeviceInfoList(deviceInfo);
348 qDebug() << "detectUsb: Got" << m_device;
349 qDebug() << "detected device with problems via usb!";
350 return true;
351 }
352 }
353 if(buffer) free(buffer);
354 }
355 SetupDiDestroyDeviceInfoList(deviceInfo);
356
357#endif
272 return false; 358 return false;
273} 359}
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro
index 947ffe5ce9..a4cbb886e5 100644
--- a/rbutil/rbutilqt/rbutilqt.pro
+++ b/rbutil/rbutilqt/rbutilqt.pro
@@ -115,20 +115,19 @@ win32 {
115 SOURCES += ../ipodpatcher/ipodio-win32.c 115 SOURCES += ../ipodpatcher/ipodio-win32.c
116 SOURCES += ../sansapatcher/sansaio-win32.c 116 SOURCES += ../sansapatcher/sansaio-win32.c
117 RC_FILE = rbutilqt.rc 117 RC_FILE = rbutilqt.rc
118 LIBS += -lsetupapi
118} 119}
119 120
120unix { 121unix {
121 SOURCES += ../ipodpatcher/ipodio-posix.c 122 SOURCES += ../ipodpatcher/ipodio-posix.c
122 SOURCES += ../sansapatcher/sansaio-posix.c 123 SOURCES += ../sansapatcher/sansaio-posix.c
124 LIBS += -lusb
123} 125}
124 126
125macx { 127macx {
126 QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk 128 QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk
127 CONFIG+=x86 ppc 129 CONFIG+=x86 ppc
128} 130}
129unix {
130 LIBS += -lusb
131}
132 131
133static { 132static {
134 QTPLUGIN += qtaccessiblewidgets 133 QTPLUGIN += qtaccessiblewidgets