summaryrefslogtreecommitdiffstats
path: root/logic/OneSixFTBInstance.cpp
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2013-12-20 14:47:26 +0100
committerPetr Mrázek <peterix@gmail.com>2013-12-21 23:40:37 +0100
commit82c87aa06f793b9f38e6cb42d284f00695f4bac5 (patch)
tree21f893b0336a90d4e4b9f14cb5312f2c1ea04280 /logic/OneSixFTBInstance.cpp
parent34a3fedf7b115c84ff305bf72fbc9d568682d84a (diff)
downloadMultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.tar
MultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.tar.gz
MultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.tar.lz
MultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.tar.xz
MultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.zip
Initial FTB support. Allows "tracking" of FTB instances.
Diffstat (limited to 'logic/OneSixFTBInstance.cpp')
-rw-r--r--logic/OneSixFTBInstance.cpp111
1 files changed, 111 insertions, 0 deletions
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<ForgeVersion>(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<Task> OneSixFTBInstance::doUpdate(bool only_prepare)
+{
+ std::shared_ptr<SequentialTask> task;
+ task.reset(new SequentialTask(this));
+ if (!MMC->forgelist()->isLoaded())
+ {
+ task->addTask(std::shared_ptr<Task>(MMC->forgelist()->getLoadTask()));
+ }
+ task->addTask(OneSixInstance::doUpdate(only_prepare));
+ task->addTask(std::shared_ptr<Task>(new OneSixFTBInstanceForge(m_forge->version(), this, this)));
+ return task;
+}
+
+#include "OneSixFTBInstance.moc"