MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / modrinthProjectsTask

Method modrinthProjectsTask

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

Source from the content-addressed store, hash-verified

261}
262
263Task::Ptr EnsureMetadataTask::modrinthProjectsTask()
264{
265 QHash<QString, QString> addonIds;
266 for (auto const& data : m_tempVersions)
267 addonIds.insert(data.addonId.toString(), data.hash);
268
269 Task::Ptr proj_task;
270 QByteArray* response;
271
272 if (addonIds.isEmpty()) {
273 qWarning() << "No addonId found!";
274 } else if (addonIds.size() == 1) {
275 std::tie(proj_task, response) = modrinth_api.getProject(*addonIds.keyBegin());
276 } else {
277 std::tie(proj_task, response) = modrinth_api.getProjects(addonIds.keys());
278 }
279
280 // Prevents unfortunate timings when aborting the task
281 if (!proj_task)
282 return Task::Ptr{ nullptr };
283
284 connect(proj_task.get(), &Task::succeeded, this, [this, response, addonIds] {
285 QJsonParseError parse_error{};
286 auto doc = QJsonDocument::fromJson(*response, &parse_error);
287 if (parse_error.error != QJsonParseError::NoError) {
288 qWarning() << "Error while parsing JSON response from Modrinth projects task at" << parse_error.offset
289 << "reason:" << parse_error.errorString();
290 qWarning() << *response;
291 return;
292 }
293
294 QJsonArray entries;
295
296 try {
297 if (addonIds.size() == 1)
298 entries = { doc.object() };
299 else
300 entries = Json::requireArray(doc);
301 } catch (Json::JsonException& e) {
302 qDebug() << e.cause();
303 qDebug() << doc;
304 }
305
306 for (auto entry : entries) {
307 ModPlatform::IndexedPack pack;
308
309 try {
310 auto entry_obj = Json::requireObject(entry);
311
312 Modrinth::loadIndexedPack(pack, entry_obj);
313 } catch (Json::JsonException& e) {
314 qDebug() << e.cause();
315 qDebug() << doc;
316
317 // Skip this entry, since it has problems
318 continue;
319 }
320

Callers

nothing calls this directly

Calls 15

requireArrayFunction · 0.85
requireObjectFunction · 0.85
insertMethod · 0.80
getProjectMethod · 0.80
errorStringMethod · 0.80
objectMethod · 0.80
causeMethod · 0.80
valueMethod · 0.80
toStringMethod · 0.45
isEmptyMethod · 0.45
sizeMethod · 0.45
getProjectsMethod · 0.45

Tested by

no test coverage detected