aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/modplatform')
-rw-r--r--launcher/modplatform/ModIndex.h31
-rw-r--r--launcher/modplatform/flame/FlameModIndex.cpp1
-rw-r--r--launcher/modplatform/modrinth/ModrinthPackIndex.cpp1
-rw-r--r--launcher/modplatform/packwiz/Packwiz.cpp60
-rw-r--r--launcher/modplatform/packwiz/Packwiz.h43
5 files changed, 136 insertions, 0 deletions
diff --git a/launcher/modplatform/ModIndex.h b/launcher/modplatform/ModIndex.h
index 7e1cf254..9c9ba99f 100644
--- a/launcher/modplatform/ModIndex.h
+++ b/launcher/modplatform/ModIndex.h
@@ -8,6 +8,35 @@
namespace ModPlatform {
+enum class Provider{
+ MODRINTH,
+ FLAME
+};
+
+class ProviderCapabilities {
+ public:
+ static QString hashType(Provider p)
+ {
+ switch(p){
+ case Provider::MODRINTH:
+ return "sha256";
+ case Provider::FLAME:
+ return "murmur2";
+ }
+ return "";
+ }
+ static QString providerName(Provider p)
+ {
+ switch(p){
+ case Provider::MODRINTH:
+ return "modrinth";
+ case Provider::FLAME:
+ return "curseforge";
+ }
+ return "";
+ }
+};
+
struct ModpackAuthor {
QString name;
QString url;
@@ -26,6 +55,7 @@ struct IndexedVersion {
struct IndexedPack {
QVariant addonId;
+ Provider provider;
QString name;
QString description;
QList<ModpackAuthor> authors;
@@ -40,3 +70,4 @@ struct IndexedPack {
} // namespace ModPlatform
Q_DECLARE_METATYPE(ModPlatform::IndexedPack)
+Q_DECLARE_METATYPE(ModPlatform::Provider)
diff --git a/launcher/modplatform/flame/FlameModIndex.cpp b/launcher/modplatform/flame/FlameModIndex.cpp
index ba0824cf..45f02b71 100644
--- a/launcher/modplatform/flame/FlameModIndex.cpp
+++ b/launcher/modplatform/flame/FlameModIndex.cpp
@@ -9,6 +9,7 @@
void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
{
pack.addonId = Json::requireInteger(obj, "id");
+ pack.provider = ModPlatform::Provider::FLAME;
pack.name = Json::requireString(obj, "name");
pack.websiteUrl = Json::ensureString(Json::ensureObject(obj, "links"), "websiteUrl", "");
pack.description = Json::ensureString(obj, "summary", "");
diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
index f7fa9864..6c8659dc 100644
--- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
+++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
@@ -28,6 +28,7 @@ static ModrinthAPI api;
void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
{
pack.addonId = Json::requireString(obj, "project_id");
+ pack.provider = ModPlatform::Provider::MODRINTH;
pack.name = Json::requireString(obj, "title");
QString slug = Json::ensureString(obj, "slug", "");
diff --git a/launcher/modplatform/packwiz/Packwiz.cpp b/launcher/modplatform/packwiz/Packwiz.cpp
new file mode 100644
index 00000000..ff86a8a9
--- /dev/null
+++ b/launcher/modplatform/packwiz/Packwiz.cpp
@@ -0,0 +1,60 @@
+#include "Packwiz.h"
+
+#include "modplatform/ModIndex.h"
+
+#include <QDebug>
+#include <QDir>
+#include <QObject>
+
+auto Packwiz::createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedVersion& mod_version) -> Mod
+{
+ Mod mod;
+
+ mod.name = mod_pack.name;
+ mod.filename = mod_version.fileName;
+
+ mod.url = mod_version.downloadUrl;
+ mod.hash_format = ModPlatform::ProviderCapabilities::hashType(mod_pack.provider);
+ mod.hash = ""; // FIXME
+
+ mod.provider = mod_pack.provider;
+ mod.file_id = mod_pack.addonId;
+ mod.project_id = mod_version.fileId;
+
+ return mod;
+}
+
+void Packwiz::updateModIndex(QDir& index_dir, Mod& mod)
+{
+ // Ensure the corresponding mod's info exists, and create it if not
+ auto index_file_name = QString("%1.toml").arg(mod.name);
+ QFile index_file(index_dir.absoluteFilePath(index_file_name));
+
+ // There's already data on there!
+ if (index_file.exists()) { index_file.remove(); }
+
+ if (!index_file.open(QIODevice::ReadWrite)) {
+ qCritical() << "Could not open file " << index_file_name << "!";
+ return;
+ }
+
+ // Put TOML data into the file
+ QTextStream in_stream(&index_file);
+ auto addToStream = [&in_stream](QString&& key, QString value) { in_stream << QString("%1 = \"%2\"\n").arg(key, value); };
+
+ {
+ addToStream("name", mod.name);
+ addToStream("filename", mod.filename);
+ addToStream("side", mod.side);
+
+ in_stream << QString("\n[download]\n");
+ addToStream("url", mod.url.toString());
+ addToStream("hash-format", mod.hash_format);
+ addToStream("hash", mod.hash);
+
+ in_stream << QString("\n[update]\n");
+ in_stream << QString("[update.%1]\n").arg(ModPlatform::ProviderCapabilities::providerName(mod.provider));
+ addToStream("file-id", mod.file_id.toString());
+ addToStream("project-id", mod.project_id.toString());
+ }
+}
diff --git a/launcher/modplatform/packwiz/Packwiz.h b/launcher/modplatform/packwiz/Packwiz.h
new file mode 100644
index 00000000..64b95e7a
--- /dev/null
+++ b/launcher/modplatform/packwiz/Packwiz.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <QString>
+#include <QUrl>
+#include <QVariant>
+
+namespace ModPlatform {
+enum class Provider;
+class IndexedPack;
+class IndexedVersion;
+} // namespace ModPlatform
+
+class QDir;
+
+class Packwiz {
+ public:
+ struct Mod {
+ QString name;
+ QString filename;
+ // FIXME: make side an enum
+ QString side = "both";
+
+ // [download]
+ QUrl url;
+ // FIXME: make hash-format an enum
+ QString hash_format;
+ QString hash;
+
+ // [update]
+ ModPlatform::Provider provider;
+ QVariant file_id;
+ QVariant project_id;
+ };
+
+ /* Generates the object representing the information in a mod.toml file via its common representation in the launcher */
+ static auto createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedVersion& mod_version) -> Mod;
+
+ /* Updates the mod index for the provided mod.
+ * This creates a new index if one does not exist already
+ * TODO: Ask the user if they want to override, and delete the old mod's files, or keep the old one.
+ * */
+ static void updateModIndex(QDir& index_dir, Mod& mod);
+};