Merge pull request #2795 from Trial97/fix_mc_launch
Fix launch when no java is loaded
This commit is contained in:
commit
fa68428a90
@ -181,7 +181,7 @@ class BaseInstance : public QObject, public std::enable_shared_from_this<BaseIns
|
||||
virtual void loadSpecificSettings() = 0;
|
||||
|
||||
/// returns a valid update task
|
||||
virtual Task::Ptr createUpdateTask(Net::Mode mode) = 0;
|
||||
virtual QList<Task::Ptr> createUpdateTask() = 0;
|
||||
|
||||
/// returns a valid launcher (task container)
|
||||
virtual shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account, MinecraftTarget::Ptr targetToJoin) = 0;
|
||||
@ -215,7 +215,7 @@ class BaseInstance : public QObject, public std::enable_shared_from_this<BaseIns
|
||||
|
||||
virtual QString typeName() const = 0;
|
||||
|
||||
void updateRuntimeContext();
|
||||
virtual void updateRuntimeContext();
|
||||
RuntimeContext runtimeContext() const { return m_runtimeContext; }
|
||||
|
||||
bool hasVersionBroken() const { return m_hasBrokenVersion; }
|
||||
|
@ -160,8 +160,6 @@ set(LAUNCH_SOURCES
|
||||
launch/steps/PreLaunchCommand.h
|
||||
launch/steps/TextPrint.cpp
|
||||
launch/steps/TextPrint.h
|
||||
launch/steps/Update.cpp
|
||||
launch/steps/Update.h
|
||||
launch/steps/QuitAfterGameStop.cpp
|
||||
launch/steps/QuitAfterGameStop.h
|
||||
launch/steps/PrintServers.cpp
|
||||
@ -172,6 +170,8 @@ set(LAUNCH_SOURCES
|
||||
launch/LaunchTask.h
|
||||
launch/LogModel.cpp
|
||||
launch/LogModel.h
|
||||
launch/TaskStepWrapper.cpp
|
||||
launch/TaskStepWrapper.h
|
||||
)
|
||||
|
||||
# Old update system
|
||||
@ -295,8 +295,6 @@ set(MINECRAFT_SOURCES
|
||||
minecraft/ComponentUpdateTask.h
|
||||
minecraft/MinecraftLoadAndCheck.h
|
||||
minecraft/MinecraftLoadAndCheck.cpp
|
||||
minecraft/MinecraftUpdate.h
|
||||
minecraft/MinecraftUpdate.cpp
|
||||
minecraft/MojangVersionFormat.cpp
|
||||
minecraft/MojangVersionFormat.h
|
||||
minecraft/Rule.cpp
|
||||
|
@ -53,7 +53,7 @@ class NullInstance : public BaseInstance {
|
||||
QSet<QString> traits() const override { return {}; };
|
||||
QString instanceConfigFolder() const override { return instanceRoot(); };
|
||||
shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr, MinecraftTarget::Ptr) override { return nullptr; }
|
||||
shared_qobject_ptr<Task> createUpdateTask([[maybe_unused]] Net::Mode mode) override { return nullptr; }
|
||||
QList<Task::Ptr> createUpdateTask() override { return {}; }
|
||||
QProcessEnvironment createEnvironment() override { return QProcessEnvironment(); }
|
||||
QProcessEnvironment createLaunchEnvironment() override { return QProcessEnvironment(); }
|
||||
QMap<QString, QString> getVariables() override { return QMap<QString, QString>(); }
|
||||
|
@ -20,13 +20,13 @@
|
||||
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
#include "SysInfo.h"
|
||||
#include "settings/SettingsObject.h"
|
||||
|
||||
struct RuntimeContext {
|
||||
QString javaArchitecture;
|
||||
QString javaRealArchitecture;
|
||||
QString javaPath;
|
||||
QString system;
|
||||
QString system = SysInfo::currentSystem();
|
||||
|
||||
QString mappedJavaRealArchitecture() const
|
||||
{
|
||||
@ -45,8 +45,6 @@ struct RuntimeContext {
|
||||
{
|
||||
javaArchitecture = instanceSettings->get("JavaArchitecture").toString();
|
||||
javaRealArchitecture = instanceSettings->get("JavaRealArchitecture").toString();
|
||||
javaPath = instanceSettings->get("JavaPath").toString();
|
||||
system = currentSystem();
|
||||
}
|
||||
|
||||
QString getClassifier() const { return system + "-" + mappedJavaRealArchitecture(); }
|
||||
@ -68,21 +66,4 @@ struct RuntimeContext {
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static QString currentSystem()
|
||||
{
|
||||
#if defined(Q_OS_LINUX)
|
||||
return "linux";
|
||||
#elif defined(Q_OS_MACOS)
|
||||
return "osx";
|
||||
#elif defined(Q_OS_WINDOWS)
|
||||
return "windows";
|
||||
#elif defined(Q_OS_FREEBSD)
|
||||
return "freebsd";
|
||||
#elif defined(Q_OS_OPENBSD)
|
||||
return "openbsd";
|
||||
#else
|
||||
return "unknown";
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
@ -16,9 +16,8 @@
|
||||
#include "LaunchStep.h"
|
||||
#include "LaunchTask.h"
|
||||
|
||||
void LaunchStep::bind(LaunchTask* parent)
|
||||
LaunchStep::LaunchStep(LaunchTask* parent) : Task(parent), m_parent(parent)
|
||||
{
|
||||
m_parent = parent;
|
||||
connect(this, &LaunchStep::readyForLaunch, parent, &LaunchTask::onReadyForLaunch);
|
||||
connect(this, &LaunchStep::logLine, parent, &LaunchTask::onLogLine);
|
||||
connect(this, &LaunchStep::logLines, parent, &LaunchTask::onLogLines);
|
||||
|
@ -24,11 +24,8 @@ class LaunchTask;
|
||||
class LaunchStep : public Task {
|
||||
Q_OBJECT
|
||||
public: /* methods */
|
||||
explicit LaunchStep(LaunchTask* parent) : Task(nullptr), m_parent(parent) { bind(parent); };
|
||||
virtual ~LaunchStep() {};
|
||||
|
||||
private: /* methods */
|
||||
void bind(LaunchTask* parent);
|
||||
explicit LaunchStep(LaunchTask* parent);
|
||||
virtual ~LaunchStep() = default;
|
||||
|
||||
signals:
|
||||
void logLines(QStringList lines, MessageLevel::Enum level);
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QStandardPaths>
|
||||
#include "MessageLevel.h"
|
||||
#include "java/JavaChecker.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
void LaunchTask::init()
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include "BaseInstance.h"
|
||||
#include "LaunchStep.h"
|
||||
#include "LogModel.h"
|
||||
#include "LoggedProcess.h"
|
||||
#include "MessageLevel.h"
|
||||
|
||||
class LaunchTask : public Task {
|
||||
@ -55,7 +54,7 @@ class LaunchTask : public Task {
|
||||
|
||||
public: /* methods */
|
||||
static shared_qobject_ptr<LaunchTask> create(InstancePtr inst);
|
||||
virtual ~LaunchTask() {};
|
||||
virtual ~LaunchTask() = default;
|
||||
|
||||
void appendStep(shared_qobject_ptr<LaunchStep> step);
|
||||
void prependStep(shared_qobject_ptr<LaunchStep> step);
|
||||
|
65
launcher/launch/TaskStepWrapper.cpp
Normal file
65
launcher/launch/TaskStepWrapper.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "TaskStepWrapper.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
void TaskStepWrapper::executeTask()
|
||||
{
|
||||
if (m_state == Task::State::AbortedByUser) {
|
||||
emitFailed(tr("Task aborted."));
|
||||
return;
|
||||
}
|
||||
connect(m_task.get(), &Task::finished, this, &TaskStepWrapper::updateFinished);
|
||||
connect(m_task.get(), &Task::progress, this, &TaskStepWrapper::setProgress);
|
||||
connect(m_task.get(), &Task::stepProgress, this, &TaskStepWrapper::propagateStepProgress);
|
||||
connect(m_task.get(), &Task::status, this, &TaskStepWrapper::setStatus);
|
||||
connect(m_task.get(), &Task::details, this, &TaskStepWrapper::setDetails);
|
||||
emit progressReportingRequest();
|
||||
}
|
||||
|
||||
void TaskStepWrapper::proceed()
|
||||
{
|
||||
m_task->start();
|
||||
}
|
||||
|
||||
void TaskStepWrapper::updateFinished()
|
||||
{
|
||||
if (m_task->wasSuccessful()) {
|
||||
m_task.reset();
|
||||
emitSucceeded();
|
||||
} else {
|
||||
QString reason = tr("Instance update failed because: %1\n\n").arg(m_task->failReason());
|
||||
m_task.reset();
|
||||
emit logLine(reason, MessageLevel::Fatal);
|
||||
emitFailed(reason);
|
||||
}
|
||||
}
|
||||
|
||||
bool TaskStepWrapper::canAbort() const
|
||||
{
|
||||
if (m_task) {
|
||||
return m_task->canAbort();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TaskStepWrapper::abort()
|
||||
{
|
||||
if (m_task && m_task->canAbort()) {
|
||||
return m_task->abort();
|
||||
}
|
||||
return Task::abort();
|
||||
}
|
@ -21,12 +21,11 @@
|
||||
#include <launch/LaunchStep.h>
|
||||
#include <net/Mode.h>
|
||||
|
||||
// FIXME: stupid. should be defined by the instance type? or even completely abstracted away...
|
||||
class Update : public LaunchStep {
|
||||
class TaskStepWrapper : public LaunchStep {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Update(LaunchTask* parent, Net::Mode mode) : LaunchStep(parent), m_mode(mode) {};
|
||||
virtual ~Update() {};
|
||||
explicit TaskStepWrapper(LaunchTask* parent, Task::Ptr task) : LaunchStep(parent), m_task(task) {};
|
||||
virtual ~TaskStepWrapper() = default;
|
||||
|
||||
void executeTask() override;
|
||||
bool canAbort() const override;
|
||||
@ -38,7 +37,5 @@ class Update : public LaunchStep {
|
||||
void updateFinished();
|
||||
|
||||
private:
|
||||
Task::Ptr m_updateTask;
|
||||
bool m_aborted = false;
|
||||
Net::Mode m_mode = Net::Mode::Offline;
|
||||
Task::Ptr m_task;
|
||||
};
|
@ -106,6 +106,7 @@ void CheckJava::executeTask()
|
||||
auto vendorString = instance->settings()->get("JavaVendor").toString();
|
||||
printJavaInfo(verString, archString, realArchString, vendorString);
|
||||
}
|
||||
m_parent->instance()->updateRuntimeContext();
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
@ -124,6 +125,7 @@ void CheckJava::checkJavaFinished(const JavaChecker::Result& result)
|
||||
emit logLine(QString("Java checker returned some invalid data we don't understand:"), MessageLevel::Error);
|
||||
emit logLines(result.outLog.split('\n'), MessageLevel::Warning);
|
||||
emit logLine("\nMinecraft might not start properly.", MessageLevel::Launcher);
|
||||
m_parent->instance()->updateRuntimeContext();
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
@ -135,6 +137,7 @@ void CheckJava::checkJavaFinished(const JavaChecker::Result& result)
|
||||
instance->settings()->set("JavaRealArchitecture", result.realPlatform);
|
||||
instance->settings()->set("JavaVendor", result.javaVendor);
|
||||
instance->settings()->set("JavaSignature", m_javaSignature);
|
||||
m_parent->instance()->updateRuntimeContext();
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class CheckJava : public LaunchStep {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CheckJava(LaunchTask* parent) : LaunchStep(parent) {};
|
||||
virtual ~CheckJava() {};
|
||||
virtual ~CheckJava() = default;
|
||||
|
||||
virtual void executeTask();
|
||||
virtual bool canAbort() const { return false; }
|
||||
|
@ -24,7 +24,7 @@ class QuitAfterGameStop : public LaunchStep {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QuitAfterGameStop(LaunchTask* parent) : LaunchStep(parent) {};
|
||||
virtual ~QuitAfterGameStop() {};
|
||||
virtual ~QuitAfterGameStop() = default;
|
||||
|
||||
virtual void executeTask();
|
||||
virtual bool canAbort() const { return false; }
|
||||
|
@ -1,73 +0,0 @@
|
||||
/* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "Update.h"
|
||||
#include <launch/LaunchTask.h>
|
||||
|
||||
void Update::executeTask()
|
||||
{
|
||||
if (m_aborted) {
|
||||
emitFailed(tr("Task aborted."));
|
||||
return;
|
||||
}
|
||||
m_updateTask.reset(m_parent->instance()->createUpdateTask(m_mode));
|
||||
if (m_updateTask) {
|
||||
connect(m_updateTask.get(), &Task::finished, this, &Update::updateFinished);
|
||||
connect(m_updateTask.get(), &Task::progress, this, &Update::setProgress);
|
||||
connect(m_updateTask.get(), &Task::stepProgress, this, &Update::propagateStepProgress);
|
||||
connect(m_updateTask.get(), &Task::status, this, &Update::setStatus);
|
||||
connect(m_updateTask.get(), &Task::details, this, &Update::setDetails);
|
||||
emit progressReportingRequest();
|
||||
return;
|
||||
}
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
void Update::proceed()
|
||||
{
|
||||
m_updateTask->start();
|
||||
}
|
||||
|
||||
void Update::updateFinished()
|
||||
{
|
||||
if (m_updateTask->wasSuccessful()) {
|
||||
m_updateTask.reset();
|
||||
emitSucceeded();
|
||||
} else {
|
||||
QString reason = tr("Instance update failed because: %1\n\n").arg(m_updateTask->failReason());
|
||||
m_updateTask.reset();
|
||||
emit logLine(reason, MessageLevel::Fatal);
|
||||
emitFailed(reason);
|
||||
}
|
||||
}
|
||||
|
||||
bool Update::canAbort() const
|
||||
{
|
||||
if (m_updateTask) {
|
||||
return m_updateTask->canAbort();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Update::abort()
|
||||
{
|
||||
m_aborted = true;
|
||||
if (m_updateTask) {
|
||||
if (m_updateTask->canAbort()) {
|
||||
return m_updateTask->abort();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
@ -164,6 +164,7 @@ void LaunchProfile::applyCompatibleJavaMajors(QList<int>& javaMajor)
|
||||
{
|
||||
m_compatibleJavaMajors.append(javaMajor);
|
||||
}
|
||||
|
||||
void LaunchProfile::applyCompatibleJavaName(QString javaName)
|
||||
{
|
||||
if (!javaName.isEmpty())
|
||||
|
@ -43,6 +43,9 @@
|
||||
#include "minecraft/launch/CreateGameFolders.h"
|
||||
#include "minecraft/launch/ExtractNatives.h"
|
||||
#include "minecraft/launch/PrintInstanceInfo.h"
|
||||
#include "minecraft/update/AssetUpdateTask.h"
|
||||
#include "minecraft/update/FMLLibrariesTask.h"
|
||||
#include "minecraft/update/LibrariesTask.h"
|
||||
#include "settings/Setting.h"
|
||||
#include "settings/SettingsObject.h"
|
||||
|
||||
@ -53,13 +56,13 @@
|
||||
#include "pathmatcher/RegexpMatcher.h"
|
||||
|
||||
#include "launch/LaunchTask.h"
|
||||
#include "launch/TaskStepWrapper.h"
|
||||
#include "launch/steps/CheckJava.h"
|
||||
#include "launch/steps/LookupServerAddress.h"
|
||||
#include "launch/steps/PostLaunchCommand.h"
|
||||
#include "launch/steps/PreLaunchCommand.h"
|
||||
#include "launch/steps/QuitAfterGameStop.h"
|
||||
#include "launch/steps/TextPrint.h"
|
||||
#include "launch/steps/Update.h"
|
||||
|
||||
#include "minecraft/launch/ClaimAccount.h"
|
||||
#include "minecraft/launch/LauncherPartLaunch.h"
|
||||
@ -70,9 +73,6 @@
|
||||
|
||||
#include "java/JavaUtils.h"
|
||||
|
||||
#include "meta/Index.h"
|
||||
#include "meta/VersionList.h"
|
||||
|
||||
#include "icons/IconList.h"
|
||||
|
||||
#include "mod/ModFolderModel.h"
|
||||
@ -84,7 +84,6 @@
|
||||
|
||||
#include "AssetsUtils.h"
|
||||
#include "MinecraftLoadAndCheck.h"
|
||||
#include "MinecraftUpdate.h"
|
||||
#include "PackProfile.h"
|
||||
#include "minecraft/gameoptions/GameOptions.h"
|
||||
#include "minecraft/update/FoldersTask.h"
|
||||
@ -218,6 +217,7 @@ void MinecraftInstance::loadSpecificSettings()
|
||||
void MinecraftInstance::updateRuntimeContext()
|
||||
{
|
||||
m_runtimeContext.updateFromInstanceSettings(m_settings);
|
||||
m_components->invalidateLaunchProfile();
|
||||
}
|
||||
|
||||
QString MinecraftInstance::typeName() const
|
||||
@ -1030,18 +1030,18 @@ QString MinecraftInstance::getStatusbarDescription()
|
||||
return description;
|
||||
}
|
||||
|
||||
Task::Ptr MinecraftInstance::createUpdateTask(Net::Mode mode)
|
||||
QList<LaunchStep::Ptr> MinecraftInstance::createUpdateTask()
|
||||
{
|
||||
updateRuntimeContext();
|
||||
switch (mode) {
|
||||
case Net::Mode::Offline: {
|
||||
return Task::Ptr(new MinecraftLoadAndCheck(this));
|
||||
}
|
||||
case Net::Mode::Online: {
|
||||
return Task::Ptr(new MinecraftUpdate(this));
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
return {
|
||||
// create folders
|
||||
makeShared<FoldersTask>(this),
|
||||
// libraries download
|
||||
makeShared<LibrariesTask>(this),
|
||||
// FML libraries download and copy into the instance
|
||||
makeShared<FMLLibrariesTask>(this),
|
||||
// assets update
|
||||
makeShared<AssetUpdateTask>(this),
|
||||
};
|
||||
}
|
||||
|
||||
shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPtr session, MinecraftTarget::Ptr targetToJoin)
|
||||
@ -1090,14 +1090,10 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
|
||||
process->appendStep(step);
|
||||
}
|
||||
|
||||
// if we aren't in offline mode,.
|
||||
if (session->status != AuthSession::PlayableOffline) {
|
||||
if (!session->demo) {
|
||||
process->appendStep(makeShared<ClaimAccount>(pptr, session));
|
||||
}
|
||||
process->appendStep(makeShared<Update>(pptr, Net::Mode::Online));
|
||||
} else {
|
||||
process->appendStep(makeShared<Update>(pptr, Net::Mode::Offline));
|
||||
// load meta
|
||||
{
|
||||
auto mode = session->status != AuthSession::PlayableOffline ? Net::Mode::Online : Net::Mode::Offline;
|
||||
process->appendStep(makeShared<TaskStepWrapper>(pptr, makeShared<MinecraftLoadAndCheck>(this, mode, pptr)));
|
||||
}
|
||||
|
||||
// check java
|
||||
@ -1106,6 +1102,16 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
|
||||
process->appendStep(makeShared<CheckJava>(pptr));
|
||||
}
|
||||
|
||||
// if we aren't in offline mode,.
|
||||
if (session->status != AuthSession::PlayableOffline) {
|
||||
if (!session->demo) {
|
||||
process->appendStep(makeShared<ClaimAccount>(pptr, session));
|
||||
}
|
||||
for (auto t : createUpdateTask()) {
|
||||
process->appendStep(makeShared<TaskStepWrapper>(pptr, t));
|
||||
}
|
||||
}
|
||||
|
||||
// if there are any jar mods
|
||||
{
|
||||
process->appendStep(makeShared<ModMinecraftJar>(pptr));
|
||||
|
@ -104,7 +104,7 @@ class MinecraftInstance : public BaseInstance {
|
||||
/** Returns whether the instance, with its version, has support for demo mode. */
|
||||
[[nodiscard]] bool supportsDemo() const;
|
||||
|
||||
void updateRuntimeContext();
|
||||
void updateRuntimeContext() override;
|
||||
|
||||
////// Profile management //////
|
||||
std::shared_ptr<PackProfile> getPackProfile() const;
|
||||
@ -120,7 +120,7 @@ class MinecraftInstance : public BaseInstance {
|
||||
std::shared_ptr<GameOptions> gameOptionsModel();
|
||||
|
||||
////// Launch stuff //////
|
||||
Task::Ptr createUpdateTask(Net::Mode mode) override;
|
||||
QList<Task::Ptr> createUpdateTask() override;
|
||||
shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account, MinecraftTarget::Ptr targetToJoin) override;
|
||||
QStringList extraArguments() override;
|
||||
QStringList verboseDescription(AuthSessionPtr session, MinecraftTarget::Ptr targetToJoin) override;
|
||||
|
@ -2,41 +2,42 @@
|
||||
#include "MinecraftInstance.h"
|
||||
#include "PackProfile.h"
|
||||
|
||||
MinecraftLoadAndCheck::MinecraftLoadAndCheck(MinecraftInstance* inst, QObject* parent) : Task(parent), m_inst(inst) {}
|
||||
MinecraftLoadAndCheck::MinecraftLoadAndCheck(MinecraftInstance* inst, Net::Mode netmode, QObject* parent)
|
||||
: Task(parent), m_inst(inst), m_netmode(netmode)
|
||||
{}
|
||||
|
||||
void MinecraftLoadAndCheck::executeTask()
|
||||
{
|
||||
// add offline metadata load task
|
||||
auto components = m_inst->getPackProfile();
|
||||
components->reload(Net::Mode::Offline);
|
||||
components->reload(m_netmode);
|
||||
m_task = components->getCurrentTask();
|
||||
|
||||
if (!m_task) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
connect(m_task.get(), &Task::succeeded, this, &MinecraftLoadAndCheck::subtaskSucceeded);
|
||||
connect(m_task.get(), &Task::failed, this, &MinecraftLoadAndCheck::subtaskFailed);
|
||||
connect(m_task.get(), &Task::aborted, this, [this] { subtaskFailed(tr("Aborted")); });
|
||||
connect(m_task.get(), &Task::progress, this, &MinecraftLoadAndCheck::progress);
|
||||
connect(m_task.get(), &Task::succeeded, this, &MinecraftLoadAndCheck::emitSucceeded);
|
||||
connect(m_task.get(), &Task::failed, this, &MinecraftLoadAndCheck::emitFailed);
|
||||
connect(m_task.get(), &Task::aborted, this, [this] { emitFailed(tr("Aborted")); });
|
||||
connect(m_task.get(), &Task::progress, this, &MinecraftLoadAndCheck::setProgress);
|
||||
connect(m_task.get(), &Task::stepProgress, this, &MinecraftLoadAndCheck::propagateStepProgress);
|
||||
connect(m_task.get(), &Task::status, this, &MinecraftLoadAndCheck::setStatus);
|
||||
connect(m_task.get(), &Task::details, this, &MinecraftLoadAndCheck::setDetails);
|
||||
}
|
||||
|
||||
void MinecraftLoadAndCheck::subtaskSucceeded()
|
||||
bool MinecraftLoadAndCheck::canAbort() const
|
||||
{
|
||||
if (isFinished()) {
|
||||
qCritical() << "MinecraftUpdate: Subtask" << sender() << "succeeded, but work was already done!";
|
||||
return;
|
||||
if (m_task) {
|
||||
return m_task->canAbort();
|
||||
}
|
||||
emitSucceeded();
|
||||
return true;
|
||||
}
|
||||
|
||||
void MinecraftLoadAndCheck::subtaskFailed(QString error)
|
||||
bool MinecraftLoadAndCheck::abort()
|
||||
{
|
||||
if (isFinished()) {
|
||||
qCritical() << "MinecraftUpdate: Subtask" << sender() << "failed, but work was already done!";
|
||||
return;
|
||||
if (m_task && m_task->canAbort()) {
|
||||
return m_task->abort();
|
||||
}
|
||||
emitFailed(error);
|
||||
}
|
||||
return Task::abort();
|
||||
}
|
@ -15,32 +15,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
#include <quazip/quazip.h>
|
||||
#include "net/Mode.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
|
||||
class MinecraftVersion;
|
||||
class MinecraftInstance;
|
||||
|
||||
class MinecraftLoadAndCheck : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MinecraftLoadAndCheck(MinecraftInstance* inst, QObject* parent = 0);
|
||||
virtual ~MinecraftLoadAndCheck() {};
|
||||
explicit MinecraftLoadAndCheck(MinecraftInstance* inst, Net::Mode netmode, QObject* parent = nullptr);
|
||||
virtual ~MinecraftLoadAndCheck() = default;
|
||||
void executeTask() override;
|
||||
|
||||
private slots:
|
||||
void subtaskSucceeded();
|
||||
void subtaskFailed(QString error);
|
||||
bool canAbort() const override;
|
||||
public slots:
|
||||
bool abort() override;
|
||||
|
||||
private:
|
||||
MinecraftInstance* m_inst = nullptr;
|
||||
Task::Ptr m_task;
|
||||
QString m_preFailure;
|
||||
QString m_fail_reason;
|
||||
Net::Mode m_netmode;
|
||||
};
|
||||
|
@ -1,63 +0,0 @@
|
||||
/* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MinecraftUpdate.h"
|
||||
#include "MinecraftInstance.h"
|
||||
|
||||
#include "minecraft/PackProfile.h"
|
||||
|
||||
#include "tasks/SequentialTask.h"
|
||||
#include "update/AssetUpdateTask.h"
|
||||
#include "update/FMLLibrariesTask.h"
|
||||
#include "update/FoldersTask.h"
|
||||
#include "update/LibrariesTask.h"
|
||||
|
||||
MinecraftUpdate::MinecraftUpdate(MinecraftInstance* inst, QObject* parent) : SequentialTask(parent), m_inst(inst) {}
|
||||
|
||||
void MinecraftUpdate::executeTask()
|
||||
{
|
||||
m_queue.clear();
|
||||
// create folders
|
||||
{
|
||||
addTask(makeShared<FoldersTask>(m_inst));
|
||||
}
|
||||
|
||||
// add metadata update task if necessary
|
||||
{
|
||||
auto components = m_inst->getPackProfile();
|
||||
components->reload(Net::Mode::Online);
|
||||
auto task = components->getCurrentTask();
|
||||
if (task) {
|
||||
addTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
// libraries download
|
||||
{
|
||||
addTask(makeShared<LibrariesTask>(m_inst));
|
||||
}
|
||||
|
||||
// FML libraries download and copy into the instance
|
||||
{
|
||||
addTask(makeShared<FMLLibrariesTask>(m_inst));
|
||||
}
|
||||
|
||||
// assets update
|
||||
{
|
||||
addTask(makeShared<AssetUpdateTask>(m_inst));
|
||||
}
|
||||
|
||||
SequentialTask::executeTask();
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "tasks/SequentialTask.h"
|
||||
|
||||
class MinecraftInstance;
|
||||
|
||||
// this needs to be a task because components->reload does stuff that may block
|
||||
class MinecraftUpdate : public SequentialTask {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MinecraftUpdate(MinecraftInstance* inst, QObject* parent = 0);
|
||||
virtual ~MinecraftUpdate() = default;
|
||||
|
||||
void executeTask() override;
|
||||
|
||||
private:
|
||||
MinecraftInstance* m_inst = nullptr;
|
||||
};
|
@ -148,13 +148,13 @@ class PackProfile : public QAbstractListModel {
|
||||
std::optional<ModPlatform::ModLoaderTypes> getSupportedModLoaders();
|
||||
QList<ModPlatform::ModLoaderType> getModLoadersList();
|
||||
|
||||
/// apply the component patches. Catches all the errors and returns true/false for success/failure
|
||||
void invalidateLaunchProfile();
|
||||
|
||||
private:
|
||||
void scheduleSave();
|
||||
bool saveIsScheduled() const;
|
||||
|
||||
/// apply the component patches. Catches all the errors and returns true/false for success/failure
|
||||
void invalidateLaunchProfile();
|
||||
|
||||
/// insert component so that its index is ideally the specified one (returns real index)
|
||||
void insertComponent(size_t index, ComponentPtr component);
|
||||
|
||||
|
@ -37,7 +37,6 @@
|
||||
|
||||
#include <launch/LaunchStep.h>
|
||||
#include <launch/LaunchTask.h>
|
||||
#include "java/JavaMetadata.h"
|
||||
#include "meta/Version.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "tasks/Task.h"
|
||||
|
@ -22,7 +22,7 @@ class ClaimAccount : public LaunchStep {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClaimAccount(LaunchTask* parent, AuthSessionPtr session);
|
||||
virtual ~ClaimAccount() {};
|
||||
virtual ~ClaimAccount() = default;
|
||||
|
||||
void executeTask() override;
|
||||
void finalize() override;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "AssetUpdateTask.h"
|
||||
|
||||
#include "launch/LaunchStep.h"
|
||||
#include "minecraft/AssetsUtils.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
@ -14,8 +15,6 @@ AssetUpdateTask::AssetUpdateTask(MinecraftInstance* inst)
|
||||
m_inst = inst;
|
||||
}
|
||||
|
||||
AssetUpdateTask::~AssetUpdateTask() {}
|
||||
|
||||
void AssetUpdateTask::executeTask()
|
||||
{
|
||||
setStatus(tr("Updating assets index..."));
|
||||
|
@ -7,7 +7,7 @@ class AssetUpdateTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AssetUpdateTask(MinecraftInstance* inst);
|
||||
virtual ~AssetUpdateTask();
|
||||
virtual ~AssetUpdateTask() = default;
|
||||
|
||||
void executeTask() override;
|
||||
|
||||
|
@ -9,7 +9,7 @@ class FMLLibrariesTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FMLLibrariesTask(MinecraftInstance* inst);
|
||||
virtual ~FMLLibrariesTask() {};
|
||||
virtual ~FMLLibrariesTask() = default;
|
||||
|
||||
void executeTask() override;
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include <QDir>
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
|
||||
FoldersTask::FoldersTask(MinecraftInstance* inst) : Task()
|
||||
FoldersTask::FoldersTask(MinecraftInstance* inst)
|
||||
{
|
||||
m_inst = inst;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ class FoldersTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FoldersTask(MinecraftInstance* inst);
|
||||
virtual ~FoldersTask() {};
|
||||
virtual ~FoldersTask() = default;
|
||||
|
||||
void executeTask() override;
|
||||
|
||||
|
@ -7,7 +7,7 @@ class LibrariesTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LibrariesTask(MinecraftInstance* inst);
|
||||
virtual ~LibrariesTask() {};
|
||||
virtual ~LibrariesTask() = default;
|
||||
|
||||
void executeTask() override;
|
||||
|
||||
|
@ -51,8 +51,10 @@
|
||||
#include <QUrl>
|
||||
#include <algorithm>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "VersionPage.h"
|
||||
#include "meta/JsonFormat.h"
|
||||
#include "tasks/SequentialTask.h"
|
||||
#include "ui/dialogs/InstallLoaderDialog.h"
|
||||
#include "ui_VersionPage.h"
|
||||
|
||||
@ -429,14 +431,18 @@ void VersionPage::on_actionDownload_All_triggered()
|
||||
return;
|
||||
}
|
||||
|
||||
auto updateTask = m_inst->createUpdateTask(Net::Mode::Online);
|
||||
if (!updateTask) {
|
||||
auto updateTasks = m_inst->createUpdateTask();
|
||||
if (updateTasks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
auto task = makeShared<SequentialTask>(this);
|
||||
for (auto t : updateTasks) {
|
||||
task->addTask(t);
|
||||
}
|
||||
ProgressDialog tDialog(this);
|
||||
connect(updateTask.get(), &Task::failed, this, &VersionPage::onGameUpdateError);
|
||||
connect(task.get(), &Task::failed, this, &VersionPage::onGameUpdateError);
|
||||
// FIXME: unused return value
|
||||
tDialog.execWithTask(updateTask.get());
|
||||
tDialog.execWithTask(task.get());
|
||||
updateButtons();
|
||||
m_container->refreshContainer();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user