From cdd35910c3aeb4048e2e982db0b8227f76574704 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 2 Feb 2014 14:17:44 +0100 Subject: Fix installing forge after liteloader and then removing liteloader. Also formatting. --- logic/ForgeInstaller.cpp | 6 +- logic/OneSixInstance.cpp | 10 +-- logic/OneSixInstance.h | 4 +- logic/OneSixInstance_p.h | 2 +- logic/OneSixVersion.cpp | 4 +- logic/OneSixVersion.h | 2 +- logic/OneSixVersionBuilder.cpp | 146 ++++++++++++++++++++++------------------- logic/OneSixVersionBuilder.h | 4 +- 8 files changed, 96 insertions(+), 82 deletions(-) diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 6b498d70..3e18d17f 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -151,7 +151,7 @@ bool ForgeInstaller::add(OneSixInstance *to) bool found = false; bool equals = false; // find an entry that matches this one - for (auto tolib : to->getNonCustomVersion()->libraries) + for (auto tolib : to->getVanillaVersion()->libraries) { if (tolib->name() != libName) continue; @@ -194,7 +194,7 @@ bool ForgeInstaller::add(OneSixInstance *to) match = expression.match(args); } } - if (!args.isEmpty() && args != to->getNonCustomVersion()->minecraftArguments) + if (!args.isEmpty() && args != to->getVanillaVersion()->minecraftArguments) { obj.insert("minecraftArguments", args); } @@ -203,7 +203,7 @@ bool ForgeInstaller::add(OneSixInstance *to) obj.insert("+tweakers", QJsonArray::fromStringList(tweakers)); } if (!m_forge_version->processArguments.isEmpty() && - m_forge_version->processArguments != to->getNonCustomVersion()->processArguments) + m_forge_version->processArguments != to->getVanillaVersion()->processArguments) { obj.insert("processArguments", m_forge_version->processArguments); } diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 8ecbe7a0..ae172f21 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -35,7 +35,7 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, d->m_settings->registerSetting("IntendedVersion", ""); d->m_settings->registerSetting("ShouldUpdate", false); d->version.reset(new OneSixVersion(this, this)); - d->nonCustomVersion.reset(new OneSixVersion(this, this)); + d->vanillaVersion.reset(new OneSixVersion(this, this)); if (QDir(instanceRoot()).exists("version.json")) { reloadVersion(); @@ -321,7 +321,7 @@ bool OneSixInstance::reloadVersion(QWidget *widgetParent) bool ret = d->version->reload(widgetParent); if (ret) { - ret = d->nonCustomVersion->reload(widgetParent, true); + ret = d->vanillaVersion->reload(widgetParent, true); } emit versionReloaded(); return ret; @@ -331,7 +331,7 @@ void OneSixInstance::clearVersion() { I_D(OneSixInstance); d->version->clear(); - d->nonCustomVersion->clear(); + d->vanillaVersion->clear(); emit versionReloaded(); } @@ -341,10 +341,10 @@ std::shared_ptr OneSixInstance::getFullVersion() const return d->version; } -std::shared_ptr OneSixInstance::getNonCustomVersion() const +std::shared_ptr OneSixInstance::getVanillaVersion() const { I_D(const OneSixInstance); - return d->nonCustomVersion; + return d->vanillaVersion; } QString OneSixInstance::defaultBaseJar() const diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 5aa12e44..ae95eab1 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -57,8 +57,8 @@ public: void clearVersion(); /// get the current full version info std::shared_ptr getFullVersion() const; - /// gets the current version info, excluding custom.json - std::shared_ptr getNonCustomVersion() const; + /// gets the current version info, but only for version.json + std::shared_ptr getVanillaVersion() const; /// is the current version original, or custom? virtual bool versionIsCustom() override; diff --git a/logic/OneSixInstance_p.h b/logic/OneSixInstance_p.h index 6dc74e50..0cc46f33 100644 --- a/logic/OneSixInstance_p.h +++ b/logic/OneSixInstance_p.h @@ -22,7 +22,7 @@ struct OneSixInstancePrivate : public BaseInstancePrivate { std::shared_ptr version; - std::shared_ptr nonCustomVersion; + std::shared_ptr vanillaVersion; std::shared_ptr loader_mod_list; std::shared_ptr resource_pack_list; }; diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 0b6d1986..e19683d8 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 excludeCustom) +bool OneSixVersion::reload(QWidget *widgetParent, const bool onlyVanilla) { beginResetModel(); - bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, excludeCustom); + bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, onlyVanilla); endResetModel(); return ret; } diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index d7a6684d..516f153c 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 excludeCustom = false); + bool reload(QWidget *widgetParent, const bool onlyVanilla = false); void clear(); void dump() const; diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index 55c7d48e..03555070 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -280,7 +280,8 @@ struct VersionFile QJsonValue tweakersVal = root.value("tweakers"); if (!tweakersVal.isArray()) { - QLOG_ERROR() << filename << "contains a 'tweakers' field, but it's not an array"; + QLOG_ERROR() << filename + << "contains a 'tweakers' field, but it's not an array"; return out; } out.shouldOverwriteTweakers = true; @@ -289,7 +290,8 @@ struct VersionFile { if (!tweakerVal.isString()) { - QLOG_ERROR() << filename << "contains a 'tweakers' field entry that's not a string"; + QLOG_ERROR() << filename + << "contains a 'tweakers' field entry that's not a string"; return out; } out.overwriteTweakers.append(tweakerVal.toString()); @@ -300,7 +302,8 @@ struct VersionFile QJsonValue tweakersVal = root.value("+tweakers"); if (!tweakersVal.isArray()) { - QLOG_ERROR() << filename << "contains a '+tweakers' field, but it's not an array"; + QLOG_ERROR() << filename + << "contains a '+tweakers' field, but it's not an array"; return out; } QJsonArray tweakers = root.value("+tweakers").toArray(); @@ -308,7 +311,8 @@ struct VersionFile { if (!tweakerVal.isString()) { - QLOG_ERROR() << filename << "contains a '+tweakers' field entry that's not a string"; + QLOG_ERROR() << filename + << "contains a '+tweakers' field entry that's not a string"; return out; } out.addTweakers.append(tweakerVal.toString()); @@ -319,7 +323,8 @@ struct VersionFile QJsonValue tweakersVal = root.value("-tweakers"); if (!tweakersVal.isArray()) { - QLOG_ERROR() << filename << "contains a '-tweakers' field, but it's not an array"; + QLOG_ERROR() << filename + << "contains a '-tweakers' field, but it's not an array"; return out; } out.shouldOverwriteTweakers = true; @@ -328,7 +333,8 @@ struct VersionFile { if (!tweakerVal.isString()) { - QLOG_ERROR() << filename << "contains a '-tweakers' field entry that's not a string"; + QLOG_ERROR() << filename + << "contains a '-tweakers' field entry that's not a string"; return out; } out.removeTweakers.append(tweakerVal.toString()); @@ -648,7 +654,9 @@ struct VersionFile { const int startOfVersion = lib.name.lastIndexOf(':') + 1; - const int index = findLibrary(version->libraries, QString(lib.name).replace(startOfVersion, INT_MAX, '*')); + const int index = + findLibrary(version->libraries, + QString(lib.name).replace(startOfVersion, INT_MAX, '*')); if (index < 0) { if (lib.insertType == Library::Append) @@ -665,11 +673,14 @@ struct VersionFile auto otherLib = version->libraries.at(index); const Util::Version ourVersion = lib.name.mid(startOfVersion, INT_MAX); const Util::Version otherVersion = otherLib->version(); - // if the existing version is a hard dependency we can either use it or fail, but we can't change it + // if the existing version is a hard dependency we can either use it or + // fail, but we can't change it if (otherLib->dependType == OneSixLibrary::Hard) { - // we need a higher version, or we're hard to and the versions aren't equal - if (ourVersion > otherVersion || (lib.dependType == Library::Hard && ourVersion != otherVersion)) + // we need a higher version, or we're hard to and the versions aren't + // equal + if (ourVersion > otherVersion || + (lib.dependType == Library::Hard && ourVersion != otherVersion)) { QLOG_ERROR() << "Error resolving library dependencies between" << otherLib->rawName() << "and" << lib.name << "in" @@ -695,7 +706,8 @@ struct VersionFile } else { - // our version is smaller than the existing version, but we require it: fail + // our version is smaller than the existing version, but we require + // it: fail if (lib.dependType == Library::Hard) { QLOG_ERROR() << "Error resolving library dependencies between" @@ -753,13 +765,13 @@ OneSixVersionBuilder::OneSixVersionBuilder() } bool OneSixVersionBuilder::build(OneSixVersion *version, OneSixInstance *instance, - QWidget *widgetParent, const bool excludeCustom) + QWidget *widgetParent, const bool onlyVanilla) { OneSixVersionBuilder builder; builder.m_version = version; builder.m_instance = instance; builder.m_widgetParent = widgetParent; - return builder.build(excludeCustom); + return builder.build(onlyVanilla); } bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj) @@ -771,7 +783,7 @@ bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj) return builder.read(obj); } -bool OneSixVersionBuilder::build(const bool excludeCustom) +bool OneSixVersionBuilder::build(const bool onlyVanilla) { m_version->clear(); @@ -823,77 +835,79 @@ bool OneSixVersionBuilder::build(const bool excludeCustom) 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("version.json"))); return false; } } - // patches/ + if (!onlyVanilla) { - // load all, put into map for ordering, apply in the right order - QMap> files; - for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) + // patches/ { - QLOG_INFO() << "Reading" << info.fileName(); - VersionFile file; - if (!read(info, true, &file)) + // load all, put into map for ordering, apply in the right order + + QMap> files; + for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) { - return false; + QLOG_INFO() << "Reading" << info.fileName(); + VersionFile file; + if (!read(info, true, &file)) + { + return false; + } + files.insert(file.order, qMakePair(info.fileName(), file)); } - 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) + for (auto order : files.keys()) { - 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; + 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 (!excludeCustom) - { - 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)) - { - 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) + if (QFile::exists(root.absoluteFilePath("user.json"))) { - 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 + } } // some final touches diff --git a/logic/OneSixVersionBuilder.h b/logic/OneSixVersionBuilder.h index ac8c13bf..f0d69bf6 100644 --- a/logic/OneSixVersionBuilder.h +++ b/logic/OneSixVersionBuilder.h @@ -28,7 +28,7 @@ class OneSixVersionBuilder { OneSixVersionBuilder(); public: - static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent, const bool excludeCustom); + static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent, const bool onlyVanilla); static bool read(OneSixVersion *version, const QJsonObject &obj); private: @@ -36,7 +36,7 @@ private: OneSixInstance *m_instance; QWidget *m_widgetParent; - bool build(const bool excludeCustom); + bool build(const bool onlyVanilla); bool read(const QJsonObject &obj); bool read(const QFileInfo &fileInfo, const bool requireOrder, VersionFile *out); -- cgit v1.2.3