Change LaunchTask to only accept MinecraftInstance
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
a200fca45c
commit
909114bf2a
@ -51,14 +51,14 @@ void LaunchTask::init()
|
|||||||
m_instance->setRunning(true);
|
m_instance->setRunning(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<LaunchTask> LaunchTask::create(InstancePtr inst)
|
shared_qobject_ptr<LaunchTask> LaunchTask::create(MinecraftInstancePtr inst)
|
||||||
{
|
{
|
||||||
shared_qobject_ptr<LaunchTask> proc(new LaunchTask(inst));
|
shared_qobject_ptr<LaunchTask> proc(new LaunchTask(inst));
|
||||||
proc->init();
|
proc->init();
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchTask::LaunchTask(InstancePtr instance) : m_instance(instance) {}
|
LaunchTask::LaunchTask(MinecraftInstancePtr instance) : m_instance(instance) {}
|
||||||
|
|
||||||
void LaunchTask::appendStep(shared_qobject_ptr<LaunchStep> step)
|
void LaunchTask::appendStep(shared_qobject_ptr<LaunchStep> step)
|
||||||
{
|
{
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObjectPtr.h>
|
#include <QObjectPtr.h>
|
||||||
|
#include <minecraft/MinecraftInstance.h>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include "BaseInstance.h"
|
#include "BaseInstance.h"
|
||||||
#include "LaunchStep.h"
|
#include "LaunchStep.h"
|
||||||
@ -46,21 +47,21 @@
|
|||||||
class LaunchTask : public Task {
|
class LaunchTask : public Task {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
explicit LaunchTask(InstancePtr instance);
|
explicit LaunchTask(MinecraftInstancePtr instance);
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum State { NotStarted, Running, Waiting, Failed, Aborted, Finished };
|
enum State { NotStarted, Running, Waiting, Failed, Aborted, Finished };
|
||||||
|
|
||||||
public: /* methods */
|
public: /* methods */
|
||||||
static shared_qobject_ptr<LaunchTask> create(InstancePtr inst);
|
static shared_qobject_ptr<LaunchTask> create(MinecraftInstancePtr inst);
|
||||||
virtual ~LaunchTask() = default;
|
virtual ~LaunchTask() = default;
|
||||||
|
|
||||||
void appendStep(shared_qobject_ptr<LaunchStep> step);
|
void appendStep(shared_qobject_ptr<LaunchStep> step);
|
||||||
void prependStep(shared_qobject_ptr<LaunchStep> step);
|
void prependStep(shared_qobject_ptr<LaunchStep> step);
|
||||||
void setCensorFilter(QMap<QString, QString> filter);
|
void setCensorFilter(QMap<QString, QString> filter);
|
||||||
|
|
||||||
InstancePtr instance() { return m_instance; }
|
MinecraftInstancePtr instance() { return m_instance; }
|
||||||
|
|
||||||
void setPid(qint64 pid) { m_pid = pid; }
|
void setPid(qint64 pid) { m_pid = pid; }
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ class LaunchTask : public Task {
|
|||||||
void finalizeSteps(bool successful, const QString& error);
|
void finalizeSteps(bool successful, const QString& error);
|
||||||
|
|
||||||
protected: /* data */
|
protected: /* data */
|
||||||
InstancePtr m_instance;
|
MinecraftInstancePtr m_instance;
|
||||||
shared_qobject_ptr<LogModel> m_logModel;
|
shared_qobject_ptr<LogModel> m_logModel;
|
||||||
QList<shared_qobject_ptr<LaunchStep>> m_steps;
|
QList<shared_qobject_ptr<LaunchStep>> m_steps;
|
||||||
QMap<QString, QString> m_censorFilter;
|
QMap<QString, QString> m_censorFilter;
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
|
|
||||||
AutoInstallJava::AutoInstallJava(LaunchTask* parent)
|
AutoInstallJava::AutoInstallJava(LaunchTask* parent)
|
||||||
: LaunchStep(parent)
|
: LaunchStep(parent)
|
||||||
, m_instance(std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance()))
|
, m_instance(m_parent->instance())
|
||||||
, m_supported_arch(SysInfo::getSupportedJavaArchitecture()) {};
|
, m_supported_arch(SysInfo::getSupportedJavaArchitecture()) {};
|
||||||
|
|
||||||
void AutoInstallJava::executeTask()
|
void AutoInstallJava::executeTask()
|
||||||
|
@ -8,16 +8,15 @@ CreateGameFolders::CreateGameFolders(LaunchTask* parent) : LaunchStep(parent) {}
|
|||||||
void CreateGameFolders::executeTask()
|
void CreateGameFolders::executeTask()
|
||||||
{
|
{
|
||||||
auto instance = m_parent->instance();
|
auto instance = m_parent->instance();
|
||||||
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
|
|
||||||
|
|
||||||
if (!FS::ensureFolderPathExists(minecraftInstance->gameRoot())) {
|
if (!FS::ensureFolderPathExists(instance->gameRoot())) {
|
||||||
emit logLine("Couldn't create the main game folder", MessageLevel::Error);
|
emit logLine("Couldn't create the main game folder", MessageLevel::Error);
|
||||||
emitFailed(tr("Couldn't create the main game folder"));
|
emitFailed(tr("Couldn't create the main game folder"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK: this is a workaround for MCL-3732 - 'server-resource-packs' folder is created.
|
// HACK: this is a workaround for MCL-3732 - 'server-resource-packs' folder is created.
|
||||||
if (!FS::ensureFolderPathExists(FS::PathCombine(minecraftInstance->gameRoot(), "server-resource-packs"))) {
|
if (!FS::ensureFolderPathExists(FS::PathCombine(instance->gameRoot(), "server-resource-packs"))) {
|
||||||
emit logLine("Couldn't create the 'server-resource-packs' folder", MessageLevel::Error);
|
emit logLine("Couldn't create the 'server-resource-packs' folder", MessageLevel::Error);
|
||||||
}
|
}
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
|
@ -70,17 +70,16 @@ static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibH
|
|||||||
void ExtractNatives::executeTask()
|
void ExtractNatives::executeTask()
|
||||||
{
|
{
|
||||||
auto instance = m_parent->instance();
|
auto instance = m_parent->instance();
|
||||||
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
|
auto toExtract = instance->getNativeJars();
|
||||||
auto toExtract = minecraftInstance->getNativeJars();
|
|
||||||
if (toExtract.isEmpty()) {
|
if (toExtract.isEmpty()) {
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto settings = minecraftInstance->settings();
|
auto settings = instance->settings();
|
||||||
|
|
||||||
auto outputPath = minecraftInstance->getNativePath();
|
auto outputPath = instance->getNativePath();
|
||||||
FS::ensureFolderPathExists(outputPath);
|
FS::ensureFolderPathExists(outputPath);
|
||||||
auto javaVersion = minecraftInstance->getJavaVersion();
|
auto javaVersion = instance->getJavaVersion();
|
||||||
bool jniHackEnabled = javaVersion.major() >= 8;
|
bool jniHackEnabled = javaVersion.major() >= 8;
|
||||||
for (const auto& source : toExtract) {
|
for (const auto& source : toExtract) {
|
||||||
if (!unzipNatives(source, outputPath, jniHackEnabled)) {
|
if (!unzipNatives(source, outputPath, jniHackEnabled)) {
|
||||||
|
@ -50,16 +50,16 @@
|
|||||||
|
|
||||||
LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent) : LaunchStep(parent)
|
LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent) : LaunchStep(parent)
|
||||||
{
|
{
|
||||||
auto instance = parent->instance();
|
if (parent->instance()->settings()->get("CloseAfterLaunch").toBool()) {
|
||||||
if (instance->settings()->get("CloseAfterLaunch").toBool()) {
|
|
||||||
std::shared_ptr<QMetaObject::Connection> connection{ new QMetaObject::Connection };
|
std::shared_ptr<QMetaObject::Connection> connection{ new QMetaObject::Connection };
|
||||||
*connection = connect(&m_process, &LoggedProcess::log, this, [=](QStringList lines, [[maybe_unused]] MessageLevel::Enum level) {
|
*connection =
|
||||||
qDebug() << lines;
|
connect(&m_process, &LoggedProcess::log, this, [=](const QStringList& lines, [[maybe_unused]] MessageLevel::Enum level) {
|
||||||
if (lines.filter(QRegularExpression(".*Setting user.+", QRegularExpression::CaseInsensitiveOption)).length() != 0) {
|
qDebug() << lines;
|
||||||
APPLICATION->closeAllWindows();
|
if (lines.filter(QRegularExpression(".*Setting user.+", QRegularExpression::CaseInsensitiveOption)).length() != 0) {
|
||||||
disconnect(*connection);
|
APPLICATION->closeAllWindows();
|
||||||
}
|
disconnect(*connection);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(&m_process, &LoggedProcess::log, this, &LauncherPartLaunch::logLines);
|
connect(&m_process, &LoggedProcess::log, this, &LauncherPartLaunch::logLines);
|
||||||
@ -77,10 +77,9 @@ void LauncherPartLaunch::executeTask()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto instance = m_parent->instance();
|
auto instance = m_parent->instance();
|
||||||
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
|
|
||||||
|
|
||||||
QString legacyJarPath;
|
QString legacyJarPath;
|
||||||
if (minecraftInstance->getLauncher() == "legacy" || minecraftInstance->shouldApplyOnlineFixes()) {
|
if (instance->getLauncher() == "legacy" || instance->shouldApplyOnlineFixes()) {
|
||||||
legacyJarPath = APPLICATION->getJarPath("NewLaunchLegacy.jar");
|
legacyJarPath = APPLICATION->getJarPath("NewLaunchLegacy.jar");
|
||||||
if (legacyJarPath.isEmpty()) {
|
if (legacyJarPath.isEmpty()) {
|
||||||
const char* reason = QT_TR_NOOP("Legacy launcher library could not be found. Please check your installation.");
|
const char* reason = QT_TR_NOOP("Legacy launcher library could not be found. Please check your installation.");
|
||||||
@ -90,8 +89,8 @@ void LauncherPartLaunch::executeTask()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_launchScript = minecraftInstance->createLaunchScript(m_session, m_targetToJoin);
|
m_launchScript = instance->createLaunchScript(m_session, m_targetToJoin);
|
||||||
QStringList args = minecraftInstance->javaArguments();
|
QStringList args = instance->javaArguments();
|
||||||
QString allArgs = args.join(", ");
|
QString allArgs = args.join(", ");
|
||||||
emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::Launcher);
|
emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::Launcher);
|
||||||
|
|
||||||
@ -102,13 +101,13 @@ void LauncherPartLaunch::executeTask()
|
|||||||
// make detachable - this will keep the process running even if the object is destroyed
|
// make detachable - this will keep the process running even if the object is destroyed
|
||||||
m_process.setDetachable(true);
|
m_process.setDetachable(true);
|
||||||
|
|
||||||
auto classPath = minecraftInstance->getClassPath();
|
auto classPath = instance->getClassPath();
|
||||||
classPath.prepend(jarPath);
|
classPath.prepend(jarPath);
|
||||||
|
|
||||||
if (!legacyJarPath.isEmpty())
|
if (!legacyJarPath.isEmpty())
|
||||||
classPath.prepend(legacyJarPath);
|
classPath.prepend(legacyJarPath);
|
||||||
|
|
||||||
auto natPath = minecraftInstance->getNativePath();
|
auto natPath = instance->getNativePath();
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
natPath = FS::getPathNameInLocal8bit(natPath);
|
natPath = FS::getPathNameInLocal8bit(natPath);
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
void ModMinecraftJar::executeTask()
|
void ModMinecraftJar::executeTask()
|
||||||
{
|
{
|
||||||
auto m_inst = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
|
auto m_inst = m_parent->instance();
|
||||||
|
|
||||||
if (!m_inst->getJarMods().size()) {
|
if (!m_inst->getJarMods().size()) {
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
@ -82,7 +82,7 @@ void ModMinecraftJar::finalize()
|
|||||||
|
|
||||||
bool ModMinecraftJar::removeJar()
|
bool ModMinecraftJar::removeJar()
|
||||||
{
|
{
|
||||||
auto m_inst = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
|
auto m_inst = m_parent->instance();
|
||||||
auto finalJarPath = QDir(m_inst->binRoot()).absoluteFilePath("minecraft.jar");
|
auto finalJarPath = QDir(m_inst->binRoot()).absoluteFilePath("minecraft.jar");
|
||||||
QFile finalJar(finalJarPath);
|
QFile finalJar(finalJarPath);
|
||||||
if (finalJar.exists()) {
|
if (finalJar.exists()) {
|
||||||
|
@ -22,12 +22,11 @@
|
|||||||
void ReconstructAssets::executeTask()
|
void ReconstructAssets::executeTask()
|
||||||
{
|
{
|
||||||
auto instance = m_parent->instance();
|
auto instance = m_parent->instance();
|
||||||
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
|
auto components = instance->getPackProfile();
|
||||||
auto components = minecraftInstance->getPackProfile();
|
|
||||||
auto profile = components->getProfile();
|
auto profile = components->getProfile();
|
||||||
auto assets = profile->getMinecraftAssets();
|
auto assets = profile->getMinecraftAssets();
|
||||||
|
|
||||||
if (!AssetsUtils::reconstructAssets(assets->id, minecraftInstance->resourcesDir())) {
|
if (!AssetsUtils::reconstructAssets(assets->id, instance->resourcesDir())) {
|
||||||
emit logLine("Failed to reconstruct Minecraft assets.", MessageLevel::Error);
|
emit logLine("Failed to reconstruct Minecraft assets.", MessageLevel::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
void ScanModFolders::executeTask()
|
void ScanModFolders::executeTask()
|
||||||
{
|
{
|
||||||
auto m_inst = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
|
auto m_inst = m_parent->instance();
|
||||||
|
|
||||||
auto loaders = m_inst->loaderModList();
|
auto loaders = m_inst->loaderModList();
|
||||||
connect(loaders.get(), &ModFolderModel::updateFinished, this, &ScanModFolders::modsDone);
|
connect(loaders.get(), &ModFolderModel::updateFinished, this, &ScanModFolders::modsDone);
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
void VerifyJavaInstall::executeTask()
|
void VerifyJavaInstall::executeTask()
|
||||||
{
|
{
|
||||||
auto instance = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
|
auto instance = m_parent->instance();
|
||||||
auto packProfile = instance->getPackProfile();
|
auto packProfile = instance->getPackProfile();
|
||||||
auto settings = instance->settings();
|
auto settings = instance->settings();
|
||||||
auto storedVersion = settings->get("JavaVersion").toString();
|
auto storedVersion = settings->get("JavaVersion").toString();
|
||||||
|
Loading…
Reference in New Issue
Block a user