2023-06-22 18:03:44 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* Prism Launcher - Minecraft Launcher
|
|
|
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "FlamePackExportTask.h"
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QtConcurrentRun>
|
2023-06-23 23:05:49 +01:00
|
|
|
#include <algorithm>
|
2023-06-23 17:35:41 +01:00
|
|
|
#include <memory>
|
2023-06-22 18:03:44 +01:00
|
|
|
#include "Json.h"
|
|
|
|
#include "MMCZip.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
|
|
|
#include "minecraft/mod/ModFolderModel.h"
|
2023-06-22 19:06:01 +01:00
|
|
|
#include "modplatform/ModIndex.h"
|
2023-06-23 23:05:49 +01:00
|
|
|
#include "modplatform/flame/FlameModIndex.h"
|
2023-06-23 17:35:41 +01:00
|
|
|
#include "modplatform/helpers/HashUtils.h"
|
2023-06-23 20:41:01 +01:00
|
|
|
#include "tasks/Task.h"
|
2023-06-22 18:03:44 +01:00
|
|
|
|
2023-06-24 09:13:08 +01:00
|
|
|
const QString FlamePackExportTask::TEMPLATE = "<li><a href={url}>{name} (by {authors})</a></li>";
|
2023-06-22 18:03:44 +01:00
|
|
|
|
|
|
|
FlamePackExportTask::FlamePackExportTask(const QString& name,
|
|
|
|
const QString& version,
|
2023-06-22 19:06:01 +01:00
|
|
|
const QString& author,
|
2023-06-22 18:03:44 +01:00
|
|
|
const QVariant& projectID,
|
|
|
|
InstancePtr instance,
|
|
|
|
const QString& output,
|
|
|
|
MMCZip::FilterFunction filter)
|
|
|
|
: name(name)
|
|
|
|
, version(version)
|
2023-06-22 19:06:01 +01:00
|
|
|
, author(author)
|
2023-06-22 18:03:44 +01:00
|
|
|
, projectID(projectID)
|
|
|
|
, instance(instance)
|
|
|
|
, mcInstance(dynamic_cast<MinecraftInstance*>(instance.get()))
|
|
|
|
, gameRoot(instance->gameRoot())
|
|
|
|
, output(output)
|
|
|
|
, filter(filter)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void FlamePackExportTask::executeTask()
|
|
|
|
{
|
|
|
|
setStatus(tr("Searching for files..."));
|
|
|
|
setProgress(0, 0);
|
|
|
|
collectFiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FlamePackExportTask::abort()
|
|
|
|
{
|
|
|
|
if (task != nullptr) {
|
|
|
|
task->abort();
|
|
|
|
task = nullptr;
|
|
|
|
emitAborted();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buildZipFuture.isRunning()) {
|
|
|
|
buildZipFuture.cancel();
|
|
|
|
// NOTE: Here we don't do `emitAborted()` because it will be done when `buildZipFuture` actually cancels, which may not occur
|
|
|
|
// immediately.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlamePackExportTask::collectFiles()
|
|
|
|
{
|
|
|
|
setAbortable(false);
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
files.clear();
|
|
|
|
if (!MMCZip::collectFileListRecursively(instance->gameRoot(), nullptr, &files, filter)) {
|
|
|
|
emitFailed(tr("Could not search for files"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-23 17:35:41 +01:00
|
|
|
pendingHashes.clear();
|
2023-06-22 18:03:44 +01:00
|
|
|
resolvedFiles.clear();
|
|
|
|
|
2023-06-23 20:41:01 +01:00
|
|
|
if (mcInstance != nullptr) {
|
|
|
|
connect(mcInstance->loaderModList().get(), &ModFolderModel::updateFinished, this, &FlamePackExportTask::collectHashes);
|
2023-06-23 17:35:41 +01:00
|
|
|
mcInstance->loaderModList()->update();
|
|
|
|
} else
|
|
|
|
collectHashes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlamePackExportTask::collectHashes()
|
|
|
|
{
|
2023-06-23 20:41:01 +01:00
|
|
|
setAbortable(true);
|
|
|
|
setStatus(tr("Find file hashes..."));
|
|
|
|
auto mods = mcInstance->loaderModList()->allMods();
|
2023-06-23 17:35:41 +01:00
|
|
|
ConcurrentTask::Ptr hashing_task(new ConcurrentTask(this, "MakeHashesTask", 10));
|
2023-06-23 20:41:01 +01:00
|
|
|
task.reset(hashing_task);
|
2023-06-24 12:37:02 +01:00
|
|
|
int totalProgres = mods.count();
|
|
|
|
setProgress(0, totalProgres);
|
2023-06-23 17:35:41 +01:00
|
|
|
for (auto* mod : mods) {
|
2023-06-23 20:41:01 +01:00
|
|
|
if (!mod || mod->type() == ResourceType::FOLDER) {
|
2023-06-24 12:37:02 +01:00
|
|
|
setProgress(m_progress + 1, totalProgres);
|
2023-06-23 17:35:41 +01:00
|
|
|
continue;
|
2023-06-23 20:41:01 +01:00
|
|
|
}
|
2023-06-23 17:35:41 +01:00
|
|
|
if (mod->metadata() && mod->metadata()->provider == ModPlatform::ResourceProvider::FLAME) {
|
|
|
|
resolvedFiles.insert(mod->fileinfo().absoluteFilePath(),
|
2023-06-23 23:05:49 +01:00
|
|
|
{ mod->metadata()->project_id.toInt(), mod->metadata()->file_id.toInt(), mod->enabled(),
|
|
|
|
mod->metadata()->name, mod->metadata()->slug, mod->authors().join(", ") });
|
2023-06-24 12:37:02 +01:00
|
|
|
setProgress(m_progress + 1, totalProgres);
|
2023-06-23 17:35:41 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto hash_task = Hashing::createFlameHasher(mod->fileinfo().absoluteFilePath());
|
2023-06-24 12:37:02 +01:00
|
|
|
connect(hash_task.get(), &Hashing::Hasher::resultsReady, [this, mod, totalProgres](QString hash) {
|
2023-06-23 20:41:01 +01:00
|
|
|
if (m_state == Task::State::Running) {
|
2023-06-24 12:37:02 +01:00
|
|
|
setProgress(m_progress + 1, totalProgres);
|
|
|
|
pendingHashes.insert(hash, { mod->name(), mod->fileinfo().absoluteFilePath(), mod->enabled() });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
connect(hash_task.get(), &Task::failed, this, &FlamePackExportTask::emitFailed);
|
|
|
|
hashing_task->addTask(hash_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const QFileInfo& file : files) {
|
|
|
|
const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath());
|
|
|
|
if (!relative.endsWith(".zip") || !relative.startsWith("resourcepacks/"))
|
|
|
|
continue;
|
|
|
|
totalProgres++;
|
|
|
|
auto hash_task = Hashing::createFlameHasher(file.absoluteFilePath());
|
|
|
|
connect(hash_task.get(), &Hashing::Hasher::resultsReady, [this, relative, file, totalProgres](QString hash) {
|
|
|
|
if (m_state == Task::State::Running) {
|
|
|
|
setProgress(m_progress + 1, totalProgres);
|
|
|
|
pendingHashes.insert(hash, { relative, file.absoluteFilePath(), true });
|
2023-06-23 20:41:01 +01:00
|
|
|
}
|
|
|
|
});
|
2023-06-23 17:35:41 +01:00
|
|
|
connect(hash_task.get(), &Task::failed, this, &FlamePackExportTask::emitFailed);
|
|
|
|
hashing_task->addTask(hash_task);
|
|
|
|
}
|
|
|
|
connect(hashing_task.get(), &Task::succeeded, this, &FlamePackExportTask::makeApiRequest);
|
|
|
|
connect(hashing_task.get(), &Task::failed, this, &FlamePackExportTask::emitFailed);
|
|
|
|
hashing_task->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlamePackExportTask::makeApiRequest()
|
|
|
|
{
|
2023-06-23 20:41:01 +01:00
|
|
|
setStatus(tr("Find versions for hashes..."));
|
2023-06-23 17:35:41 +01:00
|
|
|
if (pendingHashes.isEmpty()) {
|
|
|
|
buildZip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto response = std::make_shared<QByteArray>();
|
|
|
|
|
|
|
|
QList<uint> fingerprints;
|
|
|
|
for (auto& murmur : pendingHashes.keys()) {
|
|
|
|
fingerprints.push_back(murmur.toUInt());
|
|
|
|
}
|
|
|
|
|
2023-06-23 20:41:01 +01:00
|
|
|
task.reset(api.matchFingerprints(fingerprints, response));
|
2023-06-23 17:35:41 +01:00
|
|
|
|
|
|
|
connect(task.get(), &Task::succeeded, this, [this, response] {
|
|
|
|
QJsonParseError parse_error{};
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
|
|
|
if (parse_error.error != QJsonParseError::NoError) {
|
|
|
|
qWarning() << "Error while parsing JSON response from Modrinth::CurrentVersions at " << parse_error.offset
|
|
|
|
<< " reason: " << parse_error.errorString();
|
|
|
|
qWarning() << *response;
|
|
|
|
|
|
|
|
failed(parse_error.errorString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
auto doc_obj = Json::requireObject(doc);
|
|
|
|
auto data_obj = Json::requireObject(doc_obj, "data");
|
|
|
|
auto data_arr = Json::requireArray(data_obj, "exactMatches");
|
|
|
|
|
|
|
|
if (data_arr.isEmpty()) {
|
|
|
|
qWarning() << "No matches found for fingerprint search!";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2023-06-23 20:41:01 +01:00
|
|
|
size_t progress = 0;
|
2023-06-23 17:35:41 +01:00
|
|
|
for (auto match : data_arr) {
|
2023-06-23 20:41:01 +01:00
|
|
|
setProgress(progress++, data_arr.count());
|
2023-06-23 17:35:41 +01:00
|
|
|
auto match_obj = Json::ensureObject(match, {});
|
|
|
|
auto file_obj = Json::ensureObject(match_obj, "file", {});
|
|
|
|
|
|
|
|
if (match_obj.isEmpty() || file_obj.isEmpty()) {
|
|
|
|
qWarning() << "Fingerprint match is empty!";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto fingerprint = QString::number(Json::ensureVariant(file_obj, "fileFingerprint").toUInt());
|
|
|
|
auto mod = pendingHashes.find(fingerprint);
|
|
|
|
if (mod == pendingHashes.end()) {
|
|
|
|
qWarning() << "Invalid fingerprint from the API response.";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-06-24 12:37:02 +01:00
|
|
|
setStatus(tr("Parsing API response from CurseForge for '%1'...").arg(mod->name));
|
2023-06-24 11:24:40 +01:00
|
|
|
if (Json::ensureBoolean(file_obj, "isAvailable", false, "isAvailable"))
|
2023-06-24 12:37:02 +01:00
|
|
|
resolvedFiles.insert(mod->path,
|
|
|
|
{ Json::requireInteger(file_obj, "modId"), Json::requireInteger(file_obj, "id"), mod->enabled });
|
2023-06-23 17:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Json::JsonException& e) {
|
|
|
|
qDebug() << e.cause();
|
|
|
|
qDebug() << doc;
|
|
|
|
}
|
|
|
|
pendingHashes.clear();
|
2023-06-22 18:03:44 +01:00
|
|
|
});
|
2023-06-23 23:05:49 +01:00
|
|
|
connect(task.get(), &Task::finished, this, &FlamePackExportTask::getProjectsInfo);
|
2023-06-23 17:35:41 +01:00
|
|
|
connect(task.get(), &NetJob::failed, this, &FlamePackExportTask::emitFailed);
|
|
|
|
task->start();
|
2023-06-22 18:03:44 +01:00
|
|
|
}
|
|
|
|
|
2023-06-23 23:05:49 +01:00
|
|
|
void FlamePackExportTask::getProjectsInfo()
|
|
|
|
{
|
2023-06-24 12:50:05 +01:00
|
|
|
setStatus(tr("Find project info from CurseForge..."));
|
2023-06-23 23:05:49 +01:00
|
|
|
QList<QString> addonIds;
|
|
|
|
for (auto resolved : resolvedFiles) {
|
|
|
|
if (resolved.slug.isEmpty()) {
|
|
|
|
addonIds << QString::number(resolved.addonId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto response = std::make_shared<QByteArray>();
|
|
|
|
Task::Ptr proj_task;
|
|
|
|
|
|
|
|
if (addonIds.isEmpty()) {
|
|
|
|
buildZip();
|
|
|
|
return;
|
|
|
|
} else if (addonIds.size() == 1) {
|
|
|
|
proj_task = api.getProject(*addonIds.begin(), response);
|
|
|
|
} else {
|
|
|
|
proj_task = api.getProjects(addonIds, response);
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(proj_task.get(), &Task::succeeded, this, [this, response, addonIds] {
|
|
|
|
QJsonParseError parse_error{};
|
|
|
|
auto doc = QJsonDocument::fromJson(*response, &parse_error);
|
|
|
|
if (parse_error.error != QJsonParseError::NoError) {
|
|
|
|
qWarning() << "Error while parsing JSON response from Modrinth projects task at " << parse_error.offset
|
|
|
|
<< " reason: " << parse_error.errorString();
|
|
|
|
qWarning() << *response;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
QJsonArray entries;
|
|
|
|
if (addonIds.size() == 1)
|
|
|
|
entries = { Json::requireObject(Json::requireObject(doc), "data") };
|
|
|
|
else
|
|
|
|
entries = Json::requireArray(Json::requireObject(doc), "data");
|
|
|
|
|
|
|
|
size_t progress = 0;
|
|
|
|
for (auto entry : entries) {
|
|
|
|
setProgress(progress++, entries.count());
|
|
|
|
auto entry_obj = Json::requireObject(entry);
|
|
|
|
|
|
|
|
try {
|
|
|
|
setStatus(tr("Parsing API response from CurseForge for '%1'...").arg(Json::requireString(entry_obj, "name")));
|
|
|
|
|
|
|
|
ModPlatform::IndexedPack pack;
|
|
|
|
FlameMod::loadIndexedPack(pack, entry_obj);
|
|
|
|
for (auto key : resolvedFiles.keys()) {
|
|
|
|
auto val = resolvedFiles.value(key);
|
|
|
|
if (val.addonId == pack.addonId) {
|
|
|
|
val.name = pack.name;
|
|
|
|
val.slug = pack.slug;
|
|
|
|
QStringList authors;
|
|
|
|
for (auto author : pack.authors)
|
|
|
|
authors << author.name;
|
|
|
|
|
|
|
|
val.authors = authors.join(", ");
|
|
|
|
resolvedFiles[key] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Json::JsonException& e) {
|
|
|
|
qDebug() << e.cause();
|
|
|
|
qDebug() << entries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Json::JsonException& e) {
|
|
|
|
qDebug() << e.cause();
|
|
|
|
qDebug() << doc;
|
|
|
|
}
|
|
|
|
buildZip();
|
|
|
|
});
|
|
|
|
task.reset(proj_task);
|
|
|
|
task->start();
|
|
|
|
}
|
|
|
|
|
2023-06-22 18:03:44 +01:00
|
|
|
void FlamePackExportTask::buildZip()
|
|
|
|
{
|
|
|
|
setStatus(tr("Adding files..."));
|
|
|
|
|
|
|
|
buildZipFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this]() {
|
|
|
|
QuaZip zip(output);
|
|
|
|
if (!zip.open(QuaZip::mdCreate)) {
|
|
|
|
QFile::remove(output);
|
|
|
|
return BuildZipResult(tr("Could not create file"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buildZipFuture.isCanceled())
|
|
|
|
return BuildZipResult();
|
|
|
|
|
|
|
|
QuaZipFile indexFile(&zip);
|
|
|
|
if (!indexFile.open(QIODevice::WriteOnly, QuaZipNewInfo("manifest.json"))) {
|
|
|
|
QFile::remove(output);
|
|
|
|
return BuildZipResult(tr("Could not create index"));
|
|
|
|
}
|
|
|
|
indexFile.write(generateIndex());
|
|
|
|
|
2023-06-24 09:12:23 +01:00
|
|
|
QuaZipFile modlist(&zip);
|
|
|
|
if (!modlist.open(QIODevice::WriteOnly, QuaZipNewInfo("modlist.html"))) {
|
|
|
|
QFile::remove(output);
|
|
|
|
return BuildZipResult(tr("Could not create index"));
|
|
|
|
}
|
|
|
|
QString content = "";
|
|
|
|
for (auto mod : resolvedFiles) {
|
|
|
|
content += QString(TEMPLATE)
|
|
|
|
.replace("{name}", mod.name)
|
|
|
|
.replace("{url}", ModPlatform::getMetaURL(ModPlatform::ResourceProvider::FLAME, mod.slug))
|
|
|
|
.replace("{authors}", mod.authors) +
|
|
|
|
"\n";
|
2023-06-22 18:03:44 +01:00
|
|
|
}
|
2023-06-24 09:12:23 +01:00
|
|
|
content = "<ul>" + content + "</ul>";
|
|
|
|
modlist.write(content.toUtf8());
|
2023-06-22 18:03:44 +01:00
|
|
|
|
|
|
|
size_t progress = 0;
|
|
|
|
for (const QFileInfo& file : files) {
|
|
|
|
if (buildZipFuture.isCanceled()) {
|
|
|
|
QFile::remove(output);
|
|
|
|
return BuildZipResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
setProgress(progress, files.length());
|
|
|
|
const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath());
|
2023-06-23 20:41:01 +01:00
|
|
|
if (!resolvedFiles.contains(file.absoluteFilePath()) &&
|
|
|
|
!JlCompress::compressFile(&zip, file.absoluteFilePath(), "overrides/" + relative)) {
|
2023-06-22 18:03:44 +01:00
|
|
|
QFile::remove(output);
|
|
|
|
return BuildZipResult(tr("Could not read and compress %1").arg(relative));
|
|
|
|
}
|
|
|
|
progress++;
|
|
|
|
}
|
|
|
|
|
|
|
|
zip.close();
|
|
|
|
|
|
|
|
if (zip.getZipError() != 0) {
|
|
|
|
QFile::remove(output);
|
|
|
|
return BuildZipResult(tr("A zip error occurred"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return BuildZipResult();
|
|
|
|
});
|
|
|
|
connect(&buildZipWatcher, &QFutureWatcher<BuildZipResult>::finished, this, &FlamePackExportTask::finish);
|
|
|
|
buildZipWatcher.setFuture(buildZipFuture);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlamePackExportTask::finish()
|
|
|
|
{
|
|
|
|
if (buildZipFuture.isCanceled())
|
|
|
|
emitAborted();
|
|
|
|
else {
|
|
|
|
const BuildZipResult result = buildZipFuture.result();
|
|
|
|
if (result.has_value())
|
|
|
|
emitFailed(result.value());
|
|
|
|
else
|
|
|
|
emitSucceeded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray FlamePackExportTask::generateIndex()
|
|
|
|
{
|
|
|
|
QJsonObject obj;
|
|
|
|
obj["manifestType"] = "minecraftModpack";
|
|
|
|
obj["manifestVersion"] = 1;
|
|
|
|
obj["name"] = name;
|
|
|
|
obj["version"] = version;
|
|
|
|
obj["author"] = author;
|
2023-06-23 17:35:41 +01:00
|
|
|
if (projectID.toInt() != 0)
|
|
|
|
obj["projectID"] = projectID.toInt();
|
2023-06-22 18:03:44 +01:00
|
|
|
obj["overrides"] = "overrides";
|
|
|
|
if (mcInstance) {
|
|
|
|
QJsonObject version;
|
|
|
|
auto profile = mcInstance->getPackProfile();
|
|
|
|
// collect all supported components
|
|
|
|
const ComponentPtr minecraft = profile->getComponent("net.minecraft");
|
|
|
|
const ComponentPtr quilt = profile->getComponent("org.quiltmc.quilt-loader");
|
|
|
|
const ComponentPtr fabric = profile->getComponent("net.fabricmc.fabric-loader");
|
|
|
|
const ComponentPtr forge = profile->getComponent("net.minecraftforge");
|
|
|
|
|
|
|
|
// convert all available components to mrpack dependencies
|
|
|
|
if (minecraft != nullptr)
|
|
|
|
version["version"] = minecraft->m_version;
|
|
|
|
|
|
|
|
QJsonObject loader;
|
|
|
|
if (quilt != nullptr)
|
2023-06-22 19:06:01 +01:00
|
|
|
loader["id"] = "quilt-" + quilt->getVersion();
|
2023-06-22 18:03:44 +01:00
|
|
|
else if (fabric != nullptr)
|
2023-06-22 19:06:01 +01:00
|
|
|
loader["id"] = "fabric-" + fabric->getVersion();
|
2023-06-22 18:03:44 +01:00
|
|
|
else if (forge != nullptr)
|
2023-06-22 19:06:01 +01:00
|
|
|
loader["id"] = "forge-" + forge->getVersion();
|
2023-06-22 18:03:44 +01:00
|
|
|
loader["primary"] = true;
|
|
|
|
version["modLoaders"] = QJsonArray({ loader });
|
|
|
|
obj["minecraft"] = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonArray files;
|
2023-06-23 17:35:41 +01:00
|
|
|
for (auto mod : resolvedFiles) {
|
2023-06-22 18:03:44 +01:00
|
|
|
QJsonObject file;
|
2023-06-23 17:35:41 +01:00
|
|
|
file["projectID"] = mod.addonId;
|
|
|
|
file["fileID"] = mod.version;
|
|
|
|
file["required"] = mod.enabled;
|
2023-06-22 18:03:44 +01:00
|
|
|
files << file;
|
|
|
|
}
|
|
|
|
obj["files"] = files;
|
|
|
|
|
|
|
|
return QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
|
|
|
}
|