Tried to fix codeQL

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-04-15 00:10:45 +03:00
parent 5079ce8d64
commit bcea19b957
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
6 changed files with 19 additions and 16 deletions

View File

@ -75,7 +75,7 @@ void GetModDependenciesTask::prepareDependecies()
m_getNetworkDep->start();
}
void GetModDependenciesTask::addDependecies(ModPlatform::IndexedVersion new_version, int level)
void GetModDependenciesTask::addDependecies(const ModPlatform::IndexedVersion& new_version, int level)
{
// some mutex?
m_dependencies.append(new_version);
@ -85,6 +85,7 @@ void GetModDependenciesTask::addDependecies(ModPlatform::IndexedVersion new_vers
}
if (level == 0) {
qWarning() << "Dependency cycle exeeded";
return;
}
for (auto dep : c_dependencies) {
auto task = m_getDependenciesVersionAPI(
@ -93,20 +94,20 @@ void GetModDependenciesTask::addDependecies(ModPlatform::IndexedVersion new_vers
}
};
QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersions(QList<ModPlatform::IndexedVersion> selected)
QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersions(const QList<ModPlatform::IndexedVersion>& selected)
{
auto c_dependencies = QList<ModPlatform::Dependency>();
for (auto version : selected) {
for (auto ver_dep : version.dependencies) {
if (ver_dep.type == ModPlatform::DependencyType::REQUIRED) {
if (auto dep = std::find_if(c_dependencies.begin(), c_dependencies.end(),
[ver_dep](auto i) { return i.addonId == ver_dep.addonId; });
[&ver_dep](auto i) { return i.addonId == ver_dep.addonId; });
dep == c_dependencies.end()) { // check the current dependency list
if (auto dep =
std::find_if(selected.begin(), selected.end(), [ver_dep](auto i) { return i.addonId == ver_dep.addonId; });
std::find_if(selected.begin(), selected.end(), [&ver_dep](auto i) { return i.addonId == ver_dep.addonId; });
dep == selected.end()) { // check the selected versions
if (auto dep =
std::find_if(m_mods.begin(), m_mods.end(), [ver_dep](auto i) { return i.mod_id() == ver_dep.addonId; });
std::find_if(m_mods.begin(), m_mods.end(), [&ver_dep](auto i) { return i.mod_id() == ver_dep.addonId; });
dep == m_mods.end()) { // check the existing mods
c_dependencies.append(ver_dep);
}
@ -118,15 +119,15 @@ QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersion
return c_dependencies;
};
QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersion(ModPlatform::IndexedVersion version)
QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersion(const ModPlatform::IndexedVersion& version)
{
auto c_dependencies = QList<ModPlatform::Dependency>();
for (auto ver_dep : version.dependencies) {
if (ver_dep.type == ModPlatform::DependencyType::REQUIRED) {
if (auto dep =
std::find_if(c_dependencies.begin(), c_dependencies.end(), [ver_dep](auto i) { return i.addonId == ver_dep.addonId; });
std::find_if(c_dependencies.begin(), c_dependencies.end(), [&ver_dep](auto i) { return i.addonId == ver_dep.addonId; });
dep == c_dependencies.end()) { // check the current dependency list
if (auto dep = std::find_if(m_mods.begin(), m_mods.end(), [ver_dep](auto i) { return i.mod_id() == ver_dep.addonId; });
if (auto dep = std::find_if(m_mods.begin(), m_mods.end(), [&ver_dep](auto i) { return i.mod_id() == ver_dep.addonId; });
dep == m_mods.end()) { // check the existing mods
c_dependencies.append(ver_dep);
}

View File

@ -34,7 +34,8 @@ class GetModDependenciesTask : public Task {
using Ptr = shared_qobject_ptr<GetModDependenciesTask>;
using LocalModGetAllTaskPtr = shared_qobject_ptr<LocalModGetAllTask>;
using NewDependecyVersionAPITask = std::function<Task::Ptr(ModPlatform::Dependency, std::function<void(ModPlatform::IndexedVersion)>)>;
using NewDependecyVersionAPITask =
std::function<Task::Ptr(const ModPlatform::Dependency&, std::function<void(const ModPlatform::IndexedVersion&)>)>;
explicit GetModDependenciesTask(QDir index_dir, QList<ModPlatform::IndexedVersion> selected, NewDependecyVersionAPITask api);
@ -48,9 +49,9 @@ class GetModDependenciesTask : public Task {
void executeTask() override;
void prepareDependecies();
void addDependecies(ModPlatform::IndexedVersion, int);
QList<ModPlatform::Dependency> getDependenciesForVersions(QList<ModPlatform::IndexedVersion>);
QList<ModPlatform::Dependency> getDependenciesForVersion(ModPlatform::IndexedVersion);
void addDependecies(const ModPlatform::IndexedVersion&, int);
QList<ModPlatform::Dependency> getDependenciesForVersions(const QList<ModPlatform::IndexedVersion>&);
QList<ModPlatform::Dependency> getDependenciesForVersion(const ModPlatform::IndexedVersion&);
private:
QList<ModPlatform::IndexedVersion> m_selected;

View File

@ -49,7 +49,7 @@ ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& en
return { pack, versions, profile->getModLoaders() };
}
ResourceAPI::DependencySearchArgs ModModel::createDependecyArguments(ModPlatform::Dependency& dep)
ResourceAPI::DependencySearchArgs ModModel::createDependecyArguments(const ModPlatform::Dependency& dep)
{
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();

View File

@ -40,7 +40,7 @@ class ModModel : public ResourceModel {
ResourceAPI::SearchArgs createSearchArguments() override;
ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) override;
ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) override;
ResourceAPI::DependencySearchArgs createDependecyArguments(ModPlatform::Dependency&) override;
ResourceAPI::DependencySearchArgs createDependecyArguments(const ModPlatform::Dependency&) override;
protected:
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override = 0;

View File

@ -452,7 +452,8 @@ void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::Indexe
QList<ModPlatform::IndexedVersion> ResourceModel::getDependecies(QDir& dir, QList<ModPlatform::IndexedVersion> selected)
{
auto task = new GetModDependenciesTask(
dir, selected, [this](ModPlatform::Dependency dependency, std::function<void(ModPlatform::IndexedVersion)> succeeded) -> Task::Ptr {
dir, selected,
[this](const ModPlatform::Dependency& dependency, std::function<void(const ModPlatform::IndexedVersion&)> succeeded) -> Task::Ptr {
auto args{ createDependecyArguments(dependency) };
auto callbacks{ createDependecyCallbacks() };

View File

@ -70,7 +70,7 @@ class ResourceModel : public QAbstractListModel {
virtual ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) = 0;
virtual ResourceAPI::ProjectInfoCallbacks createInfoCallbacks(QModelIndex&) { return {}; }
virtual ResourceAPI::DependencySearchArgs createDependecyArguments(ModPlatform::Dependency&) { return {}; };
virtual ResourceAPI::DependencySearchArgs createDependecyArguments(const ModPlatform::Dependency&) { return {}; };
virtual ResourceAPI::DependencySearchCallbacks createDependecyCallbacks() { return {}; }
/** Requests the API for more entries. */