summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base/utils.cpp
diff options
context:
space:
mode:
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 @@
51#include <windows.h> 51#include <windows.h>
52#include <setupapi.h> 52#include <setupapi.h>
53#include <winioctl.h> 53#include <winioctl.h>
54#include <tlhelp32.h>
54#endif 55#endif
55#if defined(Q_OS_MACX) 56#if defined(Q_OS_MACX)
56#include <CoreFoundation/CoreFoundation.h> 57#include <CoreFoundation/CoreFoundation.h>
@@ -606,3 +607,58 @@ QStringList Utils::mountpoints()
606} 607}
607 608
608 609
610/** Check if a process with a given name is running
611 * @param names list of names to check
612 * @return list of detected processes.
613 */
614QStringList Utils::findRunningProcess(QStringList names)
615{
616 QStringList processlist;
617 QStringList found;
618#if defined(Q_OS_WIN32)
619 HANDLE hdl;
620 PROCESSENTRY32 entry;
621 bool result;
622
623 hdl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
624 if(hdl == INVALID_HANDLE_VALUE) {
625 qDebug() << "[Utils] CreateToolhelp32Snapshot failed.";
626 return found;
627 }
628 entry.dwSize = sizeof(PROCESSENTRY32);
629 entry.szExeFile[0] = '\0';
630 if(!Process32First(hdl, &entry)) {
631 qDebug() << "[Utils] Process32First failed.";
632 return found;
633 }
634
635 processlist.append(QString::fromWCharArray(entry.szExeFile));
636 do {
637 entry.dwSize = sizeof(PROCESSENTRY32);
638 entry.szExeFile[0] = '\0';
639 result = Process32Next(hdl, &entry);
640 if(result) {
641 processlist.append(QString::fromWCharArray(entry.szExeFile));
642 }
643 } while(result);
644 CloseHandle(hdl);
645 qDebug() << processlist;
646#endif
647#if defined(Q_OS_MACX)
648
649#endif
650 // check for given names in list of processes
651 for(int i = 0; i < names.size(); ++i) {
652#if defined(Q_OS_WIN32)
653 // the process name might be truncated. Allow the extension to be partial.
654 int index = processlist.indexOf(QRegExp(names.at(i) + "(\\.(e(x(e?)?)?)?)?"));
655#else
656 int index = processlist.indexOf(names.at(i));
657#endif
658 if(index != -1) {
659 found.append(processlist.at(index));
660 }
661 }
662 qDebug() << "[Utils] Found listed processes running:" << found;
663 return found;
664}