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
This commit is contained in:
Dominik Riebeling 2008-10-24 22:31:07 +00:00
parent 6371460172
commit b208000c36
5 changed files with 64 additions and 62 deletions

View file

@ -22,10 +22,9 @@
#include <QtCore> #include <QtCore>
#include <QDebug> #include <QDebug>
#include <cstdlib> #include <cstdlib>
#include <stdio.h> #include <stdio.h>
#include <QMessageBox>
// Windows Includes // Windows Includes
#if defined(Q_OS_WIN32) #if defined(Q_OS_WIN32)
@ -72,11 +71,11 @@ enum Detect::userlevel Detect::userPermissions(void)
DWORD usersize = UNLEN; DWORD usersize = UNLEN;
BOOL status; BOOL status;
enum userlevel result; enum userlevel result;
status = GetUserNameW(userbuf, &usersize); status = GetUserNameW(userbuf, &usersize);
if(!status) if(!status)
return ERR; return ERR;
napistatus = NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf); napistatus = NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf);
switch(buf->usri1_priv) { switch(buf->usri1_priv) {
@ -122,7 +121,7 @@ QString Detect::userPermissionsString(void)
return result; return result;
} }
#endif #endif
/** @brief detects current Username. /** @brief detects current Username.
* @return string with Username. * @return string with Username.
@ -133,7 +132,7 @@ QString Detect::userName(void)
wchar_t userbuf[UNLEN]; wchar_t userbuf[UNLEN];
DWORD usersize = UNLEN; DWORD usersize = UNLEN;
BOOL status; BOOL status;
status = GetUserNameW(userbuf, &usersize); status = GetUserNameW(userbuf, &usersize);
return QString::fromWCharArray(userbuf); return QString::fromWCharArray(userbuf);
@ -331,7 +330,7 @@ QUrl Detect::systemProxy(void)
ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen); ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
if(ret != ERROR_SUCCESS) return QUrl(""); if(ret != ERROR_SUCCESS) return QUrl("");
ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen); ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen);
if(ret != ERROR_SUCCESS) return QUrl(""); if(ret != ERROR_SUCCESS) return QUrl("");
@ -341,9 +340,9 @@ QUrl Detect::systemProxy(void)
if(enable != 0) if(enable != 0)
return QUrl("http://" + QString::fromWCharArray(proxyval)); return QUrl("http://" + QString::fromWCharArray(proxyval));
else else
return QUrl(""); return QUrl("");
#else #else
return QUrl(""); return QUrl("");
#endif #endif
} }
@ -359,14 +358,14 @@ QString Detect::installedVersion(QString mountpoint)
{ {
return ""; return "";
} }
while (!info.atEnd()) { while (!info.atEnd()) {
QString line = info.readLine(); QString line = info.readLine();
if(line.contains("Version:")) if(line.contains("Version:"))
{ {
return line.remove("Version:").trimmed(); return line.remove("Version:").trimmed();
} }
} }
info.close(); info.close();
return ""; return "";
@ -384,15 +383,15 @@ int Detect::installedTargetId(QString mountpoint)
{ {
return -1; return -1;
} }
while (!info.atEnd()) while (!info.atEnd())
{ {
QString line = info.readLine(); QString line = info.readLine();
if(line.contains("Target id:")) if(line.contains("Target id:"))
{ {
qDebug() << line; qDebug() << line;
return line.remove("Target id:").trimmed().toInt(); return line.remove("Target id:").trimmed().toInt();
} }
} }
info.close(); info.close();
return -1; return -1;
@ -403,9 +402,9 @@ int Detect::installedTargetId(QString mountpoint)
* @param settings A pointer to rbutils settings class * @param settings A pointer to rbutils settings class
* @param permission if it should check for permission * @param permission if it should check for permission
* @param targetId the targetID to check for. if it is -1 no check is done. * @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 * @return string with error messages if problems occurred, empty strings if none.
*/ */
bool Detect::check(RbSettings* settings,bool permission,int targetId) QString Detect::check(RbSettings* settings, bool permission, int targetId)
{ {
QString text = ""; QString text = "";
@ -415,36 +414,28 @@ bool Detect::check(RbSettings* settings,bool permission,int targetId)
#if defined(Q_OS_WIN32) #if defined(Q_OS_WIN32)
if(Detect::userPermissions() != Detect::ADMIN) if(Detect::userPermissions() != Detect::ADMIN)
{ {
text += QObject::tr("Permissions are not sufficient! \n Run with admin rights. \n\n"); text += QObject::tr("<li>Permissions insufficient for bootloader "
} "installation.\nAdministrator priviledges are necessary.</li>");
}
#endif #endif
} }
// Check TargetId // Check TargetId
if(targetId > 0) if(targetId > 0)
{ {
int installedID = Detect::installedTargetId(settings->mountpoint()); int installedID = Detect::installedTargetId(settings->mountpoint());
if( installedID != -1 && installedID != targetId) if( installedID != -1 && installedID != targetId)
{ {
text += QObject::tr("Target mismatch detected. \n\n" text += QObject::tr("<li>Target mismatch detected.\n"
"Installed target: %1.\n" "Installed target: %1, selected target: %2.</li>")
"New Target: %2.\n\n").arg(settings->nameOfTargetId(installedID),settings->curName()); .arg(settings->nameOfTargetId(installedID),settings->curName());
}
}
} }
// show message Box if(!text.isEmpty())
if(text != "") return QObject::tr("Problem detected:") + "<ul>" + text + "</ul>";
{ else
text += QObject::tr("\n Do you want to continue ?"); return text;
if(QMessageBox::warning(NULL, QObject::tr("Problems detected"),text,
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
{
return false;
}
}
return true;
} }

