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

Method libraryFromJson

launcher/minecraft/MojangVersionFormat.cpp:333–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333LibraryPtr MojangVersionFormat::libraryFromJson(ProblemContainer & problems, const QJsonObject &libObj, const QString &filename)
334{
335 LibraryPtr out(new Library());
336 if (!libObj.contains("name"))
337 {
338 throw JSONValidationError(filename + "contains a library that doesn't have a 'name' field");
339 }
340 auto rawName = libObj.value("name").toString();
341 out->m_name = rawName;
342 if(!out->m_name.valid()) {
343 problems.addProblem(ProblemSeverity::Error, QObject::tr("Library %1 name is broken and cannot be processed.").arg(rawName));
344 }
345
346 Bits::readString(libObj, "url", out->m_repositoryURL);
347 if (libObj.contains("extract"))
348 {
349 out->m_hasExcludes = true;
350 auto extractObj = requireObject(libObj.value("extract"));
351 for (auto excludeVal : requireArray(extractObj.value("exclude")))
352 {
353 out->m_extractExcludes.append(requireString(excludeVal));
354 }
355 }
356 if (libObj.contains("natives"))
357 {
358 QJsonObject nativesObj = requireObject(libObj.value("natives"));
359 for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it)
360 {
361 if (!it.value().isString())
362 {
363 qWarning() << filename << "contains an invalid native (skipping)";
364 }
365 // FIXME: Skip unknown platforms
366 out->m_nativeClassifiers[it.key()] = it.value().toString();
367 }
368 }
369 if (libObj.contains("rules"))
370 {
371 out->applyRules = true;
372 out->m_rules = rulesFromJsonV4(libObj);
373 }
374 if (libObj.contains("downloads"))
375 {
376 out->m_mojangDownloads = libDownloadInfoFromJson(libObj);
377 }
378 return out;
379}
380
381QJsonObject MojangVersionFormat::libraryToJson(Library *library)
382{

Callers

nothing calls this directly

Calls 12

requireObjectFunction · 0.85
requireArrayFunction · 0.85
rulesFromJsonV4Function · 0.85
libDownloadInfoFromJsonFunction · 0.85
addProblemMethod · 0.80
appendMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
readStringFunction · 0.70
containsMethod · 0.45
toStringMethod · 0.45
validMethod · 0.45

Tested by

no test coverage detected