NOISSUE make new Mojang version format pass through MultiMC structures
Not yet used effectively, but it is read and written properly
This commit is contained in:
parent
3d8728f52f
commit
d4eacb56b3
21 changed files with 493 additions and 155 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "minecraft/ParseUtils.h"
|
||||
#include <minecraft/MinecraftVersion.h>
|
||||
#include <minecraft/VersionBuildError.h>
|
||||
#include <minecraft/MojangVersionFormat.h>
|
||||
|
||||
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 <typename T>
|
||||
struct libraryConversion
|
||||
{
|
||||
static QJsonObject convert(std::shared_ptr<RawLibrary> &value)
|
||||
static QJsonObject convert(std::shared_ptr<Library> &value)
|
||||
{
|
||||
return OneSixVersionFormat::libraryToJson(value.get());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue