summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/utils.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2012-01-22 22:23:49 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2012-01-22 22:26:01 +0100
commit250a73317f6933ab72e1557d479ee3f09412d135 (patch)
tree51e7095bd8b564454e5fa97c716141303212436d /rbutil/rbutilqt/base/utils.cpp
parent8a3af263641dfa6e6bd8f9dfe06654c4e27b094e (diff)
downloadrockbox-250a73317f6933ab72e1557d479ee3f09412d135.tar.gz
rockbox-250a73317f6933ab72e1557d479ee3f09412d135.tar.bz2
rockbox-250a73317f6933ab72e1557d479ee3f09412d135.zip
Check running processes at startup.
Retrieve the processes running at startup and compare with a list of potentially problematic ones. Right now this is Itunes which is known to be able to cause problems when trying to install the bootloader on an Ipod. No user notification yet. This adds the implementation for Windows. Change-Id: I5ce8a85da52e0ed8f523b5ae6fb5d8f14f6a14c9
Diffstat (limited to 'rbutil/rbutilqt/base/utils.cpp')
-rw-r--r--rbutil/rbutilqt/base/utils.cpp56
1 files changed, 56 insertions, 0 deletions
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 <windows.h>
#include <setupapi.h>
#include <winioctl.h>
+#include <tlhelp32.h>
#endif
#if defined(Q_OS_MACX)
#include <CoreFoundation/CoreFoundation.h>
@@ -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;
+}