summaryrefslogtreecommitdiff
path: root/src/organizercore.cpp
diff options
context:
space:
mode:
authorLePresidente <brian.alexander.munro@gmail.com>2017-10-31 12:13:25 +0200
committerLePresidente <brian.alexander.munro@gmail.com>2017-10-31 12:13:25 +0200
commit2f1d270c08eb43f043e342accc64b1cd1bbff25f (patch)
tree48655eb0a051d97b82507367a8e58e9e21c11bff /src/organizercore.cpp
parent701e6e4927ed887fc569aab97a1a6850e0f3dbdf (diff)
multiple fixes to waitForProcessCompletion.
Diffstat (limited to 'src/organizercore.cpp')
-rw-r--r--src/organizercore.cpp87
1 files changed, 46 insertions, 41 deletions
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<size_t>(static_cast<size_t>(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;
}