summaryrefslogtreecommitdiff
path: root/src/organizercore.cpp
diff options
context:
space:
mode:
authorTannin <sherb@gmx.net>2016-02-09 20:54:54 +0100
committerTannin <sherb@gmx.net>2016-02-09 20:54:54 +0100
commit8d1dd6238f8d754aef1385409f4f97273a0d226f (patch)
treebedcdfd26a20fcd29ba20c365f15aec24bf3aac4 /src/organizercore.cpp
parentaaa1f52bddfe87bdba1ec4acd44fdf08de5a0377 (diff)
fixed display of process name in unlock-widget
Diffstat (limited to 'src/organizercore.cpp')
-rw-r--r--src/organizercore.cpp61
1 files changed, 40 insertions, 21 deletions
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index d39235f5..ecadfb5d 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -978,40 +978,59 @@ void OrganizerCore::spawnBinary(const QFileInfo &binary,
QCoreApplication::processEvents();
DWORD processExitCode;
- DWORD retLen;
- JOBOBJECT_BASIC_PROCESS_ID_LIST info;
+
+ dialog->setProcessName(
+ QString::fromStdWString(getProcessName(::GetProcessId(processHandle))));
{
DWORD currentProcess = 0UL;
- bool isJobHandle = true;
- DWORD res = ::MsgWaitForMultipleObjects(1, &processHandle, false, 1000, QS_KEY | QS_MOUSE);
- while ((res != WAIT_FAILED) && (res != WAIT_OBJECT_0) && !dialog->unlockClicked()) {
- if (isJobHandle) {
- if (::QueryInformationJobObject(processHandle, JobObjectBasicProcessIdList, &info, sizeof(info), &retLen) > 0) {
- if (info.NumberOfProcessIdsInList == 0) {
- break;
- } else {
- if (info.ProcessIdList[0] != currentProcess) {
- currentProcess = info.ProcessIdList[0];
- dialog->setProcessName(ToQString(getProcessName(currentProcess)));
+ DWORD res = ::MsgWaitForMultipleObjects(1, &processHandle, false, 1000,
+ QS_KEY | QS_MOUSE);
+ bool tryAgain = true;
+ while ((res != WAIT_FAILED) && !dialog->unlockClicked()) {
+ if (res == WAIT_OBJECT_0) {
+ // process ended, is there another one in the group?
+ static const DWORD maxCount = 5;
+ size_t numProcesses = maxCount;
+ LPDWORD processes = new DWORD[maxCount];
+ if (::GetVFSProcessList(&numProcesses, processes)) {
+ bool found = false;
+ for (size_t i = 0; i < std::min<DWORD>(maxCount, numProcesses);
+ ++i) {
+ std::wstring processName = getProcessName(processes[i]);
+ if (!boost::starts_with(processName, L"ModOrganizer.exe")) {
+ currentProcess = processes[i];
+ dialog->setProcessName(QString::fromStdWString(processName));
+ processHandle
+ = ::OpenProcess(SYNCHRONIZE, FALSE, currentProcess);
+ found = true;
}
}
- } else {
- // the info-object I passed only provides space for 1 process id. but since this code only cares about whether there
- // is more than one that's good enough. ERROR_MORE_DATA simply signals there are at least two processes running.
- // any other error probably means the handle is a regular process handle, probably caused by running MO in a job without
- // the right to break out.
- if (::GetLastError() != ERROR_MORE_DATA) {
- isJobHandle = false;
+ if (!found) {
+ // it's possible the previous process has deregistered before
+ // the new one has registered, so we should try one more time
+ // with a little delay
+ if (tryAgain) {
+ tryAgain = false;
+ QThread::msleep(500);
+ continue;
+ } else {
+ break;
+ }
+ } else {
+ tryAgain = true;
}
+ } else {
+ break;
}
}
// keep processing events so the app doesn't appear dead
QCoreApplication::processEvents();
- res = ::MsgWaitForMultipleObjects(1, &processHandle, false, 1000, QS_KEY | QS_MOUSE);
+ res = ::MsgWaitForMultipleObjects(1, &processHandle, false, 1000,
+ QS_KEY | QS_MOUSE);
}
::GetExitCodeProcess(processHandle, &processExitCode);