From d4eacb56b30baaef801f42545398a4f29755fadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 7 Mar 2016 02:01:28 +0100 Subject: NOISSUE make new Mojang version format pass through MultiMC structures Not yet used effectively, but it is read and written properly --- logic/minecraft/onesix/OneSixUpdate.cpp | 4 +- logic/minecraft/onesix/OneSixVersionFormat.cpp | 88 ++------------------------ logic/minecraft/onesix/OneSixVersionFormat.h | 6 +- 3 files changed, 11 insertions(+), 87 deletions(-) (limited to 'logic/minecraft/onesix') diff --git a/logic/minecraft/onesix/OneSixUpdate.cpp b/logic/minecraft/onesix/OneSixUpdate.cpp index 3fd66920..da3bd504 100644 --- a/logic/minecraft/onesix/OneSixUpdate.cpp +++ b/logic/minecraft/onesix/OneSixUpdate.cpp @@ -28,7 +28,7 @@ #include "BaseInstance.h" #include "minecraft/MinecraftVersionList.h" #include "minecraft/MinecraftProfile.h" -#include "minecraft/RawLibrary.h" +#include "minecraft/Library.h" #include "minecraft/forge/ForgeMirrors.h" #include "net/URLConstants.h" #include "minecraft/AssetsUtils.h" @@ -213,7 +213,7 @@ void OneSixUpdate::jarlibStart() auto metacache = ENV.metacache(); QList ForgeLibs; - QList brokenLocalLibs; + QList brokenLocalLibs; for (auto lib : libs) { diff --git a/logic/minecraft/onesix/OneSixVersionFormat.cpp b/logic/minecraft/onesix/OneSixVersionFormat.cpp index 45eef278..4ccf6e78 100644 --- a/logic/minecraft/onesix/OneSixVersionFormat.cpp +++ b/logic/minecraft/onesix/OneSixVersionFormat.cpp @@ -4,6 +4,7 @@ #include "minecraft/ParseUtils.h" #include #include +#include using namespace Json; @@ -24,99 +25,22 @@ static QString readStringRet(const QJsonObject &root, const QString &key) return QString(); } -RawLibraryPtr OneSixVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename) +LibraryPtr OneSixVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename) { - RawLibraryPtr out(new RawLibrary()); - if (!libObj.contains("name")) - { - throw JSONValidationError(filename + - "contains a library that doesn't have a 'name' field"); - } - out->m_name = libObj.value("name").toString(); - - readString(libObj, "url", out->m_base_url); + LibraryPtr out = MojangVersionFormat::libraryFromJson(libObj, filename); readString(libObj, "MMC-hint", out->m_hint); readString(libObj, "MMC-absulute_url", out->m_absolute_url); readString(libObj, "MMC-absoluteUrl", out->m_absolute_url); - if (libObj.contains("extract")) - { - out->applyExcludes = true; - auto extractObj = requireObject(libObj.value("extract")); - for (auto excludeVal : requireArray(extractObj.value("exclude"))) - { - out->extract_excludes.append(requireString(excludeVal)); - } - } - if (libObj.contains("natives")) - { - QJsonObject nativesObj = requireObject(libObj.value("natives")); - for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it) - { - if (!it.value().isString()) - { - qWarning() << filename << "contains an invalid native (skipping)"; - } - OpSys opSys = OpSys_fromString(it.key()); - if (opSys != Os_Other) - { - out->m_native_classifiers[opSys] = it.value().toString(); - } - } - } - if (libObj.contains("rules")) - { - out->applyRules = true; - out->m_rules = rulesFromJsonV4(libObj); - } return out; } -QJsonObject OneSixVersionFormat::libraryToJson(RawLibrary *library) +QJsonObject OneSixVersionFormat::libraryToJson(Library *library) { - QJsonObject libRoot; - libRoot.insert("name", (QString)library->m_name); + QJsonObject libRoot = MojangVersionFormat::libraryToJson(library); if (library->m_absolute_url.size()) libRoot.insert("MMC-absoluteUrl", library->m_absolute_url); if (library->m_hint.size()) libRoot.insert("MMC-hint", library->m_hint); - if (library->m_base_url != "http://" + URLConstants::AWS_DOWNLOAD_LIBRARIES && - library->m_base_url != "https://" + URLConstants::AWS_DOWNLOAD_LIBRARIES && - library->m_base_url != "https://" + URLConstants::LIBRARY_BASE && !library->m_base_url.isEmpty()) - { - libRoot.insert("url", library->m_base_url); - } - if (library->isNative()) - { - QJsonObject nativeList; - auto iter = library->m_native_classifiers.begin(); - while (iter != library->m_native_classifiers.end()) - { - nativeList.insert(OpSys_toString(iter.key()), iter.value()); - iter++; - } - libRoot.insert("natives", nativeList); - if (library->extract_excludes.size()) - { - QJsonArray excludes; - QJsonObject extract; - for (auto exclude : library->extract_excludes) - { - excludes.append(exclude); - } - extract.insert("exclude", excludes); - libRoot.insert("extract", extract); - } - } - if (library->m_rules.size()) - { - QJsonArray allRules; - for (auto &rule : library->m_rules) - { - QJsonObject ruleObj = rule->toJson(); - allRules.append(ruleObj); - } - libRoot.insert("rules", allRules); - } return libRoot; } @@ -253,7 +177,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc template struct libraryConversion { - static QJsonObject convert(std::shared_ptr &value) + static QJsonObject convert(std::shared_ptr &value) { return OneSixVersionFormat::libraryToJson(value.get()); } diff --git a/logic/minecraft/onesix/OneSixVersionFormat.h b/logic/minecraft/onesix/OneSixVersionFormat.h index 9d16cced..45a961e4 100644 --- a/logic/minecraft/onesix/OneSixVersionFormat.h +++ b/logic/minecraft/onesix/OneSixVersionFormat.h @@ -2,7 +2,7 @@ #include #include -#include +#include #include class OneSixVersionFormat @@ -16,8 +16,8 @@ public: static QJsonDocument profilePatchToJson(const ProfilePatchPtr &patch, bool saveOrder); // libraries - static RawLibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename); - static QJsonObject libraryToJson(RawLibrary *library); + static LibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename); + static QJsonObject libraryToJson(Library *library); // jar mods static JarmodPtr jarModFromJson(const QJsonObject &libObj, const QString &filename, const QString &originalName); -- cgit v1.2.3