MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / flameVersionsTask

Method flameVersionsTask

launcher/modplatform/EnsureMetadataTask.cpp:338–401  ·  view source on GitHub ↗

Flame

Source from the content-addressed store, hash-verified

336
337// Flame
338NetJob::Ptr EnsureMetadataTask::flameVersionsTask()
339{
340 auto* response = new QByteArray();
341
342 QList<uint> fingerprints;
343 for (auto& murmur : m_mods.keys()) {
344 fingerprints.push_back(murmur.toUInt());
345 }
346
347 auto ver_task = flame_api.matchFingerprints(fingerprints, response);
348
349 connect(ver_task.get(), &Task::succeeded, this, [this, response] {
350 QJsonParseError parse_error{};
351 QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
352 if (parse_error.error != QJsonParseError::NoError) {
353 qWarning() << "Error while parsing JSON response from Modrinth::CurrentVersions at " << parse_error.offset
354 << " reason: " << parse_error.errorString();
355 qWarning() << *response;
356
357 failed(parse_error.errorString());
358 return;
359 }
360
361 try {
362 auto doc_obj = Json::requireObject(doc);
363 auto data_obj = Json::requireObject(doc_obj, "data");
364 auto data_arr = Json::requireArray(data_obj, "exactMatches");
365
366 if (data_arr.isEmpty()) {
367 qWarning() << "No matches found for fingerprint search!";
368
369 return;
370 }
371
372 for (auto match : data_arr) {
373 auto match_obj = Json::ensureObject(match, {});
374 auto file_obj = Json::ensureObject(match_obj, "file", {});
375
376 if (match_obj.isEmpty() || file_obj.isEmpty()) {
377 qWarning() << "Fingerprint match is empty!";
378
379 return;
380 }
381
382 auto fingerprint = QString::number(Json::ensureVariant(file_obj, "fileFingerprint").toUInt());
383 auto mod = m_mods.find(fingerprint);
384 if (mod == m_mods.end()) {
385 qWarning() << "Invalid fingerprint from the API response.";
386 continue;
387 }
388
389 setStatus(tr("Parsing API response from CurseForge for '%1'...").arg((*mod)->name()));
390
391 m_temp_versions.insert(fingerprint, FlameMod::loadIndexedPackVersion(file_obj));
392 }
393
394 } catch (Json::JsonException& e) {
395 qDebug() << e.cause();

Callers

nothing calls this directly

Calls 11

fromJsonFunction · 0.85
requireObjectFunction · 0.85
requireArrayFunction · 0.85
matchFingerprintsMethod · 0.80
isEmptyMethod · 0.80
endMethod · 0.80
insertMethod · 0.80
causeMethod · 0.80
getMethod · 0.45
findMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected