diff options
| author | Jeremy Rimpo <jeremy.rimpo@servermonkey.com> | 2017-12-13 15:58:43 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-12-13 15:58:43 -0600 |
| commit | 554b46847589fffb6cd7bc5c54689665c34ed95b (patch) | |
| tree | 235f1cad320f73e6b22cdf330d9a14d42bd33092 /src/organizercore.cpp | |
| parent | e4b952278d978567af3210d6a4be992eef3ba205 (diff) | |
| parent | 604d86ed07711651bc71871f6d37a794d916da6a (diff) | |
Merge pull request #148 from erasmux/lockeddialog_fixes
Lockeddialog fixes
Diffstat (limited to 'src/organizercore.cpp')
| -rw-r--r-- | src/organizercore.cpp | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/src/organizercore.cpp b/src/organizercore.cpp index deb0b718..dd77f19a 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -1340,53 +1340,40 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode, IL newHandle = false;
}
- // keep processing events so the app doesn't appear dead
- QCoreApplication::processEvents();
-
// Wait for a an event on the handle, a key press, mouse click or timeout
- res = MsgWaitForMultipleObjects(1, &handle, FALSE, 500, QS_KEY | QS_MOUSEBUTTON);
+ res = MsgWaitForMultipleObjects(1, &handle, FALSE, 200, QS_KEY | QS_MOUSEBUTTON);
if (res == WAIT_FAILED) {
qWarning() << "Failed waiting for process completion : MsgWaitForMultipleObjects WAIT_FAILED" << GetLastError();
break;
}
- if (uilock && uilock->unlockClicked()) {
+ // keep processing events so the app doesn't appear dead
+ QCoreApplication::sendPostedEvents();
+ QCoreApplication::processEvents();
+
+ if (uilock && uilock->unlockForced()) {
uiunlocked = true;
break;
}
if (res == WAIT_OBJECT_0) {
// process we were waiting on has completed
- if (originalHandle && !::GetExitCodeProcess(handle, exitCode))
+ if (originalHandle && exitCode && !::GetExitCodeProcess(handle, exitCode))
qWarning() << "Failed getting exit code of complete process :" << GetLastError();
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
originalHandle = false;
// if the previous process spawned a child process and immediately exits we may miss it if we check immediately
- QThread::msleep(500);
-
- // search if there is another usvfs process active and if so wait for it
- // in theory a querySize of 1 is probably enough since the MO process doesn't seem to be returned by GetVFSProcessList
- constexpr size_t querySize = 2; // just to be on the safe side
- DWORD pids[querySize];
- size_t found = querySize;
- if (!::GetVFSProcessList(&found, pids)) {
- qWarning() << "Failed waiting for process completion : GetVFSProcessList failed?!";
- break;
+ for (int i = 0; i < 3; ++i) {
+ QThread::msleep(200);
+ QCoreApplication::sendPostedEvents();
+ QCoreApplication::processEvents();
}
- for (size_t i = 0; i < found; ++i) {
- if (pids[i] == GetCurrentProcessId())
- continue; // obviously don't wait for MO process
- handle = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION|SYNCHRONIZE, FALSE, pids[i]);
- if (handle == INVALID_HANDLE_VALUE) {
- qWarning() << "Failed waiting for process completion : OpenProcess failed" << GetLastError();
- continue;
- }
- newHandle = true;
- break;
- }
+ // search if there is another usvfs process active and if so wait for it
+ handle = findAndOpenAUSVFSProcess();
+ newHandle = handle != INVALID_HANDLE_VALUE;
}
}
@@ -1403,6 +1390,29 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode, IL return res == WAIT_OBJECT_0;
}
+HANDLE OrganizerCore::findAndOpenAUSVFSProcess() {
+ // in theory a querySize of 1 is probably enough since the MO process doesn't seem to be returned by GetVFSProcessList
+ constexpr size_t querySize = 2; // just to be on the safe side
+ DWORD pids[querySize];
+ size_t found = querySize;
+ if (!::GetVFSProcessList(&found, pids)) {
+ qWarning() << "Failed seeking USVFS processes : GetVFSProcessList failed?!";
+ return INVALID_HANDLE_VALUE;
+ }
+
+ for (size_t i = 0; i < found; ++i) {
+ if (pids[i] == GetCurrentProcessId())
+ continue; // obviously don't wait for MO process
+ HANDLE handle = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, FALSE, pids[i]);
+ if (handle != INVALID_HANDLE_VALUE)
+ return handle;
+ else
+ qWarning() << "Failed openning USVFS process " << pids[i] << " : OpenProcess failed" << GetLastError();
+ }
+
+ return INVALID_HANDLE_VALUE;
+}
+
bool OrganizerCore::onAboutToRun(
const std::function<bool(const QString &)> &func)
{
|
