From e2f508691646935685c122af36a9bbce0cc7ba3c Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Mon, 10 Aug 2009 19:46:51 +0000 Subject: Clean up and rename Detect class. Move check() function out of the Detect class and place it into utils.cpp for now. Rename Detect class to System, as it now only retrieves data about the underlying system and doesn't detect anything anymore. Cleans up with the confusion between Detect and Autodetection. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22238 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/base/autodetection.cpp | 4 +- rbutil/rbutilqt/base/detect.cpp | 438 --------------------------------- rbutil/rbutilqt/base/detect.h | 53 ---- rbutil/rbutilqt/base/system.cpp | 398 ++++++++++++++++++++++++++++++ rbutil/rbutilqt/base/system.h | 51 ++++ rbutil/rbutilqt/base/utils.cpp | 43 ++++ rbutil/rbutilqt/base/utils.h | 1 + rbutil/rbutilqt/configure.cpp | 4 +- rbutil/rbutilqt/install.cpp | 4 +- rbutil/rbutilqt/rbutilqt.cpp | 8 +- rbutil/rbutilqt/rbutilqt.pro | 4 +- rbutil/rbutilqt/sysinfo.cpp | 10 +- 12 files changed, 510 insertions(+), 508 deletions(-) delete mode 100644 rbutil/rbutilqt/base/detect.cpp delete mode 100644 rbutil/rbutilqt/base/detect.h create mode 100644 rbutil/rbutilqt/base/system.cpp create mode 100644 rbutil/rbutilqt/base/system.h diff --git a/rbutil/rbutilqt/base/autodetection.cpp b/rbutil/rbutilqt/base/autodetection.cpp index 5bab1d6..e681999 100644 --- a/rbutil/rbutilqt/base/autodetection.cpp +++ b/rbutil/rbutilqt/base/autodetection.cpp @@ -52,7 +52,7 @@ #include #endif -#include "detect.h" +#include "system.h" #include "utils.h" Autodetection::Autodetection(QObject* parent): QObject(parent) @@ -404,7 +404,7 @@ bool Autodetection::detectUsb() // usb pid detection QList attached; - attached = Detect::listUsbIds(); + attached = System::listUsbIds(); int i = attached.size(); while(i--) { diff --git a/rbutil/rbutilqt/base/detect.cpp b/rbutil/rbutilqt/base/detect.cpp deleted file mode 100644 index 3b8547b..0000000 --- a/rbutil/rbutilqt/base/detect.cpp +++ /dev/null @@ -1,438 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Wenger - * $Id$ - * - * 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. - * - ****************************************************************************/ - - -#include "detect.h" - -#include -#include - -#include -#include - -// Windows Includes -#if defined(Q_OS_WIN32) -#if defined(UNICODE) -#define _UNICODE -#endif -#include -#include -#include -#include -#include -#endif - -// Linux and Mac includes -#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) -#if defined(LIBUSB1) -#include -#else -#include -#endif -#include -#include -#include -#endif - -// Linux includes -#if defined(Q_OS_LINUX) -#include -#endif - -// Mac includes -#if defined(Q_OS_MACX) -#include -#include -#include -#endif - -#include "utils.h" -#include "rbsettings.h" - -/** @brief detect permission of user (only Windows at moment). - * @return enum userlevel. - */ -#if defined(Q_OS_WIN32) -enum Detect::userlevel Detect::userPermissions(void) -{ - LPUSER_INFO_1 buf; - NET_API_STATUS napistatus; - wchar_t userbuf[UNLEN]; - DWORD usersize = UNLEN; - BOOL status; - enum userlevel result; - - status = GetUserNameW(userbuf, &usersize); - if(!status) - return ERR; - - napistatus = NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf); - - 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; - } - NetApiBufferFree(buf); - - return result; -} - -/** @brief detects user permissions (only Windows at moment). - * @return a user readable string with the permission. - */ -QString Detect::userPermissionsString(void) -{ - QString result; - int perm = userPermissions(); - switch(perm) { - case GUEST: - result = QObject::tr("Guest"); - break; - case ADMIN: - result = QObject::tr("Admin"); - break; - case USER: - result = QObject::tr("User"); - break; - default: - result = QObject::tr("Error"); - break; - } - return result; -} -#endif - - -/** @brief detects current Username. - * @return string with Username. - */ -QString Detect::userName(void) -{ -#if defined(Q_OS_WIN32) - wchar_t userbuf[UNLEN]; - DWORD usersize = UNLEN; - BOOL status; - - status = GetUserNameW(userbuf, &usersize); - - 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. - */ -QString Detect::osVersionString(void) -{ - QString result; -#if defined(Q_OS_WIN32) - OSVERSIONINFO osvi; - ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); - - result = QString("Windows version %1.%2, ").arg(osvi.dwMajorVersion).arg(osvi.dwMinorVersion); - if(osvi.szCSDVersion) - result += QString("build %1 (%2)").arg(osvi.dwBuildNumber) - .arg(QString::fromWCharArray(osvi.szCSDVersion)); - else - result += QString("build %1").arg(osvi.dwBuildNumber); -#endif -#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) - struct utsname u; - int ret; - ret = uname(&u); - - result = QString("CPU: %1
System: %2
Release: %3
Version: %4") - .arg(u.machine).arg(u.sysname).arg(u.release).arg(u.version); -#endif - result += QString("
Qt version %1").arg(qVersion()); - return result; -} - -QList Detect::listUsbIds(void) -{ - return listUsbDevices().keys(); -} - -/** @brief detect devices based on usb pid / vid. - * @return list with usb VID / PID values. - */ -QMap Detect::listUsbDevices(void) -{ - QMap usbids; - // usb pid detection - qDebug() << "[Detect] Searching for USB devices"; -#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) -#if defined(LIBUSB1) - libusb_device **devs; - int res; - ssize_t count; - res = libusb_init(NULL); - - count = libusb_get_device_list(NULL, &devs); - 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()) - name = QObject::tr("(no description available)"); - if(id) { - usbids.insert(id, name); - qDebug("[Detect] USB: 0x%08x, %s", id, name.toLocal8Bit().data()); - } - } - } - - libusb_free_device_list(devs, 1); - libusb_exit(NULL); -#else - 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; - // get identification strings - usb_dev_handle *dev; - QString name; - char string[256]; - int res; - dev = usb_open(u); - if(dev) { - if(u->descriptor.iManufacturer) { - res = usb_get_string_simple(dev, u->descriptor.iManufacturer, - string, sizeof(string)); - if(res > 0) - name += QString::fromAscii(string) + " "; - } - if(u->descriptor.iProduct) { - res = usb_get_string_simple(dev, u->descriptor.iProduct, - string, sizeof(string)); - if(res > 0) - name += QString::fromAscii(string); - } - } - usb_close(dev); - if(name.isEmpty()) name = QObject::tr("(no description available)"); - - if(id) { - usbids.insert(id, name); - qDebug() << "[Detect] USB:" << QString("0x%1").arg(id, 8, 16) << name; - } - u = u->next; - } - } - b = b->next; - } -#endif -#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; - QString description; - - // 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)) { - 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); - - 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) { - uint32_t id; - id = vid << 16 | pid; - usbids.insert(id, description); - qDebug("[Detect] USB VID: %04x, PID: %04x", vid, pid); - } - if(buffer) free(buffer); - } - SetupDiDestroyDeviceInfoList(deviceInfo); - -#endif - return usbids; -} - - -/** @brief detects current system proxy - * @return QUrl with proxy or empty - */ -QUrl Detect::systemProxy(void) -{ -#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(""); - - 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 - return QUrl(""); -#else - return QUrl(""); -#endif -} - - -/** @brief checks different Enviroment things. Ask if user wants to continue. - * @param settings A pointer to rbutils settings class - * @param permission if it should check for permission - * @param targetId the targetID to check for. if it is -1 no check is done. - * @return string with error messages if problems occurred, empty strings if none. - */ -QString Detect::check(bool permission) -{ - QString text = ""; - - // check permission - if(permission) - { -#if defined(Q_OS_WIN32) - if(Detect::userPermissions() != Detect::ADMIN) - { - text += QObject::tr("
  • Permissions insufficient for bootloader " - "installation.\nAdministrator priviledges are necessary.
  • "); - } -#endif - } - - // Check TargetId - RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString()); - QString installed = rbinfo.target(); - if(!installed.isEmpty() && installed != RbSettings::value(RbSettings::CurConfigureModel).toString()) - { - text += QObject::tr("
  • Target mismatch detected.\n" - "Installed target: %1, selected target: %2.
  • ") - .arg(installed, RbSettings::value(RbSettings::CurPlatformName).toString()); - // FIXME: replace installed by human-friendly name - } - - if(!text.isEmpty()) - return QObject::tr("Problem detected:") + "
      " + text + "
    "; - else - return text; -} - - diff --git a/rbutil/rbutilqt/base/detect.h b/rbutil/rbutilqt/base/detect.h deleted file mode 100644 index fe4b01f..0000000 --- a/rbutil/rbutilqt/base/detect.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Wenger - * $Id$ - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - - -#ifndef DETECT_H -#define DETECT_H - -#include - -#include -#include - -class Detect -{ -public: - Detect() {} - -#if defined(Q_OS_WIN32) - enum userlevel { ERR, GUEST, USER, ADMIN }; - static enum userlevel userPermissions(void); - static QString userPermissionsString(void); -#endif - - static QString userName(void); - static QString osVersionString(void); - static QList listUsbIds(void); - static QMap listUsbDevices(void); - - static QUrl systemProxy(void); - - static QString check(bool permission); - -}; -#endif - diff --git a/rbutil/rbutilqt/base/system.cpp b/rbutil/rbutilqt/base/system.cpp new file mode 100644 index 0000000..054f1c5 --- /dev/null +++ b/rbutil/rbutilqt/base/system.cpp @@ -0,0 +1,398 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id$ + * + * 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. + * + ****************************************************************************/ + + +#include "system.h" + +#include +#include + +#include +#include + +// Windows Includes +#if defined(Q_OS_WIN32) +#if defined(UNICODE) +#define _UNICODE +#endif +#include +#include +#include +#include +#include +#endif + +// Linux and Mac includes +#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) +#if defined(LIBUSB1) +#include +#else +#include +#endif +#include +#include +#include +#endif + +// Linux includes +#if defined(Q_OS_LINUX) +#include +#endif + +// Mac includes +#if defined(Q_OS_MACX) +#include +#include +#include +#endif + +#include "utils.h" +#include "rbsettings.h" + +/** @brief detect permission of user (only Windows at moment). + * @return enum userlevel. + */ +#if defined(Q_OS_WIN32) +enum System::userlevel System::userPermissions(void) +{ + LPUSER_INFO_1 buf; + NET_API_STATUS napistatus; + wchar_t userbuf[UNLEN]; + DWORD usersize = UNLEN; + BOOL status; + enum userlevel result; + + status = GetUserNameW(userbuf, &usersize); + if(!status) + return ERR; + + napistatus = NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf); + + 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; + } + NetApiBufferFree(buf); + + return result; +} + +/** @brief detects user permissions (only Windows at moment). + * @return a user readable string with the permission. + */ +QString System::userPermissionsString(void) +{ + QString result; + int perm = userPermissions(); + switch(perm) { + case GUEST: + result = QObject::tr("Guest"); + break; + case ADMIN: + result = QObject::tr("Admin"); + break; + case USER: + result = QObject::tr("User"); + break; + default: + result = QObject::tr("Error"); + break; + } + return result; +} +#endif + + +/** @brief detects current Username. + * @return string with Username. + */ +QString System::userName(void) +{ +#if defined(Q_OS_WIN32) + wchar_t userbuf[UNLEN]; + DWORD usersize = UNLEN; + BOOL status; + + status = GetUserNameW(userbuf, &usersize); + + 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. + */ +QString System::osVersionString(void) +{ + QString result; +#if defined(Q_OS_WIN32) + OSVERSIONINFO osvi; + ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osvi); + + result = QString("Windows version %1.%2, ").arg(osvi.dwMajorVersion).arg(osvi.dwMinorVersion); + if(osvi.szCSDVersion) + result += QString("build %1 (%2)").arg(osvi.dwBuildNumber) + .arg(QString::fromWCharArray(osvi.szCSDVersion)); + else + result += QString("build %1").arg(osvi.dwBuildNumber); +#endif +#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) + struct utsname u; + int ret; + ret = uname(&u); + + result = QString("CPU: %1
    System: %2
    Release: %3
    Version: %4") + .arg(u.machine).arg(u.sysname).arg(u.release).arg(u.version); +#endif + result += QString("
    Qt version %1").arg(qVersion()); + return result; +} + +QList System::listUsbIds(void) +{ + return listUsbDevices().keys(); +} + +/** @brief detect devices based on usb pid / vid. + * @return list with usb VID / PID values. + */ +QMap System::listUsbDevices(void) +{ + QMap usbids; + // usb pid detection + qDebug() << "[System] Searching for USB devices"; +#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) +#if defined(LIBUSB1) + libusb_device **devs; + int res; + ssize_t count; + res = libusb_init(NULL); + + count = libusb_get_device_list(NULL, &devs); + 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()) + name = QObject::tr("(no description available)"); + if(id) { + usbids.insert(id, name); + qDebug("[System] USB: 0x%08x, %s", id, name.toLocal8Bit().data()); + } + } + } + + libusb_free_device_list(devs, 1); + libusb_exit(NULL); +#else + 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; + // get identification strings + usb_dev_handle *dev; + QString name; + char string[256]; + int res; + dev = usb_open(u); + if(dev) { + if(u->descriptor.iManufacturer) { + res = usb_get_string_simple(dev, u->descriptor.iManufacturer, + string, sizeof(string)); + if(res > 0) + name += QString::fromAscii(string) + " "; + } + if(u->descriptor.iProduct) { + res = usb_get_string_simple(dev, u->descriptor.iProduct, + string, sizeof(string)); + if(res > 0) + name += QString::fromAscii(string); + } + } + usb_close(dev); + if(name.isEmpty()) name = QObject::tr("(no description available)"); + + if(id) { + usbids.insert(id, name); + qDebug() << "[System] USB:" << QString("0x%1").arg(id, 8, 16) << name; + } + u = u->next; + } + } + b = b->next; + } +#endif +#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; + QString description; + + // 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)) { + 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); + + 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) { + uint32_t id; + id = vid << 16 | pid; + usbids.insert(id, description); + qDebug("[System] USB VID: %04x, PID: %04x", vid, pid); + } + if(buffer) free(buffer); + } + SetupDiDestroyDeviceInfoList(deviceInfo); + +#endif + return usbids; +} + + +/** @brief detects current system proxy + * @return QUrl with proxy or empty + */ +QUrl System::systemProxy(void) +{ +#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(""); + + 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 + return QUrl(""); +#else + return QUrl(""); +#endif +} + + diff --git a/rbutil/rbutilqt/base/system.h b/rbutil/rbutilqt/base/system.h new file mode 100644 index 0000000..25c404e --- /dev/null +++ b/rbutil/rbutilqt/base/system.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id$ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +#ifndef SYSTEM_H +#define SYSTEM_H + +#include + +#include +#include + +class System +{ +public: + System() {} + +#if defined(Q_OS_WIN32) + enum userlevel { ERR, GUEST, USER, ADMIN }; + static enum userlevel userPermissions(void); + static QString userPermissionsString(void); +#endif + + static QString userName(void); + static QString osVersionString(void); + static QList listUsbIds(void); + static QMap listUsbDevices(void); + + static QUrl systemProxy(void); + +}; +#endif + diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp index a1b6e2b..8b5127e 100644 --- a/rbutil/rbutilqt/base/utils.cpp +++ b/rbutil/rbutilqt/base/utils.cpp @@ -18,6 +18,9 @@ ****************************************************************************/ #include "utils.h" +#include "system.h" +#include "rbsettings.h" + #ifdef UNICODE #define _UNICODE #endif @@ -159,6 +162,46 @@ QString findExecutable(QString name) } +/** @brief checks different Enviroment things. Ask if user wants to continue. + * @param settings A pointer to rbutils settings class + * @param permission if it should check for permission + * @param targetId the targetID to check for. if it is -1 no check is done. + * @return string with error messages if problems occurred, empty strings if none. + */ +QString check(bool permission) +{ + QString text = ""; + + // check permission + if(permission) + { +#if defined(Q_OS_WIN32) + if(Detect::userPermissions() != Detect::ADMIN) + { + text += QObject::tr("
  • Permissions insufficient for bootloader " + "installation.\nAdministrator priviledges are necessary.
  • "); + } +#endif + } + + // Check TargetId + RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString()); + QString installed = rbinfo.target(); + if(!installed.isEmpty() && installed != RbSettings::value(RbSettings::CurConfigureModel).toString()) + { + text += QObject::tr("
  • Target mismatch detected.\n" + "Installed target: %1, selected target: %2.
  • ") + .arg(installed, RbSettings::value(RbSettings::CurPlatformName).toString()); + // FIXME: replace installed by human-friendly name + } + + if(!text.isEmpty()) + return QObject::tr("Problem detected:") + "
      " + text + "
    "; + else + return text; +} + + RockboxInfo::RockboxInfo(QString mountpoint) { qDebug() << "[RockboxInfo] trying to find rockbox-info at" << mountpoint; diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h index 9113eba..ef7d30e 100644 --- a/rbutil/rbutilqt/base/utils.h +++ b/rbutil/rbutilqt/base/utils.h @@ -30,6 +30,7 @@ bool recRmdir( const QString &dirName ); QString resolvePathCase(QString path); qulonglong filesystemFree(QString path); QString findExecutable(QString name); +QString check(bool permission); class RockboxInfo { diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp index e32cccb..23d275d 100644 --- a/rbutil/rbutilqt/configure.cpp +++ b/rbutil/rbutilqt/configure.cpp @@ -26,7 +26,7 @@ #include "browsedirtree.h" #include "encoders.h" #include "tts.h" -#include "detect.h" +#include "system.h" #include "encttscfggui.h" #include "rbsettings.h" #include "utils.h" @@ -420,7 +420,7 @@ void Config::setSystemProxy(bool checked) proxy.setHost(ui.proxyHost->text()); proxy.setPort(ui.proxyPort->text().toInt()); // show system values in input box - QUrl envproxy = Detect::systemProxy(); + QUrl envproxy = System::systemProxy(); ui.proxyHost->setText(envproxy.host()); diff --git a/rbutil/rbutilqt/install.cpp b/rbutil/rbutilqt/install.cpp index 34a4da1..8deaf95 100644 --- a/rbutil/rbutilqt/install.cpp +++ b/rbutil/rbutilqt/install.cpp @@ -20,7 +20,7 @@ #include "install.h" #include "ui_installfrm.h" #include "rbzip.h" -#include "detect.h" +#include "system.h" #include "rbsettings.h" #include "utils.h" @@ -130,7 +130,7 @@ void Install::accept() RbSettings::sync(); - QString warning = Detect::check(false); + QString warning = check(false); if(!warning.isEmpty()) { if(QMessageBox::warning(this, tr("Really continue?"), warning, diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index f7ddb37..dff0395 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp @@ -33,7 +33,7 @@ #include "utils.h" #include "rbzip.h" #include "sysinfo.h" -#include "detect.h" +#include "system.h" #include "rbsettings.h" #include "progressloggerinterface.h" @@ -308,7 +308,7 @@ void RbUtilQt::updateSettings() updateDevice(); updateManual(); if(RbSettings::value(RbSettings::ProxyType) == "system") { - HttpGet::setGlobalProxy(Detect::systemProxy()); + HttpGet::setGlobalProxy(System::systemProxy()); } else if(RbSettings::value(RbSettings::ProxyType) == "manual") { HttpGet::setGlobalProxy(RbSettings::value(RbSettings::Proxy).toString()); @@ -526,7 +526,7 @@ bool RbUtilQt::installAuto() buildInfo.close(); // check installed Version and Target - QString warning = Detect::check(false); + QString warning = check(false); if(!warning.isEmpty()) { if(QMessageBox::warning(this, tr("Really continue?"), warning, @@ -1181,7 +1181,7 @@ QUrl RbUtilQt::proxy() if(RbSettings::value(RbSettings::ProxyType) == "manual") return QUrl(RbSettings::value(RbSettings::Proxy).toString()); else if(RbSettings::value(RbSettings::ProxyType) == "system") - return Detect::systemProxy(); + return System::systemProxy(); return QUrl(""); } diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index 998bffc..31b07bf 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro @@ -75,7 +75,7 @@ SOURCES += rbutilqt.cpp \ base/rbsettings.cpp \ base/rbunzip.cpp \ base/rbzip.cpp \ - base/detect.cpp \ + base/system.cpp \ sysinfo.cpp \ base/bootloaderinstallbase.cpp \ base/bootloaderinstallmi4.cpp \ @@ -129,7 +129,7 @@ HEADERS += rbutilqt.h \ base/rbunzip.h \ base/rbzip.h \ sysinfo.h \ - base/detect.h \ + base/system.h \ base/bootloaderinstallbase.h \ base/bootloaderinstallmi4.h \ base/bootloaderinstallhex.h \ diff --git a/rbutil/rbutilqt/sysinfo.cpp b/rbutil/rbutilqt/sysinfo.cpp index f5c0e47..ca34b4b 100644 --- a/rbutil/rbutilqt/sysinfo.cpp +++ b/rbutil/rbutilqt/sysinfo.cpp @@ -20,7 +20,7 @@ #include #include "sysinfo.h" #include "ui_sysinfofrm.h" -#include "detect.h" +#include "system.h" #include "utils.h" #include "autodetection.h" @@ -38,13 +38,13 @@ Sysinfo::Sysinfo(QWidget *parent) : QDialog(parent) void Sysinfo::updateSysinfo(void) { QString info; - info += tr("OS
    ") + Detect::osVersionString() + "
    "; - info += tr("Username
    %1
    ").arg(Detect::userName()); + info += tr("OS
    ") + System::osVersionString() + "
    "; + info += tr("Username
    %1
    ").arg(System::userName()); #if defined(Q_OS_WIN32) - info += tr("Permissions
    %1
    ").arg(Detect::userPermissionsString()); + info += tr("Permissions
    %1
    ").arg(System::userPermissionsString()); #endif info += tr("Attached USB devices
    "); - QMap usbids = Detect::listUsbDevices(); + QMap usbids = System::listUsbDevices(); QList usbkeys = usbids.keys(); for(int i = 0; i < usbkeys.size(); i++) { info += tr("VID: %1 PID: %2, %3") -- cgit v1.1