Remove ensure JSON helpers
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
@@ -967,7 +967,7 @@ void MainWindow::processURLs(QList<QUrl> urls)
|
||||
connect(job.get(), &Task::succeeded, this, [this, array, addonId, fileId, &dl_url, &version] {
|
||||
qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str();
|
||||
auto doc = Json::requireDocument(*array);
|
||||
auto data = Json::ensureObject(Json::ensureObject(doc.object()), "data");
|
||||
auto data = doc.object()["data"].toObject();
|
||||
// No way to find out if it's a mod or a modpack before here
|
||||
// And also we need to check if it ends with .zip, instead of any better way
|
||||
version = FlameMod::loadIndexedPackVersion(data);
|
||||
|
||||
@@ -481,7 +481,7 @@ void SkinManageDialog::on_userBtn_clicked()
|
||||
return;
|
||||
}
|
||||
const auto root = doc.object();
|
||||
auto id = Json::ensureString(root, "id");
|
||||
auto id = root["id"].toString();
|
||||
if (!id.isEmpty()) {
|
||||
getProfile->setUrl("https://sessionserver.mojang.com/session/minecraft/profile/" + id);
|
||||
} else {
|
||||
|
||||
@@ -141,13 +141,13 @@ void ImportPage::updateState()
|
||||
connect(job.get(), &NetJob::succeeded, this, [this, array, addonId, fileId] {
|
||||
qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str();
|
||||
auto doc = Json::requireDocument(*array);
|
||||
auto data = Json::ensureObject(Json::ensureObject(doc.object()), "data");
|
||||
auto data = doc.object()["data"].toObject();
|
||||
// No way to find out if it's a mod or a modpack before here
|
||||
// And also we need to check if it ends with .zip, instead of any better way
|
||||
auto fileName = Json::ensureString(data, "fileName");
|
||||
auto fileName = data["fileName"].toString();
|
||||
if (fileName.endsWith(".zip")) {
|
||||
// Have to use ensureString then use QUrl to get proper url encoding
|
||||
auto dl_url = QUrl(Json::ensureString(data, "downloadUrl", "", "downloadUrl"));
|
||||
auto dl_url = QUrl(data["downloadUrl"].toString(""));
|
||||
if (!dl_url.isValid()) {
|
||||
CustomMessageBox::selectable(
|
||||
this, tr("Error"),
|
||||
@@ -158,7 +158,7 @@ void ImportPage::updateState()
|
||||
}
|
||||
|
||||
QFileInfo dl_file(dl_url.fileName());
|
||||
QString pack_name = Json::ensureString(data, "displayName", dl_file.completeBaseName(), "displayName");
|
||||
QString pack_name = data["displayName"].toString(dl_file.completeBaseName());
|
||||
|
||||
QMap<QString, QString> extra_info;
|
||||
extra_info.insert("pack_id", addonId);
|
||||
|
||||
@@ -191,7 +191,7 @@ void Technic::ListModel::searchRequestFinished()
|
||||
if (pack.slug == "vanilla")
|
||||
continue;
|
||||
|
||||
auto rawURL = Json::ensureString(technicPackObject, "iconUrl", "null");
|
||||
auto rawURL = technicPackObject["iconUrl"].toString("null");
|
||||
if (rawURL == "null") {
|
||||
pack.logoUrl = "null";
|
||||
pack.logoName = "null";
|
||||
|
||||
@@ -202,11 +202,11 @@ void TechnicPage::suggestCurrent()
|
||||
}
|
||||
}
|
||||
|
||||
current.minecraftVersion = Json::ensureString(obj, "minecraft", QString(), "__placeholder__");
|
||||
current.websiteUrl = Json::ensureString(obj, "platformUrl", QString(), "__placeholder__");
|
||||
current.author = Json::ensureString(obj, "user", QString(), "__placeholder__");
|
||||
current.description = Json::ensureString(obj, "description", QString(), "__placeholder__");
|
||||
current.currentVersion = Json::ensureString(obj, "version", QString(), "__placeholder__");
|
||||
current.minecraftVersion = obj["minecraft"].toString();
|
||||
current.websiteUrl = obj["platformUrl"].toString();
|
||||
current.author = obj["user"].toString();
|
||||
current.description = obj["description"].toString();
|
||||
current.currentVersion = obj["version"].toString();
|
||||
current.metadataLoaded = true;
|
||||
|
||||
metadataLoaded();
|
||||
|
||||
@@ -63,12 +63,12 @@ QString BasicCatPack::path() const
|
||||
|
||||
JsonCatPack::PartialDate partialDate(QJsonObject date)
|
||||
{
|
||||
auto month = Json::ensureInteger(date, "month", 1);
|
||||
auto month = date["month"].toInt(1);
|
||||
if (month > 12)
|
||||
month = 12;
|
||||
else if (month <= 0)
|
||||
month = 1;
|
||||
auto day = Json::ensureInteger(date, "day", 1);
|
||||
auto day = date["day"].toInt(1);
|
||||
if (day > 31)
|
||||
day = 31;
|
||||
else if (day <= 0)
|
||||
@@ -83,9 +83,9 @@ JsonCatPack::JsonCatPack(QFileInfo& manifestInfo) : BasicCatPack(manifestInfo.di
|
||||
const auto root = doc.object();
|
||||
m_name = Json::requireString(root, "name", "Catpack name");
|
||||
m_default_path = FS::PathCombine(path, Json::requireString(root, "default", "Default Cat"));
|
||||
auto variants = Json::ensureArray(root, "variants", QJsonArray(), "Catpack Variants");
|
||||
auto variants = root["variants"].toArray();
|
||||
for (auto v : variants) {
|
||||
auto variant = Json::ensureObject(v, QJsonObject(), "Cat variant");
|
||||
auto variant = v.toObject();
|
||||
m_variants << Variant{ FS::PathCombine(path, Json::requireString(variant, "path", "Variant path")),
|
||||
partialDate(Json::requireObject(variant, "startTime", "Variant startTime")),
|
||||
partialDate(Json::requireObject(variant, "endTime", "Variant endTime")) };
|
||||
|
||||
@@ -179,10 +179,10 @@ bool CustomTheme::read(const QString& path, bool& hasCustomLogColors)
|
||||
const QJsonObject root = doc.object();
|
||||
m_name = Json::requireString(root, "name", "Theme name");
|
||||
m_widgets = Json::requireString(root, "widgets", "Qt widget theme");
|
||||
m_qssFilePath = Json::ensureString(root, "qssFilePath", "themeStyle.css");
|
||||
m_qssFilePath = root["qssFilePath"].toString("themeStyle.css");
|
||||
|
||||
auto readColor = [](const QJsonObject& colors, const QString& colorName) -> QColor {
|
||||
auto colorValue = Json::ensureString(colors, colorName, QString());
|
||||
auto colorValue = colors[colorName].toString();
|
||||
if (!colorValue.isEmpty()) {
|
||||
QColor color(colorValue);
|
||||
if (!color.isValid()) {
|
||||
@@ -222,7 +222,7 @@ bool CustomTheme::read(const QString& path, bool& hasCustomLogColors)
|
||||
|
||||
// fade
|
||||
m_fadeColor = readColor(colorsRoot, "fadeColor");
|
||||
m_fadeAmount = Json::ensureDouble(colorsRoot, "fadeAmount", 0.5, "fade amount");
|
||||
m_fadeAmount = colorsRoot["fadeAmount"].toDouble(0.5);
|
||||
}
|
||||
|
||||
if (root.contains("logColors")) {
|
||||
|
||||
Reference in New Issue
Block a user