From 43881b9cdba95259395c8bf633b670c8a6fead9a Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Thu, 20 Feb 2014 17:06:32 +0100 Subject: [PATCH 1/3] Use FTB's libraries/ and versions/ folders for non-copied instances --- logic/OneSixFTBInstance.cpp | 9 +++++++++ logic/OneSixFTBInstance.h | 3 +++ logic/OneSixInstance.cpp | 17 ++++++++++++----- logic/OneSixInstance.h | 3 +++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp index ca88142af..8f745f93c 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -95,6 +95,15 @@ QString OneSixFTBInstance::id() const return "FTB/" + BaseInstance::id(); } +QDir OneSixFTBInstance::librariesPath() const +{ + return QDir(MMC->settings()->get("FTBRoot").toString() + "/libraries"); +} +QDir OneSixFTBInstance::versionsPath() const +{ + return QDir(MMC->settings()->get("FTBRoot").toString() + "/versions"); +} + QString OneSixFTBInstance::getStatusbarDescription() { return "OneSix FTB: " + intendedVersionId(); diff --git a/logic/OneSixFTBInstance.h b/logic/OneSixFTBInstance.h index bc543aeb8..d3ceb1902 100644 --- a/logic/OneSixFTBInstance.h +++ b/logic/OneSixFTBInstance.h @@ -17,6 +17,9 @@ public: virtual QString id() const; + virtual QDir librariesPath() const override; + virtual QDir versionsPath() const override; + private: std::shared_ptr m_forge; }; diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index ae172f210..8b4de641f 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -192,12 +192,10 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session) auto libs = version->getActiveNormalLibs(); for (auto lib : libs) { - QFileInfo fi(QString("libraries/") + lib->storagePath()); - launchScript += "cp " + fi.absoluteFilePath() + "\n"; + launchScript += "cp " + librariesPath().absoluteFilePath(lib->storagePath()) + "\n"; } - QString targetstr = "versions/" + version->id + "/" + version->id + ".jar"; - QFileInfo fi(targetstr); - launchScript += "cp " + fi.absoluteFilePath() + "\n"; + QString targetstr = version->id + "/" + version->id + ".jar"; + launchScript += "cp " + versionsPath().absoluteFilePath(targetstr) + "\n"; } launchScript += "mainClass " + version->mainClass + "\n"; @@ -374,6 +372,15 @@ QString OneSixInstance::getStatusbarDescription() return descr; } +QDir OneSixInstance::librariesPath() const +{ + return QDir::current().absoluteFilePath("libraries"); +} +QDir OneSixInstance::versionsPath() const +{ + return QDir::current().absoluteFilePath("versions"); +} + QString OneSixInstance::loaderModsDir() const { return PathCombine(minecraftRoot(), "mods"); diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index ae95eab1a..4ea5fce13 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -68,6 +68,9 @@ public: virtual bool menuActionEnabled(QString action_name) const override; virtual QString getStatusbarDescription() override; + virtual QDir librariesPath() const; + virtual QDir versionsPath() const; + signals: void versionReloaded(); From f54705e1c5311e023b2e1ebd5d4db226a7c7149e Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 21 Feb 2014 18:01:06 +0100 Subject: [PATCH 2/3] Don't assume forge for FTB instances. Fix FTB related stuff. --- logic/BaseInstance.h | 2 + logic/InstanceFactory.cpp | 3 + logic/OneSixFTBInstance.cpp | 34 ++--- logic/OneSixFTBInstance.h | 8 +- logic/OneSixInstance.cpp | 14 +- logic/OneSixInstance.h | 3 + logic/OneSixVersion.cpp | 5 +- logic/OneSixVersion.h | 2 +- logic/OneSixVersionBuilder.cpp | 257 +++++++++++++++++++-------------- logic/OneSixVersionBuilder.h | 16 +- logic/lists/InstanceList.cpp | 2 - 11 files changed, 206 insertions(+), 140 deletions(-) diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index cd49f99b1..d4007a416 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -51,6 +51,8 @@ public: /// virtual destructor to make sure the destruction is COMPLETE virtual ~BaseInstance() {}; + virtual void init() {} + /// nuke thoroughly - deletes the instance contents, notifies the list/model which is /// responsible of cleaning up the husk void nuke(); diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index 807bccd0c..2c89bf439 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -75,6 +75,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst { return InstanceFactory::UnknownLoadError; } + inst->init(); return NoLoadError; } @@ -156,6 +157,8 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& return InstanceFactory::NoSuchVersion; } + inst->init(); + // FIXME: really, how do you even know? return InstanceFactory::NoCreateError; } diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp index 8f745f93c..4bd30b1db 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -5,6 +5,7 @@ #include "tasks/SequentialTask.h" #include "ForgeInstaller.h" #include "lists/ForgeVersionList.h" +#include "OneSixInstance_p.h" #include "MultiMC.h" class OneSixFTBInstanceForge : public Task @@ -80,14 +81,11 @@ private: 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(); - } +} + +void OneSixFTBInstance::init() +{ + reloadVersion(); } QString OneSixFTBInstance::id() const @@ -104,6 +102,13 @@ QDir OneSixFTBInstance::versionsPath() const return QDir(MMC->settings()->get("FTBRoot").toString() + "/versions"); } +QStringList OneSixFTBInstance::externalPatches() const +{ + I_D(OneSixInstance); + return QStringList() << versionsPath().absoluteFilePath(intendedVersionId() + "/" + intendedVersionId() + ".json") + << minecraftRoot() + "/pack.json"; +} + QString OneSixFTBInstance::getStatusbarDescription() { return "OneSix FTB: " + intendedVersionId(); @@ -115,18 +120,7 @@ bool OneSixFTBInstance::menuActionEnabled(QString action_name) const std::shared_ptr OneSixFTBInstance::doUpdate() { - 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()); - 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()); - return task; + return OneSixInstance::doUpdate(); } #include "OneSixFTBInstance.moc" diff --git a/logic/OneSixFTBInstance.h b/logic/OneSixFTBInstance.h index d3ceb1902..bcf3df8f7 100644 --- a/logic/OneSixFTBInstance.h +++ b/logic/OneSixFTBInstance.h @@ -10,6 +10,9 @@ class OneSixFTBInstance : public OneSixInstance public: explicit OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent = 0); + + void init() override; + virtual QString getStatusbarDescription(); virtual bool menuActionEnabled(QString action_name) const; @@ -17,8 +20,9 @@ public: virtual QString id() const; - virtual QDir librariesPath() const override; - virtual QDir versionsPath() const override; + QDir librariesPath() const override; + QDir versionsPath() const override; + QStringList externalPatches() const override; private: std::shared_ptr m_forge; diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 8b4de641f..f7e56591f 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -36,6 +36,10 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, d->m_settings->registerSetting("ShouldUpdate", false); d->version.reset(new OneSixVersion(this, this)); d->vanillaVersion.reset(new OneSixVersion(this, this)); +} + +void OneSixInstance::init() +{ if (QDir(instanceRoot()).exists("version.json")) { reloadVersion(); @@ -316,11 +320,12 @@ bool OneSixInstance::reloadVersion(QWidget *widgetParent) { I_D(OneSixInstance); - bool ret = d->version->reload(widgetParent); + bool ret = d->version->reload(widgetParent, false, externalPatches()); if (ret) { - ret = d->vanillaVersion->reload(widgetParent, true); + ret = d->vanillaVersion->reload(widgetParent, true, externalPatches()); } + emit versionReloaded(); return ret; } @@ -381,6 +386,11 @@ QDir OneSixInstance::versionsPath() const return QDir::current().absoluteFilePath("versions"); } +QStringList OneSixInstance::externalPatches() const +{ + return QStringList(); +} + QString OneSixInstance::loaderModsDir() const { return PathCombine(minecraftRoot(), "mods"); diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 4ea5fce13..965266935 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -27,6 +27,8 @@ public: explicit OneSixInstance(const QString &rootDir, SettingsObject *settings, QObject *parent = 0); + virtual void init() override; + ////// Mod Lists ////// std::shared_ptr loaderModList(); std::shared_ptr resourcePackList(); @@ -70,6 +72,7 @@ public: virtual QDir librariesPath() const; virtual QDir versionsPath() const; + virtual QStringList externalPatches() const; signals: void versionReloaded(); diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index fb32f3a85..ed8d5fa53 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -26,10 +26,10 @@ OneSixVersion::OneSixVersion(OneSixInstance *instance, QObject *parent) clear(); } -bool OneSixVersion::reload(QWidget *widgetParent, const bool onlyVanilla) +bool OneSixVersion::reload(QWidget *widgetParent, const bool onlyVanilla, const QStringList &external) { beginResetModel(); - bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, onlyVanilla); + bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, onlyVanilla, external); endResetModel(); return ret; } @@ -104,6 +104,7 @@ QList > OneSixVersion::getActiveNormalLibs() QList > output; for (auto lib : libraries) { + qDebug() << "Checking" << lib->rawName() << lib->isActive() << !lib->isNative(); if (lib->isActive() && !lib->isNative()) { output.append(lib); diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index ba7695d59..fee47fa36 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -37,7 +37,7 @@ public: virtual int columnCount(const QModelIndex &parent) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const; - bool reload(QWidget *widgetParent, const bool onlyVanilla = false); + bool reload(QWidget *widgetParent, const bool onlyVanilla = false, const QStringList &external = QStringList()); void clear(); void dump() const; diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index bbd33ddc4..f1d0477e2 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -192,7 +192,7 @@ struct VersionFile return out; } static VersionFile fromJson(const QJsonDocument &doc, const QString &filename, - const bool requireOrder, bool &isError) + const bool requireOrder, bool &isError, const OneSixVersionBuilder::ParseFlags flags = OneSixVersionBuilder::NoFlags) { VersionFile out; isError = true; @@ -251,7 +251,10 @@ struct VersionFile } }; - readString("id", out.id); + if (!(flags & OneSixVersionBuilder::IsFTBPackJson)) + { + readString("id", out.id); + } readString("mainClass", out.mainClass); readString("processArguments", out.processArguments); readString("minecraftArguments", out.overwriteMinecraftArguments); @@ -343,7 +346,7 @@ struct VersionFile if (root.contains("libraries")) { - out.shouldOverwriteLibs = true; + out.shouldOverwriteLibs = !(flags & OneSixVersionBuilder::IsFTBPackJson); QJsonValue librariesVal = root.value("libraries"); if (!librariesVal.isArray()) { @@ -367,7 +370,16 @@ struct VersionFile QLOG_ERROR() << "Error while reading a library entry in" << filename; return out; } - out.overwriteLibs.append(lib); + if (flags & OneSixVersionBuilder::IsFTBPackJson) + { + lib.hint = "local"; + lib.insertType = Library::Prepend; + out.addLibs.prepend(lib); + } + else + { + out.overwriteLibs.append(lib); + } } } if (root.contains("+libraries")) @@ -775,13 +787,13 @@ OneSixVersionBuilder::OneSixVersionBuilder() } bool OneSixVersionBuilder::build(OneSixVersion *version, OneSixInstance *instance, - QWidget *widgetParent, const bool onlyVanilla) + QWidget *widgetParent, const bool onlyVanilla, const QStringList &external) { OneSixVersionBuilder builder; builder.m_version = version; builder.m_instance = instance; builder.m_widgetParent = widgetParent; - return builder.build(onlyVanilla); + return builder.build(onlyVanilla, external); } bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj) @@ -793,140 +805,171 @@ bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj) return builder.read(obj); } -bool OneSixVersionBuilder::build(const bool onlyVanilla) +bool OneSixVersionBuilder::build(const bool onlyVanilla, const QStringList &external) { m_version->clear(); QDir root(m_instance->instanceRoot()); QDir patches(root.absoluteFilePath("patches/")); - if (QFile::exists(root.absoluteFilePath("custom.json"))) + if (external.isEmpty()) { - QLOG_INFO() << "Reading custom.json"; - VersionFile file; - if (!read(QFileInfo(root.absoluteFilePath("custom.json")), false, &file)) + if (QFile::exists(root.absoluteFilePath("custom.json"))) { - return false; - } - file.name = "custom.json"; - file.filename = "custom.json"; - file.fileId = "org.multimc.custom.json"; - file.version = QString(); - bool isError = false; - file.applyTo(m_version, isError); - if (isError) - { - QMessageBox::critical( - m_widgetParent, QObject::tr("Error"), - QObject::tr( - "Error while applying %1. Please check MultiMC-0.log for more info.") - .arg(root.absoluteFilePath("custom.json"))); - return false; - } - } - else - { - // version.json -> patches/*.json -> user.json - - // version.json - { - QLOG_INFO() << "Reading version.json"; + QLOG_INFO() << "Reading custom.json"; VersionFile file; - if (!read(QFileInfo(root.absoluteFilePath("version.json")), false, &file)) + if (!read(QFileInfo(root.absoluteFilePath("custom.json")), false, &file)) { return false; } - file.name = "version.json"; - file.fileId = "org.multimc.version.json"; - file.version = m_instance->intendedVersionId(); - file.mcVersion = m_instance->intendedVersionId(); + file.name = "custom.json"; + file.filename = "custom.json"; + file.fileId = "org.multimc.custom.json"; + file.version = QString(); bool isError = false; file.applyTo(m_version, isError); if (isError) { QMessageBox::critical( - m_widgetParent, QObject::tr("Error"), - QObject::tr( - "Error while applying %1. Please check MultiMC-0.log for more info.") - .arg(root.absoluteFilePath("version.json"))); + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(root.absoluteFilePath("custom.json"))); return false; } } - - if (!onlyVanilla) + else { + // version.json -> patches/*.json -> user.json - // patches/ + // version.json { - // load all, put into map for ordering, apply in the right order - QMap overrideOrder = readOverrideOrders(m_instance); - - QMap> files; - for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) + QLOG_INFO() << "Reading version.json"; + VersionFile file; + if (!read(QFileInfo(root.absoluteFilePath("version.json")), false, &file)) { - QLOG_INFO() << "Reading" << info.fileName(); - VersionFile file; - if (!read(info, true, &file)) - { - return false; - } - if (overrideOrder.contains(file.fileId)) - { - file.order = overrideOrder.value(file.fileId); - } - if (files.contains(file.order)) - { - QLOG_ERROR() << file.fileId << "has the same order as" << files[file.order].second.fileId; - return false; - } - files.insert(file.order, qMakePair(info.fileName(), file)); + return false; } - for (auto order : files.keys()) + file.name = "version.json"; + file.fileId = "org.multimc.version.json"; + file.version = m_instance->intendedVersionId(); + file.mcVersion = m_instance->intendedVersionId(); + bool isError = false; + file.applyTo(m_version, isError); + if (isError) { - QLOG_DEBUG() << "Applying file with order" << order; - auto filePair = files[order]; - bool isError = false; - filePair.second.applyTo(m_version, isError); - if (isError) - { - QMessageBox::critical( - m_widgetParent, QObject::tr("Error"), - QObject::tr("Error while applying %1. Please check MultiMC-0.log " - "for more info.").arg(filePair.first)); - return false; - } + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(root.absoluteFilePath("version.json"))); + return false; } } + if (!onlyVanilla) + { + + // patches/ + { + // load all, put into map for ordering, apply in the right order + QMap overrideOrder = readOverrideOrders(m_instance); + + QMap> files; + for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) + { + QLOG_INFO() << "Reading" << info.fileName(); + VersionFile file; + if (!read(info, true, &file)) + { + return false; + } + if (overrideOrder.contains(file.fileId)) + { + file.order = overrideOrder.value(file.fileId); + } + if (files.contains(file.order)) + { + QLOG_ERROR() << file.fileId << "has the same order as" << files[file.order].second.fileId; + return false; + } + files.insert(file.order, qMakePair(info.fileName(), file)); + } + for (auto order : files.keys()) + { + QLOG_DEBUG() << "Applying file with order" << order; + auto filePair = files[order]; + bool isError = false; + filePair.second.applyTo(m_version, isError); + if (isError) + { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr("Error while applying %1. Please check MultiMC-0.log " + "for more info.").arg(filePair.first)); + return false; + } + } + } + #if 0 - // user.json - { - if (QFile::exists(root.absoluteFilePath("user.json"))) + // user.json { - QLOG_INFO() << "Reading user.json"; - VersionFile file; - if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file)) + if (QFile::exists(root.absoluteFilePath("user.json"))) { - return false; - } - file.name = "user.json"; - file.fileId = "org.multimc.user.json"; - file.version = QString(); - file.mcVersion = QString(); - bool isError = false; - file.applyTo(m_version, isError); - if (isError) - { - QMessageBox::critical( - m_widgetParent, QObject::tr("Error"), - QObject::tr( - "Error while applying %1. Please check MultiMC-0.log for more info.") - .arg(root.absoluteFilePath("user.json"))); - return false; + QLOG_INFO() << "Reading user.json"; + VersionFile file; + if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file)) + { + return false; + } + file.name = "user.json"; + file.fileId = "org.multimc.user.json"; + file.version = QString(); + file.mcVersion = QString(); + bool isError = false; + file.applyTo(m_version, isError); + if (isError) + { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(root.absoluteFilePath("user.json"))); + return false; + } } } - } #endif + } + } + } + else + { + for (auto fileName : external) + { + QLOG_INFO() << "Reading" << fileName; + VersionFile file; + ParseFlags flags = fileName.endsWith("pack.json") ? IsFTBPackJson : NoFlags; + if (!read(QFileInfo(fileName), false, &file, flags)) + { + return false; + } + file.name = QFileInfo(fileName).fileName(); + file.fileId = "org.multimc.external." + file.name; + file.version = QString(); + file.mcVersion = QString(); + bool isError = false; + file.applyTo(m_version, isError); + if (isError) + { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(fileName)); + return false; + } } } @@ -986,7 +1029,7 @@ bool OneSixVersionBuilder::read(const QJsonObject &obj) } bool OneSixVersionBuilder::read(const QFileInfo &fileInfo, const bool requireOrder, - VersionFile *out) + VersionFile *out, const ParseFlags flags) { QFile file(fileInfo.absoluteFilePath()); if (!file.open(QFile::ReadOnly)) @@ -1007,7 +1050,7 @@ bool OneSixVersionBuilder::read(const QFileInfo &fileInfo, const bool requireOrd return false; } bool isError = false; - *out = VersionFile::fromJson(doc, file.fileName(), requireOrder, isError); + *out = VersionFile::fromJson(doc, file.fileName(), requireOrder, isError, flags); if (isError) { QMessageBox::critical( diff --git a/logic/OneSixVersionBuilder.h b/logic/OneSixVersionBuilder.h index ab0966df8..8cf6f32f8 100644 --- a/logic/OneSixVersionBuilder.h +++ b/logic/OneSixVersionBuilder.h @@ -29,19 +29,27 @@ class OneSixVersionBuilder { OneSixVersionBuilder(); public: - static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent, const bool onlyVanilla); + static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent, const bool onlyVanilla, const QStringList &external); static bool read(OneSixVersion *version, const QJsonObject &obj); static QMap readOverrideOrders(OneSixInstance *instance); static bool writeOverrideOrders(const QMap &order, OneSixInstance *instance); + enum ParseFlag + { + NoFlags = 0x0, + IsFTBPackJson = 0x1 + }; + Q_DECLARE_FLAGS(ParseFlags, ParseFlag) + private: OneSixVersion *m_version; OneSixInstance *m_instance; QWidget *m_widgetParent; - bool build(const bool onlyVanilla); + bool build(const bool onlyVanilla, const QStringList &external); bool read(const QJsonObject &obj); - bool read(const QFileInfo &fileInfo, const bool requireOrder, VersionFile *out); - + bool read(const QFileInfo &fileInfo, const bool requireOrder, VersionFile *out, const ParseFlags flags = NoFlags); }; + +Q_DECLARE_OPERATORS_FOR_FLAGS(OneSixVersionBuilder::ParseFlags) diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index cd59e6d6f..9a61e2dd1 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -336,8 +336,6 @@ QList InstanceList::discoverFTBInstances() if (!test.exists()) continue; record.name = attrs.value("name").toString(); - if(record.name.contains("voxel", Qt::CaseInsensitive)) - continue; record.logo = attrs.value("logo").toString(); record.mcVersion = attrs.value("mcVersion").toString(); record.description = attrs.value("description").toString(); From 4883d1526222f9804f304f4cc189d6e44cb22b97 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 21 Feb 2014 19:15:59 +0100 Subject: [PATCH 3/3] Copying of FTB instances working again --- logic/BaseInstance.h | 2 ++ logic/InstanceFactory.cpp | 2 ++ logic/OneSixFTBInstance.cpp | 71 +++++++++++++++++++++++++++++++++++++ logic/OneSixFTBInstance.h | 2 ++ logic/OneSixInstance.cpp | 5 +++ logic/OneSixInstance.h | 1 + logic/OneSixUpdate.cpp | 7 +++- logic/OneSixUpdate.h | 6 ++-- logic/OneSixVersion.cpp | 1 - 9 files changed, 92 insertions(+), 5 deletions(-) diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index d4007a416..341a6adb7 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -25,6 +25,7 @@ #include "logic/auth/MojangAccount.h" class QDialog; +class QDir; class Task; class MinecraftProcess; class OneSixUpdate; @@ -52,6 +53,7 @@ public: virtual ~BaseInstance() {}; virtual void init() {} + virtual void copy(const QDir &newDir) {} /// nuke thoroughly - deletes the instance contents, notifies the list/model which is /// responsible of cleaning up the husk diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index 2c89bf439..d6e06133f 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -184,6 +184,8 @@ InstanceFactory::InstCreateError InstanceFactory::copyInstance(BaseInstance *&ne if(inst_type == "LegacyFTB") m_settings->set("InstanceType", "Legacy"); + oldInstance->copy(instDir); + auto error = loadInstance(newInstance, instDir); switch (error) diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp index 4bd30b1db..307ddb7cc 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -6,7 +6,9 @@ #include "ForgeInstaller.h" #include "lists/ForgeVersionList.h" #include "OneSixInstance_p.h" +#include "OneSixVersionBuilder.h" #include "MultiMC.h" +#include "pathutils.h" class OneSixFTBInstanceForge : public Task { @@ -88,6 +90,70 @@ void OneSixFTBInstance::init() reloadVersion(); } +void OneSixFTBInstance::copy(const QDir &newDir) +{ + QStringList libraryNames; + // create patch file + { + QLOG_DEBUG() << "Creating patch file for FTB instance..."; + QFile f(minecraftRoot() + "/pack.json"); + if (!f.open(QFile::ReadOnly)) + { + QLOG_ERROR() << "Couldn't open" << f.fileName() << ":" << f.errorString(); + return; + } + QJsonObject root = QJsonDocument::fromJson(f.readAll()).object(); + QJsonArray libs = root.value("libraries").toArray(); + QJsonArray outLibs; + for (auto lib : libs) + { + QJsonObject libObj = lib.toObject(); + libObj.insert("MMC-hint", QString("local")); + libObj.insert("insert", QString("prepend")); + libraryNames.append(libObj.value("name").toString()); + outLibs.append(libObj); + } + root.remove("libraries"); + root.remove("id"); + root.insert("+libraries", outLibs); + root.insert("order", 1); + root.insert("fileId", QString("org.multimc.ftb.pack.json")); + root.insert("name", name()); + root.insert("mcVersion", intendedVersionId()); + root.insert("version", intendedVersionId()); + ensureFilePathExists(newDir.absoluteFilePath("patches/ftb.json")); + QFile out(newDir.absoluteFilePath("patches/ftb.json")); + if (!out.open(QFile::WriteOnly | QFile::Truncate)) + { + QLOG_ERROR() << "Couldn't open" << out.fileName() << ":" << out.errorString(); + return; + } + out.write(QJsonDocument(root).toJson()); + } + // copy libraries + { + QLOG_DEBUG() << "Copying FTB libraries"; + for (auto library : libraryNames) + { + OneSixLibrary *lib = new OneSixLibrary(library); + lib->finalize(); + const QString out = QDir::current().absoluteFilePath("libraries/" + lib->storagePath()); + if (QFile::exists(out)) + { + continue; + } + if (!ensureFilePathExists(out)) + { + QLOG_ERROR() << "Couldn't create folder structure for" << out; + } + if (!QFile::copy(librariesPath().absoluteFilePath(lib->storagePath()), out)) + { + QLOG_ERROR() << "Couldn't copy" << lib->rawName(); + } + } + } +} + QString OneSixFTBInstance::id() const { return "FTB/" + BaseInstance::id(); @@ -109,6 +175,11 @@ QStringList OneSixFTBInstance::externalPatches() const << minecraftRoot() + "/pack.json"; } +bool OneSixFTBInstance::providesVersionFile() const +{ + return true; +} + QString OneSixFTBInstance::getStatusbarDescription() { return "OneSix FTB: " + intendedVersionId(); diff --git a/logic/OneSixFTBInstance.h b/logic/OneSixFTBInstance.h index bcf3df8f7..c4f845e08 100644 --- a/logic/OneSixFTBInstance.h +++ b/logic/OneSixFTBInstance.h @@ -12,6 +12,7 @@ public: QObject *parent = 0); void init() override; + void copy(const QDir &newDir) override; virtual QString getStatusbarDescription(); virtual bool menuActionEnabled(QString action_name) const; @@ -23,6 +24,7 @@ public: QDir librariesPath() const override; QDir versionsPath() const override; QStringList externalPatches() const override; + bool providesVersionFile() const override; private: std::shared_ptr m_forge; diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index f7e56591f..bc085c8e8 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -391,6 +391,11 @@ QStringList OneSixInstance::externalPatches() const return QStringList(); } +bool OneSixInstance::providesVersionFile() const +{ + return false; +} + QString OneSixInstance::loaderModsDir() const { return PathCombine(minecraftRoot(), "mods"); diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 965266935..06fd9de30 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -73,6 +73,7 @@ public: virtual QDir librariesPath() const; virtual QDir versionsPath() const; virtual QStringList externalPatches() const; + virtual bool providesVersionFile() const; signals: void versionReloaded(); diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index d3ac80c25..f87c65e73 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -35,7 +35,7 @@ #include "pathutils.h" #include -OneSixUpdate::OneSixUpdate(BaseInstance *inst, QObject *parent) +OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent), m_inst(inst) { } @@ -73,6 +73,11 @@ void OneSixUpdate::executeTask() void OneSixUpdate::versionFileStart() { + if (m_inst->providesVersionFile()) + { + jarlibStart(); + return; + } QLOG_INFO() << m_inst->name() << ": getting version file."; setStatus(tr("Getting the version files from Mojang...")); diff --git a/logic/OneSixUpdate.h b/logic/OneSixUpdate.h index 3c18211ef..eac882b54 100644 --- a/logic/OneSixUpdate.h +++ b/logic/OneSixUpdate.h @@ -23,13 +23,13 @@ #include "logic/tasks/Task.h" class MinecraftVersion; -class BaseInstance; +class OneSixInstance; class OneSixUpdate : public Task { Q_OBJECT public: - explicit OneSixUpdate(BaseInstance *inst, QObject *parent = 0); + explicit OneSixUpdate(OneSixInstance *inst, QObject *parent = 0); virtual void executeTask(); private @@ -55,5 +55,5 @@ private: // target version, determined during this task std::shared_ptr targetVersion; - BaseInstance *m_inst = nullptr; + OneSixInstance *m_inst = nullptr; }; diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index ed8d5fa53..06e748bd6 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -104,7 +104,6 @@ QList > OneSixVersion::getActiveNormalLibs() QList > output; for (auto lib : libraries) { - qDebug() << "Checking" << lib->rawName() << lib->isActive() << !lib->isNative(); if (lib->isActive() && !lib->isNative()) { output.append(lib);