2023-06-22 18:03:44 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* Prism Launcher - Minecraft Launcher
|
2023-06-24 13:11:15 +01:00
|
|
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
2023-06-22 18:03:44 +01:00
|
|
|
* 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-07-17 14:25:51 +01:00
|
|
|
#include <iterator>
|
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-07-03 14:08:20 +01:00
|
|
|
const QString FlamePackExportTask::TEMPLATE = "<li><a href=\"{url}\">{name}{authors}</a></li>\n";
|
2023-06-25 12:43:11 +01:00
|
|
|
const QStringList FlamePackExportTask::FILE_EXTENSIONS({ "jar", "zip" });
|
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
|
|
|
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
|
|
|
, instance(instance)
|
|
|
|
, mcInstance(dynamic_cast<MinecraftInstance*>(instance.get()))
|
|
|
|
, gameRoot(instance->gameRoot())
|
|
|
|
, output(output)
|
|
|
|
, filter(filter)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void FlamePackExportTask::executeTask()
|
|
|
|
{
|
|
|
|
setStatus(tr("Searching for files..."));
|
2023-06-25 17:44:18 +01:00
|
|
|
setProgress(0, 5);
|
2023-06-22 18:03:44 +01:00
|
|
|
collectFiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FlamePackExportTask::abort()
|
|
|
|
{
|
2023-07-17 14:25:51 +01:00
|
|
|
if (task) {
|
2023-06-22 18:03:44 +01:00
|
|
|
task->abort();
|
|
|
|
emitAborted();
|
|
|
|
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) {
|
2023-06-23 17:35:41 +01:00
|
|
|
mcInstance->loaderModList()->update();
|
2023-06-24 21:48:18 +01:00
|
|
|
connect(mcInstance->loaderModList().get(), &ModFolderModel::updateFinished, this, &FlamePackExportTask::collectHashes);
|
2023-06-23 17:35:41 +01:00
|
|
|
} else
|
|
|
|
collectHashes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlamePackExportTask::collectHashes()
|
|
|
|
{
|
2023-06-23 20:41:01 +01:00
|
|
|
setAbortable(true);
|
2023-07-02 14:45:15 +01:00
|
|
|
setStatus(tr("Finding file hashes..."));
|
2023-06-25 17:44:18 +01:00
|
|
|
setProgress(1, 5);
|
2023-06-25 12:43:11 +01:00
|
|
|
auto allMods = mcInstance->loaderModList()->allMods();
|
2023-07-02 16:50:29 +01:00
|
|
|
ConcurrentTask::Ptr hashingTask(new ConcurrentTask(this, "MakeHashesTask", 10));
|
|
|
|
task.reset(hashingTask);
|
2023-06-25 12:43:11 +01:00
|
|
|
for (const QFileInfo& file : files) {
|
|
|
|
const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath());
|
|
|
|
// require sensible file types
|
|
|
|
if (!std::any_of(FILE_EXTENSIONS.begin(), FILE_EXTENSIONS.end(), [&relative](const QString& extension) {
|
|
|
|
return relative.endsWith('.' + extension) || relative.endsWith('.' + extension + ".disabled");
|
|
|
|
}))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (relative.startsWith("resourcepacks/") &&
|
|
|
|
(relative.endsWith(".zip") || relative.endsWith(".zip.disabled"))) { // is resourcepack
|
2023-07-02 16:50:29 +01:00
|
|
|
auto hashTask = Hashing::createFlameHasher(file.absoluteFilePath());
|
|
|
|
connect(hashTask.get(), &Hashing::Hasher::resultsReady, [this, relative, file](QString hash) {
|
2023-06-25 12:43:11 +01:00
|
|
|
if (m_state == Task::State::Running) {
|
|
|
|
pendingHashes.insert(hash, { relative, file.absoluteFilePath(), relative.endsWith(".zip") });
|
|
|
|
}
|
|
|
|
});
|
2023-07-02 16:50:29 +01:00
|
|
|
connect(hashTask.get(), &Task::failed, this, &FlamePackExportTask::emitFailed);
|
|
|
|
hashingTask->addTask(hashTask);
|
2023-06-23 17:35:41 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-06-25 12:43:11 +01:00
|
|
|
if (auto modIter = std::find_if(allMods.begin(), allMods.end(), [&file](Mod* mod) { return mod->fileinfo() == file; });
|
|
|
|
modIter != allMods.end()) {
|
|
|
|
const Mod* mod = *modIter;
|
|
|
|
if (!mod || mod->type() == ResourceType::FOLDER) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mod->metadata() && mod->metadata()->provider == ModPlatform::ResourceProvider::FLAME) {
|
|
|
|
resolvedFiles.insert(mod->fileinfo().absoluteFilePath(),
|
|
|
|
{ mod->metadata()->project_id.toInt(), mod->metadata()->file_id.toInt(), mod->enabled(), true,
|
|
|
|
mod->metadata()->name, mod->metadata()->slug, mod->authors().join(", ") });
|
|
|
|
continue;
|
2023-06-24 12:37:02 +01:00
|
|
|
}
|
2023-06-25 12:43:11 +01:00
|
|
|
|
2023-07-02 16:50:29 +01:00
|
|
|
auto hashTask = Hashing::createFlameHasher(mod->fileinfo().absoluteFilePath());
|
|
|
|
connect(hashTask.get(), &Hashing::Hasher::resultsReady, [this, mod](QString hash) {
|
2023-06-25 12:43:11 +01:00
|
|
|
if (m_state == Task::State::Running) {
|
|
|
|
pendingHashes.insert(hash, { mod->name(), mod->fileinfo().absoluteFilePath(), mod->enabled(), true });
|
|
|
|
}
|
|
|
|
});
|
2023-07-02 16:50:29 +01:00
|
|
|
connect(hashTask.get(), &Task::failed, this, &FlamePackExportTask::emitFailed);
|
|
|
|
hashingTask->addTask(hashTask);
|
2023-06-25 12:43:11 +01:00
|
|
|
}
|
2023-06-24 12:37:02 +01:00
|
|
|
}
|
2023-07-02 16:50:29 +01:00
|
|
|
auto progressStep = std::make_shared<TaskStepProgress>();
|
|
|
|
connect(hashingTask.get(), &Task::finished, this, [this, progressStep] {
|
|
|
|
progressStep->state = TaskStepState::Succeeded;
|
|
|
|
stepProgress(*progressStep);
|
2023-06-25 17:44:18 +01:00
|
|
|
});
|
2023-06-24 12:37:02 +01:00
|
|
|
|
2023-07-02 16:50:29 +01:00
|
|
|
connect(hashingTask.get(), &Task::succeeded, this, &FlamePackExportTask::makeApiRequest);
|
|
|
|
connect(hashingTask.get(), &Task::failed, this, [this, progressStep](QString reason) {
|
|
|
|
progressStep->state = TaskStepState::Failed;
|
|
|
|
stepProgress(*progressStep);
|
2023-06-25 17:44:18 +01:00
|
|
|
emitFailed(reason);
|
|
|
|
});
|
2023-07-02 16:50:29 +01:00
|
|
|
connect(hashingTask.get(), &Task::stepProgress, this, &FlamePackExportTask::propogateStepProgress);
|
2023-06-25 17:44:18 +01:00
|
|
|
|
2023-07-02 16:50:29 +01:00
|
|
|
connect(hashingTask.get(), &Task::progress, this, [this, progressStep](qint64 current, qint64 total) {
|
|
|
|
progressStep->update(current, total);
|
|
|
|
stepProgress(*progressStep);
|
2023-06-25 17:44:18 +01:00
|
|
|
});
|
2023-07-02 16:50:29 +01:00
|
|
|
connect(hashingTask.get(), &Task::status, this, [this, progressStep](QString status) {
|
|
|
|
progressStep->status = status;
|
|
|
|
stepProgress(*progressStep);
|
2023-06-25 17:44:18 +01:00
|
|
|
});
|
2023-07-02 16:50:29 +01:00
|
|
|
hashingTask->start();
|
2023-06-23 17:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FlamePackExportTask::makeApiRequest()
|
|
|
|
{
|
|
|
|
if (pendingHashes.isEmpty()) {
|
|
|
|
buildZip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-02 14:45:15 +01:00
|
|
|
setStatus(tr("Finding versions for hashes..."));
|
2023-06-25 17:44:18 +01:00
|
|
|
setProgress(2, 5);
|
2023-06-23 17:35:41 +01:00
|
|
|
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] {
|
2023-07-02 16:50:29 +01:00
|
|
|
QJsonParseError parseError{};
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parseError);
|
|
|
|
if (parseError.error != QJsonParseError::NoError) {
|
|
|
|
qWarning() << "Error while parsing JSON response from CurseForge::CurrentVersions at " << parseError.offset
|
|
|
|
<< " reason: " << parseError.errorString();
|
2023-06-23 17:35:41 +01:00
|
|
|
qWarning() << *response;
|
|
|
|
|
2023-07-02 16:50:29 +01:00
|
|
|
failed(parseError.errorString());
|
2023-06-23 17:35:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-07-02 16:50:29 +01:00
|
|
|
auto docObj = Json::requireObject(doc);
|
|
|
|
auto dataObj = Json::requireObject(docObj, "data");
|
|
|
|
auto dataArr = Json::requireArray(dataObj, "exactMatches");
|
2023-06-23 17:35:41 +01:00
|
|
|
|
2023-07-02 16:50:29 +01:00
|
|
|
if (dataArr.isEmpty()) {
|
2023-06-23 17:35:41 +01:00
|
|
|
qWarning() << "No matches found for fingerprint search!";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2023-07-02 16:50:29 +01:00
|
|
|
for (auto match : dataArr) {
|
|
|
|
auto matchObj = Json::ensureObject(match, {});
|
|
|
|
auto fileObj = Json::ensureObject(matchObj, "file", {});
|
2023-06-23 17:35:41 +01:00
|
|
|
|
2023-07-02 16:50:29 +01:00
|
|
|
if (matchObj.isEmpty() || fileObj.isEmpty()) {
|
2023-06-23 17:35:41 +01:00
|
|
|
qWarning() << "Fingerprint match is empty!";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-02 16:50:29 +01:00
|
|
|
auto fingerprint = QString::number(Json::ensureVariant(fileObj, "fileFingerprint").toUInt());
|
2023-06-23 17:35:41 +01:00
|
|
|
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-07-02 16:50:29 +01:00
|
|
|
if (Json::ensureBoolean(fileObj, "isAvailable", false, "isAvailable"))
|
|
|
|
resolvedFiles.insert(mod->path, { Json::requireInteger(fileObj, "modId"), Json::requireInteger(fileObj, "id"),
|
2023-06-24 13:02:00 +01:00
|
|
|
mod->enabled, mod->isMod });
|
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-07-02 14:45:15 +01:00
|
|
|
setStatus(tr("Finding project info from CurseForge..."));
|
2023-06-25 17:44:18 +01:00
|
|
|
setProgress(3, 5);
|
2023-07-02 14:45:15 +01:00
|
|
|
QStringList addonIds;
|
|
|
|
for (const auto& resolved : resolvedFiles) {
|
2023-06-23 23:05:49 +01:00
|
|
|
if (resolved.slug.isEmpty()) {
|
|
|
|
addonIds << QString::number(resolved.addonId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto response = std::make_shared<QByteArray>();
|
2023-07-02 16:50:29 +01:00
|
|
|
Task::Ptr projTask;
|
2023-06-23 23:05:49 +01:00
|
|
|
|
|
|
|
if (addonIds.isEmpty()) {
|
|
|
|
buildZip();
|
|
|
|
return;
|
|
|
|
} else if (addonIds.size() == 1) {
|
2023-07-02 16:50:29 +01:00
|
|
|
projTask = api.getProject(*addonIds.begin(), response);
|
2023-06-23 23:05:49 +01:00
|
|
|
} else {
|
2023-07-02 16:50:29 +01:00
|
|
|
projTask = api.getProjects(addonIds, response);
|
2023-06-23 23:05:49 +01:00
|
|
|
}
|
|
|
|
|
2023-07-02 16:50:29 +01:00
|
|
|
connect(projTask.get(), &Task::succeeded, this, [this, response, addonIds] {
|
|
|
|
QJsonParseError parseError{};
|
|
|
|
auto doc = QJsonDocument::fromJson(*response, &parseError);
|
|
|
|
if (parseError.error != QJsonParseError::NoError) {
|
|
|
|
qWarning() << "Error while parsing JSON response from CurseForge projects task at " << parseError.offset
|
|
|
|
<< " reason: " << parseError.errorString();
|
2023-06-23 23:05:49 +01:00
|
|
|
qWarning() << *response;
|
2023-07-02 16:50:29 +01:00
|
|
|
failed(parseError.errorString());
|
2023-06-23 23:05:49 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
QJsonArray entries;
|
|
|
|
if (addonIds.size() == 1)
|
|
|
|
entries = { Json::requireObject(Json::requireObject(doc), "data") };
|
|
|
|
else
|
|
|
|
entries = Json::requireArray(Json::requireObject(doc), "data");
|
|
|
|
|
|
|
|
for (auto entry : entries) {
|
2023-07-02 16:50:29 +01:00
|
|
|
auto entryObj = Json::requireObject(entry);
|
2023-06-23 23:05:49 +01:00
|
|
|
|
|
|
|
try {
|
2023-07-02 16:50:29 +01:00
|
|
|
setStatus(tr("Parsing API response from CurseForge for '%1'...").arg(Json::requireString(entryObj, "name")));
|
2023-06-23 23:05:49 +01:00
|
|
|
|
|
|
|
ModPlatform::IndexedPack pack;
|
2023-07-02 16:50:29 +01:00
|
|
|
FlameMod::loadIndexedPack(pack, entryObj);
|
2023-06-23 23:05:49 +01:00
|
|
|
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();
|
|
|
|
});
|
2023-07-02 16:50:29 +01:00
|
|
|
task.reset(projTask);
|
2023-06-23 23:05:49 +01:00
|
|
|
task->start();
|
|
|
|
}
|
|
|
|
|
2023-06-22 18:03:44 +01:00
|
|
|
void FlamePackExportTask::buildZip()
|
|
|
|
{
|
|
|
|
setStatus(tr("Adding files..."));
|
2023-06-25 17:44:18 +01:00
|
|
|
setProgress(4, 5);
|
2023-06-22 18:03:44 +01:00
|
|
|
|
2023-07-17 14:25:51 +01:00
|
|
|
auto zipTask = makeShared<MMCZip::ExportToZipTask>(output, gameRoot, files, "overrides/", true);
|
|
|
|
zipTask->addExtraFile("manifest.json", generateIndex());
|
|
|
|
zipTask->addExtraFile("modlist.html", generateHTML());
|
2023-06-22 18:03:44 +01:00
|
|
|
|
2023-07-17 14:25:51 +01:00
|
|
|
QStringList exclude;
|
|
|
|
std::transform(resolvedFiles.keyBegin(), resolvedFiles.keyEnd(), std::back_insert_iterator(exclude),
|
|
|
|
[this](QString file) { return gameRoot.relativeFilePath(file); });
|
|
|
|
zipTask->setExcludeFiles(exclude);
|
2023-06-22 18:03:44 +01:00
|
|
|
|
2023-07-17 14:25:51 +01:00
|
|
|
auto progressStep = std::make_shared<TaskStepProgress>();
|
|
|
|
connect(zipTask.get(), &Task::finished, this, [this, progressStep] {
|
2023-07-02 16:50:29 +01:00
|
|
|
progressStep->state = TaskStepState::Succeeded;
|
|
|
|
stepProgress(*progressStep);
|
2023-06-22 18:03:44 +01:00
|
|
|
});
|
|
|
|
|
2023-07-17 14:25:51 +01:00
|
|
|
connect(zipTask.get(), &Task::succeeded, this, &FlamePackExportTask::emitSucceeded);
|
|
|
|
connect(zipTask.get(), &Task::aborted, this, [this]() {
|
|
|
|
QFile::remove(output);
|
2023-06-22 18:03:44 +01:00
|
|
|
emitAborted();
|
2023-07-17 14:25:51 +01:00
|
|
|
});
|
|
|
|
connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) {
|
|
|
|
progressStep->state = TaskStepState::Failed;
|
|
|
|
stepProgress(*progressStep);
|
|
|
|
QFile::remove(output);
|
|
|
|
emitFailed(reason);
|
|
|
|
});
|
|
|
|
connect(zipTask.get(), &Task::stepProgress, this, &FlamePackExportTask::propogateStepProgress);
|
|
|
|
|
|
|
|
connect(zipTask.get(), &Task::progress, this, [this, progressStep](qint64 current, qint64 total) {
|
|
|
|
progressStep->update(current, total);
|
|
|
|
stepProgress(*progressStep);
|
|
|
|
});
|
|
|
|
connect(zipTask.get(), &Task::status, this, [this, progressStep](QString status) {
|
|
|
|
progressStep->status = status;
|
|
|
|
stepProgress(*progressStep);
|
|
|
|
});
|
|
|
|
task.reset(zipTask);
|
|
|
|
zipTask->start();
|
2023-06-22 18:03:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray FlamePackExportTask::generateIndex()
|
|
|
|
{
|
|
|
|
QJsonObject obj;
|
|
|
|
obj["manifestType"] = "minecraftModpack";
|
|
|
|
obj["manifestVersion"] = 1;
|
|
|
|
obj["name"] = name;
|
|
|
|
obj["version"] = version;
|
|
|
|
obj["author"] = author;
|
|
|
|
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;
|
2023-06-25 10:24:59 +01:00
|
|
|
QString id;
|
2023-06-22 18:03:44 +01:00
|
|
|
if (quilt != nullptr)
|
2023-06-25 10:24:59 +01:00
|
|
|
id = "quilt-" + quilt->getVersion();
|
2023-06-22 18:03:44 +01:00
|
|
|
else if (fabric != nullptr)
|
2023-06-25 10:24:59 +01:00
|
|
|
id = "fabric-" + fabric->getVersion();
|
2023-06-22 18:03:44 +01:00
|
|
|
else if (forge != nullptr)
|
2023-06-25 10:24:59 +01:00
|
|
|
id = "forge-" + forge->getVersion();
|
|
|
|
version["modLoaders"] = QJsonArray();
|
|
|
|
if (!id.isEmpty()) {
|
|
|
|
QJsonObject loader;
|
|
|
|
loader["id"] = id;
|
|
|
|
loader["primary"] = true;
|
|
|
|
version["modLoaders"] = QJsonArray({ loader });
|
|
|
|
}
|
2023-06-22 18:03:44 +01:00
|
|
|
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);
|
|
|
|
}
|
2023-07-17 14:25:51 +01:00
|
|
|
|
|
|
|
QByteArray FlamePackExportTask::generateHTML()
|
|
|
|
{
|
|
|
|
QString content = "";
|
|
|
|
for (auto mod : resolvedFiles) {
|
|
|
|
if (mod.isMod) {
|
|
|
|
content += QString(TEMPLATE)
|
|
|
|
.replace("{name}", mod.name.toHtmlEscaped())
|
|
|
|
.replace("{url}", ModPlatform::getMetaURL(ModPlatform::ResourceProvider::FLAME, mod.addonId).toHtmlEscaped())
|
|
|
|
.replace("{authors}", !mod.authors.isEmpty() ? QString(" (by %1)").arg(mod.authors).toHtmlEscaped() : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
content = "<ul>" + content + "</ul>";
|
|
|
|
return content.toUtf8();
|
|
|
|
}
|