Skip to content

Commit

Permalink
Merge pull request PrismLauncher#2795 from Trial97/fix_mc_launch
Browse files Browse the repository at this point in the history
Fix launch when no java is loaded
  • Loading branch information
Trial97 authored Sep 10, 2024
2 parents b17a688 + 2622d3d commit fa68428
Show file tree
Hide file tree
Showing 31 changed files with 163 additions and 290 deletions.
4 changes: 2 additions & 2 deletions launcher/BaseInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand Down
6 changes: 2 additions & 4 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion launcher/NullInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>(); }
Expand Down
23 changes: 2 additions & 21 deletions launcher/RuntimeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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(); }
Expand All @@ -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
}
};
3 changes: 1 addition & 2 deletions launcher/launch/LaunchStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions launcher/launch/LaunchStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion launcher/launch/LaunchTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <QRegularExpression>
#include <QStandardPaths>
#include "MessageLevel.h"
#include "java/JavaChecker.h"
#include "tasks/Task.h"

void LaunchTask::init()
Expand Down
3 changes: 1 addition & 2 deletions launcher/launch/LaunchTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "BaseInstance.h"
#include "LaunchStep.h"
#include "LogModel.h"
#include "LoggedProcess.h"
#include "MessageLevel.h"

class LaunchTask : public Task {
Expand All @@ -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);
Expand Down
65 changes: 65 additions & 0 deletions launcher/launch/TaskStepWrapper.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};
3 changes: 3 additions & 0 deletions launcher/launch/steps/CheckJava.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void CheckJava::executeTask()
auto vendorString = instance->settings()->get("JavaVendor").toString();
printJavaInfo(verString, archString, realArchString, vendorString);
}
m_parent->instance()->updateRuntimeContext();
emitSucceeded();
}

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion launcher/launch/steps/CheckJava.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion launcher/launch/steps/QuitAfterGameStop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
73 changes: 0 additions & 73 deletions launcher/launch/steps/Update.cpp

This file was deleted.

1 change: 1 addition & 0 deletions launcher/minecraft/LaunchProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ void LaunchProfile::applyCompatibleJavaMajors(QList<int>& javaMajor)
{
m_compatibleJavaMajors.append(javaMajor);
}

void LaunchProfile::applyCompatibleJavaName(QString javaName)
{
if (!javaName.isEmpty())
Expand Down
Loading

0 comments on commit fa68428

Please sign in to comment.