From 907aa367046bde6ad05893917cff11320019ddda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 2 May 2017 23:29:47 +0200 Subject: GH-1874 Do not allow launching instances during an update --- application/MainWindow.cpp | 6 ++++++ application/MultiMC.cpp | 12 +++++++++++- application/MultiMC.h | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 4ec0af86..9ecfbfd0 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -989,8 +989,14 @@ void MainWindow::downloadUpdates(GoUpdate::Status status) // If the task succeeds, install the updates. if (updateDlg.execWithTask(&updateTask)) { + /** + * NOTE: This disables launching instances until the update either succeeds (and this process exits) + * or the update fails (and the control leaves this scope). + */ + MMC->updateIsRunning(true); UpdateController update(this, MMC->root(), updateTask.updateFilesDir(), updateTask.operations()); update.installUpdates(); + MMC->updateIsRunning(false); } else { diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 6d83fd07..d9d59aa6 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -939,7 +939,11 @@ bool MultiMC::openJsonEditor(const QString &filename) bool MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *profiler) { - if(instance->canLaunch()) + if(m_updateRunning) + { + qDebug() << "Cannot launch instances while an update is running."; + } + else if(instance->canLaunch()) { auto & extras = m_instanceExtras[instance->id()]; auto & window = extras.window; @@ -1027,6 +1031,12 @@ bool MultiMC::updatesAreAllowed() return m_runningInstances == 0; } +void MultiMC::updateIsRunning(bool running) +{ + m_updateRunning = running; +} + + void MultiMC::controllerSucceeded() { auto controller = qobject_cast(QObject::sender()); diff --git a/application/MultiMC.h b/application/MultiMC.h index 48be3b22..de768a98 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -151,6 +151,7 @@ public: return m_runningInstances; } + void updateIsRunning(bool running); bool updatesAreAllowed(); signals: @@ -227,8 +228,11 @@ private: shared_qobject_ptr controller; }; std::map m_instanceExtras; + + // main state variables size_t m_openWindows = 0; size_t m_runningInstances = 0; + bool m_updateRunning = false; // main window, if any MainWindow * m_mainWindow = nullptr; -- cgit v1.2.3