summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r--rbutil/rbutilqt/autodetection.cpp4
-rw-r--r--rbutil/rbutilqt/configure.cpp4
-rw-r--r--rbutil/rbutilqt/install.cpp26
-rw-r--r--rbutil/rbutilqt/rbutilqt.cpp28
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro6
-rw-r--r--rbutil/rbutilqt/sysinfo.cpp11
-rw-r--r--rbutil/rbutilqt/utils.cpp306
-rw-r--r--rbutil/rbutilqt/utils.h13
8 files changed, 31 insertions, 367 deletions
diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp
index f257f5c0c9..c356cc6307 100644
--- a/rbutil/rbutilqt/autodetection.cpp
+++ b/rbutil/rbutilqt/autodetection.cpp
@@ -40,7 +40,7 @@
40#include <windows.h> 40#include <windows.h>
41#include <setupapi.h> 41#include <setupapi.h>
42#endif 42#endif
43#include "utils.h" 43#include "detect.h"
44 44
45Autodetection::Autodetection(QObject* parent): QObject(parent) 45Autodetection::Autodetection(QObject* parent): QObject(parent)
46{ 46{
@@ -267,7 +267,7 @@ bool Autodetection::detectUsb()
267 267
268 // usb pid detection 268 // usb pid detection
269 QList<uint32_t> attached; 269 QList<uint32_t> attached;
270 attached = listUsbIds(); 270 attached = Detect::listUsbIds();
271 271
272 int i = attached.size(); 272 int i = attached.size();
273 while(i--) { 273 while(i--) {
diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp
index 4b2a13ace0..c149741d86 100644
--- a/rbutil/rbutilqt/configure.cpp
+++ b/rbutil/rbutilqt/configure.cpp
@@ -25,7 +25,7 @@
25#include "browsedirtree.h" 25#include "browsedirtree.h"
26#include "encoders.h" 26#include "encoders.h"
27#include "tts.h" 27#include "tts.h"
28#include "utils.h" 28#include "detect.h"
29 29
30#include <stdio.h> 30#include <stdio.h>
31#if defined(Q_OS_WIN32) 31#if defined(Q_OS_WIN32)
@@ -361,7 +361,7 @@ void Config::setSystemProxy(bool checked)
361 proxy.setHost(ui.proxyHost->text()); 361 proxy.setHost(ui.proxyHost->text());
362 proxy.setPort(ui.proxyPort->text().toInt()); 362 proxy.setPort(ui.proxyPort->text().toInt());
363 // show system values in input box 363 // show system values in input box
364 QUrl envproxy = systemProxy(); 364 QUrl envproxy = Detect::systemProxy();
365 365
366 ui.proxyHost->setText(envproxy.host()); 366 ui.proxyHost->setText(envproxy.host());
367 367
diff --git a/rbutil/rbutilqt/install.cpp b/rbutil/rbutilqt/install.cpp
index 8ee1dc1ff5..d45b374f70 100644
--- a/rbutil/rbutilqt/install.cpp
+++ b/rbutil/rbutilqt/install.cpp
@@ -20,7 +20,7 @@
20#include "install.h" 20#include "install.h"
21#include "ui_installfrm.h" 21#include "ui_installfrm.h"
22#include "rbzip.h" 22#include "rbzip.h"
23#include "utils.h" 23#include "detect.h"
24 24
25Install::Install(RbSettings *sett,QWidget *parent) : QDialog(parent) 25Install::Install(RbSettings *sett,QWidget *parent) : QDialog(parent)
26{ 26{
@@ -35,7 +35,7 @@ Install::Install(RbSettings *sett,QWidget *parent) : QDialog(parent)
35 connect(ui.backup,SIGNAL(stateChanged(int)),this,SLOT(backupCheckboxChanged(int))); 35 connect(ui.backup,SIGNAL(stateChanged(int)),this,SLOT(backupCheckboxChanged(int)));
36 36
37 //! check if rockbox is already installed 37 //! check if rockbox is already installed
38 QString version = installedVersion(settings->mountpoint()); 38 QString version = Detect::installedVersion(settings->mountpoint());
39 39
40 if(version != "") 40 if(version != "")
41 { 41 {
@@ -120,23 +120,13 @@ void Install::accept()
120 return; 120 return;
121 } 121 }
122 settings->sync(); 122 settings->sync();
123 123
124 int rbTarget = installedTargetId(settings->mountpoint()); 124 if(Detect::check(settings,false,settings->curTargetId()) == false)
125 if(rbTarget != -1 && rbTarget != settings->curTargetId())
126 { 125 {
127 if(QMessageBox::question(this, tr("Device mismatch detected"), 126 logger->addItem(tr("Aborted!"),LOGERROR);
128 tr("Device mismatch detected.\n\n" 127 logger->abort();
129 "Installed Rockbox is for Device: %1.\n" 128 return;
130 "New Rockbox is for Device: %2.\n\n" 129 }
131 "Do you want to continue?").arg(settings->nameOfTargetId(rbTarget),settings->curName()),
132 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
133 {
134 logger->addItem(tr("Aborted!"),LOGERROR);
135 logger->abort();
136 return;
137 }
138 }
139
140 130
141 //! check if we should backup 131 //! check if we should backup
142 if(ui.backup->isChecked()) 132 if(ui.backup->isChecked())
diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp
index 461d45f076..b5e485c57c 100644
--- a/rbutil/rbutilqt/rbutilqt.cpp
+++ b/rbutil/rbutilqt/rbutilqt.cpp
@@ -35,7 +35,7 @@
35#include "utils.h" 35#include "utils.h"
36#include "rbzip.h" 36#include "rbzip.h"
37#include "sysinfo.h" 37#include "sysinfo.h"
38 38#include "detect.h"
39 39
40#if defined(Q_OS_LINUX) 40#if defined(Q_OS_LINUX)
41#include <stdio.h> 41#include <stdio.h>
@@ -266,7 +266,7 @@ void RbUtilQt::updateSettings()
266 updateDevice(); 266 updateDevice();
267 updateManual(); 267 updateManual();
268 if(settings->proxyType() == "system") { 268 if(settings->proxyType() == "system") {
269 HttpGet::setGlobalProxy(systemProxy()); 269 HttpGet::setGlobalProxy(Detect::systemProxy());
270 } 270 }
271 else if(settings->proxyType() == "manual") { 271 else if(settings->proxyType() == "manual") {
272 HttpGet::setGlobalProxy(settings->proxy()); 272 HttpGet::setGlobalProxy(settings->proxy());
@@ -475,23 +475,15 @@ bool RbUtilQt::installAuto()
475 QString myversion = "r" + versmap.value("bleed_rev"); 475 QString myversion = "r" + versmap.value("bleed_rev");
476 476
477 // check installed Version and Target 477 // check installed Version and Target
478 QString rbVersion = installedVersion(settings->mountpoint()); 478 QString rbVersion = Detect::installedVersion(settings->mountpoint());
479 int rbTarget = installedTargetId(settings->mountpoint()); 479
480 if(rbTarget != -1 && rbTarget != settings->curTargetId()) 480 if(Detect::check(settings,false,settings->curTargetId()) == false)
481 { 481 {
482 if(QMessageBox::question(this, tr("Target mismatch detected"), 482 logger->addItem(tr("Aborted!"),LOGERROR);
483 tr("Target mismatch detected. \n\n" 483 logger->abort();
484 "Installed target: %1.\n" 484 return false;
485 "New Target: %2.\n\n"
486 "Do you want to continue?").arg(settings->nameOfTargetId(rbTarget),settings->curName()),
487 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
488 {
489 logger->addItem(tr("Aborted!"),LOGERROR);
490 logger->abort();
491 return false;
492 }
493 } 485 }
494 486
495 // check version 487 // check version
496 if(rbVersion != "") 488 if(rbVersion != "")
497 { 489 {
@@ -1001,7 +993,7 @@ QUrl RbUtilQt::proxy()
1001 return QUrl(settings->proxy()); 993 return QUrl(settings->proxy());
1002 else if(settings->proxy() == "system") 994 else if(settings->proxy() == "system")
1003 { 995 {
1004 return systemProxy(); 996 return Detect::systemProxy();
1005 } 997 }
1006 return QUrl(""); 998 return QUrl("");
1007} 999}
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro
index 9be9197f22..aebdca268c 100644
--- a/rbutil/rbutilqt/rbutilqt.pro
+++ b/rbutil/rbutilqt/rbutilqt.pro
@@ -65,7 +65,8 @@ SOURCES += rbutilqt.cpp \
65 rbsettings.cpp \ 65 rbsettings.cpp \
66 rbunzip.cpp \ 66 rbunzip.cpp \
67 rbzip.cpp \ 67 rbzip.cpp \
68 sysinfo.cpp 68 sysinfo.cpp \
69 detect.cpp
69 70
70HEADERS += rbutilqt.h \ 71HEADERS += rbutilqt.h \
71 install.h \ 72 install.h \
@@ -113,7 +114,8 @@ HEADERS += rbutilqt.h \
113 rbsettings.h \ 114 rbsettings.h \
114 rbunzip.h \ 115 rbunzip.h \
115 rbzip.h \ 116 rbzip.h \
116 sysinfo.h 117 sysinfo.h \
118 detect.h
117 119
118# Needed by QT on Win 120# Needed by QT on Win
119INCLUDEPATH = . irivertools zip zlib ../ipodpatcher ../sansapatcher ../../tools/rbspeex ../../tools 121INCLUDEPATH = . irivertools zip zlib ../ipodpatcher ../sansapatcher ../../tools/rbspeex ../../tools
diff --git a/rbutil/rbutilqt/sysinfo.cpp b/rbutil/rbutilqt/sysinfo.cpp
index 413494c679..4cd2666e8b 100644
--- a/rbutil/rbutilqt/sysinfo.cpp
+++ b/rbutil/rbutilqt/sysinfo.cpp
@@ -20,7 +20,7 @@
20#include <QtGui> 20#include <QtGui>
21#include "sysinfo.h" 21#include "sysinfo.h"
22#include "ui_sysinfofrm.h" 22#include "ui_sysinfofrm.h"
23#include "utils.h" 23#include "detect.h"
24 24
25 25
26Sysinfo::Sysinfo(QWidget *parent) : QDialog(parent) 26Sysinfo::Sysinfo(QWidget *parent) : QDialog(parent)
@@ -33,17 +33,16 @@ Sysinfo::Sysinfo(QWidget *parent) : QDialog(parent)
33 connect(ui.buttonRefresh, SIGNAL(clicked()), this, SLOT(updateSysinfo())); 33 connect(ui.buttonRefresh, SIGNAL(clicked()), this, SLOT(updateSysinfo()));
34} 34}
35 35
36
37void Sysinfo::updateSysinfo(void) 36void Sysinfo::updateSysinfo(void)
38{ 37{
39 QString info; 38 QString info;
40 info += tr("<b>OS</b><br/>") + getOsVersionString() + "<hr/>"; 39 info += tr("<b>OS</b><br/>") + Detect::osVersionString() + "<hr/>";
41 info += tr("<b>Username:</b><br/>%1<hr/>").arg(getUserName()); 40 info += tr("<b>Username:</b><br/>%1<hr/>").arg(Detect::userName());
42#if defined(Q_OS_WIN32) 41#if defined(Q_OS_WIN32)
43 info += tr("<b>Permissions:</b><br/>%1<hr/>").arg(getUserPermissionsString()); 42 info += tr("<b>Permissions:</b><br/>%1<hr/>").arg(Detect::userPermissionsString());
44#endif 43#endif
45 info += tr("<b>Attached USB devices:</b><br/>"); 44 info += tr("<b>Attached USB devices:</b><br/>");
46 QList<uint32_t> usbids = listUsbIds(); 45 QList<uint32_t> usbids = Detect::listUsbIds();
47 for(int i = 0; i < usbids.size(); i++) 46 for(int i = 0; i < usbids.size(); i++)
48 info += tr("VID: %1 PID: %2<br/>") 47 info += tr("VID: %1 PID: %2<br/>")
49 .arg((usbids.at(i)&0xffff0000)>>16, 4, 16, QChar('0')) 48 .arg((usbids.at(i)&0xffff0000)>>16, 4, 16, QChar('0'))
diff --git a/rbutil/rbutilqt/utils.cpp b/rbutil/rbutilqt/utils.cpp
index 9359522f04..236f28babd 100644
--- a/rbutil/rbutilqt/utils.cpp
+++ b/rbutil/rbutilqt/utils.cpp
@@ -24,37 +24,6 @@
24#include <cstdlib> 24#include <cstdlib>
25#include <stdio.h> 25#include <stdio.h>
26 26
27#if defined(Q_OS_WIN32)
28#if defined(UNICODE)
29#define _UNICODE
30#endif
31#include <windows.h>
32#include <tchar.h>
33#include <lm.h>
34#endif
35#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
36#include <usb.h>
37#include <sys/utsname.h>
38#include <unistd.h>
39#include <pwd.h>
40#endif
41#if defined(Q_OS_LINUX)
42#include <mntent.h>
43#endif
44#if defined(Q_OS_MACX)
45#include <sys/param.h>
46#include <sys/ucred.h>
47#include <sys/mount.h>
48#endif
49#if defined(Q_OS_WIN32)
50#if defined(UNICODE)
51#define _UNICODE
52#endif
53#include <tchar.h>
54#include <windows.h>
55#include <setupapi.h>
56#endif
57
58// recursive function to delete a dir with files 27// recursive function to delete a dir with files
59bool recRmdir( const QString &dirName ) 28bool recRmdir( const QString &dirName )
60{ 29{
@@ -122,278 +91,3 @@ QString resolvePathCase(QString path)
122} 91}
123 92
124 93
125//! @brief get system proxy value.
126QUrl systemProxy(void)
127{
128#if defined(Q_OS_LINUX)
129 return QUrl(getenv("http_proxy"));
130#elif defined(Q_OS_WIN32)
131 HKEY hk;
132 wchar_t proxyval[80];
133 DWORD buflen = 80;
134 long ret;
135 DWORD enable;
136 DWORD enalen = sizeof(DWORD);
137
138 ret = RegOpenKeyEx(HKEY_CURRENT_USER,
139 _TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
140 0, KEY_QUERY_VALUE, &hk);
141 if(ret != ERROR_SUCCESS) return QUrl("");
142
143 ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
144 if(ret != ERROR_SUCCESS) return QUrl("");
145
146 ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen);
147 if(ret != ERROR_SUCCESS) return QUrl("");
148
149 RegCloseKey(hk);
150
151 //qDebug() << QString::fromWCharArray(proxyval) << QString("%1").arg(enable);
152 if(enable != 0)
153 return QUrl("http://" + QString::fromWCharArray(proxyval));
154 else
155 return QUrl("");
156#else
157 return QUrl("");
158#endif
159}
160
161QString installedVersion(QString mountpoint)
162{
163 // read rockbox-info.txt
164 QFile info(mountpoint +"/.rockbox/rockbox-info.txt");
165 if(!info.open(QIODevice::ReadOnly))
166 {
167 return "";
168 }
169
170 QString target, features,version;
171 while (!info.atEnd()) {
172 QString line = info.readLine();
173
174 if(line.contains("Version:"))
175 {
176 return line.remove("Version:").trimmed();
177 }
178 }
179 info.close();
180 return "";
181}
182
183int installedTargetId(QString mountpoint)
184{
185 // read rockbox-info.txt
186 QFile info(mountpoint +"/.rockbox/rockbox-info.txt");
187 if(!info.open(QIODevice::ReadOnly))
188 {
189 return -1;
190 }
191
192 QString target, features,version;
193 while (!info.atEnd()) {
194 QString line = info.readLine();
195
196 if(line.contains("Target id:"))
197 {
198 return line.remove("Target id:").trimmed().toInt();
199 }
200 }
201 info.close();
202 return -1;
203
204}
205
206QString getUserName(void)
207{
208#if defined(Q_OS_WIN32)
209 wchar_t userbuf[UNLEN];
210 DWORD usersize = UNLEN;
211 BOOL status;
212
213 status = GetUserNameW(userbuf, &usersize);
214
215 return QString::fromWCharArray(userbuf);
216#endif
217#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
218 struct passwd *user;
219 user = getpwuid(geteuid());
220 return QString(user->pw_name);
221#endif
222}
223
224
225#if defined(Q_OS_WIN32)
226enum userlevel getUserPermissions(void)
227{
228 LPUSER_INFO_1 buf;
229 NET_API_STATUS napistatus;
230 wchar_t userbuf[UNLEN];
231 DWORD usersize = UNLEN;
232 BOOL status;
233 enum userlevel result;
234
235 status = GetUserNameW(userbuf, &usersize);
236 if(!status)
237 return ERR;
238
239 napistatus = NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf);
240
241 switch(buf->usri1_priv) {
242 case USER_PRIV_GUEST:
243 result = GUEST;
244 break;
245 case USER_PRIV_USER:
246 result = USER;
247 break;
248 case USER_PRIV_ADMIN:
249 result = ADMIN;
250 break;
251 default:
252 result = ERR;
253 break;
254 }
255 NetApiBufferFree(buf);
256
257 return result;
258}
259
260QString getUserPermissionsString(void)
261{
262 QString result;
263 int perm = getUserPermissions();
264 switch(perm) {
265 case GUEST:
266 result = QObject::tr("Guest");
267 break;
268 case ADMIN:
269 result = QObject::tr("Admin");
270 break;
271 case USER:
272 result = QObject::tr("User");
273 break;
274 default:
275 result = QObject::tr("Error");
276 break;
277 }
278 return result;
279}
280#endif
281
282QString getOsVersionString(void)
283{
284 QString result;
285#if defined(Q_OS_WIN32)
286 OSVERSIONINFO osvi;
287 ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
288 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
289 GetVersionEx(&osvi);
290
291 result = QString("Windows version %1.%2, ").arg(osvi.dwMajorVersion).arg(osvi.dwMinorVersion);
292 result += QString("build %1 (%2)").arg(osvi.dwBuildNumber).arg(QString::fromWCharArray(osvi.szCSDVersion));
293#endif
294#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
295 struct utsname u;
296 int ret;
297 ret = uname(&u);
298
299 result = QString("CPU: %1<br/>System: %2<br/>Release: %3<br/>Version: %4")
300 .arg(u.machine).arg(u.sysname).arg(u.release).arg(u.version);
301#endif
302 return result;
303
304}
305
306/** @brief detect devices based on usb pid / vid.
307 * @return list with usb VID / PID values.
308 */
309QList<uint32_t> listUsbIds(void)
310{
311 QList<uint32_t> usbids;
312 // usb pid detection
313#if defined(Q_OS_LINUX) | defined(Q_OS_MACX)
314 usb_init();
315 usb_find_busses();
316 usb_find_devices();
317 struct usb_bus *b;
318 b = usb_busses;
319
320 while(b) {
321 qDebug() << "bus:" << b->dirname << b->devices;
322 if(b->devices) {
323 qDebug() << "devices present.";
324 struct usb_device *u;
325 u = b->devices;
326 while(u) {
327 uint32_t id;
328 id = u->descriptor.idVendor << 16 | u->descriptor.idProduct;
329 if(id) usbids.append(id);
330 u = u->next;
331 }
332 }
333 b = b->next;
334 }
335#endif
336
337#if defined(Q_OS_WIN32)
338 HDEVINFO deviceInfo;
339 SP_DEVINFO_DATA infoData;
340 DWORD i;
341
342 // Iterate over all devices
343 // by doing it this way it's unneccessary to use GUIDs which might be not
344 // present in current MinGW. It also seemed to be more reliably than using
345 // a GUID.
346 // See KB259695 for an example.
347 deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
348
349 infoData.cbSize = sizeof(SP_DEVINFO_DATA);
350
351 for(i = 0; SetupDiEnumDeviceInfo(deviceInfo, i, &infoData); i++) {
352 DWORD data;
353 LPTSTR buffer = NULL;
354 DWORD buffersize = 0;
355
356 // get device desriptor first
357 // for some reason not doing so results in bad things (tm)
358 while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
359 SPDRP_DEVICEDESC,&data, (PBYTE)buffer, buffersize, &buffersize)) {
360 if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
361 if(buffer) free(buffer);
362 // double buffer size to avoid problems as per KB888609
363 buffer = (LPTSTR)malloc(buffersize * 2);
364 }
365 else {
366 break;
367 }
368 }
369
370 // now get the hardware id, which contains PID and VID.
371 while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
372 SPDRP_HARDWAREID,&data, (PBYTE)buffer, buffersize, &buffersize)) {
373 if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
374 if(buffer) free(buffer);
375 // double buffer size to avoid problems as per KB888609
376 buffer = (LPTSTR)malloc(buffersize * 2);
377 }
378 else {
379 break;
380 }
381 }
382
383 unsigned int vid, pid, rev;
384 if(_stscanf(buffer, _TEXT("USB\\Vid_%x&Pid_%x&Rev_%x"), &vid, &pid, &rev) != 3) {
385 qDebug() << "Error getting USB ID -- possibly no USB device";
386 }
387 else {
388 uint32_t id;
389 id = vid << 16 | pid;
390 usbids.append(id);
391 qDebug("VID: %04x PID: %04x", vid, pid);
392 }
393 if(buffer) free(buffer);
394 }
395 SetupDiDestroyDeviceInfoList(deviceInfo);
396
397#endif
398 return usbids;
399}
diff --git a/rbutil/rbutilqt/utils.h b/rbutil/rbutilqt/utils.h
index b4d660520e..ba8b97f6b7 100644
--- a/rbutil/rbutilqt/utils.h
+++ b/rbutil/rbutilqt/utils.h
@@ -24,21 +24,8 @@
24#include <QString> 24#include <QString>
25#include <QUrl> 25#include <QUrl>
26 26
27#if defined(Q_OS_WIN32)
28enum userlevel { ERR, GUEST, USER, ADMIN };
29enum userlevel getUserPermissions(void);
30QString getUserPermissionsString(void);
31#endif
32QString getUserName(void);
33QString getOsVersionString(void);
34QList<uint32_t> listUsbIds(void);
35
36bool recRmdir( const QString &dirName ); 27bool recRmdir( const QString &dirName );
37QString resolvePathCase(QString path); 28QString resolvePathCase(QString path);
38 29
39QUrl systemProxy(void);
40QString installedVersion(QString mountpoint);
41int installedTargetId(QString mountpoint);
42
43#endif 30#endif
44 31