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