| 416 | } |
| 417 | |
| 418 | Task::Ptr EnsureMetadataTask::flameProjectsTask() |
| 419 | { |
| 420 | QHash<QString, QString> addonIds; |
| 421 | for (auto const& hash : m_mods.keys()) { |
| 422 | if (m_temp_versions.contains(hash)) { |
| 423 | auto data = m_temp_versions.find(hash).value(); |
| 424 | |
| 425 | auto id_str = data.addonId.toString(); |
| 426 | if (!id_str.isEmpty()) |
| 427 | addonIds.insert(data.addonId.toString(), hash); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | auto response = std::make_shared<QByteArray>(); |
| 432 | Task::Ptr proj_task; |
| 433 | |
| 434 | if (addonIds.isEmpty()) { |
| 435 | qWarning() << "No addonId found!"; |
| 436 | } else if (addonIds.size() == 1) { |
| 437 | proj_task = flame_api.getProject(*addonIds.keyBegin(), response); |
| 438 | } else { |
| 439 | proj_task = flame_api.getProjects(addonIds.keys(), response); |
| 440 | } |
| 441 | |
| 442 | // Prevents unfortunate timings when aborting the task |
| 443 | if (!proj_task) |
| 444 | return Task::Ptr{ nullptr }; |
| 445 | |
| 446 | connect(proj_task.get(), &Task::succeeded, this, [this, response, addonIds] { |
| 447 | QJsonParseError parse_error{}; |
| 448 | auto doc = QJsonDocument::fromJson(*response, &parse_error); |
| 449 | if (parse_error.error != QJsonParseError::NoError) { |
| 450 | qWarning() << "Error while parsing JSON response from Modrinth projects task at " << parse_error.offset |
| 451 | << " reason: " << parse_error.errorString(); |
| 452 | qWarning() << *response; |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | try { |
| 457 | QJsonArray entries; |
| 458 | if (addonIds.size() == 1) |
| 459 | entries = { Json::requireObject(Json::requireObject(doc), "data") }; |
| 460 | else |
| 461 | entries = Json::requireArray(Json::requireObject(doc), "data"); |
| 462 | |
| 463 | for (auto entry : entries) { |
| 464 | auto entry_obj = Json::requireObject(entry); |
| 465 | |
| 466 | auto id = QString::number(Json::requireInteger(entry_obj, "id")); |
| 467 | auto hash = addonIds.find(id).value(); |
| 468 | auto mod = m_mods.find(hash).value(); |
| 469 | |
| 470 | try { |
| 471 | setStatus(tr("Parsing API response from CurseForge for '%1'...").arg(mod->name())); |
| 472 | |
| 473 | ModPlatform::IndexedPack pack; |
| 474 | FlameMod::loadIndexedPack(pack, entry_obj); |
| 475 |
nothing calls this directly
no test coverage detected