GH-1874 Do not allow launching instances during an update
This commit is contained in:
		| @@ -989,8 +989,14 @@ void MainWindow::downloadUpdates(GoUpdate::Status status) | |||||||
| 	// If the task succeeds, install the updates. | 	// If the task succeeds, install the updates. | ||||||
| 	if (updateDlg.execWithTask(&updateTask)) | 	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()); | 		UpdateController update(this, MMC->root(), updateTask.updateFilesDir(), updateTask.operations()); | ||||||
| 		update.installUpdates(); | 		update.installUpdates(); | ||||||
|  | 		MMC->updateIsRunning(false); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|   | |||||||
| @@ -939,7 +939,11 @@ bool MultiMC::openJsonEditor(const QString &filename) | |||||||
|  |  | ||||||
| bool MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *profiler) | 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 & extras = m_instanceExtras[instance->id()]; | ||||||
| 		auto & window = extras.window; | 		auto & window = extras.window; | ||||||
| @@ -1027,6 +1031,12 @@ bool MultiMC::updatesAreAllowed() | |||||||
| 	return m_runningInstances == 0; | 	return m_runningInstances == 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void MultiMC::updateIsRunning(bool running) | ||||||
|  | { | ||||||
|  | 	m_updateRunning = running; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void MultiMC::controllerSucceeded() | void MultiMC::controllerSucceeded() | ||||||
| { | { | ||||||
| 	auto controller = qobject_cast<LaunchController *>(QObject::sender()); | 	auto controller = qobject_cast<LaunchController *>(QObject::sender()); | ||||||
|   | |||||||
| @@ -151,6 +151,7 @@ public: | |||||||
| 		return m_runningInstances; | 		return m_runningInstances; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	void updateIsRunning(bool running); | ||||||
| 	bool updatesAreAllowed(); | 	bool updatesAreAllowed(); | ||||||
|  |  | ||||||
| signals: | signals: | ||||||
| @@ -227,8 +228,11 @@ private: | |||||||
| 		shared_qobject_ptr<LaunchController> controller; | 		shared_qobject_ptr<LaunchController> controller; | ||||||
| 	}; | 	}; | ||||||
| 	std::map<QString, InstanceXtras> m_instanceExtras; | 	std::map<QString, InstanceXtras> m_instanceExtras; | ||||||
|  |  | ||||||
|  | 	// main state variables | ||||||
| 	size_t m_openWindows = 0; | 	size_t m_openWindows = 0; | ||||||
| 	size_t m_runningInstances = 0; | 	size_t m_runningInstances = 0; | ||||||
|  | 	bool m_updateRunning = false; | ||||||
|  |  | ||||||
| 	// main window, if any | 	// main window, if any | ||||||
| 	MainWindow * m_mainWindow = nullptr; | 	MainWindow * m_mainWindow = nullptr; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Petr Mrázek
					Petr Mrázek