From ece826bdbc5ca525e253cafcfef3d93e492949f5 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 2 Feb 2014 14:05:07 +0100 Subject: Add a MMC-depend field (soft/hard) for version checking --- logic/ForgeInstaller.cpp | 6 ++- logic/LiteLoaderInstaller.cpp | 3 +- logic/OneSixLibrary.cpp | 2 +- logic/OneSixLibrary.h | 11 ++++- logic/OneSixVersionBuilder.cpp | 110 ++++++++++++++++++++++++++++++----------- 5 files changed, 100 insertions(+), 32 deletions(-) (limited to 'logic') diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 47c42694..6b498d70 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -171,7 +171,11 @@ bool ForgeInstaller::add(OneSixInstance *to) if (!found) { // add lib - libObj.insert("insert", QString("prepend-if-not-exists")); + libObj.insert("insert", QString("prepend")); + if (lib->name() == "minecraftforge") + { + libObj.insert("MMC-depend", QString("hard")); + } sliding_insert_window++; } librariesPlus.prepend(libObj); diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index 60a43d49..c363cad6 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -63,7 +63,7 @@ bool LiteLoaderInstaller::add(OneSixInstance *to) OneSixLibrary launchwrapperLib("net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[to->intendedVersionId()]); launchwrapperLib.finalize(); QJsonObject lwLibObj = launchwrapperLib.toJson(); - lwLibObj.insert("insert", QString("prepend-if-not-exists")); + lwLibObj.insert("insert", QString("prepend")); libraries.append(lwLibObj); } @@ -74,6 +74,7 @@ bool LiteLoaderInstaller::add(OneSixInstance *to) liteloaderLib.finalize(); QJsonObject llLibObj = liteloaderLib.toJson(); llLibObj.insert("insert", QString("prepend")); + llLibObj.insert("MMC-depend", QString("hard")); libraries.append(llLibObj); } diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp index 2b1f0600..c78679d1 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -46,7 +46,7 @@ void OneSixLibrary::finalize() } m_decentname = parts[1]; - m_decentversion = parts[2]; + m_decentversion = minVersion = parts[2]; m_storage_path = relative; m_download_url = m_base_url + relative; diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index 5384015a..371ca6f4 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -60,12 +60,21 @@ private: public: QStringList extract_excludes; + QString minVersion; + + enum DependType + { + Soft, + Hard + }; + DependType dependType; public: /// Constructor - OneSixLibrary(const QString &name) + OneSixLibrary(const QString &name, const DependType type = Soft) { m_name = name; + dependType = type; } /// Returns the raw name field diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index 4d6fb05a..55c7d48e 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -29,6 +29,7 @@ #include "OneSixVersion.h" #include "OneSixInstance.h" #include "OneSixRule.h" +#include "modutils.h" #include "logger/QsLog.h" struct VersionFile @@ -78,12 +79,16 @@ struct VersionFile Apply, Append, Prepend, - AppendIfNotExists, - PrependIfNotExists, Replace }; - InsertType insertType; + InsertType insertType = Append; QString insertData; + enum DependType + { + Soft, + Hard + }; + DependType dependType = Soft; }; bool shouldOverwriteLibs = false; QList overwriteLibs; @@ -414,21 +419,13 @@ struct VersionFile { lib.insertType = Library::Apply; } - else if (insertString == "append") - { - lib.insertType = Library::Append; - } else if (insertString == "prepend") { lib.insertType = Library::Prepend; } - else if (insertString == "prepend-if-not-exists") - { - lib.insertType = Library::PrependIfNotExists; - } - else if (insertString == "append-if-not-exists") + else if (insertString == "append") { - lib.insertType = Library::PrependIfNotExists; + lib.insertType = Library::Prepend; } else if (insertString == "replace") { @@ -440,6 +437,24 @@ struct VersionFile << "contains an invalid insert type"; return out; } + if (libObj.contains("MMC-depend") && libObj.value("MMC-depend").isString()) + { + const QString dependString = libObj.value("MMC-depend").toString(); + if (dependString == "hard") + { + lib.dependType = Library::Hard; + } + else if (dependString == "soft") + { + lib.dependType = Library::Soft; + } + else + { + QLOG_ERROR() << "A '+' library in" << filename + << "contains an invalid depend type"; + return out; + } + } out.addLibs.append(lib); } } @@ -629,28 +644,67 @@ struct VersionFile break; } case Library::Append: - version->libraries.append(createLibrary(lib)); - break; case Library::Prepend: - version->libraries.prepend(createLibrary(lib)); - break; - case Library::AppendIfNotExists: { - int index = findLibrary(version->libraries, lib.name); + const int startOfVersion = lib.name.lastIndexOf(':') + 1; + const int index = findLibrary(version->libraries, QString(lib.name).replace(startOfVersion, INT_MAX, '*')); if (index < 0) { - version->libraries.append(createLibrary(lib)); + if (lib.insertType == Library::Append) + { + version->libraries.append(createLibrary(lib)); + } + else + { + version->libraries.prepend(createLibrary(lib)); + } } - break; - } - case Library::PrependIfNotExists: - { - - int index = findLibrary(version->libraries, lib.name); - if (index < 0) + else { - version->libraries.prepend(createLibrary(lib)); + 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 (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)) + { + QLOG_ERROR() << "Error resolving library dependencies between" + << otherLib->rawName() << "and" << lib.name << "in" + << filename; + return; + } + else + { + // the library is already existing, so we don't have to do anything + } + } + else if (otherLib->dependType == OneSixLibrary::Soft) + { + // if we are higher it means we should update + if (ourVersion > otherVersion) + { + auto library = createLibrary(lib); + if (Util::Version(otherLib->minVersion) < ourVersion) + { + library->minVersion = ourVersion.toString(); + } + version->libraries.replace(index, library); + } + else + { + // 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" + << otherLib->rawName() << "and" << lib.name << "in" + << filename; + return; + } + } + } } break; } -- cgit v1.2.3