forked from len0rd/rockbox
Add System Info screen showing some values that could be helpful in case of problems using rbutil. Most noteable is showing the permission level of the user on windows.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17736 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
5b2d06ad51
commit
1876a0bcf2
12 changed files with 436 additions and 134 deletions
|
|
@ -40,6 +40,7 @@
|
|||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
#endif
|
||||
#include "utils.h"
|
||||
|
||||
Autodetection::Autodetection(QObject* parent): QObject(parent)
|
||||
{
|
||||
|
|
@ -265,132 +266,27 @@ bool Autodetection::detectUsb()
|
|||
QMap<int, QString> usbincompat = settings->usbIdIncompatMap();
|
||||
|
||||
// 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_get_busses();
|
||||
QList<uint32_t> attached;
|
||||
attached = listUsbIds();
|
||||
|
||||
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;
|
||||
m_usbconid.append(id);
|
||||
qDebug("%x", id);
|
||||
|
||||
if(usbids.contains(id)) {
|
||||
m_device = usbids.value(id);
|
||||
int i = attached.size();
|
||||
while(i--) {
|
||||
if(usbids.contains(attached.at(i))) {
|
||||
m_device = usbids.value(attached.at(i));
|
||||
qDebug() << "[USB] detected supported player" << m_device;
|
||||
return true;
|
||||
}
|
||||
if(usberror.contains(id)) {
|
||||
m_errdev = usberror.value(id);
|
||||
// we detected something, so return true
|
||||
qDebug() << "detected device with problems via usb!";
|
||||
if(usberror.contains(attached.at(i))) {
|
||||
m_errdev = usberror.value(attached.at(i));
|
||||
qDebug() << "[USB] detected problem with player" << m_errdev;
|
||||
return true;
|
||||
}
|
||||
if(usbincompat.contains(id)) {
|
||||
m_incompat = usbincompat.value(id);
|
||||
qDebug() << "detected incompatible player variant";
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
|
||||
// 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_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) {
|
||||
qDebug() << "Error getting USB ID -- possibly no USB device";
|
||||
}
|
||||
else {
|
||||
uint32_t id;
|
||||
id = vid << 16 | pid;
|
||||
m_usbconid.append(id);
|
||||
qDebug("VID: %04x PID: %04x", vid, pid);
|
||||
if(usbids.contains(id)) {
|
||||
m_device = usbids.value(id);
|
||||
if(buffer) free(buffer);
|
||||
SetupDiDestroyDeviceInfoList(deviceInfo);
|
||||
qDebug() << "detectUsb: Got" << m_device;
|
||||
return true;
|
||||
}
|
||||
if(usberror.contains(id)) {
|
||||
m_errdev = usberror.value(id);
|
||||
// we detected something, so return true
|
||||
if(buffer) free(buffer);
|
||||
SetupDiDestroyDeviceInfoList(deviceInfo);
|
||||
qDebug() << "detectUsb: Got" << m_device;
|
||||
qDebug() << "detected device with problems via usb!";
|
||||
return true;
|
||||
}
|
||||
if(usbincompat.contains(id)) {
|
||||
m_incompat = usbincompat.value(id);
|
||||
// we detected an incompatible player variant
|
||||
if(buffer) free(buffer);
|
||||
SetupDiDestroyDeviceInfoList(deviceInfo);
|
||||
qDebug() << "detectUsb: detected incompatible variant";
|
||||
if(usbincompat.contains(attached.at(i))) {
|
||||
m_incompat = usbincompat.value(attached.at(i));
|
||||
qDebug() << "[USB] detected incompatible player" << m_incompat;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(buffer) free(buffer);
|
||||
}
|
||||
SetupDiDestroyDeviceInfoList(deviceInfo);
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
BIN
rbutil/rbutilqt/icons/view-refresh.png
Normal file
BIN
rbutil/rbutilqt/icons/view-refresh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 912 B |
|
|
@ -34,6 +34,8 @@
|
|||
#include "browseof.h"
|
||||
#include "utils.h"
|
||||
#include "rbzip.h"
|
||||
#include "sysinfo.h"
|
||||
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
#include <stdio.h>
|
||||
|
|
@ -101,6 +103,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
|
|||
connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
|
||||
connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
|
||||
connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
|
||||
connect(ui.action_System_Info, SIGNAL(triggered()), this, SLOT(sysinfo()));
|
||||
|
||||
#if !defined(STATIC)
|
||||
ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
|
||||
|
|
@ -115,6 +118,12 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
|
|||
}
|
||||
|
||||
|
||||
void RbUtilQt::sysinfo(void)
|
||||
{
|
||||
Sysinfo *info = new Sysinfo(this);
|
||||
info->show();
|
||||
}
|
||||
|
||||
void RbUtilQt::updateTabs(int count)
|
||||
{
|
||||
switch(count) {
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class RbUtilQt : public QMainWindow
|
|||
private slots:
|
||||
void about(void);
|
||||
void help(void);
|
||||
void sysinfo(void);
|
||||
void configDialog(void);
|
||||
void updateDevice(void);
|
||||
void updateSettings(void);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ SOURCES += rbutilqt.cpp \
|
|||
createvoicewindow.cpp \
|
||||
rbsettings.cpp \
|
||||
rbunzip.cpp \
|
||||
rbzip.cpp
|
||||
rbzip.cpp \
|
||||
sysinfo.cpp
|
||||
|
||||
HEADERS += rbutilqt.h \
|
||||
install.h \
|
||||
|
|
@ -109,7 +110,8 @@ HEADERS += rbutilqt.h \
|
|||
createvoicewindow.h \
|
||||
rbsettings.h \
|
||||
rbunzip.h \
|
||||
rbzip.h
|
||||
rbzip.h \
|
||||
sysinfo.h
|
||||
|
||||
# Needed by QT on Win
|
||||
INCLUDEPATH = . irivertools zip zlib ../ipodpatcher ../sansapatcher ../../tools/rbspeex ../../tools
|
||||
|
|
@ -145,7 +147,8 @@ FORMS += rbutilqtfrm.ui \
|
|||
encexescfgfrm.ui \
|
||||
ttsexescfgfrm.ui \
|
||||
sapicfgfrm.ui \
|
||||
createvoicefrm.ui
|
||||
createvoicefrm.ui \
|
||||
sysinfofrm.ui
|
||||
|
||||
RESOURCES += rbutilqt.qrc
|
||||
win32 {
|
||||
|
|
@ -164,7 +167,7 @@ win32 {
|
|||
SOURCES += ../ipodpatcher/ipodio-win32.c
|
||||
SOURCES += ../sansapatcher/sansaio-win32.c
|
||||
RC_FILE = rbutilqt.rc
|
||||
LIBS += -lsetupapi
|
||||
LIBS += -lsetupapi -lnetapi32
|
||||
}
|
||||
|
||||
unix {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
<file>icons/talkfile_btn.png</file>
|
||||
<file>icons/themes_btn.png</file>
|
||||
<file>icons/user-trash-full.png</file>
|
||||
<file>icons/view-refresh.png</file>
|
||||
<file>icons/wizard.xpm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/ini" >
|
||||
|
|
|
|||
|
|
@ -94,9 +94,9 @@
|
|||
<item row="0" column="1" >
|
||||
<widget class="QLabel" name="labelDevice" >
|
||||
<property name="text" >
|
||||
<string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">none</span> at <span style=" font-weight:600;">unknown</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
|
|
@ -539,7 +539,7 @@ p, li { white-space: pre-wrap; }
|
|||
<item row="1" column="1" >
|
||||
<widget class="QLabel" name="labelCreateVoice" >
|
||||
<property name="text" >
|
||||
<string><b>Create Voice file</b><br/>Voice files are needed to make Rockbox speak the user interface. Speaking is enabled by default, so
|
||||
<string><b>Create Voice file</b><br/>Voice files are needed to make Rockbox speak the user interface. Speaking is enabled by default, so
|
||||
if you installed the voice file Rockbox will speak.</string>
|
||||
</property>
|
||||
<property name="wordWrap" >
|
||||
|
|
@ -806,6 +806,7 @@ p, li { white-space: pre-wrap; }
|
|||
<addaction name="action_About" />
|
||||
<addaction name="actionAbout_Qt" />
|
||||
<addaction name="separator" />
|
||||
<addaction name="action_System_Info" />
|
||||
<addaction name="action_Help" />
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuA_ctions" >
|
||||
|
|
@ -1022,6 +1023,11 @@ p, li { white-space: pre-wrap; }
|
|||
<string>Create Voice File</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_System_Info" >
|
||||
<property name="text" >
|
||||
<string>&System Info</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
|
|
|
|||
54
rbutil/rbutilqt/sysinfo.cpp
Normal file
54
rbutil/rbutilqt/sysinfo.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2007 by Dominik Riebeling
|
||||
* $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 <QtGui>
|
||||
#include "sysinfo.h"
|
||||
#include "ui_sysinfofrm.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
Sysinfo::Sysinfo(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
this->setModal(true);
|
||||
|
||||
updateSysinfo();
|
||||
connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(close()));
|
||||
connect(ui.buttonRefresh, SIGNAL(clicked()), this, SLOT(updateSysinfo()));
|
||||
}
|
||||
|
||||
|
||||
void Sysinfo::updateSysinfo(void)
|
||||
{
|
||||
QString info;
|
||||
info += tr("<b>OS</b><br/>") + getOsVersionString() + "<hr/>";
|
||||
info += tr("<b>Username:</b><br/>%1<hr/>").arg(getUserName());
|
||||
#if defined(Q_OS_WIN32)
|
||||
info += tr("<b>Permissions:</b><br/>%1<hr/>").arg(getUserPermissionsString());
|
||||
#endif
|
||||
info += tr("<b>Attached USB devices:</b><br/>");
|
||||
QList<uint32_t> usbids = listUsbIds();
|
||||
for(int i = 0; i < usbids.size(); i++)
|
||||
info += tr("VID: %1 PID: %2<br/>")
|
||||
.arg((usbids.at(i)&0xffff0000)>>16, 4, 16, QChar('0'))
|
||||
.arg(usbids.at(i)&0xffff, 4, 16, QChar('0'));
|
||||
|
||||
ui.textBrowser->setHtml(info);
|
||||
}
|
||||
|
||||
42
rbutil/rbutilqt/sysinfo.h
Normal file
42
rbutil/rbutilqt/sysinfo.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2007 by Dominik Riebeling
|
||||
* $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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef SYSINFO_H
|
||||
#define SYSINFO_H
|
||||
|
||||
#include <QtGui>
|
||||
#include "ui_sysinfofrm.h"
|
||||
|
||||
class Sysinfo : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Sysinfo(QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
Ui::SysinfoFrm ui;
|
||||
|
||||
private slots:
|
||||
void updateSysinfo(void);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
66
rbutil/rbutilqt/sysinfofrm.ui
Normal file
66
rbutil/rbutilqt/sysinfofrm.ui
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<ui version="4.0" >
|
||||
<class>SysinfoFrm</class>
|
||||
<widget class="QWidget" name="SysinfoFrm" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>System Info</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" colspan="3" >
|
||||
<widget class="QTextBrowser" name="textBrowser" />
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QPushButton" name="buttonRefresh" >
|
||||
<property name="text" >
|
||||
<string>&Refresh</string>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="rbutilqt.qrc" >:/icons/view-refresh.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2" >
|
||||
<widget class="QPushButton" name="buttonOk" >
|
||||
<property name="text" >
|
||||
<string>&OK</string>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="rbutilqt.qrc" >:/icons/go-next.png</iconset>
|
||||
</property>
|
||||
<property name="default" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>buttonOk</tabstop>
|
||||
<tabstop>buttonRefresh</tabstop>
|
||||
<tabstop>textBrowser</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="rbutilqt.qrc" />
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -19,9 +19,10 @@
|
|||
|
||||
#include "utils.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QDebug>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <QDir>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
#if defined(UNICODE)
|
||||
|
|
@ -29,8 +30,29 @@
|
|||
#endif
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <lm.h>
|
||||
#endif
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
||||
#include <usb.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if defined(Q_OS_LINUX)
|
||||
#include <mntent.h>
|
||||
#endif
|
||||
#if defined(Q_OS_MACX)
|
||||
#include <sys/param.h>
|
||||
#include <sys/ucred.h>
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
#if defined(Q_OS_WIN32)
|
||||
#if defined(UNICODE)
|
||||
#define _UNICODE
|
||||
#endif
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
#endif
|
||||
#include <QDebug>
|
||||
|
||||
// recursive function to delete a dir with files
|
||||
bool recRmdir( const QString &dirName )
|
||||
|
|
@ -157,3 +179,196 @@ QString installedVersion(QString mountpoint)
|
|||
return "";
|
||||
}
|
||||
|
||||
|
||||
QString getUserName(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)
|
||||
return QString(getlogin());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
enum userlevel getUserPermissions(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;
|
||||
}
|
||||
|
||||
QString getUserPermissionsString(void)
|
||||
{
|
||||
QString result;
|
||||
int perm = getUserPermissions();
|
||||
switch(perm) {
|
||||
case GUEST:
|
||||
result = tr("Guest");
|
||||
break;
|
||||
case ADMIN:
|
||||
result = tr("Admin");
|
||||
break;
|
||||
case USER:
|
||||
result = tr("User");
|
||||
break;
|
||||
default:
|
||||
result = tr("Error");
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
QString getOsVersionString(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);
|
||||
result += QString("build %1 (%2)").arg(osvi.dwBuildNumber).arg(QString::fromWCharArray(osvi.szCSDVersion));
|
||||
#endif
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
||||
struct utsname u;
|
||||
int ret;
|
||||
ret = uname(&u);
|
||||
|
||||
result = QString("CPU: %1<br/>System: %2<br/>Release: %3<br/>Version: %4")
|
||||
.arg(u.machine).arg(u.sysname).arg(u.release).arg(u.version);
|
||||
#endif
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/** @brief detect devices based on usb pid / vid.
|
||||
* @return list with usb VID / PID values.
|
||||
*/
|
||||
QList<uint32_t> listUsbIds(void)
|
||||
{
|
||||
QList<uint32_t> 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;
|
||||
if(id) usbids.append(id);
|
||||
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;
|
||||
|
||||
// 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_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) {
|
||||
qDebug() << "Error getting USB ID -- possibly no USB device";
|
||||
}
|
||||
else {
|
||||
uint32_t id;
|
||||
id = vid << 16 | pid;
|
||||
usbids.append(id);
|
||||
qDebug("VID: %04x PID: %04x", vid, pid);
|
||||
}
|
||||
if(buffer) free(buffer);
|
||||
}
|
||||
SetupDiDestroyDeviceInfoList(deviceInfo);
|
||||
|
||||
#endif
|
||||
return usbids;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,15 @@
|
|||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
enum userlevel { ERR, GUEST, USER, ADMIN };
|
||||
enum userlevel getUserPermissions(void);
|
||||
QString getUserPermissionsString(void);
|
||||
#endif
|
||||
QString getUserName(void);
|
||||
QString getOsVersionString(void);
|
||||
QList<uint32_t> listUsbIds(void);
|
||||
|
||||
bool recRmdir( const QString &dirName );
|
||||
QString resolvePathCase(QString path);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue