diff --git a/launcher/modplatform/CheckUpdateTask.h b/launcher/modplatform/CheckUpdateTask.h index 1ffcc97ce..540998287 100644 --- a/launcher/modplatform/CheckUpdateTask.h +++ b/launcher/modplatform/CheckUpdateTask.h @@ -21,7 +21,8 @@ class CheckUpdateTask : public Task { , m_resources(resources) , m_game_versions(mcVersions) , m_loaders_list(std::move(loadersList)) - , m_resource_model(resourceModel){}; + , m_resource_model(std::move(resourceModel)) + {} struct Update { QString name; diff --git a/launcher/modplatform/flame/FlameCheckUpdate.h b/launcher/modplatform/flame/FlameCheckUpdate.h index 0094bb13a..2b5c6ac17 100644 --- a/launcher/modplatform/flame/FlameCheckUpdate.h +++ b/launcher/modplatform/flame/FlameCheckUpdate.h @@ -12,7 +12,7 @@ class FlameCheckUpdate : public CheckUpdateTask { std::list& mcVersions, QList loadersList, std::shared_ptr resourceModel) - : CheckUpdateTask(resources, mcVersions, loadersList, resourceModel) + : CheckUpdateTask(resources, mcVersions, std::move(loadersList), std::move(resourceModel)) {} public slots: diff --git a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp index c004bd8f2..f77c5598a 100644 --- a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp +++ b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp @@ -29,7 +29,7 @@ bool ModrinthCheckUpdate::abort() void ModrinthCheckUpdate::executeTask() { setStatus(tr("Preparing resources for Modrinth...")); - setProgress(0, 9); + setProgress(0, (m_loaders_list.isEmpty() ? 1 : m_loaders_list.length()) * 2 + 1); auto hashing_task = makeShared(this, "MakeModrinthHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt()); @@ -54,10 +54,30 @@ void ModrinthCheckUpdate::executeTask() hashing_task->start(); } -void ModrinthCheckUpdate::checkVersionsResponse(std::shared_ptr response, - ModPlatform::ModLoaderTypes loader, - bool forceModLoaderCheck) +void ModrinthCheckUpdate::getUpdateModsForLoader(std::optional loader) { + setStatus(tr("Waiting for the API response from Modrinth...")); + setProgress(m_progress + 1, m_progressTotal); + + auto response = std::make_shared(); + QStringList hashes = m_mappings.keys(); + auto job = api.latestVersions(hashes, m_hash_type, m_game_versions, loader, response); + + connect(job.get(), &Task::succeeded, this, + [this, response, loader] { checkVersionsResponse(response, loader); }); + + connect(job.get(), &Task::failed, this, &ModrinthCheckUpdate::checkNextLoader); + + m_job = job; + job->start(); +} + +void ModrinthCheckUpdate::checkVersionsResponse(std::shared_ptr response, + std::optional loader) +{ + 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) { @@ -69,17 +89,11 @@ void ModrinthCheckUpdate::checkVersionsResponse(std::shared_ptr resp return; } - setStatus(tr("Parsing the API response from Modrinth...")); - setProgress(m_next_loader_idx * 2, 9); - try { for (auto iter = m_mappings.begin(); iter != m_mappings.end(); iter++) { const QString& hash = iter.key(); Resource* resource = iter.value(); - if (forceModLoaderCheck && !(resource->metadata()->loaders & loader)) - continue; - auto project_obj = doc[hash].toObject(); // If the returned project is empty, but we have Modrinth metadata, @@ -97,7 +111,7 @@ void ModrinthCheckUpdate::checkVersionsResponse(std::shared_ptr resp static auto flags = { ModPlatform::ModLoaderType::NeoForge, ModPlatform::ModLoaderType::Forge, ModPlatform::ModLoaderType::Quilt, ModPlatform::ModLoaderType::Fabric }; for (auto flag : flags) { - if (loader.testFlag(flag)) { + if (loader.has_value() && loader->testFlag(flag)) { loader_filter = ModPlatform::getModLoaderAsString(flag); break; } @@ -153,63 +167,38 @@ void ModrinthCheckUpdate::checkVersionsResponse(std::shared_ptr resp checkNextLoader(); } -void ModrinthCheckUpdate::getUpdateModsForLoader(ModPlatform::ModLoaderTypes loader, bool forceModLoaderCheck) -{ - auto response = std::make_shared(); - QStringList hashes; - if (forceModLoaderCheck) { - for (auto hash : m_mappings.keys()) { - if (m_mappings[hash]->metadata()->loaders & loader) { - hashes.append(hash); - } - } - } else { - hashes = m_mappings.keys(); - } - auto job = api.latestVersions(hashes, m_hash_type, m_game_versions, loader, response); - - connect(job.get(), &Task::succeeded, this, - [this, response, loader, forceModLoaderCheck] { checkVersionsResponse(response, loader, forceModLoaderCheck); }); - - connect(job.get(), &Task::failed, this, &ModrinthCheckUpdate::checkNextLoader); - - setStatus(tr("Waiting for the API response from Modrinth...")); - setProgress(m_next_loader_idx * 2 - 1, 9); - - m_job = job; - job->start(); -} - void ModrinthCheckUpdate::checkNextLoader() { if (m_mappings.isEmpty()) { emitSucceeded(); return; } - if (m_next_loader_idx < m_loaders_list.size()) { - getUpdateModsForLoader(m_loaders_list.at(m_next_loader_idx)); - m_next_loader_idx++; - return; - } - static auto flags = { ModPlatform::ModLoaderType::NeoForge, ModPlatform::ModLoaderType::Forge, ModPlatform::ModLoaderType::Quilt, - ModPlatform::ModLoaderType::Fabric }; - for (auto flag : flags) { - if (!m_loaders_list.contains(flag)) { - m_loaders_list.append(flag); - m_next_loader_idx++; - setProgress(m_next_loader_idx * 2 - 1, 9); - for (auto resource : m_mappings) { - if (resource->metadata()->loaders & flag) { - getUpdateModsForLoader(flag, true); - return; - } - } - setProgress(m_next_loader_idx * 2, 9); + + if (m_loaders_list.size() == 0) { + if (m_loader_idx == 0) { + getUpdateModsForLoader({}); + m_loader_idx++; + return; } } - for (auto m : m_mappings) { - emit checkFailed(m, - tr("No valid version found for this mod. It's probably unavailable for the current game version / mod loader.")); + if (m_loader_idx < m_loaders_list.size()) { + getUpdateModsForLoader(m_loaders_list.at(m_loader_idx)); + m_loader_idx++; + return; } + + for (auto resource : m_mappings) { + QString reason; + + if (dynamic_cast(resource) != nullptr) + reason = + tr("No valid version found for this resource. It's probably unavailable for the current game " + "version / mod loader."); + else + reason = tr("No valid version found for this resource. It's probably unavailable for the current game version."); + + emit checkFailed(resource, reason); + } + emitSucceeded(); } diff --git a/launcher/modplatform/modrinth/ModrinthCheckUpdate.h b/launcher/modplatform/modrinth/ModrinthCheckUpdate.h index 0bbd21321..204b24784 100644 --- a/launcher/modplatform/modrinth/ModrinthCheckUpdate.h +++ b/launcher/modplatform/modrinth/ModrinthCheckUpdate.h @@ -7,10 +7,10 @@ class ModrinthCheckUpdate : public CheckUpdateTask { public: ModrinthCheckUpdate(QList& resources, - std::list& mcVersions, - QList loadersList, - std::shared_ptr resourceModel) - : CheckUpdateTask(resources, mcVersions, loadersList, resourceModel) + std::list& mcVersions, + QList loadersList, + std::shared_ptr resourceModel) + : CheckUpdateTask(resources, mcVersions, std::move(loadersList), std::move(resourceModel)) , m_hash_type(ModPlatform::ProviderCapabilities::hashType(ModPlatform::ResourceProvider::MODRINTH).first()) {} @@ -19,13 +19,13 @@ class ModrinthCheckUpdate : public CheckUpdateTask { protected slots: void executeTask() override; - void getUpdateModsForLoader(ModPlatform::ModLoaderTypes loader, bool forceModLoaderCheck = false); - void checkVersionsResponse(std::shared_ptr response, ModPlatform::ModLoaderTypes loader, bool forceModLoaderCheck = false); + void getUpdateModsForLoader(std::optional loader); + void checkVersionsResponse(std::shared_ptr response, std::optional loader); void checkNextLoader(); private: Task::Ptr m_job = nullptr; QHash m_mappings; QString m_hash_type; - int m_next_loader_idx = 0; + int m_loader_idx = 0; };