From f77c64c3ee7e5c0a8e97e3775b69cf1e074659ec Mon Sep 17 00:00:00 2001 From: flb Date: Tue, 27 Sep 2022 00:14:13 +0200 Subject: [PATCH] chainload the forwarder in a more sensible way, refactor --- include/confirm_page.hpp | 24 ++++++++++-- source/JC_page.cpp | 4 +- source/PC_page.cpp | 4 +- source/ams_tab.cpp | 4 +- source/app_page.cpp | 2 +- source/cheats_page.cpp | 6 +-- source/confirm_page.cpp | 66 ++++++++++++++++++++------------ source/download_payload_page.cpp | 2 +- source/list_download_tab.cpp | 6 +-- source/tools_tab.cpp | 2 +- source/utils.cpp | 3 -- 11 files changed, 76 insertions(+), 47 deletions(-) diff --git a/include/confirm_page.hpp b/include/confirm_page.hpp index cdd55cf..5bcd828 100644 --- a/include/confirm_page.hpp +++ b/include/confirm_page.hpp @@ -5,19 +5,35 @@ class ConfirmPage : public brls::View { -private: +protected: brls::Button* button = nullptr; brls::Label* label = nullptr; std::chrono::system_clock::time_point start = std::chrono::high_resolution_clock::now(); bool done = false; - bool reboot = false; - bool erista = true; public: - ConfirmPage(brls::StagedAppletFrame* frame, const std::string& text, bool done = false, bool reboot = false, bool erista = true); + ConfirmPage(brls::StagedAppletFrame* frame, const std::string& text); ~ConfirmPage(); void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx) override; void layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash) override; brls::View* getDefaultFocus() override; +}; + +class ConfirmPage_Done : public ConfirmPage +{ +public: + ConfirmPage_Done(brls::StagedAppletFrame* frame, const std::string& text); +}; + +class ConfirmPage_AppUpdate : public ConfirmPage_Done +{ +public: + ConfirmPage_AppUpdate(brls::StagedAppletFrame* frame, const std::string& text); +}; + +class ConfirmPage_AmsUpdate : public ConfirmPage_Done +{ +public: + ConfirmPage_AmsUpdate(brls::StagedAppletFrame* frame, const std::string& text, bool erista = true); }; \ No newline at end of file diff --git a/source/JC_page.cpp b/source/JC_page.cpp index 16e144c..3de3546 100644 --- a/source/JC_page.cpp +++ b/source/JC_page.cpp @@ -22,7 +22,7 @@ JCPage::JCPage() : AppletFrame(true, true) new WorkerPage(stagedFrame, "menus/joy_con/backing_up"_i18n, []() { JC::backupJCColor(JC_COLOR_PATH); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); + new ConfirmPage_Done(stagedFrame, "menus/common/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); list->addView(backup); @@ -40,7 +40,7 @@ JCPage::JCPage() : AppletFrame(true, true) new WorkerPage(stagedFrame, "menus/joy_con/changing"_i18n, [value]() { JC::changeJCColor(value); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/joy_con/all_done"_i18n, true)); + new ConfirmPage_Done(stagedFrame, "menus/joy_con/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); list->addView(listItem); diff --git a/source/PC_page.cpp b/source/PC_page.cpp index 17041c5..ca915d2 100644 --- a/source/PC_page.cpp +++ b/source/PC_page.cpp @@ -23,7 +23,7 @@ PCPage::PCPage() : AppletFrame(true, true) new WorkerPage(stagedFrame, "menus/pro_con/backing_up"_i18n, []() { PC::backupPCColor(PC_COLOR_PATH); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); + new ConfirmPage_Done(stagedFrame, "menus/common/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); list->addView(backup); @@ -41,7 +41,7 @@ PCPage::PCPage() : AppletFrame(true, true) new WorkerPage(stagedFrame, "menus/pro_con/changing"_i18n, [value]() { PC::changePCColor(value); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/pro_con/all_done"_i18n, true)); + new ConfirmPage_Done(stagedFrame, "menus/pro_con/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); list->addView(listItem); diff --git a/source/ams_tab.cpp b/source/ams_tab.cpp index 9f5906f..ea9f73f 100644 --- a/source/ams_tab.cpp +++ b/source/ams_tab.cpp @@ -122,9 +122,9 @@ void AmsTab::CreateStagedFrames(const std::string& text, const std::string& url, new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(contentType::bootloaders); })); } if (ams) - stagedFrame->addStage(new ConfirmPage(stagedFrame, "menus/ams_update/reboot_rcm"_i18n, false, true, erista)); + stagedFrame->addStage(new ConfirmPage_AmsUpdate(stagedFrame, "menus/ams_update/reboot_rcm"_i18n, erista)); else - stagedFrame->addStage(new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); + stagedFrame->addStage(new ConfirmPage_Done(stagedFrame, "menus/common/all_done"_i18n)); brls::Application::pushView(stagedFrame); } diff --git a/source/app_page.cpp b/source/app_page.cpp index 233acb1..1d98a65 100644 --- a/source/app_page.cpp +++ b/source/app_page.cpp @@ -102,7 +102,7 @@ void AppPage::CreateDownloadAllButton() stagedFrame->addStage( new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(contentType::cheats); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); + new ConfirmPage_Done(stagedFrame, "menus/common/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); list->addView(download); diff --git a/source/cheats_page.cpp b/source/cheats_page.cpp index 1d7e646..b381ec2 100644 --- a/source/cheats_page.cpp +++ b/source/cheats_page.cpp @@ -36,7 +36,7 @@ CheatsPage::CheatsPage() : AppletFrame(true, true) stagedFrame->addStage( new WorkerPage(stagedFrame, "menus/cheats/deleting"_i18n, []() { extract::removeCheats(); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); + new ConfirmPage_Done(stagedFrame, "menus/common/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); list->addView(item); @@ -48,7 +48,7 @@ CheatsPage::CheatsPage() : AppletFrame(true, true) stagedFrame->addStage( new WorkerPage(stagedFrame, "menus/cheats/deleting"_i18n, []() { extract::removeOrphanedCheats(); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); + new ConfirmPage_Done(stagedFrame, "menus/common/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); list->addView(item); @@ -70,7 +70,7 @@ CheatsPage::CheatsPage() : AppletFrame(true, true) stagedFrame->addStage( new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [cheatsVer]() { extract::extractAllCheats(CHEATS_ZIP_PATH, CurrentCfw::running_cfw, cheatsVer); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); + new ConfirmPage_Done(stagedFrame, "menus/common/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); list->addView(item); diff --git a/source/confirm_page.cpp b/source/confirm_page.cpp index 2c941be..01f5be3 100644 --- a/source/confirm_page.cpp +++ b/source/confirm_page.cpp @@ -10,42 +10,58 @@ namespace i18n = brls::i18n; using namespace i18n::literals; -ConfirmPage::ConfirmPage(brls::StagedAppletFrame* frame, const std::string& text, bool done, bool reboot, bool erista) : done(done), reboot(reboot), erista(erista) +ConfirmPage::ConfirmPage(brls::StagedAppletFrame* frame, const std::string& text) { - this->button = (new brls::Button(brls::ButtonStyle::REGULAR))->setLabel(done ? "menus/common/back"_i18n : "menus/common/continue"_i18n); + this->button = (new brls::Button(brls::ButtonStyle::REGULAR))->setLabel("menus/common/back"_i18n); this->button->setParent(this); this->button->getClickEvent()->subscribe([frame, this](View* view) { - if (!frame->isLastStage()) { + if (!frame->isLastStage()) frame->nextStage(); - } - else if (this->done) { + else brls::Application::pushView(new MainFrame()); - } - else if (this->reboot) { - if (this->erista) { - util::rebootToPayload(RCM_PAYLOAD_PATH); - } - else { - if (std::filesystem::exists(UPDATE_BIN_PATH)) { - fs::copyFile(UPDATE_BIN_PATH, MARIKO_PAYLOAD_PATH_TEMP); - } - else { - fs::copyFile(REBOOT_PAYLOAD_PATH, MARIKO_PAYLOAD_PATH_TEMP); - } - fs::copyFile(RCM_PAYLOAD_PATH, MARIKO_PAYLOAD_PATH); - util::shutDown(true); - } - } }); this->label = new brls::Label(brls::LabelStyle::DIALOG, text, true); this->label->setHorizontalAlign(NVG_ALIGN_CENTER); this->label->setParent(this); - - if (this->done || this->reboot) - this->registerAction("", brls::Key::B, [this] { return true; }); } +ConfirmPage_Done::ConfirmPage_Done(brls::StagedAppletFrame* frame, const std::string& text) : ConfirmPage(frame, text) +{ + this->button->setLabel("menus/common/back"_i18n); + this->done = true; +} + +ConfirmPage_AppUpdate::ConfirmPage_AppUpdate(brls::StagedAppletFrame* frame, const std::string& text) : ConfirmPage_Done(frame, text) +{ + this->button->getClickEvent()->subscribe([](View* view) { + envSetNextLoad(FORWARDER_PATH, fmt::format("\"{}\"", FORWARDER_PATH).c_str()); + romfsExit(); + brls::Application::quit(); + }); + this->registerAction("", brls::Key::B, [this] { return true; }); +} + +ConfirmPage_AmsUpdate::ConfirmPage_AmsUpdate(brls::StagedAppletFrame* frame, const std::string& text, bool erista) : ConfirmPage_Done(frame, text) +{ + this->button->getClickEvent()->subscribe([this, erista](View* view) { + if (erista) { + util::rebootToPayload(RCM_PAYLOAD_PATH); + } + else { + if (std::filesystem::exists(UPDATE_BIN_PATH)) { + fs::copyFile(UPDATE_BIN_PATH, MARIKO_PAYLOAD_PATH_TEMP); + } + else { + fs::copyFile(REBOOT_PAYLOAD_PATH, MARIKO_PAYLOAD_PATH_TEMP); + } + fs::copyFile(RCM_PAYLOAD_PATH, MARIKO_PAYLOAD_PATH); + util::shutDown(true); + } + }); + this->registerAction("", brls::Key::B, [this] { return true; }); +}; + void ConfirmPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx) { if (!this->done) { @@ -53,7 +69,7 @@ void ConfirmPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned he auto missing = std::max(1l - std::chrono::duration_cast(end - start).count(), 0l); auto text = std::string("menus/common/continue"_i18n); if (missing > 0) { - this->button->setLabel(text + " (" + std::to_string(missing) + ")"); + this->button->setLabel(fmt::format("{} ({})", text, missing)); this->button->setState(brls::ButtonState::DISABLED); } else { diff --git a/source/download_payload_page.cpp b/source/download_payload_page.cpp index 07e5863..c57bd2d 100644 --- a/source/download_payload_page.cpp +++ b/source/download_payload_page.cpp @@ -34,7 +34,7 @@ DownloadPayloadPage::DownloadPayloadPage(const nlohmann::ordered_json& payloads) stagedFrame->addStage( new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url, path]() { download::downloadFile(url, path, OFF); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); + new ConfirmPage_Done(stagedFrame, "menus/common/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); list->addView(listItem); diff --git a/source/list_download_tab.cpp b/source/list_download_tab.cpp index 07ff050..c1e2a32 100644 --- a/source/list_download_tab.cpp +++ b/source/list_download_tab.cpp @@ -96,16 +96,16 @@ void ListDownloadTab::createList(contentType type) stagedFrame->addStage(new DialoguePage_fw(stagedFrame, doneMsg)); } else { - stagedFrame->addStage(new ConfirmPage(stagedFrame, doneMsg, true)); + stagedFrame->addStage(new ConfirmPage_Done(stagedFrame, doneMsg)); } break; } case contentType::sigpatches: doneMsg += "\n" + "menus/sigpatches/reboot"_i18n; - stagedFrame->addStage(new ConfirmPage(stagedFrame, doneMsg, true)); + stagedFrame->addStage(new ConfirmPage_Done(stagedFrame, doneMsg)); break; default: - stagedFrame->addStage(new ConfirmPage(stagedFrame, doneMsg, true)); + stagedFrame->addStage(new ConfirmPage_Done(stagedFrame, doneMsg)); break; } brls::Application::pushView(stagedFrame); diff --git a/source/tools_tab.cpp b/source/tools_tab.cpp index a7cc1df..9b1e472 100644 --- a/source/tools_tab.cpp +++ b/source/tools_tab.cpp @@ -40,7 +40,7 @@ ToolsTab::ToolsTab(const std::string& tag, const nlohmann::ordered_json& payload stagedFrame->addStage( new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(contentType::app); })); stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); + new ConfirmPage_AppUpdate(stagedFrame, "menus/common/all_done"_i18n)); brls::Application::pushView(stagedFrame); }); updateApp->setHeight(LISTITEM_HEIGHT); diff --git a/source/utils.cpp b/source/utils.cpp index 6f11911..5af06d0 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -174,9 +174,6 @@ namespace util { case contentType::app: extract::extract(APP_FILENAME, CONFIG_PATH); fs::copyFile(ROMFS_FORWARDER, FORWARDER_PATH); - envSetNextLoad(FORWARDER_PATH, fmt::format("\"{}\"", FORWARDER_PATH).c_str()); - romfsExit(); - brls::Application::quit(); break; case contentType::bootloaders: { int overwriteInis = showDialogBoxBlocking("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n);