diff options
| author | LePresidente <brian.alexander.munro@gmail.com> | 2017-10-31 16:00:58 +0200 |
|---|---|---|
| committer | LePresidente <brian.alexander.munro@gmail.com> | 2017-10-31 16:00:58 +0200 |
| commit | 6c54ef5ec2a1b5395f4292fd33e4dcddf748a145 (patch) | |
| tree | d6e0043e755488e6e3c28ba2bf43a7007f4e108f /src | |
| parent | 2f1d270c08eb43f043e342accc64b1cd1bbff25f (diff) | |
More fixes to waitForProcessCompletion
Diffstat (limited to 'src')
| -rw-r--r-- | src/organizercore.cpp | 73 |
1 files changed, 38 insertions, 35 deletions
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<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(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();
}
|
