diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp index f91f3c25c2..7df5d28da9 100644 --- a/rbutil/rbutilqt/base/utils.cpp +++ b/rbutil/rbutilqt/base/utils.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #endif #if defined(Q_OS_MACX) #include @@ -606,3 +607,58 @@ QStringList Utils::mountpoints() } +/** Check if a process with a given name is running + * @param names list of names to check + * @return list of detected processes. + */ +QStringList Utils::findRunningProcess(QStringList names) +{ + QStringList processlist; + QStringList found; +#if defined(Q_OS_WIN32) + HANDLE hdl; + PROCESSENTRY32 entry; + bool result; + + hdl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if(hdl == INVALID_HANDLE_VALUE) { + qDebug() << "[Utils] CreateToolhelp32Snapshot failed."; + return found; + } + entry.dwSize = sizeof(PROCESSENTRY32); + entry.szExeFile[0] = '\0'; + if(!Process32First(hdl, &entry)) { + qDebug() << "[Utils] Process32First failed."; + return found; + } + + processlist.append(QString::fromWCharArray(entry.szExeFile)); + do { + entry.dwSize = sizeof(PROCESSENTRY32); + entry.szExeFile[0] = '\0'; + result = Process32Next(hdl, &entry); + if(result) { + processlist.append(QString::fromWCharArray(entry.szExeFile)); + } + } while(result); + CloseHandle(hdl); + qDebug() << processlist; +#endif +#if defined(Q_OS_MACX) + +#endif + // check for given names in list of processes + for(int i = 0; i < names.size(); ++i) { +#if defined(Q_OS_WIN32) + // the process name might be truncated. Allow the extension to be partial. + int index = processlist.indexOf(QRegExp(names.at(i) + "(\\.(e(x(e?)?)?)?)?")); +#else + int index = processlist.indexOf(names.at(i)); +#endif + if(index != -1) { + found.append(processlist.at(index)); + } + } + qDebug() << "[Utils] Found listed processes running:" << found; + return found; +} diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h index aeff1e36c3..185c0323a6 100644 --- a/rbutil/rbutilqt/base/utils.h +++ b/rbutil/rbutilqt/base/utils.h @@ -49,6 +49,7 @@ public: static QStringList mountpoints(void); static QString resolveDevicename(QString path); static QString resolveMountPoint(QString device); + static QStringList findRunningProcess(QStringList names); }; #endif diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index 958550e880..cb991a21b7 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp @@ -170,6 +170,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent) #else connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable())); #endif + Utils::findRunningProcess(QStringList("iTunes")); }