示例#1
0
void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account)
{
	Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
	Q_ASSERT_X(account.get() != nullptr, "launchInstance", "account is NULL");

	proc = instance->prepareForLaunch(account);
	if (!proc)
		return;

	this->hide();

	console = new ConsoleWindow(proc);
	connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));

	proc->setLogin(account);
	proc->launch();
}
示例#2
0
void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, BaseProfilerFactory *profiler)
{
	Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
	Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL");

	QString launchScript;

	if(!instance->prepareForLaunch(session, launchScript))
		return;

	MinecraftProcess *proc = new MinecraftProcess(instance);
	proc->setLaunchScript(launchScript);
	proc->setWorkdir(instance->minecraftRoot());

	this->hide();

	console = new ConsoleWindow(proc);
	connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));

	proc->setLogin(session);
	proc->arm();

	if (profiler)
	{
		QString error;
		if (!profiler->check(&error))
		{
			QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error));
			proc->abort();
			return;
		}
		BaseProfiler *profilerInstance = profiler->createProfiler(instance, this);
		QProgressDialog dialog;
		dialog.setMinimum(0);
		dialog.setMaximum(0);
		dialog.setValue(0);
		dialog.setLabelText(tr("Waiting for profiler..."));
		connect(&dialog, &QProgressDialog::canceled, profilerInstance, &BaseProfiler::abortProfiling);
		dialog.show();
		connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this, proc](const QString &message)
		{
			dialog.accept();
			QMessageBox msg;
			msg.setText(tr("The launch of Minecraft itself is delayed until you press the "
						   "button. This is the right time to setup the profiler, as the "
						   "profiler server is running now.\n\n%1").arg(message));
			msg.setWindowTitle(tr("Waiting"));
			msg.setIcon(QMessageBox::Information);
			msg.addButton(tr("Launch"), QMessageBox::AcceptRole);
			msg.exec();
			proc->launch();
		});
		connect(profilerInstance, &BaseProfiler::abortLaunch, [&dialog, this, proc](const QString &message)
		{
			dialog.accept();
			QMessageBox msg;
			msg.setText(tr("Couldn't start the profiler: %1").arg(message));
			msg.setWindowTitle(tr("Error"));
			msg.setIcon(QMessageBox::Critical);
			msg.addButton(QMessageBox::Ok);
			msg.exec();
			proc->abort();
		});
		profilerInstance->beginProfiling(proc);
		dialog.exec();
	}
	else
	{
		proc->launch();
	}
}