summaryrefslogtreecommitdiffstats
path: root/logic/minecraft
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-06-03 21:57:22 +0200
committerPetr Mrázek <peterix@gmail.com>2015-06-06 21:23:05 +0200
commit24db645167b42adba5d9c221215be83bef39e2a1 (patch)
treecb7c797d232ac428d2a03d2166762d7bd8167e4c /logic/minecraft
parentdde35a0eb8847d6dd13219bae9648bf6c4d7b9e3 (diff)
downloadMultiMC-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
Diffstat (limited to 'logic/minecraft')
-rw-r--r--logic/minecraft/MinecraftVersionList.cpp14
-rw-r--r--logic/minecraft/ProfileUtils.cpp8
-rw-r--r--logic/minecraft/RawLibrary.cpp10
-rw-r--r--logic/minecraft/VersionFile.cpp42
4 files changed, 37 insertions, 37 deletions
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;