summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-24 22:31:07 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-24 22:31:07 +0000
commitb208000c3649526d0eeb73a328e4052759bc773c (patch)
tree675e8453392a664b859c129154d60b710b577966 /rbutil/rbutilqt
parent637146017289dd394a6f68327c56867fa8747dc5 (diff)
downloadrockbox-b208000c3649526d0eeb73a328e4052759bc773c.tar.gz
rockbox-b208000c3649526d0eeb73a328e4052759bc773c.zip
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
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r--rbutil/rbutilqt/base/detect.cpp (renamed from rbutil/rbutilqt/detect.cpp)65
-rw-r--r--rbutil/rbutilqt/base/detect.h (renamed from rbutil/rbutilqt/detect.h)8
-rw-r--r--rbutil/rbutilqt/install.cpp26
-rw-r--r--rbutil/rbutilqt/rbutilqt.cpp21
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro4
5 files changed, 63 insertions, 61 deletions
diff --git a/rbutil/rbutilqt/detect.cpp b/rbutil/rbutilqt/base/detect.cpp
index 7c3d949012..d2a65ee72f 100644
--- a/rbutil/rbutilqt/detect.cpp
+++ b/rbutil/rbutilqt/base/detect.cpp
@@ -22,10 +22,9 @@
22 22
23#include <QtCore> 23#include <QtCore>
24#include <QDebug> 24#include <QDebug>
25
25#include <cstdlib> 26#include <cstdlib>
26#include <stdio.h> 27#include <stdio.h>
27#include <QMessageBox>
28
29 28
30// Windows Includes 29// Windows Includes
31#if defined(Q_OS_WIN32) 30#if defined(Q_OS_WIN32)
@@ -72,11 +71,11 @@ enum Detect::userlevel Detect::userPermissions(void)
72 DWORD usersize = UNLEN; 71 DWORD usersize = UNLEN;
73 BOOL status; 72 BOOL status;
74 enum userlevel result; 73 enum userlevel result;
75 74
76 status = GetUserNameW(userbuf, &usersize); 75 status = GetUserNameW(userbuf, &usersize);
77 if(!status) 76 if(!status)
78 return ERR; 77 return ERR;
79 78
80 napistatus = NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf); 79 napistatus = NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf);
81 80
82 switch(buf->usri1_priv) { 81 switch(buf->usri1_priv) {
@@ -122,7 +121,7 @@ QString Detect::userPermissionsString(void)
122 return result; 121 return result;
123} 122}
124#endif 123#endif
125 124
126 125
127/** @brief detects current Username. 126/** @brief detects current Username.
128 * @return string with Username. 127 * @return string with Username.
@@ -133,7 +132,7 @@ QString Detect::userName(void)
133 wchar_t userbuf[UNLEN]; 132 wchar_t userbuf[UNLEN];
134 DWORD usersize = UNLEN; 133 DWORD usersize = UNLEN;
135 BOOL status; 134 BOOL status;
136 135
137 status = GetUserNameW(userbuf, &usersize); 136 status = GetUserNameW(userbuf, &usersize);
138 137
139 return QString::fromWCharArray(userbuf); 138 return QString::fromWCharArray(userbuf);
@@ -331,7 +330,7 @@ QUrl Detect::systemProxy(void)
331 330
332 ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen); 331 ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
333 if(ret != ERROR_SUCCESS) return QUrl(""); 332 if(ret != ERROR_SUCCESS) return QUrl("");
334 333
335 ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen); 334 ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen);
336 if(ret != ERROR_SUCCESS) return QUrl(""); 335 if(ret != ERROR_SUCCESS) return QUrl("");
337 336
@@ -341,9 +340,9 @@ QUrl Detect::systemProxy(void)
341 if(enable != 0) 340 if(enable != 0)
342 return QUrl("http://" + QString::fromWCharArray(proxyval)); 341 return QUrl("http://" + QString::fromWCharArray(proxyval));
343 else 342 else
344 return QUrl(""); 343 return QUrl("");
345#else 344#else
346 return QUrl(""); 345 return QUrl("");
347#endif 346#endif
348} 347}
349 348
@@ -359,14 +358,14 @@ QString Detect::installedVersion(QString mountpoint)
359 { 358 {
360 return ""; 359 return "";
361 } 360 }
362 361
363 while (!info.atEnd()) { 362 while (!info.atEnd()) {
364 QString line = info.readLine(); 363 QString line = info.readLine();
365 364
366 if(line.contains("Version:")) 365 if(line.contains("Version:"))
367 { 366 {
368 return line.remove("Version:").trimmed(); 367 return line.remove("Version:").trimmed();
369 } 368 }
370 } 369 }
371 info.close(); 370 info.close();
372 return ""; 371 return "";
@@ -384,15 +383,15 @@ int Detect::installedTargetId(QString mountpoint)
384 { 383 {
385 return -1; 384 return -1;
386 } 385 }
387 386
388 while (!info.atEnd()) 387 while (!info.atEnd())
389 { 388 {
390 QString line = info.readLine(); 389 QString line = info.readLine();
391 if(line.contains("Target id:")) 390 if(line.contains("Target id:"))
392 { 391 {
393 qDebug() << line; 392 qDebug() << line;
394 return line.remove("Target id:").trimmed().toInt(); 393 return line.remove("Target id:").trimmed().toInt();
395 } 394 }
396 } 395 }
397 info.close(); 396 info.close();
398 return -1; 397 return -1;
@@ -403,9 +402,9 @@ int Detect::installedTargetId(QString mountpoint)
403 * @param settings A pointer to rbutils settings class 402 * @param settings A pointer to rbutils settings class
404 * @param permission if it should check for permission 403 * @param permission if it should check for permission
405 * @param targetId the targetID to check for. if it is -1 no check is done. 404 * @param targetId the targetID to check for. if it is -1 no check is done.
406 * @return true if everything is ok, or user wants to continue 405 * @return string with error messages if problems occurred, empty strings if none.
407 */ 406 */
408bool Detect::check(RbSettings* settings,bool permission,int targetId) 407QString Detect::check(RbSettings* settings, bool permission, int targetId)
409{ 408{
410 QString text = ""; 409 QString text = "";
411 410
@@ -415,36 +414,28 @@ bool Detect::check(RbSettings* settings,bool permission,int targetId)
415#if defined(Q_OS_WIN32) 414#if defined(Q_OS_WIN32)
416 if(Detect::userPermissions() != Detect::ADMIN) 415 if(Detect::userPermissions() != Detect::ADMIN)
417 { 416 {
418 text += QObject::tr("Permissions are not sufficient! \n Run with admin rights. \n\n"); 417 text += QObject::tr("<li>Permissions insufficient for bootloader "
419 } 418 "installation.\nAdministrator priviledges are necessary.</li>");
419 }
420#endif 420#endif
421 } 421 }
422 422
423 // Check TargetId 423 // Check TargetId
424 if(targetId > 0) 424 if(targetId > 0)
425 { 425 {
426 int installedID = Detect::installedTargetId(settings->mountpoint()); 426 int installedID = Detect::installedTargetId(settings->mountpoint());
427 if( installedID != -1 && installedID != targetId) 427 if( installedID != -1 && installedID != targetId)
428 { 428 {
429 text += QObject::tr("Target mismatch detected. \n\n" 429 text += QObject::tr("<li>Target mismatch detected.\n"
430 "Installed target: %1.\n" 430 "Installed target: %1, selected target: %2.</li>")
431 "New Target: %2.\n\n").arg(settings->nameOfTargetId(installedID),settings->curName()); 431 .arg(settings->nameOfTargetId(installedID),settings->curName());
432 432 }
433 }
434 }
435
436 // show message Box
437 if(text != "")
438 {
439 text += QObject::tr("\n Do you want to continue ?");
440 if(QMessageBox::warning(NULL, QObject::tr("Problems detected"),text,
441 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
442 {
443 return false;
444 }
445 } 433 }
446 434
447 return true; 435 if(!text.isEmpty())
436 return QObject::tr("Problem detected:") + "<ul>" + text + "</ul>";
437 else
438 return text;
448} 439}
449 440
450 441
diff --git a/rbutil/rbutilqt/detect.h b/rbutil/rbutilqt/base/detect.h
index f72a8a6530..00a8daaef7 100644
--- a/rbutil/rbutilqt/detect.h
+++ b/rbutil/rbutilqt/base/detect.h
@@ -27,17 +27,17 @@
27#include <QUrl> 27#include <QUrl>
28#include "rbsettings.h" 28#include "rbsettings.h"
29 29
30class Detect 30class Detect
31{ 31{
32public: 32public:
33 Detect() {} 33 Detect() {}
34 34
35#if defined(Q_OS_WIN32) 35#if defined(Q_OS_WIN32)
36 enum userlevel { ERR, GUEST, USER, ADMIN }; 36 enum userlevel { ERR, GUEST, USER, ADMIN };
37 static enum userlevel userPermissions(void); 37 static enum userlevel userPermissions(void);
38 static QString userPermissionsString(void); 38 static QString userPermissionsString(void);
39#endif 39#endif
40 40
41 static QString userName(void); 41 static QString userName(void);
42 static QString osVersionString(void); 42 static QString osVersionString(void);
43 static QList<uint32_t> listUsbIds(void); 43 static QList<uint32_t> listUsbIds(void);
@@ -47,7 +47,7 @@ public:
47 static QString installedVersion(QString mountpoint); 47 static QString installedVersion(QString mountpoint);
48 static int installedTargetId(QString mountpoint); 48 static int installedTargetId(QString mountpoint);
49 49
50 static bool check(RbSettings* settings,bool permission,int targetId); 50 static QString check(RbSettings* settings, bool permission, int targetId);
51 51
52}; 52};
53#endif 53#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()
120 return; 120 return;
121 } 121 }
122 settings->sync(); 122 settings->sync();
123 123
124 if(Detect::check(settings,false,settings->curTargetId()) == false) 124 QString warning = Detect::check(settings, false, settings->curTargetId());
125 if(!warning.isEmpty())
125 { 126 {
126 logger->addItem(tr("Aborted!"),LOGERROR); 127 if(QMessageBox::warning(this, tr("Really continue?"), warning,
127 logger->abort(); 128 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
128 return; 129 == QMessageBox::Abort)
129 } 130 {
130 131 logger->addItem(tr("Aborted!"),LOGERROR);
132 logger->abort();
133 return;
134 }
135 }
136
131 //! check if we should backup 137 //! check if we should backup
132 if(ui.backup->isChecked()) 138 if(ui.backup->isChecked())
133 { 139 {
134 logger->addItem(tr("Beginning Backup..."),LOGINFO); 140 logger->addItem(tr("Beginning Backup..."),LOGINFO);
135 141
136 //! create dir, if it doesnt exist 142 //! create dir, if it doesnt exist
137 QFileInfo backupFile(m_backupName); 143 QFileInfo backupFile(m_backupName);
138 if(!QDir(backupFile.path()).exists()) 144 if(!QDir(backupFile.path()).exists())
@@ -140,7 +146,7 @@ void Install::accept()
140 QDir a; 146 QDir a;
141 a.mkpath(backupFile.path()); 147 a.mkpath(backupFile.path());
142 } 148 }
143 149
144 //! create backup 150 //! create backup
145 RbZip backup; 151 RbZip backup;
146 connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int))); 152 connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int)));
@@ -155,7 +161,7 @@ void Install::accept()
155 return; 161 return;
156 } 162 }
157 } 163 }
158 164
159 //! install build 165 //! install build
160 installer = new ZipInstaller(this); 166 installer = new ZipInstaller(this);
161 installer->setUrl(file); 167 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()
496 } 496 }
497 497
498 QString myversion = "r" + versmap.value("bleed_rev"); 498 QString myversion = "r" + versmap.value("bleed_rev");
499 499
500 // check installed Version and Target 500 // check installed Version and Target
501 QString rbVersion = Detect::installedVersion(settings->mountpoint()); 501 QString rbVersion = Detect::installedVersion(settings->mountpoint());
502 QString warning = Detect::check(settings, false, settings->curTargetId());
502 503
503 if(Detect::check(settings,false,settings->curTargetId()) == false) 504 if(!warning.isEmpty())
504 { 505 {
505 logger->addItem(tr("Aborted!"),LOGERROR); 506 if(QMessageBox::warning(this, tr("Really continue?"), warning,
506 logger->abort(); 507 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort) == QMessageBox::Abort)
507 return false; 508 {
509 logger->addItem(tr("Aborted!"), LOGERROR);
510 logger->abort();
511 return false;
512 }
508 } 513 }
509 514
510 // check version 515 // check version
511 if(rbVersion != "") 516 if(rbVersion != "")
512 { 517 {
@@ -516,7 +521,7 @@ bool RbUtilQt::installAuto()
516 { 521 {
517 logger->addItem(tr("Starting backup..."),LOGINFO); 522 logger->addItem(tr("Starting backup..."),LOGINFO);
518 QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip"; 523 QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip";
519 524
520 //! create dir, if it doesnt exist 525 //! create dir, if it doesnt exist
521 QFileInfo backupFile(backupName); 526 QFileInfo backupFile(backupName);
522 if(!QDir(backupFile.path()).exists()) 527 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 \
74 rbsettings.cpp \ 74 rbsettings.cpp \
75 base/rbunzip.cpp \ 75 base/rbunzip.cpp \
76 base/rbzip.cpp \ 76 base/rbzip.cpp \
77 detect.cpp \ 77 base/detect.cpp \
78 sysinfo.cpp \ 78 sysinfo.cpp \
79 base/bootloaderinstallbase.cpp \ 79 base/bootloaderinstallbase.cpp \
80 base/bootloaderinstallmi4.cpp \ 80 base/bootloaderinstallmi4.cpp \
@@ -127,7 +127,7 @@ HEADERS += rbutilqt.h \
127 base/rbunzip.h \ 127 base/rbunzip.h \
128 base/rbzip.h \ 128 base/rbzip.h \
129 sysinfo.h \ 129 sysinfo.h \
130 detect.h \ 130 base/detect.h \
131 base/bootloaderinstallbase.h \ 131 base/bootloaderinstallbase.h \
132 base/bootloaderinstallmi4.h \ 132 base/bootloaderinstallmi4.h \
133 base/bootloaderinstallhex.h \ 133 base/bootloaderinstallhex.h \