mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
chore(clang-tidy): fix clang tidy warnings
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
f9e007ca2b
commit
97d570b343
4 changed files with 111 additions and 107 deletions
|
|
@ -15,15 +15,15 @@ class CheckUpdateTask : public Task {
|
|||
std::vector<Version>& mcVersions,
|
||||
QList<ModPlatform::ModLoaderType> loadersList,
|
||||
ResourceFolderModel* resourceModel)
|
||||
: Task(), m_resources(resources), m_gameVersions(mcVersions), m_loadersList(std::move(loadersList)), m_resourceModel(resourceModel)
|
||||
: m_resources(resources), m_gameVersions(mcVersions), m_loadersList(std::move(loadersList)), m_resourceModel(resourceModel)
|
||||
{}
|
||||
|
||||
struct Update {
|
||||
QString name;
|
||||
QString old_hash;
|
||||
QString old_version;
|
||||
QString new_version;
|
||||
std::optional<ModPlatform::IndexedVersionType> new_version_type;
|
||||
QString oldHash;
|
||||
QString oldVersion;
|
||||
QString newVersion;
|
||||
std::optional<ModPlatform::IndexedVersionType> newVersionType;
|
||||
QString changelog;
|
||||
ModPlatform::ResourceProvider provider;
|
||||
shared_qobject_ptr<ResourceDownloadTask> download;
|
||||
|
|
@ -31,19 +31,19 @@ class CheckUpdateTask : public Task {
|
|||
|
||||
public:
|
||||
Update(QString name,
|
||||
QString old_h,
|
||||
QString old_v,
|
||||
QString new_v,
|
||||
std::optional<ModPlatform::IndexedVersionType> new_v_type,
|
||||
QString oldH,
|
||||
QString oldV,
|
||||
QString newV,
|
||||
std::optional<ModPlatform::IndexedVersionType> newVType,
|
||||
QString changelog,
|
||||
ModPlatform::ResourceProvider p,
|
||||
shared_qobject_ptr<ResourceDownloadTask> t,
|
||||
bool enabled = true)
|
||||
: name(std::move(name))
|
||||
, old_hash(std::move(old_h))
|
||||
, old_version(std::move(old_v))
|
||||
, new_version(std::move(new_v))
|
||||
, new_version_type(std::move(new_v_type))
|
||||
, oldHash(std::move(oldH))
|
||||
, oldVersion(std::move(oldV))
|
||||
, newVersion(std::move(newV))
|
||||
, newVersionType(newVType)
|
||||
, changelog(std::move(changelog))
|
||||
, provider(p)
|
||||
, download(std::move(t))
|
||||
|
|
@ -54,14 +54,11 @@ class CheckUpdateTask : public Task {
|
|||
auto getUpdates() -> std::vector<Update>&& { return std::move(m_updates); }
|
||||
auto getDependencies() -> QList<std::shared_ptr<GetModDependenciesTask::PackDependency>>&& { return std::move(m_deps); }
|
||||
|
||||
public slots:
|
||||
bool abort() override = 0;
|
||||
|
||||
protected slots:
|
||||
void executeTask() override = 0;
|
||||
|
||||
signals:
|
||||
void checkFailed(Resource* failed, QString reason, QUrl recover_url = {});
|
||||
void checkFailed(Resource* failed, QString reason, QUrl recoverUrl = {});
|
||||
|
||||
protected:
|
||||
QList<Resource*>& m_resources;
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
#include "net/NetJob.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
static FlameAPI api;
|
||||
|
||||
bool FlameCheckUpdate::abort()
|
||||
{
|
||||
bool result = false;
|
||||
|
|
@ -39,7 +37,7 @@ void FlameCheckUpdate::executeTask()
|
|||
{
|
||||
setStatus(tr("Preparing resources for CurseForge..."));
|
||||
|
||||
auto netJob = new NetJob("Get latest versions", APPLICATION->network());
|
||||
auto* netJob = new NetJob("Get latest versions", APPLICATION->network());
|
||||
connect(netJob, &Task::finished, this, &FlameCheckUpdate::collectBlockedMods);
|
||||
|
||||
connect(netJob, &Task::progress, this, &FlameCheckUpdate::setProgress);
|
||||
|
|
@ -48,9 +46,10 @@ void FlameCheckUpdate::executeTask()
|
|||
for (auto* resource : m_resources) {
|
||||
auto project = std::make_shared<ModPlatform::IndexedPack>();
|
||||
project->addonId = resource->metadata()->project_id.toString();
|
||||
auto versionsUrlOptional = api.getVersionsURL({ project, m_gameVersions });
|
||||
if (!versionsUrlOptional.has_value())
|
||||
auto versionsUrlOptional = FlameAPI().getVersionsURL({ .pack = project, .mcVersions = m_gameVersions });
|
||||
if (!versionsUrlOptional.has_value()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto [task, response] = Net::ApiDownload::makeByteArray(versionsUrlOptional.value());
|
||||
|
||||
|
|
@ -63,11 +62,11 @@ void FlameCheckUpdate::executeTask()
|
|||
|
||||
void FlameCheckUpdate::getLatestVersionCallback(Resource* resource, QByteArray* response)
|
||||
{
|
||||
QJsonParseError parse_error{};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||
if (parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from latest mod version at" << parse_error.offset
|
||||
<< "reason:" << parse_error.errorString();
|
||||
QJsonParseError parseError{};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parseError);
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from latest mod version at" << parseError.offset
|
||||
<< "reason:" << parseError.errorString();
|
||||
qWarning() << *response;
|
||||
return;
|
||||
}
|
||||
|
|
@ -88,100 +87,104 @@ void FlameCheckUpdate::getLatestVersionCallback(Resource* resource, QByteArray*
|
|||
qCritical() << e.what();
|
||||
qDebug() << doc;
|
||||
}
|
||||
auto latest_ver = api.getLatestVersion(pack->versions, m_loadersList, resource->metadata()->loaders, !m_loadersList.isEmpty());
|
||||
auto latestVer = FlameAPI().getLatestVersion(pack->versions, m_loadersList, resource->metadata()->loaders, !m_loadersList.isEmpty());
|
||||
|
||||
setStatus(tr("Parsing the API response from CurseForge for '%1'...").arg(resource->name()));
|
||||
|
||||
if (!latest_ver.has_value() || !latest_ver->addonId.isValid()) {
|
||||
if (!latestVer.has_value() || !latestVer->addonId.isValid()) {
|
||||
QString reason;
|
||||
if (dynamic_cast<Mod*>(resource) != nullptr)
|
||||
if (dynamic_cast<Mod*>(resource) != nullptr) {
|
||||
reason =
|
||||
tr("No valid version found for this resource. It's probably unavailable for the current game "
|
||||
"version / mod loader.");
|
||||
else
|
||||
} else {
|
||||
reason = tr("No valid version found for this resource. It's probably unavailable for the current game version.");
|
||||
}
|
||||
|
||||
emit checkFailed(resource, reason);
|
||||
return;
|
||||
}
|
||||
|
||||
if (latest_ver->downloadUrl.isEmpty() && latest_ver->fileId != resource->metadata()->file_id) {
|
||||
m_blocked[resource] = latest_ver->fileId.toString();
|
||||
if (latestVer->downloadUrl.isEmpty() && latestVer->fileId != resource->metadata()->file_id) {
|
||||
m_blocked[resource] = latestVer->fileId.toString();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!latest_ver->hash.isEmpty() &&
|
||||
(resource->metadata()->hash != latest_ver->hash || resource->status() == ResourceStatus::NOT_INSTALLED)) {
|
||||
auto old_version = resource->metadata()->version_number;
|
||||
if (old_version.isEmpty()) {
|
||||
if (resource->status() == ResourceStatus::NOT_INSTALLED)
|
||||
old_version = tr("Not installed");
|
||||
else
|
||||
old_version = tr("Unknown");
|
||||
if (!latestVer->hash.isEmpty() &&
|
||||
(resource->metadata()->hash != latestVer->hash || resource->status() == ResourceStatus::NOT_INSTALLED)) {
|
||||
auto oldVersion = resource->metadata()->version_number;
|
||||
if (oldVersion.isEmpty()) {
|
||||
if (resource->status() == ResourceStatus::NOT_INSTALLED) {
|
||||
oldVersion = tr("Not installed");
|
||||
} else {
|
||||
oldVersion = tr("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
auto download_task = makeShared<ResourceDownloadTask>(pack, latest_ver.value(), m_resourceModel, true, "update");
|
||||
m_updates.emplace_back(pack->name, resource->metadata()->hash, old_version, latest_ver->version, latest_ver->version_type,
|
||||
api.getModFileChangelog(latest_ver->addonId.toInt(), latest_ver->fileId.toInt()),
|
||||
ModPlatform::ResourceProvider::FLAME, download_task, resource->enabled());
|
||||
auto downloadTask = makeShared<ResourceDownloadTask>(pack, latestVer.value(), m_resourceModel, true, "update");
|
||||
m_updates.emplace_back(pack->name, resource->metadata()->hash, oldVersion, latestVer->version, latestVer->version_type,
|
||||
FlameAPI().getModFileChangelog(latestVer->addonId.toInt(), latestVer->fileId.toInt()),
|
||||
ModPlatform::ResourceProvider::FLAME, downloadTask, resource->enabled());
|
||||
}
|
||||
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, latest_ver.value()));
|
||||
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, latestVer.value()));
|
||||
}
|
||||
|
||||
void FlameCheckUpdate::collectBlockedMods()
|
||||
{
|
||||
QStringList addonIds;
|
||||
QHash<QString, Resource*> quickSearch;
|
||||
for (auto const& resource : m_blocked.keys()) {
|
||||
for (const auto& resource : m_blocked.keys()) {
|
||||
auto addonId = resource->metadata()->project_id.toString();
|
||||
addonIds.append(addonId);
|
||||
quickSearch[addonId] = resource;
|
||||
}
|
||||
|
||||
Task::Ptr projTask;
|
||||
QByteArray* response;
|
||||
QByteArray* response = nullptr;
|
||||
|
||||
if (addonIds.isEmpty()) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
} else if (addonIds.size() == 1) {
|
||||
std::tie(projTask, response) = api.getProject(*addonIds.begin());
|
||||
}
|
||||
if (addonIds.size() == 1) {
|
||||
std::tie(projTask, response) = FlameAPI().getProject(*addonIds.begin());
|
||||
} else {
|
||||
std::tie(projTask, response) = api.getProjects(addonIds);
|
||||
std::tie(projTask, response) = FlameAPI().getProjects(addonIds);
|
||||
}
|
||||
|
||||
connect(projTask.get(), &Task::succeeded, this, [this, response, addonIds, quickSearch] {
|
||||
QJsonParseError parse_error{};
|
||||
auto doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||
if (parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from Flame projects task at" << parse_error.offset
|
||||
<< "reason:" << parse_error.errorString();
|
||||
QJsonParseError parseError{};
|
||||
auto doc = QJsonDocument::fromJson(*response, &parseError);
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from Flame projects task at" << parseError.offset
|
||||
<< "reason:" << parseError.errorString();
|
||||
qWarning() << *response;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
QJsonArray entries;
|
||||
if (addonIds.size() == 1)
|
||||
if (addonIds.size() == 1) {
|
||||
entries = { Json::requireObject(Json::requireObject(doc), "data") };
|
||||
else
|
||||
} else {
|
||||
entries = Json::requireArray(Json::requireObject(doc), "data");
|
||||
}
|
||||
|
||||
for (auto entry : entries) {
|
||||
auto entry_obj = Json::requireObject(entry);
|
||||
auto entryObj = Json::requireObject(entry);
|
||||
|
||||
auto id = QString::number(Json::requireInteger(entry_obj, "id"));
|
||||
auto id = QString::number(Json::requireInteger(entryObj, "id"));
|
||||
|
||||
auto resource = quickSearch.find(id).value();
|
||||
auto* resource = quickSearch.find(id).value();
|
||||
|
||||
ModPlatform::IndexedPack pack;
|
||||
try {
|
||||
setStatus(tr("Parsing API response from CurseForge for '%1'...").arg(resource->name()));
|
||||
|
||||
FlameMod::loadIndexedPack(pack, entry_obj);
|
||||
auto recover_url = QString("%1/download/%2").arg(pack.websiteUrl, m_blocked[resource]);
|
||||
FlameMod::loadIndexedPack(pack, entryObj);
|
||||
auto recoverUrl = QString("%1/download/%2").arg(pack.websiteUrl, m_blocked[resource]);
|
||||
emit checkFailed(resource, tr("Resource has a new update available, but is not downloadable using CurseForge."),
|
||||
recover_url);
|
||||
recoverUrl);
|
||||
} catch (Json::JsonException& e) {
|
||||
qDebug() << e.cause();
|
||||
qDebug() << entries;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ void ModrinthCheckUpdate::executeTask()
|
|||
setStatus(tr("Preparing resources for Modrinth..."));
|
||||
setProgress(0, ((m_loadersList.isEmpty() ? 1 : m_loadersList.length()) * 2) + 1);
|
||||
|
||||
auto hashing_task =
|
||||
auto hashingTask =
|
||||
makeShared<ConcurrentTask>("MakeModrinthHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
|
||||
bool startHasing = false;
|
||||
for (auto* resource : m_resources) {
|
||||
|
|
@ -63,10 +63,11 @@ void ModrinthCheckUpdate::executeTask()
|
|||
// need to generate a new hash if the current one is innadequate
|
||||
// (though it will rarely happen, if at all)
|
||||
if (resource->metadata()->hash_format != m_hashType) {
|
||||
auto hash_task = Hashing::createHasher(resource->fileinfo().absoluteFilePath(), ModPlatform::ResourceProvider::MODRINTH);
|
||||
connect(hash_task.get(), &Hashing::Hasher::resultsReady, [this, resource](QString hash) { m_mappings.insert(hash, resource); });
|
||||
connect(hash_task.get(), &Task::failed, [this] { failed("Failed to generate hash"); });
|
||||
hashing_task->addTask(hash_task);
|
||||
auto hashTask = Hashing::createHasher(resource->fileinfo().absoluteFilePath(), ModPlatform::ResourceProvider::MODRINTH);
|
||||
connect(hashTask.get(), &Hashing::Hasher::resultsReady,
|
||||
[this, resource](const QString& hash) { m_mappings.insert(hash, resource); });
|
||||
connect(hashTask.get(), &Task::failed, [this] { failed("Failed to generate hash"); });
|
||||
hashingTask->addTask(hashTask);
|
||||
startHasing = true;
|
||||
} else {
|
||||
m_mappings.insert(hash, resource);
|
||||
|
|
@ -74,9 +75,9 @@ void ModrinthCheckUpdate::executeTask()
|
|||
}
|
||||
|
||||
if (startHasing) {
|
||||
connect(hashing_task.get(), &Task::finished, this, &ModrinthCheckUpdate::checkNextLoader);
|
||||
m_job = hashing_task;
|
||||
hashing_task->start();
|
||||
connect(hashingTask.get(), &Task::finished, this, &ModrinthCheckUpdate::checkNextLoader);
|
||||
m_job = hashingTask;
|
||||
hashingTask->start();
|
||||
} else {
|
||||
checkNextLoader();
|
||||
}
|
||||
|
|
@ -120,14 +121,14 @@ void ModrinthCheckUpdate::checkVersionsResponse(QByteArray* response, std::optio
|
|||
setStatus(tr("Parsing the API response from Modrinth..."));
|
||||
setProgress(m_progress + 1, m_progressTotal);
|
||||
|
||||
QJsonParseError parse_error{};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||
if (parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from ModrinthCheckUpdate at" << parse_error.offset
|
||||
<< "reason:" << parse_error.errorString();
|
||||
QJsonParseError parseError{};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parseError);
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from ModrinthCheckUpdate at" << parseError.offset
|
||||
<< "reason:" << parseError.errorString();
|
||||
qWarning() << *response;
|
||||
|
||||
emitFailed(parse_error.errorString());
|
||||
emitFailed(parseError.errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -138,11 +139,11 @@ void ModrinthCheckUpdate::checkVersionsResponse(QByteArray* response, std::optio
|
|||
const QString hash = iter.key();
|
||||
Resource* resource = iter.value();
|
||||
|
||||
auto project_obj = doc[hash].toObject();
|
||||
auto projectObj = doc[hash].toObject();
|
||||
|
||||
// If the returned project is empty, but we have Modrinth metadata,
|
||||
// it means this specific version is not available
|
||||
if (project_obj.isEmpty()) {
|
||||
if (projectObj.isEmpty()) {
|
||||
qDebug() << "Mod" << m_mappings.find(hash).value()->name() << "got an empty response. Hash:" << hash;
|
||||
++iter;
|
||||
continue;
|
||||
|
|
@ -150,11 +151,11 @@ void ModrinthCheckUpdate::checkVersionsResponse(QByteArray* response, std::optio
|
|||
|
||||
// Sometimes a version may have multiple files, one with "forge" and one with "fabric",
|
||||
// so we may want to filter it
|
||||
QString loader_filter;
|
||||
QString loaderFilter;
|
||||
if (loader.has_value() && loader != 0) {
|
||||
auto modLoaders = ModPlatform::modLoaderTypesToList(*loader);
|
||||
if (!modLoaders.isEmpty()) {
|
||||
loader_filter = ModPlatform::getModLoaderAsString(modLoaders.first());
|
||||
loaderFilter = ModPlatform::getModLoaderAsString(modLoaders.first());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,9 +165,9 @@ void ModrinthCheckUpdate::checkVersionsResponse(QByteArray* response, std::optio
|
|||
// - The version reported by the JAR is different from the version reported by the indexed version (it's usually the case)
|
||||
// Such is the pain of having arbitrary files for a given version .-.
|
||||
|
||||
auto project_ver = Modrinth::loadIndexedPackVersion(project_obj, m_hashType, loader_filter);
|
||||
if (project_ver.downloadUrl.isEmpty()) {
|
||||
qCritical() << "Modrinth mod without download url!" << project_ver.fileName;
|
||||
auto projectVer = Modrinth::loadIndexedPackVersion(projectObj, m_hashType, loaderFilter);
|
||||
if (projectVer.downloadUrl.isEmpty()) {
|
||||
qCritical() << "Modrinth mod without download url!" << projectVer.fileName;
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -177,21 +178,22 @@ void ModrinthCheckUpdate::checkVersionsResponse(QByteArray* response, std::optio
|
|||
pack->slug = resource->metadata()->slug;
|
||||
pack->addonId = resource->metadata()->project_id;
|
||||
pack->provider = ModPlatform::ResourceProvider::MODRINTH;
|
||||
if ((project_ver.hash != hash && project_ver.is_preferred) || (resource->status() == ResourceStatus::NOT_INSTALLED)) {
|
||||
auto download_task = makeShared<ResourceDownloadTask>(pack, project_ver, m_resourceModel, true, "update");
|
||||
if ((projectVer.hash != hash && projectVer.is_preferred) || (resource->status() == ResourceStatus::NOT_INSTALLED)) {
|
||||
auto downloadTask = makeShared<ResourceDownloadTask>(pack, projectVer, m_resourceModel, true, "update");
|
||||
|
||||
QString old_version = resource->metadata()->version_number;
|
||||
if (old_version.isEmpty()) {
|
||||
if (resource->status() == ResourceStatus::NOT_INSTALLED)
|
||||
old_version = tr("Not installed");
|
||||
else
|
||||
old_version = tr("Unknown");
|
||||
QString oldVersion = resource->metadata()->version_number;
|
||||
if (oldVersion.isEmpty()) {
|
||||
if (resource->status() == ResourceStatus::NOT_INSTALLED) {
|
||||
oldVersion = tr("Not installed");
|
||||
} else {
|
||||
oldVersion = tr("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
m_updates.emplace_back(pack->name, hash, old_version, project_ver.version_number, project_ver.version_type,
|
||||
project_ver.changelog, ModPlatform::ResourceProvider::MODRINTH, download_task, resource->enabled());
|
||||
m_updates.emplace_back(pack->name, hash, oldVersion, projectVer.version_number, projectVer.version_type,
|
||||
projectVer.changelog, ModPlatform::ResourceProvider::MODRINTH, downloadTask, resource->enabled());
|
||||
}
|
||||
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, project_ver));
|
||||
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, projectVer));
|
||||
|
||||
iter = m_mappings.erase(iter);
|
||||
}
|
||||
|
|
@ -211,20 +213,22 @@ void ModrinthCheckUpdate::checkNextLoader()
|
|||
if (m_loaderIdx < m_loadersList.size()) { // this are mods so check with loades
|
||||
getUpdateModsForLoader(m_loadersList.at(m_loaderIdx), m_loaderIdx > m_initialSize);
|
||||
return;
|
||||
} else if (m_loadersList.isEmpty() && m_loaderIdx == 0) { // this are other resources no need to check more than once with empty loader
|
||||
}
|
||||
if (m_loadersList.isEmpty() && m_loaderIdx == 0) { // this are other resources no need to check more than once with empty loader
|
||||
getUpdateModsForLoader();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto resource : m_mappings) {
|
||||
for (auto* resource : m_mappings) {
|
||||
QString reason;
|
||||
|
||||
if (dynamic_cast<Mod*>(resource) != nullptr)
|
||||
if (dynamic_cast<Mod*>(resource) != nullptr) {
|
||||
reason =
|
||||
tr("No valid version found for this resource. It's probably unavailable for the current game "
|
||||
"version / mod loader.");
|
||||
else
|
||||
} else {
|
||||
reason = tr("No valid version found for this resource. It's probably unavailable for the current game version.");
|
||||
}
|
||||
|
||||
emit checkFailed(resource, reason);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue