From 25dffbf6116ba6e6f129eda9594dd67b08c1cc32 Mon Sep 17 00:00:00 2001 From: flb Date: Wed, 15 Sep 2021 17:23:37 +0200 Subject: [PATCH] Download all the links at once --- include/ams_tab.hpp | 4 ++-- include/constants.hpp | 4 +++- include/dialogue_page.hpp | 1 - include/download_payload_page.hpp | 3 ++- include/list_download_tab.hpp | 3 ++- include/tools_tab.hpp | 2 +- source/ams_tab.cpp | 15 ++++++++------- source/app_page.cpp | 1 - source/dialogue_page.cpp | 1 - source/download_payload_page.cpp | 4 ++-- source/list_download_tab.cpp | 12 +++--------- source/main_frame.cpp | 13 ++++++++----- source/tools_tab.cpp | 6 +++--- source/utils.cpp | 6 +++--- 14 files changed, 37 insertions(+), 38 deletions(-) diff --git a/include/ams_tab.hpp b/include/ams_tab.hpp index 434f69f..8337eec 100644 --- a/include/ams_tab.hpp +++ b/include/ams_tab.hpp @@ -11,7 +11,7 @@ private: brls::Label* description; int size = 0; bool erista; - nlohmann::ordered_json cfws = {}; + nlohmann::ordered_json hekate; std::string GetRepoName(const std::string& repo); std::set GetLastDownloadedModules(const std::string& json_path); void CreateStagedFrames(const std::string& text, const std::string& url, const std::string& operation, bool erista, bool hekate = false, const std::string& text_hekate = "", const std::string& hekate_url = ""); @@ -20,7 +20,7 @@ private: void ShowCustomDeepseaBuilder(nlohmann::ordered_json& modules); public: - AmsTab(const bool erista = true, const bool hideStandardEntries = false); + AmsTab(const nlohmann::json& nxlinks, const bool erista = true, const bool hideStandardEntries = false); brls::View* getDefaultFocus() override; }; diff --git a/include/constants.hpp b/include/constants.hpp index 2f33fba..0be044a 100644 --- a/include/constants.hpp +++ b/include/constants.hpp @@ -15,6 +15,8 @@ constexpr const char APP_URL[] = "https://github.com/HamletDuFromage/aio-switch- constexpr const char TAGS_INFO[] = "https://api.github.com/repos/HamletDuFromage/aio-switch-updater/releases/latest"; constexpr const char APP_FILENAME[] = "/config/aio-switch-updater/app.zip"; +constexpr const char NXLINKS_URL[] = "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/nx-links.json"; + constexpr const char SIGPATCHES_URL[] = "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/sigpatches.json"; constexpr const char SIGPATCHES_FILENAME[] = "/config/aio-switch-updater/sigpatches.zip"; constexpr const char HEKATE_IPL_PATH[] = "/bootloader/hekate_ipl.ini"; @@ -107,7 +109,7 @@ enum class archiveType cheats, fw, app, - cfw, + bootloaders, ams_cfw, }; diff --git a/include/dialogue_page.hpp b/include/dialogue_page.hpp index 5b3e180..52112d2 100644 --- a/include/dialogue_page.hpp +++ b/include/dialogue_page.hpp @@ -2,7 +2,6 @@ #include #include -#include class DialoguePage : public brls::View { diff --git a/include/download_payload_page.hpp b/include/download_payload_page.hpp index b7cb18c..6615bb1 100644 --- a/include/download_payload_page.hpp +++ b/include/download_payload_page.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include class DownloadPayloadPage : public brls::AppletFrame { @@ -11,5 +12,5 @@ private: brls::ListItem* listItem; public: - DownloadPayloadPage(); + DownloadPayloadPage(const nlohmann::ordered_json& payloads); }; \ No newline at end of file diff --git a/include/list_download_tab.hpp b/include/list_download_tab.hpp index 1e1eb33..a1eec3a 100644 --- a/include/list_download_tab.hpp +++ b/include/list_download_tab.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "constants.hpp" @@ -18,6 +19,6 @@ private: void creategbatempItem(); public: - ListDownloadTab(const archiveType type); + ListDownloadTab(const archiveType type, const nlohmann::ordered_json& nxlinks = nlohmann::ordered_json::object()); brls::View* getDefaultFocus() override; }; \ No newline at end of file diff --git a/include/tools_tab.hpp b/include/tools_tab.hpp index ae2721f..d3d8e68 100644 --- a/include/tools_tab.hpp +++ b/include/tools_tab.hpp @@ -25,5 +25,5 @@ private: brls::StagedAppletFrame* stagedFrame; public: - ToolsTab(const std::string& tag, bool erista = true, const nlohmann::json& hideStatus = {}); + ToolsTab(const std::string& tag, const nlohmann::ordered_json& payloads, bool erista = true, const nlohmann::json& hideStatus = {}); }; \ No newline at end of file diff --git a/source/ams_tab.cpp b/source/ams_tab.cpp index e0cc117..8060c6d 100644 --- a/source/ams_tab.cpp +++ b/source/ams_tab.cpp @@ -15,15 +15,16 @@ namespace i18n = brls::i18n; using namespace i18n::literals; -AmsTab::AmsTab(const bool erista, const bool hideStandardEntries) : brls::List() +AmsTab::AmsTab(const nlohmann::json& nxlinks, const bool erista, const bool hideStandardEntries) : brls::List() { this->erista = erista; - download::getRequest(AMS_URL, cfws); + this->hekate = nxlinks["hekate"]; + auto cfws = 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() ? cfws.at("Atmosphere") : nlohmann::ordered_json::object()); + CreateDownloadItems(cfws.find("Atmosphere") != cfws.end() ? (nlohmann::ordered_json) cfws.at("Atmosphere") : nlohmann::ordered_json::object()); description = new brls::Label( brls::LabelStyle::DESCRIPTION, @@ -40,7 +41,7 @@ AmsTab::AmsTab(const bool erista, const bool hideStandardEntries) : brls::List() }); this->addView(listItem); - CreateDownloadItems(cfws.find("DeepSea") != cfws.end() ? cfws.at("DeepSea") : nlohmann::ordered_json::object()); + CreateDownloadItems(cfws.find("DeepSea") != cfws.end() ? (nlohmann::ordered_json) cfws.at("DeepSea") : nlohmann::ordered_json::object()); } auto custom_pack = fs::parseJsonFile(CUSTOM_PACKS_PATH); @@ -61,7 +62,7 @@ void AmsTab::CreateDownloadItems(const nlohmann::ordered_json& cfw_links, bool h std::vector> links; links = download::getLinksFromJson(cfw_links); if (links.size()) { - auto hekate_link = download::getLinks(HEKATE_URL); + auto hekate_link = download::getLinksFromJson(this->hekate); std::string hekate_url = hekate_link[0].second; std::string text_hekate = "menus/common/download"_i18n + hekate_link[0].first; @@ -106,9 +107,9 @@ void AmsTab::CreateStagedFrames(const std::string& text, const std::string& url, stagedFrame->addStage( new DialoguePage_ams(stagedFrame, text_hekate, erista)); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [hekate_url]() { util::downloadArchive(hekate_url, archiveType::cfw); })); + new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [hekate_url]() { util::downloadArchive(hekate_url, archiveType::bootloaders); })); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(archiveType::cfw); })); + new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(archiveType::bootloaders); })); } stagedFrame->addStage( new ConfirmPage(stagedFrame, "menus/ams_update/reboot_rcm"_i18n, false, true, erista)); diff --git a/source/app_page.cpp b/source/app_page.cpp index ca18526..80be6f5 100644 --- a/source/app_page.cpp +++ b/source/app_page.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include "confirm_page.hpp" diff --git a/source/dialogue_page.cpp b/source/dialogue_page.cpp index d2b950f..f8ef68f 100644 --- a/source/dialogue_page.cpp +++ b/source/dialogue_page.cpp @@ -2,7 +2,6 @@ #include #include -#include #include "fs.hpp" #include "main_frame.hpp" diff --git a/source/download_payload_page.cpp b/source/download_payload_page.cpp index e59e1ff..2ed49d2 100644 --- a/source/download_payload_page.cpp +++ b/source/download_payload_page.cpp @@ -8,7 +8,7 @@ namespace i18n = brls::i18n; using namespace i18n::literals; -DownloadPayloadPage::DownloadPayloadPage() : AppletFrame(true, true) +DownloadPayloadPage::DownloadPayloadPage(const nlohmann::ordered_json& payloads) : AppletFrame(true, true) { this->setTitle("menus/payloads/dl_payloads"_i18n); list = new brls::List(); @@ -18,7 +18,7 @@ DownloadPayloadPage::DownloadPayloadPage() : AppletFrame(true, true) true); list->addView(label); - auto links = download::getLinks(PAYLOAD_URL); + auto links = download::getLinksFromJson(payloads); if (links.size()) { for (const auto& link : links) { std::string url = link.second; diff --git a/source/list_download_tab.cpp b/source/list_download_tab.cpp index 3f08744..ee7b541 100644 --- a/source/list_download_tab.cpp +++ b/source/list_download_tab.cpp @@ -17,10 +17,10 @@ namespace i18n = brls::i18n; using namespace i18n::literals; -ListDownloadTab::ListDownloadTab(const archiveType type) : brls::List() +ListDownloadTab::ListDownloadTab(const archiveType type, const nlohmann::ordered_json& nxlinks) : brls::List() { //std::vector> links, sxoslinks; - std::vector> links; + std::vector> links = download::getLinksFromJson(nxlinks); std::string operation("menus/main/getting"_i18n); std::string firmwareText("menus/main/firmware_text"_i18n); @@ -30,13 +30,11 @@ ListDownloadTab::ListDownloadTab(const archiveType type) : brls::List() this->description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true); switch (type) { case archiveType::sigpatches: - links = download::getLinks(SIGPATCHES_URL); operation += "menus/main/sigpatches"_i18n; this->description->setText( "menus/main/sigpatches_text"_i18n); break; case archiveType::fw: - links = download::getLinks(FIRMWARE_URL); operation += "menus/main/firmware"_i18n; SetSysFirmwareVersion ver; if (R_SUCCEEDED(setsysGetFirmwareVersion(&ver))) @@ -49,11 +47,7 @@ ListDownloadTab::ListDownloadTab(const archiveType type) : brls::List() links.push_back(std::make_pair("menus/main/latest_cheats"_i18n, APP_URL)); operation += "menus/main/app"_i18n; break; - case archiveType::cfw: - links = download::getLinks(CFW_URL); - // sxos is dead anyways - /* sxoslinks = download::getLinks(SXOS_URL); - links.insert(links.end(), sxoslinks.begin(), sxoslinks.end()); */ + case archiveType::bootloaders: operation += "menus/main/cfw"_i18n; this->description->setText( "menus/main/bootloaders_text"_i18n); diff --git a/source/main_frame.cpp b/source/main_frame.cpp index 913226d..2590c0d 100644 --- a/source/main_frame.cpp +++ b/source/main_frame.cpp @@ -5,6 +5,7 @@ #include "about_tab.hpp" #include "ams_tab.hpp" +#include "download.hpp" #include "fs.hpp" #include "list_download_tab.hpp" #include "tools_tab.hpp" @@ -31,6 +32,8 @@ MainFrame::MainFrame() : TabFrame() R_SUCCEEDED(fs::getFreeStorageSD(freeStorage)) ? (float)freeStorage / 0x40000000 : -1)); json hideStatus = fs::parseJsonFile(HIDE_TABS_JSON); + nlohmann::ordered_json nxlinks; + download::getRequest(NXLINKS_URL, nxlinks); bool erista = util::isErista(); @@ -38,22 +41,22 @@ MainFrame::MainFrame() : TabFrame() this->addTab("menus/main/about"_i18n, new AboutTab()); if (!util::getBoolValue(hideStatus, "atmosphere")) - this->addTab("menus/main/update_ams"_i18n, new AmsTab(erista, util::getBoolValue(hideStatus, "atmosphereentries"))); + 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::cfw)); + this->addTab("menus/main/update_bootloaders"_i18n, new ListDownloadTab(archiveType::bootloaders, nxlinks["bootloaders"])); if (!util::getBoolValue(hideStatus, "sigpatches")) - this->addTab("menus/main/update_sigpatches"_i18n, new ListDownloadTab(archiveType::sigpatches)); + this->addTab("menus/main/update_sigpatches"_i18n, new ListDownloadTab(archiveType::sigpatches, nxlinks["sigpatches"])); if (!util::getBoolValue(hideStatus, "firmwares")) - this->addTab("menus/main/download_firmware"_i18n, new ListDownloadTab(archiveType::fw)); + this->addTab("menus/main/download_firmware"_i18n, new ListDownloadTab(archiveType::fw, 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, erista, hideStatus)); + this->addTab("menus/main/tools"_i18n, new ToolsTab(tag, nxlinks["payloads"], erista, hideStatus)); this->registerAction("", brls::Key::B, [this] { return true; }); } diff --git a/source/tools_tab.cpp b/source/tools_tab.cpp index 1a1c553..1e4a643 100644 --- a/source/tools_tab.cpp +++ b/source/tools_tab.cpp @@ -25,7 +25,7 @@ namespace { constexpr const char AppVersion[] = APP_VERSION; } -ToolsTab::ToolsTab(const std::string& tag, bool erista, const nlohmann::json& hideStatus) : brls::List() +ToolsTab::ToolsTab(const std::string& tag, const nlohmann::ordered_json& payloads, bool erista, const nlohmann::json& hideStatus) : brls::List() { if (!tag.empty() && tag != AppVersion) { updateApp = new brls::ListItem("menus/tools/update_app"_i18n + tag + ")"); @@ -66,8 +66,8 @@ ToolsTab::ToolsTab(const std::string& tag, bool erista, const nlohmann::json& hi PCcolor->setHeight(LISTITEM_HEIGHT); downloadPayload = new brls::ListItem("menus/tools/dl_payloads"_i18n + std::string(BOOTLOADER_PL_PATH)); - downloadPayload->getClickEvent()->subscribe([&](brls::View* view) { - brls::Application::pushView(new DownloadPayloadPage()); + downloadPayload->getClickEvent()->subscribe([&, payloads](brls::View* view) { + brls::Application::pushView(new DownloadPayloadPage(payloads)); }); downloadPayload->setHeight(LISTITEM_HEIGHT); diff --git a/source/utils.cpp b/source/utils.cpp index 19dc984..e630f7b 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -52,7 +52,7 @@ namespace util { case archiveType::app: status_code = download::downloadFile(url, APP_FILENAME, OFF); break; - case archiveType::cfw: + case archiveType::bootloaders: status_code = download::downloadFile(url, CFW_FILENAME, OFF); break; case archiveType::ams_cfw: @@ -151,7 +151,7 @@ namespace util { romfsExit(); brls::Application::quit(); break; - case archiveType::cfw: + case archiveType::bootloaders: if (isArchive(CFW_FILENAME)) { overwriteInis = showDialogBox("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); extract::extract(CFW_FILENAME, ROOT_PATH, overwriteInis); @@ -171,7 +171,7 @@ namespace util { } break; } - if (type == archiveType::ams_cfw || type == archiveType::cfw) + if (type == archiveType::ams_cfw || type == archiveType::bootloaders) fs::copyFiles(COPY_FILES_TXT); }