From cb6b78c11caa2c021b83e3b7b1d0cfb42127f23c Mon Sep 17 00:00:00 2001 From: flb Date: Thu, 21 Oct 2021 23:12:29 +0200 Subject: [PATCH] add a prompt asking about replacing reboot_payload.bin by hekate (closes https://github.com/HamletDuFromage/aio-switch-updater/issues/153) --- include/extract.hpp | 5 ++-- include/list_download_tab.hpp | 4 +-- resources/i18n/en-US/menus.json | 4 ++- source/extract.cpp | 39 +++++------------------------ source/list_download_tab.cpp | 44 +++++++++++++++++++-------------- 5 files changed, 39 insertions(+), 57 deletions(-) diff --git a/include/extract.hpp b/include/extract.hpp index 6559605..19f44d8 100644 --- a/include/extract.hpp +++ b/include/extract.hpp @@ -2,6 +2,7 @@ #include +#include #include #include #include @@ -25,8 +26,8 @@ namespace extract { } } Title; - void extract(const std::string& filename, const std::string& workingPath = ROOT_PATH, int overwriteInis = 1); - void extract(const std::string& filename, const std::string& workingPath, const std::string& toExclude); + void extract( + const std::string& filename, const std::string& workingPath = ROOT_PATH, int overwriteInis = 1, std::function func = []() { return; }); std::vector getInstalledTitlesNs(); std::vector excludeTitles(const std::string& path, const std::vector& listedTitles); void writeTitlesToFile(const std::set& titles, const std::string& path); diff --git a/include/list_download_tab.hpp b/include/list_download_tab.hpp index 8cb43f5..a4c03cf 100644 --- a/include/list_download_tab.hpp +++ b/include/list_download_tab.hpp @@ -9,17 +9,17 @@ class ListDownloadTab : public brls::List { private: brls::ListItem* listItem; - brls::ListItem* cheatslipsItem; - brls::ListItem* gbatempItem; nlohmann::ordered_json nxlinks; std::string currentCheatsVer = ""; std::string newCheatsVer = ""; contentType type; int size = 0; + void createList(); void createList(contentType type); void createCheatSlipItem(); void creategbatempItem(); void setDescription(); + void setDescription(contentType type); void displayNotFound(); public: diff --git a/resources/i18n/en-US/menus.json b/resources/i18n/en-US/menus.json index 7c861b6..c54466f 100644 --- a/resources/i18n/en-US/menus.json +++ b/resources/i18n/en-US/menus.json @@ -165,7 +165,9 @@ "fw_warning": "Because of the size of the FW archive, downloading firmwares in Applet Mode is not supported. Please launch the app with full RAM access.", "overwrite": " Do you want to overwrite existing ", "not_an_archive": "The downloaded file is not a zip archive. This is most likely due to a broken link. If the problem persists after more than 30 minutes, please open an issue on Github.", - "overwrite_inis": "Do you want to overwrite existing .ini config files?" + "overwrite_inis": "Do you want to overwrite existing .ini config files?", + "set_hekate_reboot_payload": "Do you want to copy the Hekate payload `{}` to `{}`?" + }, "ams_update": { "reboot_rcm": "The Switch will now reboot to a special payload in order to finalise the install.", diff --git a/source/extract.cpp b/source/extract.cpp index 5239a7f..dbcba49 100644 --- a/source/extract.cpp +++ b/source/extract.cpp @@ -47,12 +47,12 @@ namespace extract { brls::Application::quit(); } } - ProgressEvent::instance().setStep(1); ProgressEvent::instance().setTotalSteps(entries.size() + 1); + ProgressEvent::instance().setStep(0); } } // namespace - void extract(const std::string& filename, const std::string& workingPath, int overwriteInis) + void extract(const std::string& filename, const std::string& workingPath, int overwriteInis, std::function func) { zipper::Unzipper unzipper(filename); std::vector entries; @@ -71,7 +71,7 @@ namespace extract { unzipper.extractEntry(entry.name); } } - else if (entry.name == "sept/payload.bin" || entry.name == "atmosphere/fusee-secondary.bin" || entry.name == "atmosphere/stratosphere.romfs" || entry.name == "atmosphere/package3") { + else if (entry.name == "atmosphere/stratosphere.romfs" || entry.name == "atmosphere/package3") { std::ofstream readonlyFile(entry.name + ".aio"); unzipper.extractEntryToStream(entry.name, readonlyFile); } @@ -79,7 +79,9 @@ namespace extract { unzipper.extractEntry(entry.name); if (entry.name.substr(0, 13) == "hekate_ctcaer") { fs::copyFile("/" + entry.name, UPDATE_BIN_PATH); - fs::copyFile("/" + entry.name, REBOOT_PAYLOAD_PATH); + if (util::showDialogBox(fmt::format("menus/utils/set_hekate_reboot_payload"_i18n, UPDATE_BIN_PATH, REBOOT_PAYLOAD_PATH), "menus/common/yes"_i18n, "menus/common/no"_i18n) == 0) { + fs::copyFile(UPDATE_BIN_PATH, REBOOT_PAYLOAD_PATH); + } } } ProgressEvent::instance().incrementStep(1); @@ -88,35 +90,6 @@ namespace extract { ProgressEvent::instance().setStep(ProgressEvent::instance().getMax()); } - void extract(const std::string& filename, const std::string& workingPath, const std::string& toExclude) - { - zipper::Unzipper unzipper(filename); - std::vector entries; - preWork(unzipper, workingPath, entries); - - std::set ignoreList = fs::readLineByLine(FILES_IGNORE); - ignoreList.insert(toExclude); - - for (const auto& entry : entries) { - if (ProgressEvent::instance().getInterupt()) { - break; - } - if (find_if(ignoreList.begin(), ignoreList.end(), [&entry](std::string ignored) { - u8 res = ("/" + entry.name).find(ignored); - return (res == 0 || res == 1); }) != ignoreList.end()) { - if (!std::filesystem::exists("/" + entry.name)) { - unzipper.extractEntry(entry.name); - } - } - else { - unzipper.extractEntry(entry.name); - } - ProgressEvent::instance().incrementStep(1); - } - unzipper.close(); - ProgressEvent::instance().setStep(ProgressEvent::instance().getMax()); - } - std::vector getInstalledTitlesNs() { std::vector titles; diff --git a/source/list_download_tab.cpp b/source/list_download_tab.cpp index 889b91d..7697ab0 100644 --- a/source/list_download_tab.cpp +++ b/source/list_download_tab.cpp @@ -21,7 +21,7 @@ ListDownloadTab::ListDownloadTab(const contentType type, const nlohmann::ordered { this->setDescription(); - this->createList(this->type); + this->createList(); if (this->type == contentType::cheats) { brls::Label* cheatsLabel = new brls::Label( @@ -29,24 +29,24 @@ ListDownloadTab::ListDownloadTab(const contentType type, const nlohmann::ordered "menus/cheats/cheats_label"_i18n, true); this->addView(cheatsLabel); - creategbatempItem(); - createCheatSlipItem(); + this->creategbatempItem(); + this->createCheatSlipItem(); } if (this->type == contentType::bootloaders) { - brls::Label* payloadsLabel = new brls::Label( - brls::LabelStyle::DESCRIPTION, - fmt::format("menus/main/payloads_label"_i18n, BOOTLOADER_PL_PATH), - true); - this->addView(payloadsLabel); - createList(contentType::payloads); + this->setDescription(contentType::payloads); + this->createList(contentType::payloads); } } +void ListDownloadTab::createList() { + ListDownloadTab::createList(this->type); +} + void ListDownloadTab::createList(contentType type) { std::vector> links; - if (this->type == contentType::cheats && this->newCheatsVer != "") + if (type == contentType::cheats && this->newCheatsVer != "") links.push_back(std::make_pair(fmt::format("{}{})", "menus/main/get_cheats"_i18n, this->newCheatsVer), CurrentCfw::running_cfw == CFW::sxos ? CHEATS_URL_TITLES : CHEATS_URL_CONTENTS)); else links = download::getLinksFromJson(util::getValueFromKey(this->nxlinks, contentTypeNames[(int)type].data())); @@ -58,15 +58,15 @@ void ListDownloadTab::createList(contentType type) const std::string text("menus/common/download"_i18n + link.first + "menus/common/from"_i18n + url); listItem = new brls::ListItem(link.first); listItem->setHeight(LISTITEM_HEIGHT); - listItem->getClickEvent()->subscribe([this, text, url, title, type](brls::View* view) { + listItem->getClickEvent()->subscribe([this, type, text, url, title](brls::View* view) { brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); stagedFrame->setTitle(fmt::format("menus/main/getting"_i18n, contentTypeNames[(int)type].data())); stagedFrame->addStage(new ConfirmPage(stagedFrame, text)); if (type != contentType::payloads) { if (type != contentType::cheats || this->newCheatsVer != this->currentCheatsVer || !std::filesystem::exists(CHEATS_ZIP_PATH)) { - stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [type, url]() { util::downloadArchive(url, type); })); + stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [this, type, url]() { util::downloadArchive(url, type); })); } - stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [type]() { util::extractArchive(type); })); + stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [this, type]() { util::extractArchive(type); })); } else { fs::createTree(BOOTLOADER_PL_PATH); @@ -121,13 +121,17 @@ void ListDownloadTab::displayNotFound() } void ListDownloadTab::setDescription() +{ + this->setDescription(this->type); +} + +void ListDownloadTab::setDescription(contentType type) { brls::Label* description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true); - switch (this->type) { + switch (type) { case contentType::sigpatches: - description->setText( - "menus/main/sigpatches_text"_i18n); + description->setText("menus/main/sigpatches_text"_i18n); break; case contentType::fw: { SetSysFirmwareVersion ver; @@ -139,11 +143,13 @@ void ListDownloadTab::setDescription() "menus/main/bootloaders_text"_i18n); break; case contentType::cheats: - this->newCheatsVer = util::downloadFileToString(CHEATS_URL_VERSION); this->currentCheatsVer = util::readVersion(CHEATS_VERSION); description->setText("menus/main/cheats_text"_i18n + this->currentCheatsVer); break; + case contentType::payloads: + description->setText("menus/main/payloads_label"_i18n); + break; default: break; } @@ -153,7 +159,7 @@ void ListDownloadTab::setDescription() void ListDownloadTab::createCheatSlipItem() { - cheatslipsItem = new brls::ListItem("menus/cheats/get_cheatslips"_i18n); + brls::ListItem* cheatslipsItem = new brls::ListItem("menus/cheats/get_cheatslips"_i18n); cheatslipsItem->setHeight(LISTITEM_HEIGHT); cheatslipsItem->getClickEvent()->subscribe([](brls::View* view) { if (std::filesystem::exists(TOKEN_PATH)) { @@ -196,7 +202,7 @@ void ListDownloadTab::createCheatSlipItem() void ListDownloadTab::creategbatempItem() { - gbatempItem = new brls::ListItem("menus/cheats/get_gbatemp"_i18n); + brls::ListItem* gbatempItem = new brls::ListItem("menus/cheats/get_gbatemp"_i18n); gbatempItem->setHeight(LISTITEM_HEIGHT); gbatempItem->getClickEvent()->subscribe([](brls::View* view) { brls::Application::pushView(new AppPage_Gbatemp());