diff options
author | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-07-09 14:03:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-09 14:03:47 -0700 |
commit | d43399c2b4359b5c3c38a25197ea170388190369 (patch) | |
tree | 486bc61236aad1ff47dc666a763e42cd84bb5a68 | |
parent | 67d473aab773e7f94c394ebdde05581dc8f805de (diff) | |
parent | 6e2fcc9e1102d3955a509c3346b8df15ce52a6a1 (diff) | |
download | PrismLauncher-d43399c2b4359b5c3c38a25197ea170388190369.tar.gz PrismLauncher-d43399c2b4359b5c3c38a25197ea170388190369.tar.bz2 PrismLauncher-d43399c2b4359b5c3c38a25197ea170388190369.zip |
Merge pull request #1321 from TheKodeToad/mr-optional
Optional mods in mrpack export
-rw-r--r-- | launcher/modplatform/modrinth/ModrinthPackExportTask.cpp | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp b/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp index 4cd88aa6..50f6a33c 100644 --- a/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp @@ -263,13 +263,13 @@ void ModrinthPackExportTask::finish() QByteArray ModrinthPackExportTask::generateIndex() { - QJsonObject obj; - obj["formatVersion"] = 1; - obj["game"] = "minecraft"; - obj["name"] = name; - obj["versionId"] = version; + QJsonObject out; + out["formatVersion"] = 1; + out["game"] = "minecraft"; + out["name"] = name; + out["versionId"] = version; if (!summary.isEmpty()) - obj["summary"] = summary; + out["summary"] = summary; if (mcInstance) { auto profile = mcInstance->getPackProfile(); @@ -290,30 +290,40 @@ QByteArray ModrinthPackExportTask::generateIndex() if (forge != nullptr) dependencies["forge"] = forge->m_version; - obj["dependencies"] = dependencies; + out["dependencies"] = dependencies; } - QJsonArray files; - QMapIterator<QString, ResolvedFile> iterator(resolvedFiles); - while (iterator.hasNext()) { - iterator.next(); + QJsonArray filesOut; + for (auto iterator = resolvedFiles.constBegin(); iterator != resolvedFiles.constEnd(); iterator++) { + QJsonObject fileOut; + QString path = iterator.key(); const ResolvedFile& value = iterator.value(); - QJsonObject file; - file["path"] = iterator.key(); - file["downloads"] = QJsonArray({ iterator.value().url }); + // detect disabled mod + const QFileInfo pathInfo(path); + 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; + } + + fileOut["path"] = path; + fileOut["downloads"] = QJsonArray{ iterator.value().url }; QJsonObject hashes; hashes["sha1"] = value.sha1; hashes["sha512"] = value.sha512; + fileOut["hashes"] = hashes; - file["hashes"] = hashes; - file["fileSize"] = value.size; - - files << file; + fileOut["fileSize"] = value.size; + filesOut << fileOut; } - obj["files"] = files; + out["files"] = filesOut; - return QJsonDocument(obj).toJson(QJsonDocument::Compact); + return QJsonDocument(out).toJson(QJsonDocument::Compact); } |