mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-07-01 10:56:57 +03:00
clang-tidy
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
624121f51c
commit
148b97ef94
8 changed files with 146 additions and 89 deletions
|
|
@ -23,11 +23,12 @@
|
|||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QtConcurrentRun>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include "Json.h"
|
||||
#include "MMCZip.h"
|
||||
#include "archive/ExportToZipTask.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "minecraft/mod/MetadataHandler.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "modplatform/helpers/HashUtils.h"
|
||||
|
|
@ -51,7 +52,7 @@ ModrinthPackExportTask::ModrinthPackExportTask(const QString& name,
|
|||
, mcInstance(dynamic_cast<MinecraftInstance*>(instance))
|
||||
, gameRoot(instance->gameRoot())
|
||||
, output(output)
|
||||
, filter(filter)
|
||||
, filter(std::move(filter))
|
||||
{}
|
||||
|
||||
void ModrinthPackExportTask::executeTask()
|
||||
|
|
@ -87,8 +88,9 @@ void ModrinthPackExportTask::collectFiles()
|
|||
if (mcInstance) {
|
||||
mcInstance->loaderModList()->update();
|
||||
connect(mcInstance->loaderModList(), &ModFolderModel::updateFinished, this, &ModrinthPackExportTask::collectHashes);
|
||||
} else
|
||||
} else {
|
||||
collectHashes();
|
||||
}
|
||||
}
|
||||
|
||||
void ModrinthPackExportTask::collectHashes()
|
||||
|
|
@ -99,12 +101,14 @@ void ModrinthPackExportTask::collectHashes()
|
|||
|
||||
const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath());
|
||||
// require sensible file types
|
||||
if (!std::any_of(PREFIXES.begin(), PREFIXES.end(), [&relative](const QString& prefix) { return relative.startsWith(prefix); }))
|
||||
if (!std::ranges::any_of(PREFIXES, [&relative](const QString& prefix) { return relative.startsWith(prefix); })) {
|
||||
continue;
|
||||
if (!std::any_of(FILE_EXTENSIONS.begin(), FILE_EXTENSIONS.end(), [&relative](const QString& extension) {
|
||||
}
|
||||
if (!std::ranges::any_of(FILE_EXTENSIONS, [&relative](const QString& extension) {
|
||||
return relative.endsWith('.' + extension) || relative.endsWith('.' + extension + ".disabled");
|
||||
}))
|
||||
})) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QFile openFile(file.absoluteFilePath());
|
||||
if (!openFile.open(QFile::ReadOnly)) {
|
||||
|
|
@ -151,9 +155,9 @@ void ModrinthPackExportTask::collectHashes()
|
|||
|
||||
void ModrinthPackExportTask::makeApiRequest()
|
||||
{
|
||||
if (pendingHashes.isEmpty())
|
||||
if (pendingHashes.isEmpty()) {
|
||||
buildZip();
|
||||
else {
|
||||
} else {
|
||||
setStatus(tr("Finding versions for hashes..."));
|
||||
auto [versionsTask, response] = api.currentVersions(pendingHashes.values(), "sha512");
|
||||
task = versionsTask;
|
||||
|
|
@ -176,17 +180,19 @@ void ModrinthPackExportTask::parseApiResponse(QByteArray* response)
|
|||
iterator.next();
|
||||
|
||||
const QJsonObject obj = doc[iterator.value()].toObject();
|
||||
if (obj.isEmpty())
|
||||
if (obj.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QJsonArray files_array = obj["files"].toArray();
|
||||
if (auto fileIter = std::find_if(files_array.begin(), files_array.end(),
|
||||
[&iterator](const QJsonValue& file) { return file["hashes"]["sha512"] == iterator.value(); });
|
||||
fileIter != files_array.end()) {
|
||||
// map the file to the url
|
||||
resolvedFiles[iterator.key()] =
|
||||
ResolvedFile{ fileIter->toObject()["hashes"].toObject()["sha1"].toString(), iterator.value(),
|
||||
fileIter->toObject()["url"].toString(), fileIter->toObject()["size"].toInt() };
|
||||
resolvedFiles[iterator.key()] = ResolvedFile{ .sha1 = fileIter->toObject()["hashes"].toObject()["sha1"].toString(),
|
||||
.sha512 = iterator.value(),
|
||||
.url = fileIter->toObject()["url"].toString(),
|
||||
.size = fileIter->toObject()["size"].toInt() };
|
||||
}
|
||||
}
|
||||
} catch (const Json::JsonException& e) {
|
||||
|
|
@ -217,7 +223,7 @@ void ModrinthPackExportTask::buildZip()
|
|||
connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) {
|
||||
progressStep->state = TaskStepState::Failed;
|
||||
stepProgress(*progressStep);
|
||||
emitFailed(reason);
|
||||
emitFailed(std::move(reason));
|
||||
});
|
||||
connect(zipTask.get(), &Task::stepProgress, this, &ModrinthPackExportTask::propagateStepProgress);
|
||||
|
||||
|
|
@ -226,7 +232,7 @@ void ModrinthPackExportTask::buildZip()
|
|||
stepProgress(*progressStep);
|
||||
});
|
||||
connect(zipTask.get(), &Task::status, this, [this, progressStep](QString status) {
|
||||
progressStep->status = status;
|
||||
progressStep->status = std::move(status);
|
||||
stepProgress(*progressStep);
|
||||
});
|
||||
task.reset(zipTask);
|
||||
|
|
@ -240,11 +246,12 @@ QByteArray ModrinthPackExportTask::generateIndex()
|
|||
out["game"] = "minecraft";
|
||||
out["name"] = name;
|
||||
out["versionId"] = version;
|
||||
if (!summary.isEmpty())
|
||||
if (!summary.isEmpty()) {
|
||||
out["summary"] = summary;
|
||||
}
|
||||
|
||||
if (mcInstance) {
|
||||
auto profile = mcInstance->getPackProfile();
|
||||
auto* profile = mcInstance->getPackProfile();
|
||||
// collect all supported components
|
||||
const ComponentPtr minecraft = profile->getComponent("net.minecraft");
|
||||
const ComponentPtr quilt = profile->getComponent("org.quiltmc.quilt-loader");
|
||||
|
|
@ -254,16 +261,21 @@ QByteArray ModrinthPackExportTask::generateIndex()
|
|||
|
||||
// convert all available components to mrpack dependencies
|
||||
QJsonObject dependencies;
|
||||
if (minecraft != nullptr)
|
||||
if (minecraft != nullptr) {
|
||||
dependencies["minecraft"] = minecraft->m_version;
|
||||
if (quilt != nullptr)
|
||||
}
|
||||
if (quilt != nullptr) {
|
||||
dependencies["quilt-loader"] = quilt->m_version;
|
||||
if (fabric != nullptr)
|
||||
}
|
||||
if (fabric != nullptr) {
|
||||
dependencies["fabric-loader"] = fabric->m_version;
|
||||
if (forge != nullptr)
|
||||
}
|
||||
if (forge != nullptr) {
|
||||
dependencies["forge"] = forge->m_version;
|
||||
if (neoForge != nullptr)
|
||||
}
|
||||
if (neoForge != nullptr) {
|
||||
dependencies["neoforge"] = neoForge->m_version;
|
||||
}
|
||||
|
||||
out["dependencies"] = dependencies;
|
||||
}
|
||||
|
|
@ -291,8 +303,9 @@ QByteArray ModrinthPackExportTask::generateIndex()
|
|||
|
||||
// a server side mod does not imply that the mod does not work on the client
|
||||
// however, if a mrpack mod is marked as server-only it will not install on the client
|
||||
if (iterator->side == ModPlatform::SideType::ClientSide)
|
||||
if (iterator->side == ModPlatform::SideType::ClientSide) {
|
||||
env["server"] = "unsupported";
|
||||
}
|
||||
|
||||
fileOut["env"] = env;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue