From 9860d5ee12acde8f7893848dac53f59ea66da281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 9 May 2014 17:16:25 +0200 Subject: Introducing VersionPatch base class for version files and minecraft versions --- logic/minecraft/VersionFile.cpp | 124 ++++------------------------------------ 1 file changed, 12 insertions(+), 112 deletions(-) (limited to 'logic/minecraft/VersionFile.cpp') diff --git a/logic/minecraft/VersionFile.cpp b/logic/minecraft/VersionFile.cpp index a011ce1a..e1b03e6c 100644 --- a/logic/minecraft/VersionFile.cpp +++ b/logic/minecraft/VersionFile.cpp @@ -7,111 +7,28 @@ #include "logic/minecraft/VersionFile.h" #include "logic/minecraft/OneSixLibrary.h" #include "logic/minecraft/VersionFinal.h" -#include "logic/MMCJson.h" +#include "logic/minecraft/JarMod.h" +#include "logic/MMCJson.h" using namespace MMCJson; #define CURRENT_MINIMUM_LAUNCHER_VERSION 14 -JarmodPtr Jarmod::fromJson(const QJsonObject &libObj, const QString &filename) -{ - JarmodPtr out(new Jarmod()); - if (!libObj.contains("name")) - { - throw JSONValidationError(filename + - "contains a jarmod that doesn't have a 'name' field"); - } - out->name = libObj.value("name").toString(); - - auto readString = [libObj, filename](const QString & key, QString & variable) - { - if (libObj.contains(key)) - { - QJsonValue val = libObj.value(key); - if (!val.isString()) - { - QLOG_WARN() << key << "is not a string in" << filename << "(skipping)"; - } - else - { - variable = val.toString(); - } - } - }; - - readString("url", out->baseurl); - readString("MMC-absoluteUrl", out->absoluteUrl); - if(!out->baseurl.isEmpty() && out->absoluteUrl.isEmpty()) - { - out->absoluteUrl = out->baseurl + out->name; - } - return out; - -} - - -RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &filename) +int findLibrary(QList haystack, const QString &needle) { - RawLibraryPtr out(new RawLibrary()); - if (!libObj.contains("name")) - { - throw JSONValidationError(filename + - "contains a library that doesn't have a 'name' field"); - } - out->name = libObj.value("name").toString(); - - auto readString = [libObj, filename](const QString & key, QString & variable) - { - if (libObj.contains(key)) - { - QJsonValue val = libObj.value(key); - if (!val.isString()) - { - QLOG_WARN() << key << "is not a string in" << filename << "(skipping)"; - } - else - { - variable = val.toString(); - } - } - }; - - readString("url", out->url); - readString("MMC-hint", out->hint); - readString("MMC-absulute_url", out->absoluteUrl); - readString("MMC-absoluteUrl", out->absoluteUrl); - if (libObj.contains("extract")) - { - out->applyExcludes = true; - auto extractObj = ensureObject(libObj.value("extract")); - for (auto excludeVal : ensureArray(extractObj.value("exclude"))) - { - out->excludes.append(ensureString(excludeVal)); - } - } - if (libObj.contains("natives")) + int retval = -1; + for (int i = 0; i < haystack.size(); ++i) { - out->applyNatives = true; - QJsonObject nativesObj = ensureObject(libObj.value("natives")); - for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it) + QString chunk = haystack.at(i)->rawName(); + if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix).indexIn(chunk) != -1) { - if (!it.value().isString()) - { - QLOG_WARN() << filename << "contains an invalid native (skipping)"; - } - OpSys opSys = OpSys_fromString(it.key()); - if (opSys != Os_Other) - { - out->natives.append(qMakePair(opSys, it.value().toString())); - } + // only one is allowed. + if(retval != -1) + return -1; + retval = i; } } - if (libObj.contains("rules")) - { - out->applyRules = true; - out->rules = rulesFromJsonV4(libObj); - } - return out; + return retval; } VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &filename, @@ -351,23 +268,6 @@ OneSixLibraryPtr VersionFile::createLibrary(RawLibraryPtr lib) return out; } -int VersionFile::findLibrary(QList haystack, const QString &needle) -{ - int retval = -1; - for (int i = 0; i < haystack.size(); ++i) - { - QString chunk = haystack.at(i)->rawName(); - if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix).indexIn(chunk) != -1) - { - // only one is allowed. - if(retval != -1) - return -1; - retval = i; - } - } - return retval; -} - bool VersionFile::isVanilla() { return fileId == "org.multimc.version.json"; -- cgit v1.2.3