diff --git a/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp b/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp index aeaa4b5b4..92e652c0c 100644 --- a/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp +++ b/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp @@ -69,7 +69,8 @@ void GetModDependenciesTask::prepareDependecies() return; } for (auto dep : c_dependencies) { - auto task = m_getDependenciesVersionAPI(dep, [this](ModPlatform::IndexedVersion new_version) { addDependecies(new_version, 20); }); + auto task = + m_getDependenciesVersionAPI(dep, [this](const ModPlatform::IndexedVersion& new_version) { addDependecies(new_version, 20); }); m_getNetworkDep->addTask(task); } m_getNetworkDep->start(); @@ -89,7 +90,7 @@ void GetModDependenciesTask::addDependecies(const ModPlatform::IndexedVersion& n } for (auto dep : c_dependencies) { auto task = m_getDependenciesVersionAPI( - dep, [this, level](ModPlatform::IndexedVersion new_versions) { addDependecies(new_versions, level - 1); }); + dep, [this, level](const ModPlatform::IndexedVersion& new_versions) { addDependecies(new_versions, level - 1); }); m_getNetworkDep->addTask(task); } }; @@ -101,13 +102,13 @@ QList GetModDependenciesTask::getDependenciesForVersion 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](const 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; }); + if (auto dep = std::find_if(selected.begin(), selected.end(), + [&ver_dep](const 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; }); + if (auto dep = std::find_if(m_mods.begin(), m_mods.end(), + [&ver_dep](const auto& i) { return i.project_id == ver_dep.addonId; }); dep == m_mods.end()) { // check the existing mods c_dependencies.append(ver_dep); } @@ -124,10 +125,11 @@ QList GetModDependenciesTask::getDependenciesForVersion auto c_dependencies = QList(); 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; }); + if (auto dep = std::find_if(c_dependencies.begin(), c_dependencies.end(), + [&ver_dep](const 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](const auto& i) { return i.project_id == ver_dep.addonId; }); dep == m_mods.end()) { // check the existing mods c_dependencies.append(ver_dep); } diff --git a/launcher/modplatform/ResourceAPI.h b/launcher/modplatform/ResourceAPI.h index a8e144dc8..c23444b3a 100644 --- a/launcher/modplatform/ResourceAPI.h +++ b/launcher/modplatform/ResourceAPI.h @@ -126,7 +126,7 @@ class ResourceAPI { }; struct DependencySearchCallbacks { - std::function on_succeed; + std::function on_succeed; }; public: diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp index 9f898c393..ee9576802 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp @@ -22,6 +22,7 @@ #include "Json.h" #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" +#include "modplatform/ModIndex.h" static ModrinthAPI api; static ModPlatform::ProviderCapabilities ProviderCaps; @@ -144,7 +145,7 @@ auto Modrinth::loadIndexedPackVersion(QJsonObject& obj, QString preferred_hash_t auto dep = Json::ensureObject(d); ModPlatform::Dependency dependency; dependency.addonId = Json::requireString(dep, "project_id"); - dependency.version = Json::requireString(dep, "version_id"); + dependency.version = Json::ensureString(dep, "version_id"); auto depType = Json::requireString(dep, "dependency_type"); if (depType == "required") @@ -231,5 +232,5 @@ auto Modrinth::loadDependencyVersions(ModPlatform::Dependency m, QJsonArray& arr return a.date > b.date; }; std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate); - return unsortedVersions.front(); + return unsortedVersions.length() != 0 ? unsortedVersions.front() : ModPlatform::IndexedVersion(); } \ No newline at end of file diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp index 75585d6f7..c1ffd0daf 100644 --- a/launcher/ui/pages/modplatform/ResourceModel.cpp +++ b/launcher/ui/pages/modplatform/ResourceModel.cpp @@ -459,11 +459,18 @@ QList ResourceModel::getDependecies(QDir& dir, QLis // Use default if no callbacks are set if (!callbacks.on_succeed) - callbacks.on_succeed = [this, dependency, succeeded](auto& doc, auto pack) { + callbacks.on_succeed = [this, dependency, succeeded](auto& doc, auto& pack) { ModPlatform::IndexedVersion ver; try { - auto arr = doc.isObject() ? Json::ensureArray(doc.object(), "data") : doc.array(); + auto arr = dependency.version.length() != 0 && doc.isObject() + ? Json::toJsonArray(QList() << doc.object()) + : doc.isObject() ? Json::ensureArray(doc.object(), "data") + : doc.array(); ver = loadDependencyVersions(dependency, arr); + if (!ver.addonId.isValid()) { + qWarning() << "Error while reading " << debugName() << " resource version empty "; + qDebug() << doc; + } } catch (const JSONValidationError& e) { qDebug() << doc; qWarning() << "Error while reading " << debugName() << " resource version: " << e.cause();