From 4a0f8318d7faef4b1fea883fe8154879782143a8 Mon Sep 17 00:00:00 2001 From: flb Date: Wed, 15 Sep 2021 17:50:34 +0200 Subject: [PATCH] fixed crash in airplane mode --- include/utils.hpp | 1 + source/ams_tab.cpp | 8 ++++---- source/main_frame.cpp | 8 ++++---- source/utils.cpp | 5 +++++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/utils.hpp b/include/utils.hpp index b427e1e..259875f 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -46,4 +46,5 @@ namespace util { bool isApplet(); std::string getContentsPath(); bool getBoolValue(const nlohmann::json& jsonFile, const std::string& key); + const nlohmann::ordered_json getValueFromKey(const nlohmann::ordered_json& jsonFile, const std::string& key); } // namespace util \ No newline at end of file diff --git a/source/ams_tab.cpp b/source/ams_tab.cpp index 8060c6d..0f5b944 100644 --- a/source/ams_tab.cpp +++ b/source/ams_tab.cpp @@ -18,13 +18,13 @@ using namespace i18n::literals; AmsTab::AmsTab(const nlohmann::json& nxlinks, const bool erista, const bool hideStandardEntries) : brls::List() { this->erista = erista; - this->hekate = nxlinks["hekate"]; - auto cfws = nxlinks["cfws"]; + this->hekate = util::getValueFromKey(nxlinks, "hekate"); + auto cfws = util::getValueFromKey(nxlinks, "cfws"); if (!hideStandardEntries) { this->description = new brls::Label(brls::LabelStyle::DESCRIPTION, "menus/main/ams_text"_i18n + (CurrentCfw::running_cfw == CFW::ams ? "\n" + "menus/ams_update/current_ams"_i18n + CurrentCfw::getAmsInfo() : "") + (erista ? "\n" + "menus/ams_update/erista_rev"_i18n : "\n" + "menus/ams_update/mariko_rev"_i18n), true); this->addView(description); - CreateDownloadItems(cfws.find("Atmosphere") != cfws.end() ? (nlohmann::ordered_json) cfws.at("Atmosphere") : nlohmann::ordered_json::object()); + CreateDownloadItems(util::getValueFromKey(cfws, "Atmosphere")); description = new brls::Label( brls::LabelStyle::DESCRIPTION, @@ -41,7 +41,7 @@ AmsTab::AmsTab(const nlohmann::json& nxlinks, const bool erista, const bool hide }); this->addView(listItem); - CreateDownloadItems(cfws.find("DeepSea") != cfws.end() ? (nlohmann::ordered_json) cfws.at("DeepSea") : nlohmann::ordered_json::object()); + CreateDownloadItems(util::getValueFromKey(cfws, "DeepSea")); } auto custom_pack = fs::parseJsonFile(CUSTOM_PACKS_PATH); diff --git a/source/main_frame.cpp b/source/main_frame.cpp index 2590c0d..49583ae 100644 --- a/source/main_frame.cpp +++ b/source/main_frame.cpp @@ -44,19 +44,19 @@ MainFrame::MainFrame() : TabFrame() this->addTab("menus/main/update_ams"_i18n, new AmsTab(nxlinks, erista, util::getBoolValue(hideStatus, "atmosphereentries"))); if (!util::getBoolValue(hideStatus, "cfw")) - this->addTab("menus/main/update_bootloaders"_i18n, new ListDownloadTab(archiveType::bootloaders, nxlinks["bootloaders"])); + this->addTab("menus/main/update_bootloaders"_i18n, new ListDownloadTab(archiveType::bootloaders, util::getValueFromKey(nxlinks, "bootloaders"))); if (!util::getBoolValue(hideStatus, "sigpatches")) - this->addTab("menus/main/update_sigpatches"_i18n, new ListDownloadTab(archiveType::sigpatches, nxlinks["sigpatches"])); + this->addTab("menus/main/update_sigpatches"_i18n, new ListDownloadTab(archiveType::sigpatches, util::getValueFromKey(nxlinks, "sigpatches"))); if (!util::getBoolValue(hideStatus, "firmwares")) - this->addTab("menus/main/download_firmware"_i18n, new ListDownloadTab(archiveType::fw, nxlinks["firmwares"])); + this->addTab("menus/main/download_firmware"_i18n, new ListDownloadTab(archiveType::fw, util::getValueFromKey(nxlinks, "firmwares"))); if (!util::getBoolValue(hideStatus, "cheats")) this->addTab("menus/main/download_cheats"_i18n, new ListDownloadTab(archiveType::cheats)); if (!util::getBoolValue(hideStatus, "tools")) - this->addTab("menus/main/tools"_i18n, new ToolsTab(tag, nxlinks["payloads"], erista, hideStatus)); + this->addTab("menus/main/tools"_i18n, new ToolsTab(tag, util::getValueFromKey(nxlinks, "payloads"), erista, hideStatus)); this->registerAction("", brls::Key::B, [this] { return true; }); } diff --git a/source/utils.cpp b/source/utils.cpp index e630f7b..e8f0bf5 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -355,4 +355,9 @@ namespace util { return (jsonFile.find(key) != jsonFile.end()) ? jsonFile.at(key).get() : false; } + const nlohmann::ordered_json getValueFromKey(const nlohmann::ordered_json& jsonFile, const std::string& key) + { + return (jsonFile.find(key) != jsonFile.end()) ? jsonFile.at(key) : nlohmann::ordered_json::object(); + } + } // namespace util \ No newline at end of file