summaryrefslogtreecommitdiffstats
path: root/application/MultiMC.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-05-02 01:43:18 +0200
committerPetr Mrázek <peterix@gmail.com>2017-05-02 01:43:18 +0200
commit6a8bb3691b9e30bcb90003eead34b287010cf17f (patch)
treeafe9068330e2c1971355938b2fef7d93c172a47c /application/MultiMC.cpp
parent0132fd99291e359aae4af184c5f57ace21bf9863 (diff)
downloadMultiMC-6a8bb3691b9e30bcb90003eead34b287010cf17f.tar
MultiMC-6a8bb3691b9e30bcb90003eead34b287010cf17f.tar.gz
MultiMC-6a8bb3691b9e30bcb90003eead34b287010cf17f.tar.lz
MultiMC-6a8bb3691b9e30bcb90003eead34b287010cf17f.tar.xz
MultiMC-6a8bb3691b9e30bcb90003eead34b287010cf17f.zip
GH-1874 do not allow updating while an instance is running
This is a nasty hack. Proper solution will require moving all update related functionality out of the main window. Running instances and updating should be mutually exclusive.
Diffstat (limited to 'application/MultiMC.cpp')
-rw-r--r--application/MultiMC.cpp45
1 files changed, 39 insertions, 6 deletions
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp
index 833efc06..6d83fd07 100644
--- a/application/MultiMC.cpp
+++ b/application/MultiMC.cpp
@@ -965,7 +965,7 @@ bool MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *pro
}
connect(controller.get(), &LaunchController::succeeded, this, &MultiMC::controllerSucceeded);
connect(controller.get(), &LaunchController::failed, this, &MultiMC::controllerFailed);
- m_runningInstances ++;
+ addRunningInstance();
controller->start();
return true;
}
@@ -994,6 +994,38 @@ bool MultiMC::kill(InstancePtr instance)
return true;
}
+void MultiMC::addRunningInstance()
+{
+ m_runningInstances ++;
+ if(m_runningInstances == 1)
+ {
+ emit updateAllowedChanged(false);
+ }
+}
+
+void MultiMC::subRunningInstance()
+{
+ if(m_runningInstances == 0)
+ {
+ qCritical() << "Something went really wrong and we now have less than 0 running instances... WTF";
+ return;
+ }
+ m_runningInstances --;
+ if(m_runningInstances == 0)
+ {
+ emit updateAllowedChanged(true);
+ }
+}
+
+bool MultiMC::shouldExitNow() const
+{
+ return m_runningInstances == 0 && m_openWindows == 0;
+}
+
+bool MultiMC::updatesAreAllowed()
+{
+ return m_runningInstances == 0;
+}
void MultiMC::controllerSucceeded()
{
@@ -1012,10 +1044,10 @@ void MultiMC::controllerSucceeded()
}
}
extras.controller.reset();
- m_runningInstances --;
+ subRunningInstance();
// quit when there are no more windows.
- if(m_openWindows == 0 && m_runningInstances == 0)
+ if(shouldExitNow())
{
m_status = Status::Succeeded;
exit(0);
@@ -1033,10 +1065,10 @@ void MultiMC::controllerFailed(const QString& error)
// on failure, do... nothing
extras.controller.reset();
- m_runningInstances --;
+ subRunningInstance();
// quit when there are no more windows.
- if(m_openWindows == 0 && m_runningInstances == 0)
+ if(shouldExitNow())
{
m_status = Status::Failed;
exit(1);
@@ -1066,6 +1098,7 @@ MainWindow* MultiMC::showMainWindow(bool minimized)
}
m_mainWindow->checkInstancePathForProblems();
+ connect(this, &MultiMC::updateAllowedChanged, m_mainWindow, &MainWindow::updatesAllowedChanged);
connect(m_mainWindow, &MainWindow::isClosing, this, &MultiMC::on_windowClose);
m_openWindows++;
}
@@ -1155,7 +1188,7 @@ void MultiMC::on_windowClose()
m_mainWindow = nullptr;
}
// quit when there are no more windows.
- if(m_openWindows == 0 && m_runningInstances == 0)
+ if(shouldExitNow())
{
exit(0);
}