added side for modrinth mods
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
a2d44744fe
commit
47d1f23568
@ -31,6 +31,7 @@ class Mod;
|
||||
class Metadata {
|
||||
public:
|
||||
using ModStruct = Packwiz::V1::Mod;
|
||||
using ModSide = Packwiz::V1::Side;
|
||||
|
||||
static auto create(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedVersion& mod_version) -> ModStruct
|
||||
{
|
||||
|
@ -104,6 +104,7 @@ struct IndexedPack {
|
||||
QString logoName;
|
||||
QString logoUrl;
|
||||
QString websiteUrl;
|
||||
QString side;
|
||||
|
||||
bool versionsLoaded = false;
|
||||
QVector<IndexedVersion> versions;
|
||||
@ -128,7 +129,6 @@ struct IndexedPack {
|
||||
return std::any_of(versions.constBegin(), versions.constEnd(), [](auto const& v) { return v.is_currently_selected; });
|
||||
}
|
||||
};
|
||||
QString getMetaURL(ResourceProvider provider, QVariant projectID);
|
||||
|
||||
struct OverrideDep {
|
||||
QString quilt;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "Json.h"
|
||||
#include "MMCZip.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "minecraft/mod/MetadataHandler.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
|
||||
const QStringList ModrinthPackExportTask::PREFIXES({ "mods/", "coremods/", "resourcepacks/", "texturepacks/", "shaderpacks/" });
|
||||
@ -127,7 +128,8 @@ void ModrinthPackExportTask::collectHashes()
|
||||
QCryptographicHash sha1(QCryptographicHash::Algorithm::Sha1);
|
||||
sha1.addData(data);
|
||||
|
||||
ResolvedFile resolvedFile{ sha1.result().toHex(), sha512.result().toHex(), url.toEncoded(), openFile.size() };
|
||||
ResolvedFile resolvedFile{ sha1.result().toHex(), sha512.result().toHex(), url.toEncoded(), openFile.size(),
|
||||
mod->metadata()->side };
|
||||
resolvedFiles[relative] = resolvedFile;
|
||||
|
||||
// nice! we've managed to resolve based on local metadata!
|
||||
@ -272,18 +274,31 @@ QByteArray ModrinthPackExportTask::generateIndex()
|
||||
|
||||
// detect disabled mod
|
||||
const QFileInfo pathInfo(path);
|
||||
|
||||
QJsonObject env;
|
||||
if (pathInfo.suffix() == "disabled") {
|
||||
// rename it
|
||||
path = pathInfo.dir().filePath(pathInfo.completeBaseName());
|
||||
// ...and make it optional
|
||||
QJsonObject env;
|
||||
env["client"] = "optional";
|
||||
env["server"] = "optional";
|
||||
fileOut["env"] = env;
|
||||
} else {
|
||||
env["client"] = "required";
|
||||
env["server"] = "required";
|
||||
}
|
||||
switch (iterator->side) {
|
||||
case Metadata::ModSide::ClientSide:
|
||||
env["server"] = "unsupported";
|
||||
break;
|
||||
case Metadata::ModSide::ServerSide:
|
||||
env["client"] = "unsupported";
|
||||
break;
|
||||
case Metadata::ModSide::UniversalSide:
|
||||
break;
|
||||
}
|
||||
fileOut["env"] = env;
|
||||
|
||||
fileOut["path"] = path;
|
||||
fileOut["downloads"] = QJsonArray{ iterator.value().url };
|
||||
fileOut["downloads"] = QJsonArray{ iterator->url };
|
||||
|
||||
QJsonObject hashes;
|
||||
hashes["sha1"] = value.sha1;
|
||||
|
@ -43,6 +43,7 @@ class ModrinthPackExportTask : public Task {
|
||||
struct ResolvedFile {
|
||||
QString sha1, sha512, url;
|
||||
qint64 size;
|
||||
Metadata::ModSide side;
|
||||
};
|
||||
|
||||
static const QStringList PREFIXES;
|
||||
|
@ -27,6 +27,11 @@
|
||||
static ModrinthAPI api;
|
||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
||||
|
||||
bool shouldDownloadOnSide(QString side)
|
||||
{
|
||||
return side == "required" || side == "optional";
|
||||
}
|
||||
|
||||
// https://docs.modrinth.com/api-spec/#tag/projects/operation/getProject
|
||||
void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||
{
|
||||
@ -53,6 +58,17 @@ void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||
modAuthor.url = api.getAuthorURL(modAuthor.name);
|
||||
pack.authors.append(modAuthor);
|
||||
|
||||
auto client = shouldDownloadOnSide(Json::ensureString(obj, "client_side"));
|
||||
auto server = shouldDownloadOnSide(Json::ensureString(obj, "server_side"));
|
||||
|
||||
if (server && client) {
|
||||
pack.side = "both";
|
||||
} else if (server) {
|
||||
pack.side = "server";
|
||||
} else if (client) {
|
||||
pack.side = "client";
|
||||
}
|
||||
|
||||
// Modrinth can have more data than what's provided by the basic search :)
|
||||
pack.extraDataLoaded = false;
|
||||
}
|
||||
|
@ -113,6 +113,7 @@ auto V1::createModFormat([[maybe_unused]] QDir& index_dir, ModPlatform::IndexedP
|
||||
mod.provider = mod_pack.provider;
|
||||
mod.file_id = mod_version.fileId;
|
||||
mod.project_id = mod_pack.addonId;
|
||||
mod.side = stringToSide(mod_pack.side);
|
||||
|
||||
return mod;
|
||||
}
|
||||
@ -190,7 +191,7 @@ void V1::updateModIndex(QDir& index_dir, Mod& mod)
|
||||
{
|
||||
auto tbl = toml::table{ { "name", mod.name.toStdString() },
|
||||
{ "filename", mod.filename.toStdString() },
|
||||
{ "side", mod.side.toStdString() },
|
||||
{ "side", sideToString(mod.side).toStdString() },
|
||||
{ "download",
|
||||
toml::table{
|
||||
{ "mode", mod.mode.toStdString() },
|
||||
@ -274,7 +275,7 @@ auto V1::getIndexForMod(QDir& index_dir, QString slug) -> Mod
|
||||
{ // Basic info
|
||||
mod.name = stringEntry(table, "name");
|
||||
mod.filename = stringEntry(table, "filename");
|
||||
mod.side = stringEntry(table, "side");
|
||||
mod.side = stringToSide(stringEntry(table, "side"));
|
||||
}
|
||||
|
||||
{ // [download] info
|
||||
@ -329,4 +330,28 @@ auto V1::getIndexForMod(QDir& index_dir, QVariant& mod_id) -> Mod
|
||||
return {};
|
||||
}
|
||||
|
||||
auto V1::sideToString(Side side) -> QString
|
||||
{
|
||||
switch (side) {
|
||||
case Side::ClientSide:
|
||||
return "client";
|
||||
case Side::ServerSide:
|
||||
return "server";
|
||||
case Side::UniversalSide:
|
||||
return "both";
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
auto V1::stringToSide(QString side) -> Side
|
||||
{
|
||||
if (side == "client")
|
||||
return Side::ClientSide;
|
||||
if (side == "server")
|
||||
return Side::ServerSide;
|
||||
if (side == "both")
|
||||
return Side::UniversalSide;
|
||||
return Side::UniversalSide;
|
||||
}
|
||||
|
||||
} // namespace Packwiz
|
||||
|
@ -35,12 +35,12 @@ auto getRealIndexName(QDir& index_dir, QString normalized_index_name, bool shoul
|
||||
|
||||
class V1 {
|
||||
public:
|
||||
enum class Side { ClientSide = 1 << 0, ServerSide = 1 << 1, UniversalSide = ClientSide | ServerSide };
|
||||
struct Mod {
|
||||
QString slug{};
|
||||
QString name{};
|
||||
QString filename{};
|
||||
// FIXME: make side an enum
|
||||
QString side{ "both" };
|
||||
Side side{ Side::UniversalSide };
|
||||
|
||||
// [download]
|
||||
QString mode{};
|
||||
@ -93,6 +93,9 @@ class V1 {
|
||||
* If the mod doesn't have a metadata, it simply returns an empty Mod object.
|
||||
* */
|
||||
static auto getIndexForMod(QDir& index_dir, QVariant& mod_id) -> Mod;
|
||||
|
||||
static auto sideToString(Side side) -> QString;
|
||||
static auto stringToSide(QString side) -> Side;
|
||||
};
|
||||
|
||||
} // namespace Packwiz
|
||||
|
@ -42,7 +42,7 @@ class PackwizTest : public QObject {
|
||||
|
||||
QCOMPARE(metadata.name, "Borderless Mining");
|
||||
QCOMPARE(metadata.filename, "borderless-mining-1.1.1+1.18.jar");
|
||||
QCOMPARE(metadata.side, "client");
|
||||
QCOMPARE(metadata.side, Packwiz::V1::Side::ClientSide);
|
||||
|
||||
QCOMPARE(metadata.url, QUrl("https://cdn.modrinth.com/data/kYq5qkSL/versions/1.1.1+1.18/borderless-mining-1.1.1+1.18.jar"));
|
||||
QCOMPARE(metadata.hash_format, "sha512");
|
||||
@ -72,7 +72,7 @@ class PackwizTest : public QObject {
|
||||
|
||||
QCOMPARE(metadata.name, "Screenshot to Clipboard (Fabric)");
|
||||
QCOMPARE(metadata.filename, "screenshot-to-clipboard-1.0.7-fabric.jar");
|
||||
QCOMPARE(metadata.side, "both");
|
||||
QCOMPARE(metadata.side, Packwiz::V1::Side::UniversalSide);
|
||||
|
||||
QCOMPARE(metadata.url, QUrl("https://edge.forgecdn.net/files/3509/43/screenshot-to-clipboard-1.0.7-fabric.jar"));
|
||||
QCOMPARE(metadata.hash_format, "murmur2");
|
||||
|
Loading…
Reference in New Issue
Block a user