diff options
| author | Al12rs <gabriel.cortesi@outlook.com> | 2017-10-31 12:05:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-31 12:05:57 +0100 |
| commit | c8118ea0fa6db5102d4dcc544c4bfe1792c7c7ab (patch) | |
| tree | 6614a6746b42cbcf0f0227ae88c09e6d10b7f0ff /src | |
| parent | d53591c6c9c2702d361a70417f37f4508fc43552 (diff) | |
| parent | 2f1d270c08eb43f043e342accc64b1cd1bbff25f (diff) | |
Merge pull request #1 from LePresidente/QT5.7
merge pull request: multiple fixes to waitForProcessCompletion.
Diffstat (limited to 'src')
| -rw-r--r-- | src/organizercore.cpp | 87 |
1 files changed, 46 insertions, 41 deletions
diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 4857590d..09acc0aa 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;
}
|
