1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-09-16 20:13:35 +01:00

chainload the forwarder in a more sensible way, refactor

This commit is contained in:
flb 2022-09-27 00:14:13 +02:00
parent 2edf92b5e8
commit f77c64c3ee
11 changed files with 76 additions and 47 deletions

View file

@ -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);
};

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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);

View file

@ -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);

View file

@ -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<std::chrono::seconds>(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 {

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);