From b208000c3649526d0eeb73a328e4052759bc773c Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Fri, 24 Oct 2008 22:31:07 +0000 Subject: Make Detect::check() return an error string instead of a boolean result and move the handling of an occurred error to the application to make detection Gui-clean. Move detect class to base folder. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18873 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/base/detect.cpp | 441 +++++++++++++++++++++++++++++++++++++++ rbutil/rbutilqt/base/detect.h | 54 +++++ rbutil/rbutilqt/detect.cpp | 450 ---------------------------------------- rbutil/rbutilqt/detect.h | 54 ----- rbutil/rbutilqt/install.cpp | 26 ++- rbutil/rbutilqt/rbutilqt.cpp | 21 +- rbutil/rbutilqt/rbutilqt.pro | 4 +- 7 files changed, 526 insertions(+), 524 deletions(-) create mode 100644 rbutil/rbutilqt/base/detect.cpp create mode 100644 rbutil/rbutilqt/base/detect.h delete mode 100644 rbutil/rbutilqt/detect.cpp delete mode 100644 rbutil/rbutilqt/detect.h (limited to 'rbutil') diff --git a/rbutil/rbutilqt/base/detect.cpp b/rbutil/rbutilqt/base/detect.cpp new file mode 100644 index 0000000000..d2a65ee72f --- /dev/null +++ b/rbutil/rbutilqt/base/detect.cpp @@ -0,0 +1,441 @@ +/*************************************************************************** + * __________ __ ___. + * 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) +#include +#include +#include +#include +#endif + +// Linux includes +#if defined(Q_OS_LINUX) +#include +#endif + +// Mac includes +#if defined(Q_OS_MACX) +#include +#include +#include +#endif + + +/** @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 + 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 +#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) + usb_init(); + usb_find_busses(); + usb_find_devices(); + struct usb_bus *b; + b = usb_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; + // 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); + u = u->next; + } + } + 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; + 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("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 detects the installed Rockbox version + * @return QString with version. Empty if not aviable + */ +QString Detect::installedVersion(QString mountpoint) +{ + // read rockbox-info.txt + QFile info(mountpoint +"/.rockbox/rockbox-info.txt"); + if(!info.open(QIODevice::ReadOnly)) + { + return ""; + } + + while (!info.atEnd()) { + QString line = info.readLine(); + + if(line.contains("Version:")) + { + return line.remove("Version:").trimmed(); + } + } + info.close(); + return ""; +} + + +/** @brief detects installed rockbox target id + * @return TargetId of installed rockbox, or -1 if not available + */ +int Detect::installedTargetId(QString mountpoint) +{ + // read rockbox-info.txt + QFile info(mountpoint +"/.rockbox/rockbox-info.txt"); + if(!info.open(QIODevice::ReadOnly)) + { + return -1; + } + + while (!info.atEnd()) + { + QString line = info.readLine(); + if(line.contains("Target id:")) + { + qDebug() << line; + return line.remove("Target id:").trimmed().toInt(); + } + } + info.close(); + return -1; +} + + +/** @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(RbSettings* settings, bool permission, int targetId) +{ + 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 + if(targetId > 0) + { + int installedID = Detect::installedTargetId(settings->mountpoint()); + if( installedID != -1 && installedID != targetId) + { + text += QObject::tr("
  • Target mismatch detected.\n" + "Installed target: %1, selected target: %2.
  • ") + .arg(settings->nameOfTargetId(installedID),settings->curName()); + } + } + + 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 new file mode 100644 index 0000000000..00a8daaef7 --- /dev/null +++ b/rbutil/rbutilqt/base/detect.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * __________ __ ___. + * 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 "rbsettings.h" + +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 installedVersion(QString mountpoint); + static int installedTargetId(QString mountpoint); + + static QString check(RbSettings* settings, bool permission, int targetId); + +}; +#endif + diff --git a/rbutil/rbutilqt/detect.cpp b/rbutil/rbutilqt/detect.cpp deleted file mode 100644 index 7c3d949012..0000000000 --- a/rbutil/rbutilqt/detect.cpp +++ /dev/null @@ -1,450 +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 -#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) -#include -#include -#include -#include -#endif - -// Linux includes -#if defined(Q_OS_LINUX) -#include -#endif - -// Mac includes -#if defined(Q_OS_MACX) -#include -#include -#include -#endif - - -/** @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 - 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 -#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) - usb_init(); - usb_find_busses(); - usb_find_devices(); - struct usb_bus *b; - b = usb_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; - // 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); - u = u->next; - } - } - 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; - 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("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 detects the installed Rockbox version - * @return QString with version. Empty if not aviable - */ -QString Detect::installedVersion(QString mountpoint) -{ - // read rockbox-info.txt - QFile info(mountpoint +"/.rockbox/rockbox-info.txt"); - if(!info.open(QIODevice::ReadOnly)) - { - return ""; - } - - while (!info.atEnd()) { - QString line = info.readLine(); - - if(line.contains("Version:")) - { - return line.remove("Version:").trimmed(); - } - } - info.close(); - return ""; -} - - -/** @brief detects installed rockbox target id - * @return TargetId of installed rockbox, or -1 if not available - */ -int Detect::installedTargetId(QString mountpoint) -{ - // read rockbox-info.txt - QFile info(mountpoint +"/.rockbox/rockbox-info.txt"); - if(!info.open(QIODevice::ReadOnly)) - { - return -1; - } - - while (!info.atEnd()) - { - QString line = info.readLine(); - if(line.contains("Target id:")) - { - qDebug() << line; - return line.remove("Target id:").trimmed().toInt(); - } - } - info.close(); - return -1; -} - - -/** @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 true if everything is ok, or user wants to continue - */ -bool Detect::check(RbSettings* settings,bool permission,int targetId) -{ - QString text = ""; - - // check permission - if(permission) - { -#if defined(Q_OS_WIN32) - if(Detect::userPermissions() != Detect::ADMIN) - { - text += QObject::tr("Permissions are not sufficient! \n Run with admin rights. \n\n"); - } -#endif - } - - // Check TargetId - if(targetId > 0) - { - int installedID = Detect::installedTargetId(settings->mountpoint()); - if( installedID != -1 && installedID != targetId) - { - text += QObject::tr("Target mismatch detected. \n\n" - "Installed target: %1.\n" - "New Target: %2.\n\n").arg(settings->nameOfTargetId(installedID),settings->curName()); - - } - } - - // show message Box - if(text != "") - { - text += QObject::tr("\n Do you want to continue ?"); - if(QMessageBox::warning(NULL, QObject::tr("Problems detected"),text, - QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) - { - return false; - } - } - - return true; -} - - diff --git a/rbutil/rbutilqt/detect.h b/rbutil/rbutilqt/detect.h deleted file mode 100644 index f72a8a6530..0000000000 --- a/rbutil/rbutilqt/detect.h +++ /dev/null @@ -1,54 +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 "rbsettings.h" - -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 installedVersion(QString mountpoint); - static int installedTargetId(QString mountpoint); - - static bool check(RbSettings* settings,bool permission,int targetId); - -}; -#endif - diff --git a/rbutil/rbutilqt/install.cpp b/rbutil/rbutilqt/install.cpp index d9c750ea4d..ee0d2114da 100644 --- a/rbutil/rbutilqt/install.cpp +++ b/rbutil/rbutilqt/install.cpp @@ -120,19 +120,25 @@ void Install::accept() return; } settings->sync(); - - if(Detect::check(settings,false,settings->curTargetId()) == false) + + QString warning = Detect::check(settings, false, settings->curTargetId()); + if(!warning.isEmpty()) { - logger->addItem(tr("Aborted!"),LOGERROR); - logger->abort(); - return; - } - + if(QMessageBox::warning(this, tr("Really continue?"), warning, + QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort) + == QMessageBox::Abort) + { + logger->addItem(tr("Aborted!"),LOGERROR); + logger->abort(); + return; + } + } + //! check if we should backup if(ui.backup->isChecked()) { logger->addItem(tr("Beginning Backup..."),LOGINFO); - + //! create dir, if it doesnt exist QFileInfo backupFile(m_backupName); if(!QDir(backupFile.path()).exists()) @@ -140,7 +146,7 @@ void Install::accept() QDir a; a.mkpath(backupFile.path()); } - + //! create backup RbZip backup; connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int))); @@ -155,7 +161,7 @@ void Install::accept() return; } } - + //! install build installer = new ZipInstaller(this); installer->setUrl(file); diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index e9f6f7fcf2..8c0691c52b 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp @@ -496,17 +496,22 @@ bool RbUtilQt::installAuto() } QString myversion = "r" + versmap.value("bleed_rev"); - + // check installed Version and Target - QString rbVersion = Detect::installedVersion(settings->mountpoint()); + QString rbVersion = Detect::installedVersion(settings->mountpoint()); + QString warning = Detect::check(settings, false, settings->curTargetId()); - if(Detect::check(settings,false,settings->curTargetId()) == false) + if(!warning.isEmpty()) { - logger->addItem(tr("Aborted!"),LOGERROR); - logger->abort(); - return false; + if(QMessageBox::warning(this, tr("Really continue?"), warning, + QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort) == QMessageBox::Abort) + { + logger->addItem(tr("Aborted!"), LOGERROR); + logger->abort(); + return false; + } } - + // check version if(rbVersion != "") { @@ -516,7 +521,7 @@ bool RbUtilQt::installAuto() { logger->addItem(tr("Starting backup..."),LOGINFO); QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip"; - + //! create dir, if it doesnt exist QFileInfo backupFile(backupName); if(!QDir(backupFile.path()).exists()) diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index 9fc74da25a..bf6e7459d1 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro @@ -74,7 +74,7 @@ SOURCES += rbutilqt.cpp \ rbsettings.cpp \ base/rbunzip.cpp \ base/rbzip.cpp \ - detect.cpp \ + base/detect.cpp \ sysinfo.cpp \ base/bootloaderinstallbase.cpp \ base/bootloaderinstallmi4.cpp \ @@ -127,7 +127,7 @@ HEADERS += rbutilqt.h \ base/rbunzip.h \ base/rbzip.h \ sysinfo.h \ - detect.h \ + base/detect.h \ base/bootloaderinstallbase.h \ base/bootloaderinstallmi4.h \ base/bootloaderinstallhex.h \ -- cgit v1.2.3