2008-06-27 22:48:25 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Wenger
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
2009-08-10 19:46:51 +00:00
|
|
|
#include "system.h"
|
2008-06-27 22:48:25 +00:00
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QDebug>
|
2008-10-24 22:31:07 +00:00
|
|
|
|
2008-06-27 22:48:25 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
// Windows Includes
|
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
#if defined(UNICODE)
|
|
|
|
#define _UNICODE
|
|
|
|
#endif
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <lm.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <setupapi.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Linux and Mac includes
|
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
2009-08-08 12:28:47 +00:00
|
|
|
#if defined(LIBUSB1)
|
|
|
|
#include <libusb-1.0/libusb.h>
|
|
|
|
#else
|
2008-06-27 22:48:25 +00:00
|
|
|
#include <usb.h>
|
2009-08-08 12:28:47 +00:00
|
|
|
#endif
|
2008-06-27 22:48:25 +00:00
|
|
|
#include <sys/utsname.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Linux includes
|
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
#include <mntent.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Mac includes
|
|
|
|
#if defined(Q_OS_MACX)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ucred.h>
|
|
|
|
#include <sys/mount.h>
|
2010-04-02 19:22:32 +00:00
|
|
|
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
#include <SystemConfiguration/SystemConfiguration.h>
|
2010-04-02 21:32:51 +00:00
|
|
|
#include <CoreServices/CoreServices.h>
|
2010-09-05 18:19:23 +00:00
|
|
|
#include <IOKit/IOKitLib.h>
|
|
|
|
#include <IOKit/usb/IOUSBLib.h>
|
2008-06-27 22:48:25 +00:00
|
|
|
#endif
|
|
|
|
|
2009-03-21 16:30:40 +00:00
|
|
|
#include "utils.h"
|
2009-05-09 16:59:14 +00:00
|
|
|
#include "rbsettings.h"
|
2008-06-27 22:48:25 +00:00
|
|
|
|
|
|
|
/** @brief detect permission of user (only Windows at moment).
|
|
|
|
* @return enum userlevel.
|
|
|
|
*/
|
|
|
|
#if defined(Q_OS_WIN32)
|
2009-08-10 19:46:51 +00:00
|
|
|
enum System::userlevel System::userPermissions(void)
|
2008-06-27 22:48:25 +00:00
|
|
|
{
|
2012-01-17 21:03:11 +00:00
|
|
|
LPUSER_INFO_1 buf = NULL;
|
2008-06-27 22:48:25 +00:00
|
|
|
wchar_t userbuf[UNLEN];
|
|
|
|
DWORD usersize = UNLEN;
|
|
|
|
BOOL status;
|
2012-01-17 21:03:11 +00:00
|
|
|
enum userlevel result = ERR;
|
2008-10-24 22:31:07 +00:00
|
|
|
|
2008-06-27 22:48:25 +00:00
|
|
|
status = GetUserNameW(userbuf, &usersize);
|
|
|
|
if(!status)
|
|
|
|
return ERR;
|
2008-10-24 22:31:07 +00:00
|
|
|
|
2012-01-17 21:03:11 +00:00
|
|
|
if(NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf) == NERR_Success) {
|
|
|
|
switch(buf->usri1_priv) {
|
|
|
|
case USER_PRIV_GUEST:
|
|
|
|
result = GUEST;
|
|
|
|
break;
|
|
|
|
case USER_PRIV_USER:
|
|
|
|
result = USER;
|
|
|
|
break;
|
|
|
|
case USER_PRIV_ADMIN:
|
|
|
|
result = ADMIN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = ERR;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-27 22:48:25 +00:00
|
|
|
}
|
2012-01-17 21:03:11 +00:00
|
|
|
if(buf != NULL)
|
|
|
|
NetApiBufferFree(buf);
|
2008-06-27 22:48:25 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief detects user permissions (only Windows at moment).
|
|
|
|
* @return a user readable string with the permission.
|
|
|
|
*/
|
2009-08-10 19:46:51 +00:00
|
|
|
QString System::userPermissionsString(void)
|
2008-06-27 22:48:25 +00:00
|
|
|
{
|
|
|
|
QString result;
|
2008-06-27 23:19:59 +00:00
|
|
|
int perm = userPermissions();
|
2008-06-27 22:48:25 +00:00
|
|
|
switch(perm) {
|
|
|
|
case GUEST:
|
2010-06-18 19:04:06 +00:00
|
|
|
result = tr("Guest");
|
2008-06-27 22:48:25 +00:00
|
|
|
break;
|
|
|
|
case ADMIN:
|
2010-06-18 19:04:06 +00:00
|
|
|
result = tr("Admin");
|
2008-06-27 22:48:25 +00:00
|
|
|
break;
|
|
|
|
case USER:
|
2010-06-18 19:04:06 +00:00
|
|
|
result = tr("User");
|
2008-06-27 22:48:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-06-18 19:04:06 +00:00
|
|
|
result = tr("Error");
|
2008-06-27 22:48:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
2008-10-24 22:31:07 +00:00
|
|
|
|
2008-06-27 22:48:25 +00:00
|
|
|
|
|
|
|
/** @brief detects current Username.
|
|
|
|
* @return string with Username.
|
|
|
|
*/
|
2009-08-10 19:46:51 +00:00
|
|
|
QString System::userName(void)
|
2008-06-27 22:48:25 +00:00
|
|
|
{
|
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
wchar_t userbuf[UNLEN];
|
|
|
|
DWORD usersize = UNLEN;
|
2008-10-24 22:31:07 +00:00
|
|
|
|
2012-01-17 21:03:11 +00:00
|
|
|
if(GetUserNameW(userbuf, &usersize) == 0)
|
|
|
|
return QString();
|
2008-06-27 22:48:25 +00:00
|
|
|
|
|
|
|
return QString::fromWCharArray(userbuf);
|
|
|
|
#endif
|
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
|
|
|
struct passwd *user;
|
|
|
|
user = getpwuid(geteuid());
|
|
|
|
return QString(user->pw_name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief detects the OS Version
|
|
|
|
* @return String with OS Version.
|
|
|
|
*/
|
2009-08-10 19:46:51 +00:00
|
|
|
QString System::osVersionString(void)
|
2008-06-27 22:48:25 +00:00
|
|
|
{
|
|
|
|
QString result;
|
|
|
|
#if defined(Q_OS_WIN32)
|
2010-09-18 20:41:03 +00:00
|
|
|
SYSTEM_INFO sysinfo;
|
2008-06-27 22:48:25 +00:00
|
|
|
OSVERSIONINFO osvi;
|
|
|
|
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
GetVersionEx(&osvi);
|
2010-09-18 20:50:11 +00:00
|
|
|
GetSystemInfo(&sysinfo);
|
2008-06-27 22:48:25 +00:00
|
|
|
|
|
|
|
result = QString("Windows version %1.%2, ").arg(osvi.dwMajorVersion).arg(osvi.dwMinorVersion);
|
2008-07-04 20:26:36 +00:00
|
|
|
if(osvi.szCSDVersion)
|
|
|
|
result += QString("build %1 (%2)").arg(osvi.dwBuildNumber)
|
|
|
|
.arg(QString::fromWCharArray(osvi.szCSDVersion));
|
|
|
|
else
|
|
|
|
result += QString("build %1").arg(osvi.dwBuildNumber);
|
2010-09-18 20:41:03 +00:00
|
|
|
result += QString("<br/>CPU: %1, %2 processor(s)").arg(sysinfo.dwProcessorType)
|
|
|
|
.arg(sysinfo.dwNumberOfProcessors);
|
2008-06-27 22:48:25 +00:00
|
|
|
#endif
|
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
|
|
|
struct utsname u;
|
|
|
|
int ret;
|
|
|
|
ret = uname(&u);
|
|
|
|
|
2010-09-18 20:41:03 +00:00
|
|
|
#if defined(Q_OS_MACX)
|
|
|
|
ItemCount cores = MPProcessors();
|
|
|
|
#else
|
|
|
|
long cores = sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
|
#endif
|
2011-05-29 19:46:20 +00:00
|
|
|
if(ret != -1) {
|
|
|
|
result = QString("CPU: %1, %2 processor(s)").arg(u.machine).arg(cores);
|
|
|
|
result += QString("<br/>System: %2<br/>Release: %3<br/>Version: %4")
|
|
|
|
.arg(u.sysname).arg(u.release).arg(u.version);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = QString("(Error when retrieving system information)");
|
|
|
|
}
|
2010-04-02 21:32:51 +00:00
|
|
|
#if defined(Q_OS_MACX)
|
|
|
|
SInt32 major;
|
|
|
|
SInt32 minor;
|
|
|
|
SInt32 bugfix;
|
|
|
|
OSErr error;
|
|
|
|
error = Gestalt(gestaltSystemVersionMajor, &major);
|
|
|
|
error = Gestalt(gestaltSystemVersionMinor, &minor);
|
|
|
|
error = Gestalt(gestaltSystemVersionBugFix, &bugfix);
|
|
|
|
|
|
|
|
result += QString("<br/>OS X %1.%2.%3 ").arg(major).arg(minor).arg(bugfix);
|
|
|
|
// 1: 86k, 2: ppc, 10: i386
|
|
|
|
SInt32 arch;
|
|
|
|
error = Gestalt(gestaltSysArchitecture, &arch);
|
|
|
|
switch(arch) {
|
|
|
|
case 1:
|
|
|
|
result.append("(86k)");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
result.append("(ppc)");
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
result.append("(x86)");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result.append("(unknown)");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2008-06-27 22:48:25 +00:00
|
|
|
#endif
|
2009-06-05 21:49:53 +00:00
|
|
|
result += QString("<br/>Qt version %1").arg(qVersion());
|
2008-06-27 22:48:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-08-10 19:46:51 +00:00
|
|
|
QList<uint32_t> System::listUsbIds(void)
|
2008-06-28 18:06:55 +00:00
|
|
|
{
|
|
|
|
return listUsbDevices().keys();
|
|
|
|
}
|
|
|
|
|
2008-06-27 22:48:25 +00:00
|
|
|
/** @brief detect devices based on usb pid / vid.
|
|
|
|
* @return list with usb VID / PID values.
|
|
|
|
*/
|
2009-08-10 19:46:51 +00:00
|
|
|
QMap<uint32_t, QString> System::listUsbDevices(void)
|
2008-06-27 22:48:25 +00:00
|
|
|
{
|
2008-06-28 18:06:55 +00:00
|
|
|
QMap<uint32_t, QString> usbids;
|
2008-06-27 22:48:25 +00:00
|
|
|
// usb pid detection
|
2009-08-10 19:46:51 +00:00
|
|
|
qDebug() << "[System] Searching for USB devices";
|
2010-09-05 18:19:23 +00:00
|
|
|
#if defined(Q_OS_LINUX)
|
2009-08-08 12:28:47 +00:00
|
|
|
#if defined(LIBUSB1)
|
|
|
|
libusb_device **devs;
|
2012-01-17 21:03:11 +00:00
|
|
|
if(libusb_init(NULL) != 0) {
|
|
|
|
qDebug() << "[System] Initializing libusb-1 failed.";
|
|
|
|
return usbids;
|
|
|
|
}
|
2009-08-08 12:28:47 +00:00
|
|
|
|
2012-01-17 21:03:11 +00:00
|
|
|
if(libusb_get_device_list(NULL, &devs) < 1) {
|
|
|
|
qDebug() << "[System] Error getting device list.";
|
|
|
|
return usbids;
|
|
|
|
}
|
2009-08-08 12:28:47 +00:00
|
|
|
libusb_device *dev;
|
|
|
|
int i = 0;
|
|
|
|
while((dev = devs[i++]) != NULL) {
|
|
|
|
QString name;
|
|
|
|
unsigned char buf[256];
|
|
|
|
uint32_t id;
|
|
|
|
struct libusb_device_descriptor descriptor;
|
|
|
|
if(libusb_get_device_descriptor(dev, &descriptor) == 0) {
|
|
|
|
id = descriptor.idVendor << 16 | descriptor.idProduct;
|
|
|
|
|
|
|
|
libusb_device_handle *dh;
|
|
|
|
if(libusb_open(dev, &dh) == 0) {
|
|
|
|
libusb_get_string_descriptor_ascii(dh, descriptor.iManufacturer, buf, 256);
|
|
|
|
name += QString::fromAscii((char*)buf) + " ";
|
|
|
|
libusb_get_string_descriptor_ascii(dh, descriptor.iProduct, buf, 256);
|
|
|
|
name += QString::fromAscii((char*)buf);
|
|
|
|
libusb_close(dh);
|
|
|
|
}
|
|
|
|
if(name.isEmpty())
|
2010-06-18 19:04:06 +00:00
|
|
|
name = tr("(no description available)");
|
2009-08-08 12:28:47 +00:00
|
|
|
if(id) {
|
|
|
|
usbids.insert(id, name);
|
2009-08-10 19:46:51 +00:00
|
|
|
qDebug("[System] USB: 0x%08x, %s", id, name.toLocal8Bit().data());
|
2009-08-08 12:28:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
libusb_free_device_list(devs, 1);
|
|
|
|
libusb_exit(NULL);
|
|
|
|
#else
|
2008-06-27 22:48:25 +00:00
|
|
|
usb_init();
|
|
|
|
usb_find_busses();
|
|
|
|
usb_find_devices();
|
|
|
|
struct usb_bus *b;
|
|
|
|
b = usb_busses;
|
|
|
|
|
|
|
|
while(b) {
|
|
|
|
if(b->devices) {
|
|
|
|
struct usb_device *u;
|
|
|
|
u = b->devices;
|
|
|
|
while(u) {
|
|
|
|
uint32_t id;
|
|
|
|
id = u->descriptor.idVendor << 16 | u->descriptor.idProduct;
|
2008-07-02 17:48:50 +00:00
|
|
|
// get identification strings
|
|
|
|
usb_dev_handle *dev;
|
|
|
|
QString name;
|
|
|
|
char string[256];
|
|
|
|
int res;
|
|
|
|
dev = usb_open(u);
|
|
|
|
if(dev) {
|
|
|
|
if(u->descriptor.iManufacturer) {
|
2009-08-08 12:12:49 +00:00
|
|
|
res = usb_get_string_simple(dev, u->descriptor.iManufacturer,
|
|
|
|
string, sizeof(string));
|
2008-07-02 17:48:50 +00:00
|
|
|
if(res > 0)
|
|
|
|
name += QString::fromAscii(string) + " ";
|
|
|
|
}
|
|
|
|
if(u->descriptor.iProduct) {
|
2009-08-08 12:12:49 +00:00
|
|
|
res = usb_get_string_simple(dev, u->descriptor.iProduct,
|
|
|
|
string, sizeof(string));
|
2008-07-02 17:48:50 +00:00
|
|
|
if(res > 0)
|
|
|
|
name += QString::fromAscii(string);
|
|
|
|
}
|
2010-06-22 20:13:39 +00:00
|
|
|
usb_close(dev);
|
2008-07-02 17:48:50 +00:00
|
|
|
}
|
2010-06-18 19:04:06 +00:00
|
|
|
if(name.isEmpty()) name = tr("(no description available)");
|
2008-07-02 17:48:50 +00:00
|
|
|
|
2009-08-08 12:12:49 +00:00
|
|
|
if(id) {
|
|
|
|
usbids.insert(id, name);
|
2009-08-10 19:46:51 +00:00
|
|
|
qDebug() << "[System] USB:" << QString("0x%1").arg(id, 8, 16) << name;
|
2009-08-08 12:12:49 +00:00
|
|
|
}
|
2008-06-27 22:48:25 +00:00
|
|
|
u = u->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b = b->next;
|
|
|
|
}
|
|
|
|
#endif
|
2009-08-08 12:28:47 +00:00
|
|
|
#endif
|
2008-06-27 22:48:25 +00:00
|
|
|
|
2010-09-05 18:19:23 +00:00
|
|
|
#if defined(Q_OS_MACX)
|
|
|
|
kern_return_t result = KERN_FAILURE;
|
|
|
|
CFMutableDictionaryRef usb_matching_dictionary;
|
|
|
|
io_iterator_t usb_iterator = IO_OBJECT_NULL;
|
|
|
|
usb_matching_dictionary = IOServiceMatching(kIOUSBDeviceClassName);
|
|
|
|
result = IOServiceGetMatchingServices(kIOMasterPortDefault, usb_matching_dictionary,
|
|
|
|
&usb_iterator);
|
|
|
|
if(result) {
|
|
|
|
qDebug() << "[System] USB: IOKit: Could not get matching services.";
|
|
|
|
return usbids;
|
|
|
|
}
|
|
|
|
|
|
|
|
io_object_t usbCurrentObj;
|
|
|
|
while((usbCurrentObj = IOIteratorNext(usb_iterator))) {
|
|
|
|
uint32_t id;
|
|
|
|
QString name;
|
|
|
|
/* get vendor ID */
|
|
|
|
CFTypeRef vidref = NULL;
|
|
|
|
int vid = 0;
|
|
|
|
vidref = IORegistryEntryCreateCFProperty(usbCurrentObj, CFSTR("idVendor"),
|
|
|
|
kCFAllocatorDefault, 0);
|
|
|
|
CFNumberGetValue((CFNumberRef)vidref, kCFNumberIntType, &vid);
|
|
|
|
CFRelease(vidref);
|
|
|
|
|
|
|
|
/* get product ID */
|
|
|
|
CFTypeRef pidref = NULL;
|
|
|
|
int pid = 0;
|
|
|
|
pidref = IORegistryEntryCreateCFProperty(usbCurrentObj, CFSTR("idProduct"),
|
|
|
|
kCFAllocatorDefault, 0);
|
|
|
|
CFNumberGetValue((CFNumberRef)pidref, kCFNumberIntType, &pid);
|
|
|
|
CFRelease(pidref);
|
|
|
|
id = vid << 16 | pid;
|
|
|
|
|
|
|
|
/* get product vendor */
|
|
|
|
char vendor_buf[256];
|
|
|
|
CFIndex vendor_buflen = 256;
|
|
|
|
CFTypeRef vendor_name_ref = NULL;
|
|
|
|
|
|
|
|
vendor_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj,
|
|
|
|
kIOServicePlane, CFSTR("USB Vendor Name"),
|
|
|
|
kCFAllocatorDefault, 0);
|
|
|
|
if(vendor_name_ref != NULL) {
|
|
|
|
CFStringGetCString((CFStringRef)vendor_name_ref, vendor_buf, vendor_buflen,
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
name += QString::fromUtf8(vendor_buf) + " ";
|
|
|
|
CFRelease(vendor_name_ref);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
name += QObject::tr("(unknown vendor name) ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get product name */
|
|
|
|
char product_buf[256];
|
|
|
|
CFIndex product_buflen = 256;
|
|
|
|
CFTypeRef product_name_ref = NULL;
|
|
|
|
|
|
|
|
product_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj,
|
|
|
|
kIOServicePlane, CFSTR("USB Product Name"),
|
|
|
|
kCFAllocatorDefault, 0);
|
|
|
|
if(product_name_ref != NULL) {
|
|
|
|
CFStringGetCString((CFStringRef)product_name_ref, product_buf, product_buflen,
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
name += QString::fromUtf8(product_buf);
|
|
|
|
CFRelease(product_name_ref);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
name += QObject::tr("(unknown product name)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(id) {
|
|
|
|
usbids.insert(id, name);
|
|
|
|
qDebug() << "[System] USB:" << QString("0x%1").arg(id, 8, 16) << name;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
IOObjectRelease(usb_iterator);
|
|
|
|
#endif
|
|
|
|
|
2008-06-27 22:48:25 +00:00
|
|
|
#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;
|
2008-06-28 18:06:55 +00:00
|
|
|
QString description;
|
2008-06-27 22:48:25 +00:00
|
|
|
|
|
|
|
// get device desriptor first
|
|
|
|
// for some reason not doing so results in bad things (tm)
|
|
|
|
while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
|
2010-07-25 19:25:38 +00:00
|
|
|
SPDRP_DEVICEDESC, &data, (PBYTE)buffer, buffersize, &buffersize)) {
|
2008-06-28 18:06:55 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
description = QString::fromWCharArray(buffer);
|
|
|
|
|
2010-07-25 19:25:38 +00:00
|
|
|
// now get the hardware id, which contains PID and VID.
|
2008-06-27 22:48:25 +00:00
|
|
|
while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
|
2010-07-25 19:25:38 +00:00
|
|
|
SPDRP_HARDWAREID, &data, (PBYTE)buffer, buffersize, &buffersize)) {
|
2008-06-27 22:48:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-30 20:05:51 +00:00
|
|
|
unsigned int vid, pid;
|
2010-07-25 19:25:38 +00:00
|
|
|
// 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) {
|
2008-06-27 22:48:25 +00:00
|
|
|
uint32_t id;
|
|
|
|
id = vid << 16 | pid;
|
2008-06-28 18:06:55 +00:00
|
|
|
usbids.insert(id, description);
|
2009-08-10 19:46:51 +00:00
|
|
|
qDebug("[System] USB VID: %04x, PID: %04x", vid, pid);
|
2008-06-27 22:48:25 +00:00
|
|
|
}
|
|
|
|
if(buffer) free(buffer);
|
|
|
|
}
|
|
|
|
SetupDiDestroyDeviceInfoList(deviceInfo);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return usbids;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief detects current system proxy
|
|
|
|
* @return QUrl with proxy or empty
|
|
|
|
*/
|
2009-08-10 19:46:51 +00:00
|
|
|
QUrl System::systemProxy(void)
|
2008-06-27 22:48:25 +00:00
|
|
|
{
|
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
return QUrl(getenv("http_proxy"));
|
|
|
|
#elif defined(Q_OS_WIN32)
|
|
|
|
HKEY hk;
|
|
|
|
wchar_t proxyval[80];
|
|
|
|
DWORD buflen = 80;
|
|
|
|
long ret;
|
|
|
|
DWORD enable;
|
|
|
|
DWORD enalen = sizeof(DWORD);
|
|
|
|
|
|
|
|
ret = RegOpenKeyEx(HKEY_CURRENT_USER,
|
|
|
|
_TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
|
|
|
|
0, KEY_QUERY_VALUE, &hk);
|
|
|
|
if(ret != ERROR_SUCCESS) return QUrl("");
|
|
|
|
|
|
|
|
ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
|
|
|
|
if(ret != ERROR_SUCCESS) return QUrl("");
|
2008-10-24 22:31:07 +00:00
|
|
|
|
2008-06-27 22:48:25 +00:00
|
|
|
ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen);
|
|
|
|
if(ret != ERROR_SUCCESS) return QUrl("");
|
|
|
|
|
|
|
|
RegCloseKey(hk);
|
|
|
|
|
|
|
|
//qDebug() << QString::fromWCharArray(proxyval) << QString("%1").arg(enable);
|
|
|
|
if(enable != 0)
|
|
|
|
return QUrl("http://" + QString::fromWCharArray(proxyval));
|
|
|
|
else
|
2008-10-24 22:31:07 +00:00
|
|
|
return QUrl("");
|
2010-04-02 19:22:32 +00:00
|
|
|
#elif defined(Q_OS_MACX)
|
|
|
|
|
|
|
|
CFDictionaryRef dictref;
|
|
|
|
CFStringRef stringref;
|
|
|
|
CFNumberRef numberref;
|
2010-10-05 19:53:48 +00:00
|
|
|
int enable = 0;
|
|
|
|
int port = 0;
|
2010-04-02 19:22:32 +00:00
|
|
|
unsigned int bufsize = 0;
|
|
|
|
char *buf;
|
|
|
|
QUrl proxy;
|
|
|
|
|
|
|
|
dictref = SCDynamicStoreCopyProxies(NULL);
|
2010-10-05 19:53:48 +00:00
|
|
|
if(dictref == NULL)
|
|
|
|
return proxy;
|
2010-04-02 19:22:32 +00:00
|
|
|
numberref = (CFNumberRef)CFDictionaryGetValue(dictref, kSCPropNetProxiesHTTPEnable);
|
2010-10-05 19:53:48 +00:00
|
|
|
if(numberref != NULL)
|
|
|
|
CFNumberGetValue(numberref, kCFNumberIntType, &enable);
|
2010-04-02 19:22:32 +00:00
|
|
|
if(enable == 1) {
|
2010-10-05 19:53:48 +00:00
|
|
|
// get proxy string
|
|
|
|
stringref = (CFStringRef)CFDictionaryGetValue(dictref, kSCPropNetProxiesHTTPProxy);
|
|
|
|
if(stringref != NULL) {
|
|
|
|
// get number of characters. CFStringGetLength uses UTF-16 code pairs
|
|
|
|
bufsize = CFStringGetLength(stringref) * 2 + 1;
|
|
|
|
buf = (char*)malloc(sizeof(char) * bufsize);
|
|
|
|
if(buf == NULL) {
|
|
|
|
qDebug() << "[System] can't allocate memory for proxy string!";
|
|
|
|
CFRelease(dictref);
|
|
|
|
return QUrl("");
|
|
|
|
}
|
|
|
|
CFStringGetCString(stringref, buf, bufsize, kCFStringEncodingUTF16);
|
|
|
|
numberref = (CFNumberRef)CFDictionaryGetValue(dictref, kSCPropNetProxiesHTTPPort);
|
|
|
|
if(numberref != NULL)
|
|
|
|
CFNumberGetValue(numberref, kCFNumberIntType, &port);
|
|
|
|
proxy.setScheme("http");
|
|
|
|
proxy.setHost(QString::fromUtf16((unsigned short*)buf));
|
|
|
|
proxy.setPort(port);
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
}
|
2010-04-02 19:22:32 +00:00
|
|
|
}
|
|
|
|
CFRelease(dictref);
|
|
|
|
|
|
|
|
return proxy;
|
2008-06-27 22:48:25 +00:00
|
|
|
#else
|
2008-10-24 22:31:07 +00:00
|
|
|
return QUrl("");
|
2008-06-27 22:48:25 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|