diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-06-03 21:57:22 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-06-06 21:23:05 +0200 |
commit | 24db645167b42adba5d9c221215be83bef39e2a1 (patch) | |
tree | cb7c797d232ac428d2a03d2166762d7bd8167e4c | |
parent | dde35a0eb8847d6dd13219bae9648bf6c4d7b9e3 (diff) | |
download | MultiMC-24db645167b42adba5d9c221215be83bef39e2a1.tar MultiMC-24db645167b42adba5d9c221215be83bef39e2a1.tar.gz MultiMC-24db645167b42adba5d9c221215be83bef39e2a1.tar.lz MultiMC-24db645167b42adba5d9c221215be83bef39e2a1.tar.xz MultiMC-24db645167b42adba5d9c221215be83bef39e2a1.zip |
NOISSUE sanitize Json
Removes magical parameter madness.
All require* can throw
All ensure* need a default value and never throw
-rw-r--r-- | logic/Json.cpp | 55 | ||||
-rw-r--r-- | logic/Json.h | 119 | ||||
-rw-r--r-- | logic/minecraft/MinecraftVersionList.cpp | 14 | ||||
-rw-r--r-- | logic/minecraft/ProfileUtils.cpp | 8 | ||||
-rw-r--r-- | logic/minecraft/RawLibrary.cpp | 10 | ||||
-rw-r--r-- | logic/minecraft/VersionFile.cpp | 42 |
6 files changed, 130 insertions, 118 deletions
diff --git a/logic/Json.cpp b/logic/Json.cpp index 97bab474..f2cbc8a3 100644 --- a/logic/Json.cpp +++ b/logic/Json.cpp @@ -44,7 +44,7 @@ static bool isBinaryJson(const QByteArray &data) decltype(QJsonDocument::BinaryFormatTag) tag = QJsonDocument::BinaryFormatTag; return memcmp(data.constData(), &tag, sizeof(QJsonDocument::BinaryFormatTag)) == 0; } -QJsonDocument ensureDocument(const QByteArray &data, const QString &what) +QJsonDocument requireDocument(const QByteArray &data, const QString &what) { if (isBinaryJson(data)) { @@ -66,11 +66,11 @@ QJsonDocument ensureDocument(const QByteArray &data, const QString &what) return doc; } } -QJsonDocument ensureDocument(const QString &filename, const QString &what) +QJsonDocument requireDocument(const QString &filename, const QString &what) { - return ensureDocument(FS::read(filename), what); + return requireDocument(FS::read(filename), what); } -QJsonObject ensureObject(const QJsonDocument &doc, const QString &what) +QJsonObject requireObject(const QJsonDocument &doc, const QString &what) { if (!doc.isObject()) { @@ -78,7 +78,7 @@ QJsonObject ensureObject(const QJsonDocument &doc, const QString &what) } return doc.object(); } -QJsonArray ensureArray(const QJsonDocument &doc, const QString &what) +QJsonArray requireArray(const QJsonDocument &doc, const QString &what) { if (!doc.isArray()) { @@ -140,10 +140,9 @@ QJsonValue toJson<QVariant>(const QVariant &variant) } -template<> QByteArray ensureIsType<QByteArray>(const QJsonValue &value, const Requirement, - const QString &what) +template<> QByteArray requireIsType<QByteArray>(const QJsonValue &value, const QString &what) { - const QString string = ensureIsType<QString>(value, Required, what); + const QString string = ensureIsType<QString>(value, what); // ensure that the string can be safely cast to Latin1 if (string != QString::fromLatin1(string.toLatin1())) { @@ -152,7 +151,7 @@ template<> QByteArray ensureIsType<QByteArray>(const QJsonValue &value, const Re return QByteArray::fromHex(string.toLatin1()); } -template<> QJsonArray ensureIsType<QJsonArray>(const QJsonValue &value, const Requirement, const QString &what) +template<> QJsonArray requireIsType<QJsonArray>(const QJsonValue &value, const QString &what) { if (!value.isArray()) { @@ -162,7 +161,7 @@ template<> QJsonArray ensureIsType<QJsonArray>(const QJsonValue &value, const Re } -template<> QString ensureIsType<QString>(const QJsonValue &value, const Requirement, const QString &what) +template<> QString requireIsType<QString>(const QJsonValue &value, const QString &what) { if (!value.isString()) { @@ -171,8 +170,7 @@ template<> QString ensureIsType<QString>(const QJsonValue &value, const Requirem return value.toString(); } -template<> bool ensureIsType<bool>(const QJsonValue &value, const Requirement, - const QString &what) +template<> bool requireIsType<bool>(const QJsonValue &value, const QString &what) { if (!value.isBool()) { @@ -181,8 +179,7 @@ template<> bool ensureIsType<bool>(const QJsonValue &value, const Requirement, return value.toBool(); } -template<> double ensureIsType<double>(const QJsonValue &value, const Requirement, - const QString &what) +template<> double requireIsType<double>(const QJsonValue &value, const QString &what) { if (!value.isDouble()) { @@ -191,10 +188,9 @@ template<> double ensureIsType<double>(const QJsonValue &value, const Requiremen return value.toDouble(); } -template<> int ensureIsType<int>(const QJsonValue &value, const Requirement, - const QString &what) +template<> int requireIsType<int>(const QJsonValue &value, const QString &what) { - const double doubl = ensureIsType<double>(value, Required, what); + const double doubl = requireIsType<double>(value, what); if (fmod(doubl, 1) != 0) { throw JsonException(what + " is not an integer"); @@ -202,10 +198,9 @@ template<> int ensureIsType<int>(const QJsonValue &value, const Requirement, return int(doubl); } -template<> QDateTime ensureIsType<QDateTime>(const QJsonValue &value, const Requirement, - const QString &what) +template<> QDateTime requireIsType<QDateTime>(const QJsonValue &value, const QString &what) { - const QString string = ensureIsType<QString>(value, Required, what); + const QString string = requireIsType<QString>(value, what); const QDateTime datetime = QDateTime::fromString(string, Qt::ISODate); if (!datetime.isValid()) { @@ -214,10 +209,9 @@ template<> QDateTime ensureIsType<QDateTime>(const QJsonValue &value, const Requ return datetime; } -template<> QUrl ensureIsType<QUrl>(const QJsonValue &value, const Requirement, - const QString &what) +template<> QUrl requireIsType<QUrl>(const QJsonValue &value, const QString &what) { - const QString string = ensureIsType<QString>(value, Required, what); + const QString string = ensureIsType<QString>(value, what); if (string.isEmpty()) { return QUrl(); @@ -230,15 +224,16 @@ template<> QUrl ensureIsType<QUrl>(const QJsonValue &value, const Requirement, return url; } -template<> QDir ensureIsType<QDir>(const QJsonValue &value, const Requirement, const QString &what) +template<> QDir requireIsType<QDir>(const QJsonValue &value, const QString &what) { - const QString string = ensureIsType<QString>(value, Required, what); + const QString string = requireIsType<QString>(value, what); + // FIXME: does not handle invalid characters! return QDir::current().absoluteFilePath(string); } -template<> QUuid ensureIsType<QUuid>(const QJsonValue &value, const Requirement, const QString &what) +template<> QUuid requireIsType<QUuid>(const QJsonValue &value, const QString &what) { - const QString string = ensureIsType<QString>(value, Required, what); + const QString string = requireIsType<QString>(value, what); const QUuid uuid = QUuid(string); if (uuid.toString() != string) // converts back => valid { @@ -247,7 +242,7 @@ template<> QUuid ensureIsType<QUuid>(const QJsonValue &value, const Requirement, return uuid; } -template<> QJsonObject ensureIsType<QJsonObject>(const QJsonValue &value, const Requirement, const QString &what) +template<> QJsonObject requireIsType<QJsonObject>(const QJsonValue &value, const QString &what) { if (!value.isObject()) { @@ -256,7 +251,7 @@ template<> QJsonObject ensureIsType<QJsonObject>(const QJsonValue &value, const return value.toObject(); } -template<> QVariant ensureIsType<QVariant>(const QJsonValue &value, const Requirement, const QString &what) +template<> QVariant requireIsType<QVariant>(const QJsonValue &value, const QString &what) { if (value.isNull() || value.isUndefined()) { @@ -265,7 +260,7 @@ template<> QVariant ensureIsType<QVariant>(const QJsonValue &value, const Requir return value.toVariant(); } -template<> QJsonValue ensureIsType<QJsonValue>(const QJsonValue &value, const Requirement, const QString &what) +template<> QJsonValue requireIsType<QJsonValue>(const QJsonValue &value, const QString &what) { if (value.isNull() || value.isUndefined()) { diff --git a/logic/Json.h b/logic/Json.h index 9f4c5445..55f0cfc1 100644 --- a/logic/Json.h +++ b/logic/Json.h @@ -18,11 +18,6 @@ namespace Json { DECLARE_EXCEPTION(Json); -enum Requirement -{ - Required -}; - /// @throw FileSystemException void write(const QJsonDocument &doc, const QString &filename); /// @throw FileSystemException @@ -36,13 +31,13 @@ QByteArray toText(const QJsonObject &obj); QByteArray toText(const QJsonArray &array); /// @throw JsonException -QJsonDocument ensureDocument(const QByteArray &data, const QString &what = "Document"); +QJsonDocument requireDocument(const QByteArray &data, const QString &what = "Document"); /// @throw JsonException -QJsonDocument ensureDocument(const QString &filename, const QString &what = "Document"); +QJsonDocument requireDocument(const QString &filename, const QString &what = "Document"); /// @throw JsonException -QJsonObject ensureObject(const QJsonDocument &doc, const QString &what = "Document"); +QJsonObject requireObject(const QJsonDocument &doc, const QString &what = "Document"); /// @throw JsonException -QJsonArray ensureArray(const QJsonDocument &doc, const QString &what = "Document"); +QJsonArray requireArray(const QJsonDocument &doc, const QString &what = "Document"); /////////////////// WRITING //////////////////// @@ -107,22 +102,36 @@ QJsonArray toJsonArray(const QList<T> &container) ////////////////// READING //////////////////// +/// @throw JsonException template <typename T> -T ensureIsType(const QJsonValue &value, const Requirement requirement = Required, const QString &what = "Value"); - -template<> double ensureIsType<double>(const QJsonValue &value, const Requirement, const QString &what); -template<> bool ensureIsType<bool>(const QJsonValue &value, const Requirement, const QString &what); -template<> int ensureIsType<int>(const QJsonValue &value, const Requirement, const QString &what); -template<> QJsonObject ensureIsType<QJsonObject>(const QJsonValue &value, const Requirement, const QString &what); -template<> QJsonArray ensureIsType<QJsonArray>(const QJsonValue &value, const Requirement, const QString &what); -template<> QJsonValue ensureIsType<QJsonValue>(const QJsonValue &value, const Requirement, const QString &what); -template<> QByteArray ensureIsType<QByteArray>(const QJsonValue &value, const Requirement, const QString &what); -template<> QDateTime ensureIsType<QDateTime>(const QJsonValue &value, const Requirement, const QString &what); -template<> QVariant ensureIsType<QVariant>(const QJsonValue &value, const Requirement, const QString &what); -template<> QString ensureIsType<QString>(const QJsonValue &value, const Requirement, const QString &what); -template<> QUuid ensureIsType<QUuid>(const QJsonValue &value, const Requirement, const QString &what); -template<> QDir ensureIsType<QDir>(const QJsonValue &value, const Requirement, const QString &what); -template<> QUrl ensureIsType<QUrl>(const QJsonValue &value, const Requirement, const QString &what); +T requireIsType(const QJsonValue &value, const QString &what = "Value"); + +/// @throw JsonException +template<> double requireIsType<double>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> bool requireIsType<bool>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> int requireIsType<int>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QJsonObject requireIsType<QJsonObject>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QJsonArray requireIsType<QJsonArray>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QJsonValue requireIsType<QJsonValue>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QByteArray requireIsType<QByteArray>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QDateTime requireIsType<QDateTime>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QVariant requireIsType<QVariant>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QString requireIsType<QString>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QUuid requireIsType<QUuid>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QDir requireIsType<QDir>(const QJsonValue &value, const QString &what); +/// @throw JsonException +template<> QUrl requireIsType<QUrl>(const QJsonValue &value, const QString &what); // the following functions are higher level functions, that make use of the above functions for // type conversion @@ -133,26 +142,30 @@ T ensureIsType(const QJsonValue &value, const T default_, const QString &what = { return default_; } - return ensureIsType<T>(value, Required, what); + try + { + return requireIsType<T>(value, what); + } + catch (JsonException &) + { + return default_; + } } /// @throw JsonException template <typename T> -T ensureIsType(const QJsonObject &parent, const QString &key, - const Requirement requirement = Required, - const QString &what = "__placeholder__") +T requireIsType(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") { const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); if (!parent.contains(key)) { throw JsonException(localWhat + "s parent does not contain " + localWhat); } - return ensureIsType<T>(parent.value(key), requirement, localWhat); + return requireIsType<T>(parent.value(key), localWhat); } template <typename T> -T ensureIsType(const QJsonObject &parent, const QString &key, const T default_, - const QString &what = "__placeholder__") +T ensureIsType(const QJsonObject &parent, const QString &key, const T default_, const QString &what = "__placeholder__") { const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); if (!parent.contains(key)) @@ -163,53 +176,49 @@ T ensureIsType(const QJsonObject &parent, const QString &key, const T default_, } template <typename T> -QList<T> ensureIsArrayOf(const QJsonDocument &doc) +QList<T> requireIsArrayOf(const QJsonDocument &doc) { - const QJsonArray array = ensureArray(doc); + const QJsonArray array = requireArray(doc); QList<T> out; for (const QJsonValue val : array) { - out.append(ensureIsType<T>(val, Required, "Document")); + out.append(requireIsType<T>(val, "Document")); } return out; } template <typename T> -QList<T> ensureIsArrayOf(const QJsonValue &value, const Requirement = Required, - const QString &what = "Value") +QList<T> ensureIsArrayOf(const QJsonValue &value, const QString &what = "Value") { - const QJsonArray array = ensureIsType<QJsonArray>(value, Required, what); + const QJsonArray array = requireIsType<QJsonArray>(value, what); QList<T> out; for (const QJsonValue val : array) { - out.append(ensureIsType<T>(val, Required, what)); + out.append(ensureIsType<T>(val, what)); } return out; } template <typename T> -QList<T> ensureIsArrayOf(const QJsonValue &value, const QList<T> default_, - const QString &what = "Value") +QList<T> ensureIsArrayOf(const QJsonValue &value, const QList<T> default_, const QString &what = "Value") { if (value.isUndefined()) { return default_; } - return ensureIsArrayOf<T>(value, Required, what); + return ensureIsArrayOf<T>(value, what); } /// @throw JsonException template <typename T> -QList<T> ensureIsArrayOf(const QJsonObject &parent, const QString &key, - const Requirement requirement = Required, - const QString &what = "__placeholder__") +QList<T> requireIsArrayOf(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") { const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); if (!parent.contains(key)) { throw JsonException(localWhat + "s parent does not contain " + localWhat); } - return ensureIsArrayOf<T>(parent.value(key), requirement, localWhat); + return requireIsArrayOf<T>(parent.value(key), localWhat); } template <typename T> @@ -226,14 +235,22 @@ QList<T> ensureIsArrayOf(const QJsonObject &parent, const QString &key, // this macro part could be replaced by variadic functions that just pass on their arguments, but that wouldn't work well with IDE helpers #define JSON_HELPERFUNCTIONS(NAME, TYPE) \ - inline TYPE ensure##NAME(const QJsonValue &value, const Requirement requirement = Required, const QString &what = "Value") \ -{ return ensureIsType<TYPE>(value, requirement, what); } \ + inline TYPE require##NAME(const QJsonValue &value, const QString &what = "Value") \ + { \ + return requireIsType<TYPE>(value, what); \ + } \ inline TYPE ensure##NAME(const QJsonValue &value, const TYPE default_, const QString &what = "Value") \ -{ return ensureIsType<TYPE>(value, default_, what); } \ - inline TYPE ensure##NAME(const QJsonObject &parent, const QString &key, const Requirement requirement = Required, const QString &what = "__placeholder__") \ -{ return ensureIsType<TYPE>(parent, key, requirement, what); } \ + { \ + return ensureIsType<TYPE>(value, default_, what); \ + } \ + inline TYPE require##NAME(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") \ + { \ + return requireIsType<TYPE>(parent, key, what); \ + } \ inline TYPE ensure##NAME(const QJsonObject &parent, const QString &key, const TYPE default_, const QString &what = "__placeholder") \ -{ return ensureIsType<TYPE>(parent, key, default_, what); } + { \ + return ensureIsType<TYPE>(parent, key, default_, what); \ + } JSON_HELPERFUNCTIONS(Array, QJsonArray) JSON_HELPERFUNCTIONS(Object, QJsonObject) diff --git a/logic/minecraft/MinecraftVersionList.cpp b/logic/minecraft/MinecraftVersionList.cpp index 44be281b..8ba51b99 100644 --- a/logic/minecraft/MinecraftVersionList.cpp +++ b/logic/minecraft/MinecraftVersionList.cpp @@ -157,11 +157,11 @@ void MinecraftVersionList::loadBuiltinList() qDebug() << "Loading builtin version list."; // grab the version list data from internal resources. const QJsonDocument doc = - Json::ensureDocument(QString(":/versions/minecraft.json"), "builtin version list"); + Json::requireDocument(QString(":/versions/minecraft.json"), "builtin version list"); const QJsonObject root = doc.object(); // parse all the versions - for (const auto version : Json::ensureArray(root.value("versions"))) + for (const auto version : Json::requireArray(root.value("versions"))) { QJsonObject versionObj = version.toObject(); QString versionID = versionObj.value("id").toString(""); @@ -203,9 +203,9 @@ void MinecraftVersionList::loadBuiltinList() mcVersion->m_processArguments = versionObj.value("processArguments").toString("legacy"); if (versionObj.contains("+traits")) { - for (auto traitVal : Json::ensureArray(versionObj.value("+traits"))) + for (auto traitVal : Json::requireArray(versionObj.value("+traits"))) { - mcVersion->m_traits.insert(Json::ensureString(traitVal)); + mcVersion->m_traits.insert(Json::requireString(traitVal)); } } m_lookup[versionID] = mcVersion; @@ -226,9 +226,9 @@ void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource s try { - QJsonObject latest = Json::ensureObject(root.value("latest")); - m_latestReleaseID = Json::ensureString(latest.value("release")); - m_latestSnapshotID = Json::ensureString(latest.value("snapshot")); + QJsonObject latest = Json::requireObject(root.value("latest")); + m_latestReleaseID = Json::requireString(latest.value("release")); + m_latestSnapshotID = Json::requireString(latest.value("snapshot")); } catch (Exception &err) { diff --git a/logic/minecraft/ProfileUtils.cpp b/logic/minecraft/ProfileUtils.cpp index 68fe0f14..9a886f1d 100644 --- a/logic/minecraft/ProfileUtils.cpp +++ b/logic/minecraft/ProfileUtils.cpp @@ -74,18 +74,18 @@ bool readOverrideOrders(QString path, PatchOrder &order) // and then read it and process it if all above is true. try { - auto obj = Json::ensureObject(doc); + auto obj = Json::requireObject(doc); // check order file version. - auto version = Json::ensureInteger(obj.value("version")); + auto version = Json::requireInteger(obj.value("version")); if (version != currentOrderFileVersion) { throw JSONValidationError(QObject::tr("Invalid order file version, expected %1") .arg(currentOrderFileVersion)); } - auto orderArray = Json::ensureArray(obj.value("order")); + auto orderArray = Json::requireArray(obj.value("order")); for(auto item: orderArray) { - order.append(Json::ensureString(item)); + order.append(Json::requireString(item)); } } catch (JSONValidationError &err) diff --git a/logic/minecraft/RawLibrary.cpp b/logic/minecraft/RawLibrary.cpp index 90883312..ceaa9dd0 100644 --- a/logic/minecraft/RawLibrary.cpp +++ b/logic/minecraft/RawLibrary.cpp @@ -39,15 +39,15 @@ RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &fil if (libObj.contains("extract")) { out->applyExcludes = true; - auto extractObj = ensureObject(libObj.value("extract")); - for (auto excludeVal : ensureArray(extractObj.value("exclude"))) + auto extractObj = requireObject(libObj.value("extract")); + for (auto excludeVal : requireArray(extractObj.value("exclude"))) { - out->extract_excludes.append(ensureString(excludeVal)); + out->extract_excludes.append(requireString(excludeVal)); } } if (libObj.contains("natives")) { - QJsonObject nativesObj = ensureObject(libObj.value("natives")); + QJsonObject nativesObj = requireObject(libObj.value("natives")); for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it) { if (!it.value().isString()) @@ -127,7 +127,7 @@ RawLibraryPtr RawLibrary::fromJsonPlus(const QJsonObject &libObj, const QString } if (libObj.contains("MMC-depend")) { - const QString dependString = ensureString(libObj.value("MMC-depend")); + const QString dependString = requireString(libObj.value("MMC-depend")); if (dependString == "hard") { lib->dependType = RawLibrary::Hard; diff --git a/logic/minecraft/VersionFile.cpp b/logic/minecraft/VersionFile.cpp index 426cba8c..24f2eb9c 100644 --- a/logic/minecraft/VersionFile.cpp +++ b/logic/minecraft/VersionFile.cpp @@ -52,7 +52,7 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi { if (root.contains("order")) { - out->order = ensureInteger(root.value("order")); + out->order = requireInteger(root.value("order")); } else { @@ -71,7 +71,7 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi { if (root.contains(key)) { - variable = ensureString(root.value(key)); + variable = requireString(root.value(key)); } }; @@ -79,7 +79,7 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi { if (root.contains(key)) { - return ensureString(root.value(key)); + return requireString(root.value(key)); } return QString(); }; @@ -101,48 +101,48 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi if (root.contains("minimumLauncherVersion")) { - out->minimumLauncherVersion = ensureInteger(root.value("minimumLauncherVersion")); + out->minimumLauncherVersion = requireInteger(root.value("minimumLauncherVersion")); } if (root.contains("tweakers")) { out->shouldOverwriteTweakers = true; - for (auto tweakerVal : ensureArray(root.value("tweakers"))) + for (auto tweakerVal : requireArray(root.value("tweakers"))) { - out->overwriteTweakers.append(ensureString(tweakerVal)); + out->overwriteTweakers.append(requireString(tweakerVal)); } } if (root.contains("+tweakers")) { - for (auto tweakerVal : ensureArray(root.value("+tweakers"))) + for (auto tweakerVal : requireArray(root.value("+tweakers"))) { - out->addTweakers.append(ensureString(tweakerVal)); + out->addTweakers.append(requireString(tweakerVal)); } } if (root.contains("-tweakers")) { - for (auto tweakerVal : ensureArray(root.value("-tweakers"))) + for (auto tweakerVal : requireArray(root.value("-tweakers"))) { - out->removeTweakers.append(ensureString(tweakerVal)); + out->removeTweakers.append(requireString(tweakerVal)); } } if (root.contains("+traits")) { - for (auto tweakerVal : ensureArray(root.value("+traits"))) + for (auto tweakerVal : requireArray(root.value("+traits"))) { - out->traits.insert(ensureString(tweakerVal)); + out->traits.insert(requireString(tweakerVal)); } } if (root.contains("libraries")) { out->shouldOverwriteLibs = true; - for (auto libVal : ensureArray(root.value("libraries"))) + for (auto libVal : requireArray(root.value("libraries"))) { - auto libObj = ensureObject(libVal); + auto libObj = requireObject(libVal); auto lib = RawLibrary::fromJson(libObj, filename); out->overwriteLibs.append(lib); @@ -151,9 +151,9 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi if (root.contains("+jarMods")) { - for (auto libVal : ensureArray(root.value("+jarMods"))) + for (auto libVal : requireArray(root.value("+jarMods"))) { - QJsonObject libObj = ensureObject(libVal); + QJsonObject libObj = requireObject(libVal); // parse the jarmod auto lib = Jarmod::fromJson(libObj, filename, out->name); if(lib->originalName.isEmpty()) @@ -169,9 +169,9 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi if (root.contains("+libraries")) { - for (auto libVal : ensureArray(root.value("+libraries"))) + for (auto libVal : requireArray(root.value("+libraries"))) { - QJsonObject libObj = ensureObject(libVal); + QJsonObject libObj = requireObject(libVal); // parse the library auto lib = RawLibrary::fromJsonPlus(libObj, filename); out->addLibs.append(lib); @@ -180,10 +180,10 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi if (root.contains("-libraries")) { - for (auto libVal : ensureArray(root.value("-libraries"))) + for (auto libVal : requireArray(root.value("-libraries"))) { - auto libObj = ensureObject(libVal); - out->removeLibs.append(ensureString(libObj.value("name"))); + auto libObj = requireObject(libVal); + out->removeLibs.append(requireString(libObj.value("name"))); } } return out; |