Exemplo n.º 1
0
void MainWindow::updateInstance(BaseInstance *instance, MojangAccountPtr account)
{
	bool only_prepare = account->accountStatus() != Online;
	auto updateTask = instance->doUpdate(only_prepare);
	if (!updateTask)
	{
		launchInstance(instance, account);
		return;
	}
	ProgressDialog tDialog(this);
	connect(updateTask.get(), &Task::succeeded, [this, instance, account]
	{ launchInstance(instance, account); });
	connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
	tDialog.exec(updateTask.get());
}
Exemplo n.º 2
0
void MainWindow::doLaunch()
{
	if (!m_selectedInstance)
		return;

	// Find an account to use.
	std::shared_ptr<MojangAccountList> accounts = MMC->accounts();
	MojangAccountPtr account = accounts->activeAccount();
	if (accounts->count() <= 0)
	{
		// Tell the user they need to log in at least one account in order to play.
		auto reply = CustomMessageBox::selectable(
			this, tr("No Accounts"),
			tr("In order to play Minecraft, you must have at least one Mojang or Minecraft "
			   "account logged in to MultiMC."
			   "Would you like to open the account manager to add an account now?"),
			QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec();

		if (reply == QMessageBox::Yes)
		{
			// Open the account manager.
			on_actionManageAccounts_triggered();
		}
	}
	else if (account.get() == nullptr)
	{
		// If no default account is set, ask the user which one to use.
		AccountSelectDialog selectDialog(tr("Which account would you like to use?"),
										 AccountSelectDialog::GlobalDefaultCheckbox, this);

		selectDialog.exec();

		// Launch the instance with the selected account.
		account = selectDialog.selectedAccount();

		// If the user said to use the account as default, do that.
		if (selectDialog.useAsGlobalDefault() && account.get() != nullptr)
			accounts->setActiveAccount(account->username());
	}

	// if no account is selected, we bail
	if (!account.get())
		return;

	QString failReason = tr("Your account is currently not logged in. Please enter "
							"your password to log in again.");
	// do the login. if the account has an access token, try to refresh it first.
	if (account->accountStatus() != NotVerified)
	{
		// We'll need to validate the access token to make sure the account is still logged in.
		ProgressDialog progDialog(this);
		progDialog.setSkipButton(true, tr("Play Offline"));
		auto task = account->login();
		progDialog.exec(task.get());

		auto status = account->accountStatus();
		if (status != NotVerified)
		{
			updateInstance(m_selectedInstance, account);
		}
		else
		{
			if (!task->successful())
			{
				failReason = task->failReason();
			}
			if (loginWithPassword(account, failReason))
				updateInstance(m_selectedInstance, account);
		}
		// in any case, revert from online to verified.
		account->downgrade();
	}
	else
	{
		if (loginWithPassword(account, failReason))
		{
			updateInstance(m_selectedInstance, account);
			account->downgrade();
		}
		// in any case, revert from online to verified.
		account->downgrade();
	}
}