| 331 | } |
| 332 | |
| 333 | LibraryPtr 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 | |
| 381 | QJsonObject MojangVersionFormat::libraryToJson(Library *library) |
| 382 | { |
nothing calls this directly
no test coverage detected