| 75 | } |
| 76 | |
| 77 | VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename, const bool requireOrder) |
| 78 | { |
| 79 | VersionFilePtr out(new VersionFile()); |
| 80 | if (doc.isEmpty() || doc.isNull()) |
| 81 | { |
| 82 | throw JSONValidationError(filename + " is empty or null"); |
| 83 | } |
| 84 | if (!doc.isObject()) |
| 85 | { |
| 86 | throw JSONValidationError(filename + " is not an object"); |
| 87 | } |
| 88 | |
| 89 | QJsonObject root = doc.object(); |
| 90 | |
| 91 | Meta::MetadataVersion formatVersion = Meta::parseFormatVersion(root, false); |
| 92 | switch(formatVersion) |
| 93 | { |
| 94 | case Meta::MetadataVersion::InitialRelease: |
| 95 | break; |
| 96 | case Meta::MetadataVersion::Invalid: |
| 97 | throw JSONValidationError(filename + " does not contain a recognizable version of the metadata format."); |
| 98 | } |
| 99 | |
| 100 | if (requireOrder) |
| 101 | { |
| 102 | if (root.contains("order")) |
| 103 | { |
| 104 | out->order = requireInteger(root.value("order")); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | // FIXME: evaluate if we don't want to throw exceptions here instead |
| 109 | qCritical() << filename << "doesn't contain an order field"; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | out->name = root.value("name").toString(); |
| 114 | |
| 115 | if(root.contains("uid")) |
| 116 | { |
| 117 | out->uid = root.value("uid").toString(); |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | out->uid = root.value("fileId").toString(); |
| 122 | } |
| 123 | |
| 124 | out->version = root.value("version").toString(); |
| 125 | |
| 126 | MojangVersionFormat::readVersionProperties(root, out.get()); |
| 127 | |
| 128 | // added for legacy Minecraft window embedding, TODO: remove |
| 129 | readString(root, "appletClass", out->appletClass); |
| 130 | |
| 131 | if (root.contains("+tweakers")) |
| 132 | { |
| 133 | for (auto tweakerVal : requireArray(root.value("+tweakers"))) |
| 134 | { |
nothing calls this directly
no test coverage detected