From 9ea2a52be75e7d7b278a645a9017ce298b0c5818 Mon Sep 17 00:00:00 2001 From: flb Date: Wed, 7 Jul 2021 16:59:52 +0200 Subject: [PATCH] Support for Team Neptune's pack builder --- Makefile | 2 +- include/ams_tab.hpp | 1 + include/constants.hpp | 4 ++ source/ams_tab.cpp | 91 +++++++++++++++++++++++++++++++++++++++ source/changelog_page.cpp | 3 ++ source/confirm_page.cpp | 2 +- 6 files changed, 101 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6a57ef5..7a45181 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ DATA := data INCLUDES := include lib/zipper/include /lib/borealis/library/include/borealis/extern/nlohmann APP_TITLE := All-in-One Switch Updater APP_AUTHOR := HamletDuFromage -APP_VERSION := 2.8.0 +APP_VERSION := 2.9.0 TARGET := $(notdir $(CURDIR)) ROMFS := resources diff --git a/include/ams_tab.hpp b/include/ams_tab.hpp index bf620f6..c810189 100644 --- a/include/ams_tab.hpp +++ b/include/ams_tab.hpp @@ -17,6 +17,7 @@ class AmsTab : public brls::List 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 = ""); void CreateDownloadItems(const std::string& key, bool hekate = true); nlohmann::ordered_json SortDeepseaModules(const nlohmann::ordered_json& modules); + void ShowCustomDeepseaBuilder(nlohmann::ordered_json& modules); public: AmsTab(const bool erista = true); diff --git a/include/constants.hpp b/include/constants.hpp index 9b0e05d..c702402 100644 --- a/include/constants.hpp +++ b/include/constants.hpp @@ -34,6 +34,10 @@ constexpr const char HEKATE_URL[] = "https://raw.githubusercontent.com/H constexpr const char PAYLOAD_URL[] = "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/payloads.json"; +constexpr const char DEEPSEA_META_JSON[] = "https://builder.teamneptune.net/meta.json"; +constexpr const char DEEPSEA_BUILD_URL[] = "https://builder.teamneptune.net/build/"; +constexpr const char DEEPSEA_PACKAGE_PATH[] = "/config/deepsea/customPackage.json"; + constexpr const char CHEATS_RELEASE_URL[] = "https://github.com/HamletDuFromage/switch-cheats-db/releases/tag/v1.0"; constexpr const char CHEATS_URL_TITLES[] = "https://github.com/HamletDuFromage/switch-cheats-db/releases/download/v1.0/titles.zip"; constexpr const char CHEATS_URL_CONTENTS[] ="https://github.com/HamletDuFromage/switch-cheats-db/releases/download/v1.0/contents.zip"; diff --git a/source/ams_tab.cpp b/source/ams_tab.cpp index c68af0c..6d0e21b 100644 --- a/source/ams_tab.cpp +++ b/source/ams_tab.cpp @@ -29,6 +29,15 @@ AmsTab::AmsTab(const bool erista) : brls::List() ); this->addView(description); + listItem = new brls::ListItem("menus/ams_update/get_custom_deepsea"_i18n); + listItem->setHeight(LISTITEM_HEIGHT); + listItem->getClickEvent()->subscribe([&](brls::View* view) { + nlohmann::ordered_json modules; + download::getRequest(DEEPSEA_META_JSON, modules); + ShowCustomDeepseaBuilder(modules); + }); + this->addView(listItem); + CreateDownloadItems("DeepSea", false); } @@ -123,6 +132,88 @@ nlohmann::ordered_json AmsTab::SortDeepseaModules(const nlohmann::ordered_json& return sorted_modules; } +void AmsTab::ShowCustomDeepseaBuilder(nlohmann::ordered_json& modules) +{ + modules = SortDeepseaModules(modules); + std::map name_map; + + brls::TabFrame* appView = new brls::TabFrame(); + appView->setIcon("romfs:/deepsea_icon.png"); + + std::vector lists; + std::set old_modules = GetLastDownloadedModules(DEEPSEA_PACKAGE_PATH); + + brls::ToggleListItem* deepseaListItem; + for (const auto& category : modules.items()) { + brls::List* list = new brls::List(); + + for (const auto& module : category.value().items()) { + auto module_value = module.value(); + std::string requirements = ""; + if(!module_value["requires"].empty()) { + requirements = "menus/ams_update/depends_on"_i18n; + for (const auto& r : module.value()["requires"]) { + requirements += " " + r.get() + ","; + } + requirements.pop_back(); + } + if(module_value["required"]) { + deepseaListItem = new UnTogglableListItem(module_value["displayName"], 1, requirements, "Required", "o"); + } + else { + deepseaListItem = new::brls::ToggleListItem(module_value["displayName"], + old_modules.find(module.key()) != old_modules.end() ? 1 : 0, + requirements, + "menus/common/selected"_i18n, + "menus/common/off"_i18n + ); + } + name_map.insert(std::pair(module_value["displayName"], module.key())); + deepseaListItem->registerAction("menus/ams_update/show_module_description"_i18n, brls::Key::Y, [this, module_value] { + brls::Dialog* dialog; + dialog = new brls::Dialog(fmt::format("{}:\n{}", module_value["repo"], module_value["description"])); + brls::GenericEvent::Callback callback = [dialog](brls::View* view) { + dialog->close(); + }; + dialog->addButton("menus/common/ok"_i18n, callback); + dialog->setCancelable(true); + dialog->open(); + return true; + }); + list->addView(deepseaListItem); + } + lists.push_back(list); + appView->addTab(category.key(), list); + } + + appView->registerAction("menus/ams_update/download_deepsea_package"_i18n, brls::Key::X, [this, lists, name_map] { + std::set desired_modules; + for (const auto& list: lists) { + for (size_t i = 0; i < list->getViewsCount(); i++) { + if(brls::ToggleListItem* item = dynamic_cast(list->getChild(i))) { + if (item->getToggleState()) { + desired_modules.insert(name_map.at(item->getLabel())); + } + } + } + } + + std::string request_url = DEEPSEA_BUILD_URL; + for(const auto& e : desired_modules) + request_url += e +";"; + + CreateStagedFrames("menus/common/download"_i18n + "Custom DeepSea package" + "menus/common/from"_i18n + request_url, + request_url, + "menus/ams_update/get_custom_deepsea"_i18n, + erista + ); + return true; + }); + appView->registerAction("", brls::Key::PLUS, [this] { return true; }); + + brls::PopupFrame::open("menus/ams_update/deepsea_builder"_i18n, appView, modules.empty() ? "menus/ams_update/cant_fetch_deepsea"_i18n : "menus/ams_update/build_your_deepsea"_i18n, ""); +} + bool UnTogglableListItem::onClick() { return true; diff --git a/source/changelog_page.cpp b/source/changelog_page.cpp index 4acb5b5..7514c49 100644 --- a/source/changelog_page.cpp +++ b/source/changelog_page.cpp @@ -169,6 +169,9 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true) verTitles.push_back("v2.8.0"); changes.push_back("\uE016 Restored and improved \"View installed cheats\" menu. You can now browse the content of your cheatsheets from the app."); + verTitles.push_back("v2.9.0"); + changes.push_back("\uE016 Added support for Team-Neptune's custom pack builder."); + for(int i = verTitles.size() -1 ; i >= 0; i--){ listItem = new brls::ListItem(verTitles[i]); change = changes[i]; diff --git a/source/confirm_page.cpp b/source/confirm_page.cpp index 7959a7a..d0dd537 100644 --- a/source/confirm_page.cpp +++ b/source/confirm_page.cpp @@ -41,7 +41,7 @@ ConfirmPage::ConfirmPage(brls::StagedAppletFrame* frame, std::string text, bool this->label->setHorizontalAlign(NVG_ALIGN_CENTER); this->label->setParent(this); - if(this->done) + if(this->done || this->reboot) this->registerAction("", brls::Key::B, [this] { return true; }); }