summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEran Mizrahi <erasmux@gmail.com>2017-12-09 21:39:22 +0200
committerEran Mizrahi <erasmux@gmail.com>2017-12-10 02:53:19 +0200
commit66b17eea8ac83ee6f7b729974240d995a1e8ed3a (patch)
tree8a89aef1c9122dc7b233aa823880d9f60231e91f /src
parent89b1f1d48dd05b372abca64b311b1107f044a897 (diff)
Wait for processes run using command line shortcuts
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/ilockedwaitingforprocess.h13
-rw-r--r--src/iuserinterface.h7
-rw-r--r--src/lockeddialog.h7
-rw-r--r--src/mainwindow.cpp21
-rw-r--r--src/mainwindow.h4
-rw-r--r--src/organizercore.cpp46
-rw-r--r--src/organizercore.h2
8 files changed, 62 insertions, 39 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d603336c..39aabb91 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -169,6 +169,7 @@ SET(organizer_HDRS
viewmarkingscrollbar.h
plugincontainer.h
organizercore.h
+ ilockedwaitingforprocess.h
iuserinterface.h
instancemanager.h
usvfsconnector.h
diff --git a/src/ilockedwaitingforprocess.h b/src/ilockedwaitingforprocess.h
new file mode 100644
index 00000000..6a4267d4
--- /dev/null
+++ b/src/ilockedwaitingforprocess.h
@@ -0,0 +1,13 @@
+#ifndef ILOCKEDWAITINGFORPROCESS_H
+#define ILOCKEDWAITINGFORPROCESS_H
+
+class QString;
+
+class ILockedWaitingForProcess
+{
+public:
+ virtual bool unlockClicked() = 0;
+ virtual void setProcessName(QString const &) = 0;
+};
+
+#endif // ILOCKEDWAITINGFORPROCESS_H
diff --git a/src/iuserinterface.h b/src/iuserinterface.h
index 0af1c2ac..255c7ac0 100644
--- a/src/iuserinterface.h
+++ b/src/iuserinterface.h
@@ -3,6 +3,7 @@
#include "modinfo.h"
+#include "ilockedwaitingforprocess.h"
#include <iplugintool.h>
#include <ipluginmodpage.h>
#include <delayedfilewriter.h>
@@ -27,12 +28,8 @@ public:
virtual void displayModInformation(ModInfo::Ptr modInfo, unsigned int index, int tab) = 0;
- virtual void lock() = 0;
+ virtual ILockedWaitingForProcess* lock() = 0;
virtual void unlock() = 0;
- virtual bool unlockClicked() = 0;
- virtual void setProcessName(QString const &) = 0;
-
-
};
#endif // IUSERINTERFACE_H
diff --git a/src/lockeddialog.h b/src/lockeddialog.h
index 29ac459b..8803efae 100644
--- a/src/lockeddialog.h
+++ b/src/lockeddialog.h
@@ -20,6 +20,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#ifndef LOCKEDDIALOG_H
#define LOCKEDDIALOG_H
+#include "ilockedwaitingforprocess.h"
#include <QDialog> // for QDialog
#include <QObject> // for Q_OBJECT, slots
#include <QString> // for QString
@@ -39,7 +40,7 @@ namespace Ui {
* data on which Mod Organizer works. After the UI is unlocked (manually or after the
* external application closed) MO will refresh all of its data sources
**/
-class LockedDialog : public QDialog
+class LockedDialog : public QDialog, public ILockedWaitingForProcess
{
Q_OBJECT
@@ -52,13 +53,13 @@ public:
*
* @return true if the user clicked the unlock button
**/
- bool unlockClicked() const { return m_UnlockClicked; }
+ bool unlockClicked() override { return m_UnlockClicked; }
/**
* @brief set the name of the process being run
* @param name of process
*/
- void setProcessName(const QString &name);
+ void setProcessName(const QString &name) override;
protected:
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index b47e9c57..1db895fc 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1465,17 +1465,18 @@ void MainWindow::storeSettings(QSettings &settings) {
}
}
-void MainWindow::lock()
+ILockedWaitingForProcess* MainWindow::lock()
{
if (m_LockDialog != nullptr) {
++m_LockCount;
- return;
+ return m_LockDialog;
}
m_LockDialog = new LockedDialog(qApp->activeWindow());
m_LockDialog->show();
setEnabled(false);
m_LockDialog->setEnabled(true); //What's the point otherwise?
++m_LockCount;
+ return m_LockDialog;
}
void MainWindow::unlock()
@@ -1494,22 +1495,6 @@ void MainWindow::unlock()
}
}
-bool MainWindow::unlockClicked()
-{
- if (m_LockDialog != nullptr) {
- return m_LockDialog->unlockClicked();
- } else {
- return false;
- }
-}
-
-void MainWindow::setProcessName(QString const &name)
-{
- if (m_LockDialog != nullptr) {
- m_LockDialog->setProcessName(name);
- }
-}
-
void MainWindow::on_btnRefreshData_clicked()
{
m_OrganizerCore.refreshDirectoryStructure();
diff --git a/src/mainwindow.h b/src/mainwindow.h
index cec6c407..f6f11157 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -116,10 +116,8 @@ public:
void storeSettings(QSettings &settings) override;
void readSettings();
- virtual void lock() override;
+ virtual ILockedWaitingForProcess* lock() override;
virtual void unlock() override;
- virtual bool unlockClicked() override;
- virtual void setProcessName(QString const &name) override;
bool addProfile();
void refreshDataTree();
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 54cfed54..f0dfa8d4 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -31,6 +31,7 @@
#include "appconfig.h"
#include <report.h>
#include <questionboxmemory.h>
+#include "lockeddialog.h"
#include <QApplication>
#include <QCoreApplication>
@@ -1067,8 +1068,9 @@ QStringList OrganizerCore::modsSortedByProfilePriority() const
void OrganizerCore::spawnBinary(const QFileInfo &binary, const QString &arguments, const QDir &currentDirectory, const QString &steamAppID, const QString &customOverwrite)
{
+ ILockedWaitingForProcess* uilock = nullptr;
if (m_UserInterface != nullptr) {
- m_UserInterface->lock();
+ uilock = m_UserInterface->lock();
}
ON_BLOCK_EXIT([&] () {
if (m_UserInterface != nullptr) { m_UserInterface->unlock(); }
@@ -1077,7 +1079,7 @@ void OrganizerCore::spawnBinary(const QFileInfo &binary, const QString &argument
HANDLE processHandle = spawnBinaryDirect(binary, arguments, m_CurrentProfile->name(), currentDirectory, steamAppID, customOverwrite);
if (processHandle != INVALID_HANDLE_VALUE) {
DWORD processExitCode;
- (void)waitForProcessCompletion(processHandle, &processExitCode);
+ (void)waitForProcessCompletion(processHandle, &processExitCode, uilock);
refreshDirectoryStructure();
// need to remove our stored load order because it may be outdated if a foreign tool changed the
@@ -1258,24 +1260,50 @@ HANDLE OrganizerCore::startApplication(const QString &executable,
}
}
- return spawnBinaryDirect(binary, arguments, profileName, currentDirectory,
- steamAppID, customOverwrite);
+ HANDLE processHandle = spawnBinaryDirect(binary, arguments, profileName, currentDirectory, steamAppID, customOverwrite);
+ if (processHandle != INVALID_HANDLE_VALUE) {
+ std::unique_ptr<LockedDialog> dlg;
+ ILockedWaitingForProcess* uilock = nullptr;
+
+ if (m_UserInterface != nullptr) {
+ uilock = m_UserInterface->lock();
+ }
+ else {
+ // i.e. when running command line shortcuts there is no m_UserInterface
+ dlg.reset(new LockedDialog);
+ dlg->show();
+ dlg->setEnabled(true);
+ uilock = dlg.get();
+ }
+
+ ON_BLOCK_EXIT([&]() {
+ if (m_UserInterface != nullptr) {
+ m_UserInterface->unlock();
+ } });
+
+ DWORD processExitCode;
+ waitForProcessCompletion(processHandle, &processExitCode, uilock);
+ cycleDiagnostics();
+ }
+
+ return processHandle;
}
bool OrganizerCore::waitForApplication(HANDLE handle, LPDWORD exitCode)
{
+ ILockedWaitingForProcess* uilock = nullptr;
if (m_UserInterface != nullptr) {
- m_UserInterface->lock();
+ uilock = m_UserInterface->lock();
}
ON_BLOCK_EXIT([&] () {
if (m_UserInterface != nullptr) {
m_UserInterface->unlock();
} });
- return waitForProcessCompletion(handle, exitCode);
+ return waitForProcessCompletion(handle, exitCode, uilock);
}
-bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode)
+bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode, ILockedWaitingForProcess* uilock)
{
DWORD startPID = ::GetProcessId(handle);
@@ -1292,7 +1320,7 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode)
while (
res = ::MsgWaitForMultipleObjects(1, &handle, false, 500,
QS_KEY | QS_MOUSEBUTTON),
- ((m_UserInterface == nullptr) || !m_UserInterface->unlockClicked())) {
+ ((uilock == nullptr) || !uilock->unlockClicked())) {
if (!::GetVFSProcessList(&numProcesses, processes)) {
break;
@@ -1335,7 +1363,7 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode)
// Update the lock process name with the name of the lowest active PID - though this may not actually be the main process
if (handles.size() > 0)
- m_UserInterface->setProcessName(QString::fromStdWString(getProcessName(handles.begin()->second)));
+ uilock->setProcessName(QString::fromStdWString(getProcessName(handles.begin()->second)));
// If the main wait process dies, we need a backup wait process until the subprocesses close
if ((res == WAIT_FAILED) || (res == WAIT_OBJECT_0)) {
diff --git a/src/organizercore.h b/src/organizercore.h
index 40531195..0927c88e 100644
--- a/src/organizercore.h
+++ b/src/organizercore.h
@@ -267,7 +267,7 @@ private:
const MOShared::DirectoryEntry *directoryEntry,
int createDestination);
- bool waitForProcessCompletion(HANDLE handle, LPDWORD exitCode);
+ bool waitForProcessCompletion(HANDLE handle, LPDWORD exitCode, ILockedWaitingForProcess* uilock);
private slots: