2020-09-20 01:21:28 +01:00
|
|
|
#include "payload_page.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)
|
|
|
|
{
|
2020-09-23 12:21:05 +01:00
|
|
|
CFW cfw = getCFW();
|
2020-10-05 23:53:12 +01:00
|
|
|
this->setTitle("menus/payload_reboot"_i18n );
|
2020-09-20 01:21:28 +01:00
|
|
|
list = new brls::List();
|
|
|
|
label = new brls::Label(
|
|
|
|
brls::LabelStyle::DESCRIPTION,
|
2020-10-05 23:53:12 +01:00
|
|
|
"menus/payload_select"_i18n ,
|
2020-09-20 01:21:28 +01:00
|
|
|
true
|
|
|
|
);
|
|
|
|
list->addView(label);
|
|
|
|
std::vector<std::string> payloads = fetchPayloads();
|
|
|
|
int nbPayloads = payloads.size();
|
|
|
|
items.reserve(nbPayloads);
|
|
|
|
for (int i = 0; i < nbPayloads; i++){
|
|
|
|
std::string payload = payloads[i];
|
|
|
|
items[i] = new brls::ListItem(payload);
|
|
|
|
items[i]->getClickEvent()->subscribe([&, payload](brls::View* view) {
|
|
|
|
reboot_to_payload(payload.c_str());
|
|
|
|
brls::Application::popView();
|
|
|
|
});
|
2020-09-23 12:21:05 +01:00
|
|
|
if(cfw == ams){
|
2020-10-05 23:53:12 +01:00
|
|
|
items[i]->registerAction("menus/payload_set"_i18n , brls::Key::X, [this, payload] {
|
2021-01-17 17:26:20 +00:00
|
|
|
std::string res1;
|
2020-09-23 12:21:05 +01:00
|
|
|
if(R_SUCCEEDED(CopyFile(payload.c_str(), REBOOT_PAYLOAD_PATH))){
|
2021-01-17 17:26:20 +00:00
|
|
|
res1 += "menus/payload_success"_i18n + payload + "menus/payload_to"_i18n + std::string(REBOOT_PAYLOAD_PATH) + "'.";
|
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
dialog->addButton("menus/payload_ok"_i18n , callback);
|
|
|
|
dialog->setCancelable(true);
|
|
|
|
dialog->open();
|
2020-09-23 12:21:05 +01:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
2020-10-05 23:53:12 +01:00
|
|
|
items[i]->registerAction("menus/payload_set_up"_i18n , brls::Key::Y, [this, payload] {
|
2021-01-17 17:26:20 +00:00
|
|
|
std::string res2;
|
2020-10-05 23:53:12 +01:00
|
|
|
if(R_SUCCEEDED(CopyFile(payload.c_str(), UPDATE_BIN_PATH))){
|
2021-01-17 17:26:20 +00:00
|
|
|
res2 += "menus/payload_success"_i18n + payload + "menus/payload_to"_i18n + std::string(UPDATE_BIN_PATH) + "'.";
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
dialog->addButton("menus/payload_ok"_i18n , callback);
|
|
|
|
dialog->setCancelable(true);
|
|
|
|
dialog->open();
|
2020-10-05 23:53:12 +01:00
|
|
|
return true;
|
|
|
|
});
|
2020-09-20 01:21:28 +01:00
|
|
|
list->addView(items[i]);
|
|
|
|
}
|
|
|
|
list->addView(new brls::ListItemGroupSpacing(true));
|
|
|
|
|
2020-10-05 23:53:12 +01:00
|
|
|
shutDown = new brls::ListItem("menus/payload_shut"_i18n );
|
2020-09-20 01:21:28 +01:00
|
|
|
shutDown->getClickEvent()->subscribe([](brls::View* view) {
|
|
|
|
shut_down(false);
|
|
|
|
brls::Application::popView();
|
|
|
|
});
|
|
|
|
list->addView(shutDown);
|
|
|
|
|
2020-10-05 23:53:12 +01:00
|
|
|
reboot = new brls::ListItem("menus/payload_reboot_2"_i18n );
|
2020-09-20 01:21:28 +01:00
|
|
|
reboot->getClickEvent()->subscribe([](brls::View* view) {
|
|
|
|
shut_down(true);
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|