From 82c87aa06f793b9f38e6cb42d284f00695f4bac5 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 20 Dec 2013 14:47:26 +0100 Subject: Initial FTB support. Allows "tracking" of FTB instances. --- logic/OneSixFTBInstance.cpp | 111 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 logic/OneSixFTBInstance.cpp (limited to 'logic/OneSixFTBInstance.cpp') diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp new file mode 100644 index 00000000..567004b9 --- /dev/null +++ b/logic/OneSixFTBInstance.cpp @@ -0,0 +1,111 @@ +#include "OneSixFTBInstance.h" + +#include "OneSixVersion.h" +#include "OneSixLibrary.h" +#include "tasks/SequentialTask.h" +#include "ForgeInstaller.h" +#include "lists/ForgeVersionList.h" +#include "MultiMC.h" + +class OneSixFTBInstanceForge : public Task +{ + Q_OBJECT +public: + explicit OneSixFTBInstanceForge(const QString &version, OneSixFTBInstance *inst, QObject *parent = 0) : + Task(parent), instance(inst), version("Forge " + version) + { + } + + void executeTask() + { + for (int i = 0; i < MMC->forgelist()->count(); ++i) + { + if (MMC->forgelist()->at(i)->name() == version) + { + forgeVersion = std::dynamic_pointer_cast(MMC->forgelist()->at(i)); + break; + } + } + if (!forgeVersion) + return; + entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename); + if (entry->stale) + { + setStatus(tr("Downloading Forge...")); + fjob = new NetJob("Forge download"); + fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry)); + connect(fjob, &NetJob::failed, [this](){emitFailed(m_failReason);}); + connect(fjob, &NetJob::succeeded, this, &OneSixFTBInstanceForge::installForge); + connect(fjob, &NetJob::progress, [this](qint64 c, qint64 total){ setProgress(100 * c / total); }); + fjob->start(); + } + else + { + installForge(); + } + } + +private +slots: + void installForge() + { + setStatus(tr("Installing Forge...")); + QString forgePath = entry->getFullPath(); + ForgeInstaller forge(forgePath, forgeVersion->universal_url); + if (!instance->reloadFullVersion()) + { + emitFailed(tr("Couldn't load the version config")); + return; + } + if (!forge.apply(instance->getFullVersion())) + { + emitFailed(tr("Couldn't install Forge")); + return; + } + emitSucceeded(); + } + +private: + OneSixFTBInstance *instance; + QString version; + ForgeVersionPtr forgeVersion; + MetaEntryPtr entry; + NetJob *fjob; +}; + +OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) : + OneSixInstance(rootDir, settings, parent) +{ + QFile f(QDir(minecraftRoot()).absoluteFilePath("pack.json")); + if (f.open(QFile::ReadOnly)) + { + QString data = QString::fromUtf8(f.readAll()); + QRegularExpressionMatch match = QRegularExpression("net.minecraftforge:minecraftforge:[\\.\\d]*").match(data); + m_forge.reset(new OneSixLibrary(match.captured())); + m_forge->finalize(); + } +} + +QString OneSixFTBInstance::getStatusbarDescription() +{ + return "OneSix FTB: " + intendedVersionId(); +} +bool OneSixFTBInstance::menuActionEnabled(QString action_name) const +{ + return false; +} + +std::shared_ptr OneSixFTBInstance::doUpdate(bool only_prepare) +{ + std::shared_ptr task; + task.reset(new SequentialTask(this)); + if (!MMC->forgelist()->isLoaded()) + { + task->addTask(std::shared_ptr(MMC->forgelist()->getLoadTask())); + } + task->addTask(OneSixInstance::doUpdate(only_prepare)); + task->addTask(std::shared_ptr(new OneSixFTBInstanceForge(m_forge->version(), this, this))); + return task; +} + +#include "OneSixFTBInstance.moc" -- cgit v1.2.3 From 74b5b5f535ec8d98ba93c629804c75fda9e32475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 22 Dec 2013 04:31:30 +0100 Subject: Make FTB instances behave better * Do not re-create on every reload * Use the version.json/custom.json logic properly * Should be offline-friendly * FTB instances can be copied, turn into normal instances --- logic/OneSixFTBInstance.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'logic/OneSixFTBInstance.cpp') diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp index 567004b9..0090c1d8 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -57,7 +57,10 @@ slots: emitFailed(tr("Couldn't load the version config")); return; } - if (!forge.apply(instance->getFullVersion())) + instance->revertCustomVersion(); + instance->customizeVersion(); + auto version = instance->getFullVersion(); + if (!forge.apply(version)) { emitFailed(tr("Couldn't install Forge")); return; -- cgit v1.2.3 From 245d441a6eee558557a01d61a726b7feaeb5dc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 22 Dec 2013 05:15:26 +0100 Subject: Fail if we fail to find the right forge version --- logic/OneSixFTBInstance.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'logic/OneSixFTBInstance.cpp') diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp index 0090c1d8..924fc790 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -27,7 +27,10 @@ public: } } if (!forgeVersion) + { + emitFailed(QString("Couldn't find forge version ") + version ); return; + } entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename); if (entry->stale) { -- cgit v1.2.3 From 7a07ed79407edcb2a543aa0dc80745a0b8c2e234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 22 Dec 2013 05:47:10 +0100 Subject: FTB fixage * Corrected an uninitialized variable that prevented forge list loadinf on Windows * Run the update step twice for FTB instances to ensure forge libs get downloaded --- logic/OneSixFTBInstance.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'logic/OneSixFTBInstance.cpp') diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp index 924fc790..4bb5cf42 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -111,6 +111,9 @@ std::shared_ptr OneSixFTBInstance::doUpdate(bool only_prepare) } task->addTask(OneSixInstance::doUpdate(only_prepare)); task->addTask(std::shared_ptr(new OneSixFTBInstanceForge(m_forge->version(), this, this))); + //FIXME: yes. this may appear dumb. but the previous step can change the list, so we do it all again. + //TODO: Add a graph task. Construct graphs of tasks so we may capture the logic properly. + task->addTask(OneSixInstance::doUpdate(only_prepare)); return task; } -- cgit v1.2.3