View file

@ -27,17 +27,17 @@
#include <QUrl> #include <QUrl>
#include "rbsettings.h" #include "rbsettings.h"
class Detect class Detect
{ {
public: public:
Detect() {} Detect() {}
#if defined(Q_OS_WIN32) #if defined(Q_OS_WIN32)
enum userlevel { ERR, GUEST, USER, ADMIN }; enum userlevel { ERR, GUEST, USER, ADMIN };
static enum userlevel userPermissions(void); static enum userlevel userPermissions(void);
static QString userPermissionsString(void); static QString userPermissionsString(void);
#endif #endif
static QString userName(void); static QString userName(void);
static QString osVersionString(void); static QString osVersionString(void);
static QList<uint32_t> listUsbIds(void); static QList<uint32_t> listUsbIds(void);
@ -47,7 +47,7 @@ public:
static QString installedVersion(QString mountpoint); static QString installedVersion(QString mountpoint);
static int installedTargetId(QString mountpoint); static int installedTargetId(QString mountpoint);
static bool check(RbSettings* settings,bool permission,int targetId); static QString check(RbSettings* settings, bool permission, int targetId);
}; };
#endif #endif

View file

@ -120,19 +120,25 @@ void Install::accept()
return; return;
} }
settings->sync(); 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); if(QMessageBox::warning(this, tr("Really continue?"), warning,
logger->abort(); QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
return; == QMessageBox::Abort)
} {
logger->addItem(tr("Aborted!"),LOGERROR);
logger->abort();
return;
}
}
//! check if we should backup //! check if we should backup
if(ui.backup->isChecked()) if(ui.backup->isChecked())
{ {
logger->addItem(tr("Beginning Backup..."),LOGINFO); logger->addItem(tr("Beginning Backup..."),LOGINFO);
//! create dir, if it doesnt exist //! create dir, if it doesnt exist
QFileInfo backupFile(m_backupName); QFileInfo backupFile(m_backupName);
if(!QDir(backupFile.path()).exists()) if(!QDir(backupFile.path()).exists())
@ -140,7 +146,7 @@ void Install::accept()
QDir a; QDir a;
a.mkpath(backupFile.path()); a.mkpath(backupFile.path());
} }
//! create backup //! create backup
RbZip backup; RbZip backup;
connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int))); connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int)));
@ -155,7 +161,7 @@ void Install::accept()
return; return;
} }
} }
//! install build //! install build
installer = new ZipInstaller(this); installer = new ZipInstaller(this);
installer->setUrl(file); installer->setUrl(file);

View file

@ -496,17 +496,22 @@ bool RbUtilQt::installAuto()
} }
QString myversion = "r" + versmap.value("bleed_rev"); QString myversion = "r" + versmap.value("bleed_rev");
// check installed Version and Target
QString rbVersion = Detect::installedVersion(settings->mountpoint());
if(Detect::check(settings,false,settings->curTargetId()) == false) // check installed Version and Target
QString rbVersion = Detect::installedVersion(settings->mountpoint());
QString warning = Detect::check(settings, false, settings->curTargetId());
if(!warning.isEmpty())
{ {
logger->addItem(tr("Aborted!"),LOGERROR); if(QMessageBox::warning(this, tr("Really continue?"), warning,
logger->abort(); QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort) == QMessageBox::Abort)
return false; {
logger->addItem(tr("Aborted!"), LOGERROR);
logger->abort();
return false;
}
} }
// check version // check version
if(rbVersion != "") if(rbVersion != "")
{ {
@ -516,7 +521,7 @@ bool RbUtilQt::installAuto()
{ {
logger->addItem(tr("Starting backup..."),LOGINFO); logger->addItem(tr("Starting backup..."),LOGINFO);
QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip"; QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip";
//! create dir, if it doesnt exist //! create dir, if it doesnt exist
QFileInfo backupFile(backupName); QFileInfo backupFile(backupName);
if(!QDir(backupFile.path()).exists()) if(!QDir(backupFile.path()).exists())

View file

@ -74,7 +74,7 @@ SOURCES += rbutilqt.cpp \
rbsettings.cpp \ rbsettings.cpp \
base/rbunzip.cpp \ base/rbunzip.cpp \
base/rbzip.cpp \ base/rbzip.cpp \
detect.cpp \ base/detect.cpp \
sysinfo.cpp \ sysinfo.cpp \
base/bootloaderinstallbase.cpp \ base/bootloaderinstallbase.cpp \
base/bootloaderinstallmi4.cpp \ base/bootloaderinstallmi4.cpp \
@ -127,7 +127,7 @@ HEADERS += rbutilqt.h \
base/rbunzip.h \ base/rbunzip.h \
base/rbzip.h \ base/rbzip.h \
sysinfo.h \ sysinfo.h \
detect.h \ base/detect.h \
base/bootloaderinstallbase.h \ base/bootloaderinstallbase.h \
base/bootloaderinstallmi4.h \ base/bootloaderinstallmi4.h \
base/bootloaderinstallhex.h \ base/bootloaderinstallhex.h \