From 2f1d270c08eb43f043e342accc64b1cd1bbff25f Mon Sep 17 00:00:00 2001 From: LePresidente Date: Tue, 31 Oct 2017 12:13:25 +0200 Subject: multiple fixes to waitForProcessCompletion. --- src/organizercore.cpp | 87 +++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 9ae8beae..cba92d8f 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -1265,48 +1265,53 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode) std::min(static_cast(maxCount), numProcesses); for (size_t i = 0; i < count; ++i) { std::wstring processName = getProcessName(processes[i]); - if (!boost::starts_with(processName, L"ModOrganizer.exe")){ - currentProcess = processes[i]; - m_UserInterface->setProcessName(QString::fromStdWString(processName)); - processHandle = ::OpenProcess(SYNCHRONIZE, FALSE, currentProcess); - found = true; - ::CloseHandle(processHandle); - } - } - 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; - } - // keep processing events so the app doesn't appear dead - - QCoreApplication::processEvents(); - - - if (exitCode != nullptr) { - //This is actually wrong if the process we started finished before we - //got the event and so we end up with a job handle. - if (! ::GetExitCodeProcess(processHandle, exitCode)) - { - DWORD error = ::GetLastError(); - qDebug() << "Failed to get process exit code: Error " << error; - } - } + if (!boost::starts_with(processName, L"ModOrganizer.exe")) { + currentProcess = processes[i]; + m_UserInterface->setProcessName(QString::fromStdWString(processName)); + processHandle = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, currentProcess); + found = true; + } + } + 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; + } + //Cleanup + if (processHandle != INVALID_HANDLE_VALUE) { + if (exitCode != nullptr) { + //This is actually wrong if the process we started finished before we + //got the event and so we end up with a job handle. + if (!::GetExitCodeProcess(processHandle, exitCode)) + { + DWORD error = ::GetLastError(); + qDebug() << "Failed to get process exit code: Error " << error; + } + } + if (handle != processHandle) { + ::CloseHandle(processHandle); + } + } - ::CloseHandle(processHandle); - if (handle != processHandle) { - ::CloseHandle(handle); - } - } + // keep processing events so the app doesn't appear dead + QCoreApplication::processEvents(); + } + //Final Cleanup + if (handle != INVALID_HANDLE_VALUE) { + ::CloseHandle(handle); + } + delete[] processes; return res == WAIT_OBJECT_0; } -- cgit v1.3.1 From 6c54ef5ec2a1b5395f4292fd33e4dcddf748a145 Mon Sep 17 00:00:00 2001 From: LePresidente Date: Tue, 31 Oct 2017 16:00:58 +0200 Subject: More fixes to waitForProcessCompletion --- src/organizercore.cpp | 73 +++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/organizercore.cpp b/src/organizercore.cpp index cba92d8f..48e2f98a 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -1254,7 +1254,7 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode) while ( res = ::MsgWaitForMultipleObjects(1, &handle, false, 500, QS_KEY | QS_MOUSE), - ((res != WAIT_FAILED) || (res != WAIT_OBJECT_0)) && + ((res != WAIT_FAILED) && (res != WAIT_OBJECT_0)) && ((m_UserInterface == nullptr) || !m_UserInterface->unlockClicked())) { if (!::GetVFSProcessList(&numProcesses, processes)) { @@ -1263,47 +1263,50 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode) bool found = false; size_t count = std::min(static_cast(maxCount), numProcesses); - for (size_t i = 0; i < count; ++i) { - std::wstring processName = getProcessName(processes[i]); - if (!boost::starts_with(processName, L"ModOrganizer.exe")) { - currentProcess = processes[i]; - m_UserInterface->setProcessName(QString::fromStdWString(processName)); - processHandle = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, currentProcess); - found = true; + if (count > 0) { + for (size_t i = 0; i < count; ++i) { + std::wstring processName = getProcessName(processes[i]); + if (!boost::starts_with(processName, L"ModOrganizer.exe")) { + if (!boost::starts_with(processName, L"unknown")) { + currentProcess = processes[i]; + m_UserInterface->setProcessName(QString::fromStdWString(processName)); + processHandle = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, currentProcess); + found = true; + } + } } - } - 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; + 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 { - break; + tryAgain = true; } - } - else { - tryAgain = true; - } - //Cleanup - if (processHandle != INVALID_HANDLE_VALUE) { - if (exitCode != nullptr) { - //This is actually wrong if the process we started finished before we - //got the event and so we end up with a job handle. - if (!::GetExitCodeProcess(processHandle, exitCode)) - { - DWORD error = ::GetLastError(); - qDebug() << "Failed to get process exit code: Error " << error; + //Cleanup + if (processHandle != INVALID_HANDLE_VALUE) { + if (exitCode != nullptr) { + //This is actually wrong if the process we started finished before we + //got the event and so we end up with a job handle. + if (!::GetExitCodeProcess(processHandle, exitCode)) + { + DWORD error = ::GetLastError(); + qDebug() << "Failed to get process exit code: Error " << error; + } + } + if (handle != processHandle) { + ::CloseHandle(processHandle); } - } - if (handle != processHandle) { - ::CloseHandle(processHandle); } } - // keep processing events so the app doesn't appear dead QCoreApplication::processEvents(); } -- cgit v1.3.1