summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/autodetection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/autodetection.cpp')
-rw-r--r--rbutil/rbutilqt/autodetection.cpp140
1 files changed, 18 insertions, 122 deletions
diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp
index 3684d55908..f257f5c0c9 100644
--- a/rbutil/rbutilqt/autodetection.cpp
+++ b/rbutil/rbutilqt/autodetection.cpp
@@ -40,6 +40,7 @@
#include <windows.h>
#include <setupapi.h>
#endif
+#include "utils.h"
Autodetection::Autodetection(QObject* parent): QObject(parent)
{
@@ -265,132 +266,27 @@ bool Autodetection::detectUsb()
QMap<int, QString> usbincompat = settings->usbIdIncompatMap();
// usb pid detection
-#if defined(Q_OS_LINUX) | defined(Q_OS_MACX)
- usb_init();
- usb_find_busses();
- usb_find_devices();
- struct usb_bus *b;
- b = usb_get_busses();
-
- while(b) {
- qDebug() << "bus:" << b->dirname << b->devices;
- if(b->devices) {
- qDebug() << "devices present.";
- struct usb_device *u;
- u = b->devices;
- while(u) {
- uint32_t id;
- id = u->descriptor.idVendor << 16 | u->descriptor.idProduct;
- m_usbconid.append(id);
- qDebug("%x", id);
-
- if(usbids.contains(id)) {
- m_device = usbids.value(id);
- return true;
- }
- if(usberror.contains(id)) {
- m_errdev = usberror.value(id);
- // we detected something, so return true
- qDebug() << "detected device with problems via usb!";
- return true;
- }
- if(usbincompat.contains(id)) {
- m_incompat = usbincompat.value(id);
- qDebug() << "detected incompatible player variant";
- return true;
- }
- u = u->next;
- }
+ QList<uint32_t> attached;
+ attached = listUsbIds();
+
+ int i = attached.size();
+ while(i--) {
+ if(usbids.contains(attached.at(i))) {
+ m_device = usbids.value(attached.at(i));
+ qDebug() << "[USB] detected supported player" << m_device;
+ return true;
}
- b = b->next;
- }
-#endif
-
-#if defined(Q_OS_WIN32)
- HDEVINFO deviceInfo;
- SP_DEVINFO_DATA infoData;
- DWORD i;
-
- // Iterate over all devices
- // by doing it this way it's unneccessary to use GUIDs which might be not
- // present in current MinGW. It also seemed to be more reliably than using
- // a GUID.
- // See KB259695 for an example.
- deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
-
- infoData.cbSize = sizeof(SP_DEVINFO_DATA);
-
- for(i = 0; SetupDiEnumDeviceInfo(deviceInfo, i, &infoData); i++) {
- DWORD data;
- LPTSTR buffer = NULL;
- DWORD buffersize = 0;
-
- // 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;
- }
+ if(usberror.contains(attached.at(i))) {
+ m_errdev = usberror.value(attached.at(i));
+ qDebug() << "[USB] detected problem with player" << m_errdev;
+ return true;
}
-
- // now get the hardware id, which contains PID and VID.
- while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
- 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
- buffer = (LPTSTR)malloc(buffersize * 2);
- }
- else {
- break;
- }
- }
-
- unsigned int vid, pid, rev;
- if(_stscanf(buffer, _TEXT("USB\\Vid_%x&Pid_%x&Rev_%x"), &vid, &pid, &rev) != 3) {
- qDebug() << "Error getting USB ID -- possibly no USB device";
+ if(usbincompat.contains(attached.at(i))) {
+ m_incompat = usbincompat.value(attached.at(i));
+ qDebug() << "[USB] detected incompatible player" << m_incompat;
+ return true;
}
- else {
- uint32_t id;
- id = vid << 16 | pid;
- m_usbconid.append(id);
- qDebug("VID: %04x PID: %04x", vid, pid);
- if(usbids.contains(id)) {
- m_device = usbids.value(id);
- if(buffer) free(buffer);
- SetupDiDestroyDeviceInfoList(deviceInfo);
- qDebug() << "detectUsb: Got" << m_device;
- return true;
- }
- if(usberror.contains(id)) {
- m_errdev = usberror.value(id);
- // we detected something, so return true
- if(buffer) free(buffer);
- SetupDiDestroyDeviceInfoList(deviceInfo);
- qDebug() << "detectUsb: Got" << m_device;
- qDebug() << "detected device with problems via usb!";
- return true;
- }
- if(usbincompat.contains(id)) {
- m_incompat = usbincompat.value(id);
- // we detected an incompatible player variant
- if(buffer) free(buffer);
- SetupDiDestroyDeviceInfoList(deviceInfo);
- qDebug() << "detectUsb: detected incompatible variant";
- return true;
- }
- }
- if(buffer) free(buffer);
}
- SetupDiDestroyDeviceInfoList(deviceInfo);
-
-#endif
return false;
}