chore(clang-tidy): modernize the code

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2026-05-10 20:51:56 +03:00
parent 2e45d135c5
commit effa8bedb1
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
42 changed files with 854 additions and 786 deletions

View file

@ -18,6 +18,7 @@
#include "FileResolvingTask.h"
#include <algorithm>
#include <utility>
#include "Json.h"
#include "modplatform/ModIndex.h"
@ -27,13 +28,11 @@
#include "modplatform/modrinth/ModrinthPackIndex.h"
#include "net/NetJob.h"
#include "settings/SettingsObject.h"
#include "tasks/Task.h"
#include "Application.h"
static const FlameAPI flameAPI;
static ModrinthAPI modrinthAPI;
Flame::FileResolvingTask::FileResolvingTask(Flame::Manifest& toProcess) : m_manifest(toProcess) {}
bool Flame::FileResolvingTask::abort()
@ -55,32 +54,32 @@ void Flame::FileResolvingTask::executeTask()
setProgress(0, 3);
QStringList fileIds;
for (auto file : m_manifest.files) {
for (const auto& file : m_manifest.files) {
fileIds.push_back(QString::number(file.fileId));
}
auto [task, response] = flameAPI.getFiles(fileIds);
auto [task, response] = FlameAPI::getFiles(fileIds);
m_task = task;
auto step_progress = std::make_shared<TaskStepProgress>();
connect(m_task.get(), &Task::succeeded, this, [this, response, step_progress]() {
step_progress->state = TaskStepState::Succeeded;
stepProgress(*step_progress);
auto stepProgress2 = std::make_shared<TaskStepProgress>();
connect(m_task.get(), &Task::succeeded, this, [this, response, stepProgress2]() {
stepProgress2->state = TaskStepState::Succeeded;
stepProgress(*stepProgress2);
netJobFinished(response);
});
connect(m_task.get(), &Task::failed, this, [this, step_progress](QString reason) {
step_progress->state = TaskStepState::Failed;
stepProgress(*step_progress);
emitFailed(reason);
connect(m_task.get(), &Task::failed, this, [this, stepProgress2](QString reason) {
stepProgress2->state = TaskStepState::Failed;
stepProgress(*stepProgress2);
emitFailed(std::move(reason));
});
connect(m_task.get(), &Task::stepProgress, this, &FileResolvingTask::propagateStepProgress);
connect(m_task.get(), &Task::progress, this, [this, step_progress](qint64 current, qint64 total) {
connect(m_task.get(), &Task::progress, this, [this, stepProgress2](qint64 current, qint64 total) {
qDebug() << "Resolve slug progress" << current << total;
step_progress->update(current, total);
stepProgress(*step_progress);
stepProgress2->update(current, total);
stepProgress(*stepProgress2);
});
connect(m_task.get(), &Task::status, this, [this, step_progress](QString status) {
step_progress->status = status;
stepProgress(*step_progress);
connect(m_task.get(), &Task::status, this, [this, stepProgress2](QString status) {
stepProgress2->status = std::move(status);
stepProgress(*stepProgress2);
});
m_task->start();
@ -115,7 +114,7 @@ void Flame::FileResolvingTask::netJobFinished(QByteArray* response)
Q_ASSERT(m_manifest.files.contains(fileid));
m_manifest.files[fileid].version = version;
auto url = QUrl(version.downloadUrl, QUrl::TolerantMode);
if (!url.isValid() && "sha1" == version.hash_type && !version.hash.isEmpty()) {
if (!url.isValid() && "sha1" == version.hashType && !version.hash.isEmpty()) {
hashes.push_back(version.hash);
}
} catch (Json::JsonException& e) {
@ -131,18 +130,18 @@ void Flame::FileResolvingTask::netJobFinished(QByteArray* response)
getFlameProjects();
return;
}
auto [modrinthTask, modrinthResponse] = modrinthAPI.currentVersions(hashes, "sha1");
auto [modrinthTask, modrinthResponse] = ModrinthAPI::currentVersions(hashes, "sha1");
m_task = modrinthTask;
(dynamic_cast<NetJob*>(m_task.get()))->setAskRetry(false);
auto step_progress = std::make_shared<TaskStepProgress>();
connect(m_task.get(), &Task::succeeded, this, [this, modrinthResponse, step_progress]() {
step_progress->state = TaskStepState::Succeeded;
stepProgress(*step_progress);
QJsonParseError parse_error{};
QJsonDocument doc = QJsonDocument::fromJson(*modrinthResponse, &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();
auto stepProgress2 = std::make_shared<TaskStepProgress>();
connect(m_task.get(), &Task::succeeded, this, [this, modrinthResponse, stepProgress2]() {
stepProgress2->state = TaskStepState::Succeeded;
stepProgress(*stepProgress2);
QJsonParseError parseError{};
QJsonDocument doc = QJsonDocument::fromJson(*modrinthResponse, &parseError);
if (parseError.error != QJsonParseError::NoError) {
qWarning() << "Error while parsing JSON response from Modrinth::CurrentVersions at" << parseError.offset
<< "reason:" << parseError.errorString();
qWarning() << *modrinthResponse;
getFlameProjects();
@ -153,7 +152,7 @@ void Flame::FileResolvingTask::netJobFinished(QByteArray* response)
auto entries = Json::requireObject(doc);
for (auto& out : m_manifest.files) {
auto url = QUrl(out.version.downloadUrl, QUrl::TolerantMode);
if (!url.isValid() && "sha1" == out.version.hash_type && !out.version.hash.isEmpty()) {
if (!url.isValid() && "sha1" == out.version.hashType && !out.version.hash.isEmpty()) {
try {
auto entry = Json::requireObject(entries, out.version.hash);
@ -174,20 +173,20 @@ void Flame::FileResolvingTask::netJobFinished(QByteArray* response)
}
getFlameProjects();
});
connect(m_task.get(), &Task::failed, this, [this, step_progress](QString reason) {
step_progress->state = TaskStepState::Failed;
stepProgress(*step_progress);
connect(m_task.get(), &Task::failed, this, [this, stepProgress2](const QString& /*reason*/) {
stepProgress2->state = TaskStepState::Failed;
stepProgress(*stepProgress2);
getFlameProjects();
});
connect(m_task.get(), &Task::stepProgress, this, &FileResolvingTask::propagateStepProgress);
connect(m_task.get(), &Task::progress, this, [this, step_progress](qint64 current, qint64 total) {
connect(m_task.get(), &Task::progress, this, [this, stepProgress2](qint64 current, qint64 total) {
qDebug() << "Resolve slug progress" << current << total;
step_progress->update(current, total);
stepProgress(*step_progress);
stepProgress2->update(current, total);
stepProgress(*stepProgress2);
});
connect(m_task.get(), &Task::status, this, [this, step_progress](QString status) {
step_progress->status = status;
stepProgress(*step_progress);
connect(m_task.get(), &Task::status, this, [this, stepProgress2](QString status) {
stepProgress2->status = std::move(status);
stepProgress(*stepProgress2);
});
m_task->start();
}
@ -196,20 +195,20 @@ void Flame::FileResolvingTask::getFlameProjects()
{
setProgress(2, 3);
QStringList addonIds;
for (auto file : m_manifest.files) {
for (const auto& file : m_manifest.files) {
addonIds.push_back(QString::number(file.projectId));
}
auto [task, response] = flameAPI.getProjects(addonIds);
auto [task, response] = FlameAPI().getProjects(addonIds);
m_task = task;
auto step_progress = std::make_shared<TaskStepProgress>();
connect(m_task.get(), &Task::succeeded, this, [this, response, step_progress] {
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();
auto stepProgress2 = std::make_shared<TaskStepProgress>();
connect(m_task.get(), &Task::succeeded, this, [this, response, stepProgress2] {
QJsonParseError parseError{};
auto doc = QJsonDocument::fromJson(*response, &parseError);
if (parseError.error != QJsonParseError::NoError) {
qWarning() << "Error while parsing JSON response from Modrinth projects task at" << parseError.offset
<< "reason:" << parseError.errorString();
qWarning() << *response;
return;
}
@ -219,8 +218,8 @@ void Flame::FileResolvingTask::getFlameProjects()
entries = Json::requireArray(Json::requireObject(doc), "data");
for (auto entry : entries) {
auto entry_obj = Json::requireObject(entry);
auto id = Json::requireInteger(entry_obj, "id");
auto entryObj = Json::requireObject(entry);
auto id = Json::requireInteger(entryObj, "id");
auto file = std::find_if(m_manifest.files.begin(), m_manifest.files.end(),
[id](const Flame::File& file) { return file.projectId == id; });
if (file == m_manifest.files.end()) {
@ -228,7 +227,7 @@ void Flame::FileResolvingTask::getFlameProjects()
}
setStatus(tr("Parsing API response from CurseForge for '%1'...").arg(file->version.fileName));
FlameMod::loadIndexedPack(file->pack, entry_obj);
FlameMod::loadIndexedPack(file->pack, entryObj);
if (file->pack.resourceType == ModPlatform::ResourceType::World) {
file->targetFolder = "saves";
}
@ -237,25 +236,25 @@ void Flame::FileResolvingTask::getFlameProjects()
qDebug() << e.cause();
qDebug() << doc;
}
step_progress->state = TaskStepState::Succeeded;
stepProgress(*step_progress);
stepProgress2->state = TaskStepState::Succeeded;
stepProgress(*stepProgress2);
emitSucceeded();
});
connect(m_task.get(), &Task::failed, this, [this, step_progress](QString reason) {
step_progress->state = TaskStepState::Failed;
stepProgress(*step_progress);
emitFailed(reason);
connect(m_task.get(), &Task::failed, this, [this, stepProgress2](QString reason) {
stepProgress2->state = TaskStepState::Failed;
stepProgress(*stepProgress2);
emitFailed(std::move(reason));
});
connect(m_task.get(), &Task::stepProgress, this, &FileResolvingTask::propagateStepProgress);
connect(m_task.get(), &Task::progress, this, [this, step_progress](qint64 current, qint64 total) {
connect(m_task.get(), &Task::progress, this, [this, stepProgress2](qint64 current, qint64 total) {
qDebug() << "Resolve slug progress" << current << total;
step_progress->update(current, total);
stepProgress(*step_progress);
stepProgress2->update(current, total);
stepProgress(*stepProgress2);
});
connect(m_task.get(), &Task::status, this, [this, step_progress](QString status) {
step_progress->status = status;
stepProgress(*step_progress);
connect(m_task.get(), &Task::status, this, [this, stepProgress2](QString status) {
stepProgress2->status = std::move(status);
stepProgress(*stepProgress2);
});
m_task->start();