2020-09-20 01:21:28 +01:00
|
|
|
#include "payload_page.hpp"
|
2021-09-11 14:48:13 +01:00
|
|
|
|
2021-02-10 16:28:47 +00:00
|
|
|
#include "current_cfw.hpp"
|
2021-03-16 14:56:46 +00:00
|
|
|
#include "fs.hpp"
|
2021-09-11 14:48:13 +01:00
|
|
|
#include "utils.hpp"
|
2021-03-16 14:56:46 +00:00
|
|
|
|
2020-10-05 23:53:12 +01:00
|
|
|
namespace i18n = brls::i18n;
|
|
|
|
using namespace i18n::literals;
|
2021-03-16 14:56:46 +00:00
|
|
|
|
2020-09-20 01:21:28 +01:00
|
|
|
PayloadPage::PayloadPage() : AppletFrame(true, true)
|
|
|
|
{
|
2021-10-26 14:48:24 +01:00
|
|
|
this->updateActionHint(brls::Key::B, "");
|
|
|
|
this->updateActionHint(brls::Key::PLUS, "");
|
|
|
|
|
2021-10-27 16:56:29 +01:00
|
|
|
this->list = new brls::List();
|
|
|
|
this->label = new brls::Label(
|
2020-09-20 01:21:28 +01:00
|
|
|
brls::LabelStyle::DESCRIPTION,
|
2021-03-10 20:54:17 +00:00
|
|
|
"menus/payloads/select"_i18n,
|
2021-09-11 14:48:13 +01:00
|
|
|
true);
|
2021-10-27 16:56:29 +01:00
|
|
|
this->list->addView(this->label);
|
2021-03-16 02:04:21 +00:00
|
|
|
std::vector<std::string> payloads = util::fetchPayloads();
|
2021-09-11 14:48:13 +01:00
|
|
|
for (const auto& payload : payloads) {
|
2021-03-16 14:56:46 +00:00
|
|
|
std::string payload_path = payload;
|
2021-10-27 16:56:29 +01:00
|
|
|
this->listItem = new brls::ListItem(payload_path);
|
|
|
|
this->listItem->getClickEvent()->subscribe([payload_path](brls::View* view) {
|
|
|
|
util::rebootToPayload(payload_path);
|
2020-09-20 01:21:28 +01:00
|
|
|
brls::Application::popView();
|
|
|
|
});
|
2021-09-11 14:48:13 +01:00
|
|
|
if (CurrentCfw::running_cfw == CFW::ams) {
|
2021-10-27 16:56:29 +01:00
|
|
|
this->RegisterCopyAction(brls::Key::X, payload_path, REBOOT_PAYLOAD_PATH, "menus/payloads/set_reboot_payload"_i18n);
|
2020-09-23 12:21:05 +01:00
|
|
|
}
|
2021-10-27 16:56:29 +01:00
|
|
|
this->RegisterCopyAction(brls::Key::Y, payload_path, UPDATE_BIN_PATH, "menus/payloads/set_update_bin"_i18n);
|
|
|
|
this->list->addView(this->listItem);
|
2020-09-20 01:21:28 +01:00
|
|
|
}
|
2021-10-27 16:56:29 +01:00
|
|
|
this->list->addView(new brls::ListItemGroupSpacing(true));
|
2020-09-20 01:21:28 +01:00
|
|
|
|
2021-10-27 16:56:29 +01:00
|
|
|
this->listItem = new brls::ListItem("menus/common/shut_down"_i18n);
|
|
|
|
this->listItem->getClickEvent()->subscribe([](brls::View* view) {
|
2021-03-16 14:56:46 +00:00
|
|
|
util::shutDown(false);
|
2020-09-20 01:21:28 +01:00
|
|
|
brls::Application::popView();
|
|
|
|
});
|
2021-10-27 16:56:29 +01:00
|
|
|
this->list->addView(this->listItem);
|
2020-09-20 01:21:28 +01:00
|
|
|
|
2021-10-27 16:56:29 +01:00
|
|
|
this->listItem = new brls::ListItem("menus/common/reboot"_i18n);
|
|
|
|
this->listItem->getClickEvent()->subscribe([](brls::View* view) {
|
2021-03-16 14:56:46 +00:00
|
|
|
util::shutDown(true);
|
2020-09-20 01:21:28 +01:00
|
|
|
brls::Application::popView();
|
|
|
|
});
|
2021-10-27 16:56:29 +01:00
|
|
|
list->addView(this->listItem);
|
2020-09-23 12:21:05 +01:00
|
|
|
|
2020-09-20 01:21:28 +01:00
|
|
|
this->setContentView(list);
|
2021-10-27 16:56:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PayloadPage::RegisterCopyAction(brls::Key key, const std::string& payload_path, const std::string& payload_dest, const std::string& action_name)
|
|
|
|
{
|
|
|
|
this->listItem->registerAction(action_name, key, [payload_path, payload_dest] {
|
|
|
|
std::string res = fs::copyFile(payload_path, payload_dest)
|
|
|
|
? fmt::format("menus/payloads/copy_success"_i18n, payload_path, payload_dest)
|
|
|
|
: "Failed.";
|
2022-03-30 21:23:15 +01:00
|
|
|
util::showDialogBoxInfo(res);
|
2021-10-27 16:56:29 +01:00
|
|
|
return true;
|
|
|
|
});
|
2020-09-20 01:21:28 +01:00
|
|
|
}
|