2020-09-20 01:21:28 +01:00
|
|
|
#include "payload_page.hpp"
|
2021-02-10 16:28:47 +00:00
|
|
|
#include "utils.hpp"
|
|
|
|
#include "reboot_payload.h"
|
|
|
|
#include "current_cfw.hpp"
|
|
|
|
#include "utils.hpp"
|
2020-10-05 23:53:12 +01:00
|
|
|
|
|
|
|
namespace i18n = brls::i18n;
|
|
|
|
using namespace i18n::literals;
|
2020-09-20 01:21:28 +01:00
|
|
|
PayloadPage::PayloadPage() : AppletFrame(true, true)
|
|
|
|
{
|
2021-03-10 20:54:17 +00:00
|
|
|
this->setTitle("menus/payloads/reboot_title"_i18n);
|
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,
|
2020-09-20 01:21:28 +01:00
|
|
|
true
|
|
|
|
);
|
|
|
|
list->addView(label);
|
2021-03-16 02:04:21 +00:00
|
|
|
std::vector<std::string> payloads = util::fetchPayloads();
|
2020-09-20 01:21:28 +01:00
|
|
|
int nbPayloads = payloads.size();
|
|
|
|
for (int i = 0; i < nbPayloads; i++){
|
|
|
|
std::string payload = payloads[i];
|
2021-03-15 23:37:38 +00:00
|
|
|
listItem = new brls::ListItem(payload);
|
|
|
|
listItem->getClickEvent()->subscribe([&, payload](brls::View* view) {
|
2020-09-20 01:21:28 +01:00
|
|
|
reboot_to_payload(payload.c_str());
|
|
|
|
brls::Application::popView();
|
|
|
|
});
|
2021-03-16 02:04:21 +00:00
|
|
|
if(CurrentCfw::running_cfw == CFW::ams){
|
2021-03-15 23:37:38 +00:00
|
|
|
listItem->registerAction("menus/payloads/set_reboot_payload"_i18n, brls::Key::X, [this, payload] {
|
2021-01-17 17:26:20 +00:00
|
|
|
std::string res1;
|
2021-03-16 02:04:21 +00:00
|
|
|
if(R_SUCCEEDED(util::CopyFile(payload.c_str(), REBOOT_PAYLOAD_PATH))){
|
2021-03-10 20:54:17 +00:00
|
|
|
res1 += "menus/payloads/copy_success"_i18n + payload + "menus/payloads/to"_i18n + std::string(REBOOT_PAYLOAD_PATH) + "'.";
|
2021-01-17 17:26:20 +00:00
|
|
|
|
2020-09-23 12:21:05 +01:00
|
|
|
}
|
2021-01-17 17:26:20 +00:00
|
|
|
else{
|
|
|
|
res1 += "Failed.";
|
|
|
|
}
|
|
|
|
brls::Dialog* dialog = new brls::Dialog(res1);
|
|
|
|
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);
|
2021-01-17 17:26:20 +00:00
|
|
|
dialog->setCancelable(true);
|
|
|
|
dialog->open();
|
2020-09-23 12:21:05 +01:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
2021-03-15 23:37:38 +00:00
|
|
|
listItem->registerAction("menus/payloads/set_reboot_payload_up"_i18n, brls::Key::Y, [this, payload] {
|
2021-01-17 17:26:20 +00:00
|
|
|
std::string res2;
|
2021-03-16 02:04:21 +00:00
|
|
|
if(R_SUCCEEDED(util::CopyFile(payload.c_str(), UPDATE_BIN_PATH))){
|
2021-03-10 20:54:17 +00:00
|
|
|
res2 += "menus/payloads/copy_success"_i18n + payload + "menus/payloads/to"_i18n + std::string(UPDATE_BIN_PATH) + "'.";
|
2021-01-17 17:26:20 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
res2 += "Failed.";
|
2020-10-05 23:53:12 +01:00
|
|
|
}
|
2021-01-17 17:26:20 +00:00
|
|
|
brls::Dialog* dialog = new brls::Dialog(res2);
|
|
|
|
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);
|
2021-01-17 17:26:20 +00:00
|
|
|
dialog->setCancelable(true);
|
|
|
|
dialog->open();
|
2020-10-05 23:53:12 +01:00
|
|
|
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 02:04:21 +00:00
|
|
|
util::shut_down(false);
|
2020-09-20 01:21:28 +01:00
|
|
|
brls::Application::popView();
|
|
|
|
});
|
|
|
|
list->addView(shutDown);
|
|
|
|
|
2021-03-10 20:54:17 +00:00
|
|
|
reboot = new brls::ListItem("menus/payloads/reboot"_i18n);
|
2020-09-20 01:21:28 +01:00
|
|
|
reboot->getClickEvent()->subscribe([](brls::View* view) {
|
2021-03-16 02:04:21 +00:00
|
|
|
util::shut_down(true);
|
2020-09-20 01:21:28 +01:00
|
|
|
brls::Application::popView();
|
|
|
|
});
|
|
|
|
list->addView(reboot);
|
2020-09-23 12:21:05 +01:00
|
|
|
|
2020-09-20 01:21:28 +01:00
|
|
|
this->setContentView(list);
|
|
|
|
|
|
|
|
}
|