diff options
author | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-05-28 11:54:32 -0700 |
---|---|---|
committer | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-07-11 21:42:34 -0700 |
commit | 149bc8e9ce1be5edf93de4a4d63b93129ad321b8 (patch) | |
tree | ea29599b3fa82831fecdcb271bc500a1bceec2c0 /launcher/ui/pages | |
parent | 9957aeb003a28f24a7d3b2bbc46d21c31506615d (diff) | |
download | PrismLauncher-149bc8e9ce1be5edf93de4a4d63b93129ad321b8.tar.gz PrismLauncher-149bc8e9ce1be5edf93de4a4d63b93129ad321b8.tar.bz2 PrismLauncher-149bc8e9ce1be5edf93de4a4d63b93129ad321b8.zip |
cleanup: pull out data object so I'm not repeating myself
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'launcher/ui/pages')
-rw-r--r-- | launcher/ui/pages/modplatform/ImportPage.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/launcher/ui/pages/modplatform/ImportPage.cpp b/launcher/ui/pages/modplatform/ImportPage.cpp index 1e540cf2..67dfbf45 100644 --- a/launcher/ui/pages/modplatform/ImportPage.cpp +++ b/launcher/ui/pages/modplatform/ImportPage.cpp @@ -144,23 +144,24 @@ 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"); // 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(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "fileName"); + auto fileName = Json::ensureString(data, "fileName"); if (fileName.endsWith(".zip")) { // Have to use ensureString then use QUrl to get proper url encoding - auto dl_url = QUrl( - Json::ensureString(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "downloadUrl", "", "downloadUrl")); + auto dl_url = QUrl(Json::ensureString(data, "downloadUrl", "", "downloadUrl")); if (!dl_url.isValid()) { - CustomMessageBox::selectable(this, tr("Error"), tr("The modpack is blocked ! Please download it manually"), - QMessageBox::Critical) + CustomMessageBox::selectable( + this, tr("Error"), + tr("The modpack %1 is blocked for third-parties! Please download it manually.").arg(fileName), + QMessageBox::Critical) ->show(); return; } QFileInfo dl_file(dl_url.fileName()); - QString pack_name = Json::ensureString(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "displayName", - dl_file.completeBaseName(), "displayName"); + QString pack_name = Json::ensureString(data, "displayName", dl_file.completeBaseName(), "displayName"); QMap<QString, QString> extra_info; extra_info.insert("pack_id", addonId); @@ -201,7 +202,7 @@ void ImportPage::setUrl(const QString& url) } void ImportPage::setExtraInfo(const QMap<QString, QString>& extra_info) { - m_extra_info = QMap(extra_info); // copy + m_extra_info = extra_info; updateState(); } |