1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-09 12:01:44 +00:00
AIO-switch-updater/source/payload_page.cpp

76 lines
3 KiB
C++
Raw Normal View History

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
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, "");
2020-09-20 01:21:28 +01:00
list = new brls::List();
label = new brls::Label(
brls::LabelStyle::DESCRIPTION,
2021-03-10 20:54:17 +00:00
"menus/payloads/select"_i18n,
2021-09-11 14:48:13 +01:00
true);
2020-09-20 01:21:28 +01:00
list->addView(label);
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;
listItem = new brls::ListItem(payload_path);
2021-10-03 18:54:09 +01:00
listItem->getClickEvent()->subscribe([payload](brls::View* view) {
2021-05-28 14:51:30 +01:00
util::rebootToPayload(payload);
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-03 18:54:09 +01:00
listItem->registerAction("menus/payloads/set_reboot_payload"_i18n, brls::Key::X, [payload_path] {
std::string res = fs::copyFile(payload_path, REBOOT_PAYLOAD_PATH)
? "menus/payloads/copy_success"_i18n + payload_path + "menus/payloads/to"_i18n + std::string(REBOOT_PAYLOAD_PATH) + "'."
: "Failed.";
brls::Dialog* dialog = new brls::Dialog(res);
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
dialog->close();
};
2021-03-10 20:54:17 +00:00
dialog->addButton("menus/common/ok"_i18n, callback);
dialog->setCancelable(true);
dialog->open();
return true;
});
}
2021-10-03 18:54:09 +01:00
listItem->registerAction("menus/payloads/set_update_bin"_i18n, brls::Key::Y, [payload] {
std::string res = fs::copyFile(payload, UPDATE_BIN_PATH)
? "menus/payloads/copy_success"_i18n + payload + "menus/payloads/to"_i18n + std::string(UPDATE_BIN_PATH) + "'."
: "Failed.";
brls::Dialog* dialog = new brls::Dialog(res);
2021-09-11 14:48:13 +01:00
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
dialog->close();
};
dialog->addButton("menus/common/ok"_i18n, callback);
dialog->setCancelable(true);
dialog->open();
return true;
});
2021-03-15 23:37:38 +00:00
list->addView(listItem);
2020-09-20 01:21:28 +01:00
}
list->addView(new brls::ListItemGroupSpacing(true));
2021-03-10 20:54:17 +00:00
shutDown = new brls::ListItem("menus/common/shut_down"_i18n);
2020-09-20 01:21:28 +01:00
shutDown->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();
});
list->addView(shutDown);
reboot = new brls::ListItem("menus/common/reboot"_i18n);
2020-09-20 01:21:28 +01:00
reboot->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();
});
list->addView(reboot);
2020-09-20 01:21:28 +01:00
this->setContentView(list);
}