| 78 | } |
| 79 | |
| 80 | VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument& doc, const QString& filename, const bool requireOrder) |
| 81 | { |
| 82 | VersionFilePtr out(new VersionFile()); |
| 83 | if (doc.isEmpty() || doc.isNull()) { |
| 84 | throw JSONValidationError(filename + " is empty or null"); |
| 85 | } |
| 86 | if (!doc.isObject()) { |
| 87 | throw JSONValidationError(filename + " is not an object"); |
| 88 | } |
| 89 | |
| 90 | QJsonObject root = doc.object(); |
| 91 | |
| 92 | Meta::MetadataVersion formatVersion = Meta::parseFormatVersion(root, false); |
| 93 | switch (formatVersion) { |
| 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 | if (root.contains("order")) { |
| 102 | out->order = requireInteger(root.value("order")); |
| 103 | } else { |
| 104 | // FIXME: evaluate if we don't want to throw exceptions here instead |
| 105 | qCritical() << filename << "doesn't contain an order field"; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | out->name = root.value("name").toString(); |
| 110 | |
| 111 | if (root.contains("uid")) { |
| 112 | out->uid = root.value("uid").toString(); |
| 113 | } else { |
| 114 | out->uid = root.value("fileId").toString(); |
| 115 | } |
| 116 | |
| 117 | static const QRegularExpression s_validUidRegex{ QRegularExpression::anchoredPattern( |
| 118 | QStringLiteral(R"([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)*)")) }; |
| 119 | if (!s_validUidRegex.match(out->uid).hasMatch()) { |
| 120 | qCritical() << "The component's 'uid' contains illegal characters! UID:" << out->uid; |
| 121 | out->addProblem(ProblemSeverity::Error, |
| 122 | QObject::tr("The component's 'uid' contains illegal characters! This can cause security issues.")); |
| 123 | } |
| 124 | |
| 125 | out->version = root.value("version").toString(); |
| 126 | |
| 127 | MojangVersionFormat::readVersionProperties(root, out.get()); |
| 128 | |
| 129 | // added for legacy Minecraft window embedding, TODO: remove |
| 130 | readString(root, "appletClass", out->appletClass); |
| 131 | |
| 132 | if (root.contains("+tweakers")) { |
| 133 | for (auto tweakerVal : requireArray(root.value("+tweakers"))) { |
| 134 | out->addTweakers.append(requireString(tweakerVal)); |
| 135 | } |
| 136 | } |
| 137 |
nothing calls this directly
no test coverage detected