GH-1053 move instance update into the launch task (BaseLauncher)
This commit is contained in:
@ -53,7 +53,7 @@ private:
|
||||
BasePage * m_log_page;
|
||||
};
|
||||
|
||||
ConsoleWindow::ConsoleWindow(BaseLauncher *process, QWidget *parent)
|
||||
ConsoleWindow::ConsoleWindow(std::shared_ptr<BaseLauncher> process, QWidget *parent)
|
||||
: QMainWindow(parent), m_proc(process)
|
||||
{
|
||||
MultiMCPlatform::fixWM_CLASS(this);
|
||||
@ -129,11 +129,11 @@ ConsoleWindow::ConsoleWindow(BaseLauncher *process, QWidget *parent)
|
||||
}
|
||||
|
||||
// Set up signal connections
|
||||
connect(m_proc, SIGNAL(ended(InstancePtr, int, QProcess::ExitStatus)), this,
|
||||
connect(m_proc.get(), SIGNAL(ended(InstancePtr, int, QProcess::ExitStatus)), this,
|
||||
SLOT(onEnded(InstancePtr, int, QProcess::ExitStatus)));
|
||||
connect(m_proc, SIGNAL(prelaunch_failed(InstancePtr, int, QProcess::ExitStatus)), this,
|
||||
connect(m_proc.get(), SIGNAL(prelaunch_failed(InstancePtr, int, QProcess::ExitStatus)), this,
|
||||
SLOT(onEnded(InstancePtr, int, QProcess::ExitStatus)));
|
||||
connect(m_proc, SIGNAL(launch_failed(InstancePtr)), this,
|
||||
connect(m_proc.get(), SIGNAL(launch_failed(InstancePtr)), this,
|
||||
SLOT(onLaunchFailed(InstancePtr)));
|
||||
|
||||
setMayClose(false);
|
||||
|
@ -26,7 +26,7 @@ class ConsoleWindow : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConsoleWindow(BaseLauncher *proc, QWidget *parent = 0);
|
||||
explicit ConsoleWindow(std::shared_ptr<BaseLauncher> proc, QWidget *parent = 0);
|
||||
virtual ~ConsoleWindow();
|
||||
|
||||
/**
|
||||
@ -56,7 +56,7 @@ protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
|
||||
private:
|
||||
BaseLauncher *m_proc = nullptr;
|
||||
std::shared_ptr<BaseLauncher> m_proc;
|
||||
bool m_mayclose = true;
|
||||
QSystemTrayIcon *m_trayIcon = nullptr;
|
||||
PageContainer *m_container = nullptr;
|
||||
|
@ -1699,39 +1699,14 @@ void MainWindow::doLaunch(bool online, BaseProfilerFactory *profiler)
|
||||
}
|
||||
case AuthSession::PlayableOnline:
|
||||
{
|
||||
// update first if the server actually responded
|
||||
if (session->auth_server_online)
|
||||
{
|
||||
updateInstance(m_selectedInstance, session, profiler);
|
||||
}
|
||||
else
|
||||
{
|
||||
launchInstance(m_selectedInstance, session, profiler);
|
||||
}
|
||||
launchInstance(m_selectedInstance, session, profiler);
|
||||
tryagain = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateInstance(InstancePtr instance, AuthSessionPtr session,
|
||||
BaseProfilerFactory *profiler)
|
||||
{
|
||||
auto updateTask = instance->doUpdate();
|
||||
if (!updateTask)
|
||||
{
|
||||
launchInstance(instance, session, profiler);
|
||||
return;
|
||||
}
|
||||
ProgressDialog tDialog(this);
|
||||
connect(updateTask.get(), &Task::succeeded, [this, instance, session, profiler]
|
||||
{ launchInstance(instance, session, profiler); });
|
||||
connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
|
||||
tDialog.exec(updateTask.get());
|
||||
}
|
||||
|
||||
void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session,
|
||||
BaseProfilerFactory *profiler)
|
||||
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");
|
||||
@ -1744,35 +1719,43 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session,
|
||||
return;
|
||||
}
|
||||
|
||||
BaseLauncher *proc = instance->prepareForLaunch(session);
|
||||
auto proc = instance->prepareForLaunch(session);
|
||||
if (!proc)
|
||||
return;
|
||||
|
||||
proc->setProfiler(profiler);
|
||||
|
||||
this->hide();
|
||||
|
||||
console = new ConsoleWindow(proc);
|
||||
connect(console, &ConsoleWindow::isClosing, this, &MainWindow::instanceEnded);
|
||||
connect(proc.get(), &BaseLauncher::readyForLaunch, this, &MainWindow::readyForLaunch);
|
||||
|
||||
proc->setHeader("MultiMC version: " + BuildConfig.printableVersionString() + "\n\n");
|
||||
proc->arm();
|
||||
proc->start();
|
||||
}
|
||||
|
||||
void MainWindow::readyForLaunch(std::shared_ptr<BaseLauncher> launcher)
|
||||
{
|
||||
auto profiler = launcher->getProfiler();
|
||||
|
||||
if (!profiler)
|
||||
{
|
||||
proc->launch();
|
||||
launcher->launch();
|
||||
return;
|
||||
}
|
||||
|
||||
QString error;
|
||||
if (!profiler->check(&error))
|
||||
{
|
||||
proc->abort();
|
||||
launcher->abort();
|
||||
QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error));
|
||||
return;
|
||||
}
|
||||
BaseProfiler *profilerInstance = profiler->createProfiler(instance, this);
|
||||
BaseProfiler *profilerInstance = profiler->createProfiler(launcher->instance(), this);
|
||||
|
||||
connect(profilerInstance, &BaseProfiler::readyToLaunch,
|
||||
[this, proc](const QString & message)
|
||||
[this, launcher](const QString & message)
|
||||
{
|
||||
QMessageBox msg;
|
||||
msg.setText(tr("The game launch is delayed until you press the "
|
||||
@ -1783,10 +1766,10 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session,
|
||||
msg.addButton(tr("Launch"), QMessageBox::AcceptRole);
|
||||
msg.setModal(true);
|
||||
msg.exec();
|
||||
proc->launch();
|
||||
launcher->launch();
|
||||
});
|
||||
connect(profilerInstance, &BaseProfiler::abortLaunch,
|
||||
[this, proc](const QString & message)
|
||||
[this, launcher](const QString & message)
|
||||
{
|
||||
QMessageBox msg;
|
||||
msg.setText(tr("Couldn't start the profiler: %1").arg(message));
|
||||
@ -1795,17 +1778,17 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session,
|
||||
msg.addButton(QMessageBox::Ok);
|
||||
msg.setModal(true);
|
||||
msg.exec();
|
||||
proc->abort();
|
||||
launcher->abort();
|
||||
});
|
||||
profilerInstance->beginProfiling(proc);
|
||||
profilerInstance->beginProfiling(launcher);
|
||||
}
|
||||
|
||||
/*
|
||||
void MainWindow::onGameUpdateError(QString error)
|
||||
{
|
||||
CustomMessageBox::selectable(this, tr("Error updating instance"), error,
|
||||
QMessageBox::Warning)->show();
|
||||
}
|
||||
|
||||
*/
|
||||
void MainWindow::taskStart()
|
||||
{
|
||||
// Nothing to do here yet.
|
||||
|
@ -128,12 +128,7 @@ slots:
|
||||
*/
|
||||
void launchInstance(InstancePtr instance, AuthSessionPtr session, BaseProfilerFactory *profiler = 0);
|
||||
|
||||
/*!
|
||||
* Prepares the given instance for launch with the given account.
|
||||
*/
|
||||
void updateInstance(InstancePtr instance, AuthSessionPtr account, BaseProfilerFactory *profiler = 0);
|
||||
|
||||
void onGameUpdateError(QString error);
|
||||
void readyForLaunch(std::shared_ptr<BaseLauncher>);
|
||||
|
||||
void taskStart();
|
||||
void taskEnd();
|
||||
@ -196,7 +191,6 @@ private:
|
||||
class GroupView *view;
|
||||
InstanceProxyModel *proxymodel;
|
||||
NetJobPtr skin_download_job;
|
||||
MinecraftLauncher *proc;
|
||||
ConsoleWindow *console;
|
||||
LabeledToolButton *renameButton;
|
||||
QToolButton *changeIconButton;
|
||||
|
@ -11,12 +11,12 @@
|
||||
#include <settings/Setting.h>
|
||||
#include "GuiUtil.h"
|
||||
|
||||
LogPage::LogPage(BaseLauncher *proc, QWidget *parent)
|
||||
LogPage::LogPage(std::shared_ptr<BaseLauncher> proc, QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::LogPage), m_process(proc)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->tabWidget->tabBar()->hide();
|
||||
connect(m_process, SIGNAL(log(QString, MessageLevel::Enum)), this,
|
||||
connect(m_process.get(), SIGNAL(log(QString, MessageLevel::Enum)), this,
|
||||
SLOT(write(QString, MessageLevel::Enum)));
|
||||
|
||||
// create the format and set its font
|
||||
|
@ -33,7 +33,7 @@ class LogPage : public QWidget, public BasePage
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LogPage(BaseLauncher *proc, QWidget *parent = 0);
|
||||
explicit LogPage(std::shared_ptr<BaseLauncher> proc, QWidget *parent = 0);
|
||||
virtual ~LogPage();
|
||||
virtual QString displayName() const override
|
||||
{
|
||||
@ -77,7 +77,7 @@ private slots:
|
||||
|
||||
private:
|
||||
Ui::LogPage *ui;
|
||||
BaseLauncher *m_process;
|
||||
std::shared_ptr<BaseLauncher> m_process;
|
||||
int m_last_scroll_value = 0;
|
||||
bool m_scroll_active = true;
|
||||
int m_saved_offset = 0;
|
||||
|
Reference in New Issue
Block a user