feat: support quilt.mod.json metadata

This commit is contained in:
Sefa Eyeoglu 2022-05-15 23:00:09 +02:00
parent e5d0097116
commit a110d445ac
No known key found for this signature in database
GPG Key ID: C10411294912A422

View File

@ -8,6 +8,7 @@
#include <quazip/quazipfile.h> #include <quazip/quazipfile.h>
#include <toml.h> #include <toml.h>
#include "Json.h"
#include "settings/INIFile.h" #include "settings/INIFile.h"
#include "FileSystem.h" #include "FileSystem.h"
@ -262,6 +263,43 @@ std::shared_ptr<ModDetails> ReadFabricModInfo(QByteArray contents)
return details; return details;
} }
// https://github.com/QuiltMC/rfcs/blob/master/specification/0002-quilt.mod.json.md#the-schema_version-field
std::shared_ptr<ModDetails> ReadQuiltModInfo(QByteArray contents)
{
QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
auto object = Json::requireObject(jsonDoc, "quilt.mod.json");
auto schemaVersion = Json::ensureInteger(object.value("schema_version"), 0, "Quilt schema_version");
std::shared_ptr<ModDetails> details = std::make_shared<ModDetails>();
if (schemaVersion == 1)
{
auto modInfo = Json::requireObject(object.value("quilt_loader"), "Quilt mod info");
details->mod_id = Json::requireString(modInfo.value("id"), "Mod ID");
details->version = Json::requireString(modInfo.value("version"), "Mod version");
auto modMetadata = Json::ensureObject(modInfo.value("metadata"));
details->name = Json::ensureString(modMetadata.value("name"), details->mod_id);
details->description = Json::ensureString(modMetadata.value("description"));
auto modContributors = Json::ensureObject(modMetadata.value("contributors"));
// We don't really care about the role of a contributor here
details->authors += modContributors.keys();
auto modContact = Json::ensureObject(modMetadata.value("contact"));
if (modContact.contains("homepage"))
{
details->homeurl = Json::requireString(modContact.value("homepage"));
}
}
return details;
}
std::shared_ptr<ModDetails> ReadForgeInfo(QByteArray contents) std::shared_ptr<ModDetails> ReadForgeInfo(QByteArray contents)
{ {
std::shared_ptr<ModDetails> details = std::make_shared<ModDetails>(); std::shared_ptr<ModDetails> details = std::make_shared<ModDetails>();
@ -391,7 +429,7 @@ void LocalModParseTask::processAsZip()
zip.close(); zip.close();
return; return;
} }
else if (zip.setCurrentFile("fabric.mod.json")) // TODO: Support quilt.mod.json else if (zip.setCurrentFile("fabric.mod.json"))
{ {
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
{ {
@ -404,6 +442,19 @@ void LocalModParseTask::processAsZip()
zip.close(); zip.close();
return; return;
} }
else if (zip.setCurrentFile("quilt.mod.json"))
{
if (!file.open(QIODevice::ReadOnly))
{
zip.close();
return;
}
m_result->details = ReadQuiltModInfo(file.readAll());
file.close();
zip.close();
return;
}
else if (zip.setCurrentFile("forgeversion.properties")) else if (zip.setCurrentFile("forgeversion.properties"))
{ {
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))