1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-12-29 10:56:01 +00:00

add a prompt asking about replacing reboot_payload.bin by hekate (closes https://github.com/HamletDuFromage/aio-switch-updater/issues/153)

This commit is contained in:
flb 2021-10-21 23:12:29 +02:00
parent cc50d526c0
commit cb6b78c11c
5 changed files with 39 additions and 57 deletions

View file

@ -2,6 +2,7 @@
#include <switch.h>
#include <functional>
#include <set>
#include <string>
#include <vector>
@ -25,8 +26,8 @@ namespace extract {
}
} Title;
void extract(const std::string& filename, const std::string& workingPath = ROOT_PATH, int overwriteInis = 1);
void extract(const std::string& filename, const std::string& workingPath, const std::string& toExclude);
void extract(
const std::string& filename, const std::string& workingPath = ROOT_PATH, int overwriteInis = 1, std::function<void()> func = []() { return; });
std::vector<std::string> getInstalledTitlesNs();
std::vector<std::string> excludeTitles(const std::string& path, const std::vector<std::string>& listedTitles);
void writeTitlesToFile(const std::set<std::string>& titles, const std::string& path);

View file

@ -9,17 +9,17 @@ class ListDownloadTab : public brls::List
{
private:
brls::ListItem* listItem;
brls::ListItem* cheatslipsItem;
brls::ListItem* gbatempItem;
nlohmann::ordered_json nxlinks;
std::string currentCheatsVer = "";
std::string newCheatsVer = "";
contentType type;
int size = 0;
void createList();
void createList(contentType type);
void createCheatSlipItem();
void creategbatempItem();
void setDescription();
void setDescription(contentType type);
void displayNotFound();
public:

View file

@ -165,7 +165,9 @@
"fw_warning": "Because of the size of the FW archive, downloading firmwares in Applet Mode is not supported. Please launch the app with full RAM access.",
"overwrite": " Do you want to overwrite existing ",
"not_an_archive": "The downloaded file is not a zip archive. This is most likely due to a broken link. If the problem persists after more than 30 minutes, please open an issue on Github.",
"overwrite_inis": "Do you want to overwrite existing .ini config files?"
"overwrite_inis": "Do you want to overwrite existing .ini config files?",
"set_hekate_reboot_payload": "Do you want to copy the Hekate payload `{}` to `{}`?"
},
"ams_update": {
"reboot_rcm": "The Switch will now reboot to a special payload in order to finalise the install.",

View file

@ -47,12 +47,12 @@ namespace extract {
brls::Application::quit();
}
}
ProgressEvent::instance().setStep(1);
ProgressEvent::instance().setTotalSteps(entries.size() + 1);
ProgressEvent::instance().setStep(0);
}
} // namespace
void extract(const std::string& filename, const std::string& workingPath, int overwriteInis)
void extract(const std::string& filename, const std::string& workingPath, int overwriteInis, std::function<void()> func)
{
zipper::Unzipper unzipper(filename);
std::vector<zipper::ZipEntry> entries;
@ -71,7 +71,7 @@ namespace extract {
unzipper.extractEntry(entry.name);
}
}
else if (entry.name == "sept/payload.bin" || entry.name == "atmosphere/fusee-secondary.bin" || entry.name == "atmosphere/stratosphere.romfs" || entry.name == "atmosphere/package3") {
else if (entry.name == "atmosphere/stratosphere.romfs" || entry.name == "atmosphere/package3") {
std::ofstream readonlyFile(entry.name + ".aio");
unzipper.extractEntryToStream(entry.name, readonlyFile);
}
@ -79,7 +79,9 @@ namespace extract {
unzipper.extractEntry(entry.name);
if (entry.name.substr(0, 13) == "hekate_ctcaer") {
fs::copyFile("/" + entry.name, UPDATE_BIN_PATH);
fs::copyFile("/" + entry.name, REBOOT_PAYLOAD_PATH);
if (util::showDialogBox(fmt::format("menus/utils/set_hekate_reboot_payload"_i18n, UPDATE_BIN_PATH, REBOOT_PAYLOAD_PATH), "menus/common/yes"_i18n, "menus/common/no"_i18n) == 0) {
fs::copyFile(UPDATE_BIN_PATH, REBOOT_PAYLOAD_PATH);
}
}
}
ProgressEvent::instance().incrementStep(1);
@ -88,35 +90,6 @@ namespace extract {
ProgressEvent::instance().setStep(ProgressEvent::instance().getMax());
}
void extract(const std::string& filename, const std::string& workingPath, const std::string& toExclude)
{
zipper::Unzipper unzipper(filename);
std::vector<zipper::ZipEntry> entries;
preWork(unzipper, workingPath, entries);
std::set<std::string> ignoreList = fs::readLineByLine(FILES_IGNORE);
ignoreList.insert(toExclude);
for (const auto& entry : entries) {
if (ProgressEvent::instance().getInterupt()) {
break;
}
if (find_if(ignoreList.begin(), ignoreList.end(), [&entry](std::string ignored) {
u8 res = ("/" + entry.name).find(ignored);
return (res == 0 || res == 1); }) != ignoreList.end()) {
if (!std::filesystem::exists("/" + entry.name)) {
unzipper.extractEntry(entry.name);
}
}
else {
unzipper.extractEntry(entry.name);
}
ProgressEvent::instance().incrementStep(1);
}
unzipper.close();
ProgressEvent::instance().setStep(ProgressEvent::instance().getMax());
}
std::vector<std::string> getInstalledTitlesNs()
{
std::vector<std::string> titles;

View file

@ -21,7 +21,7 @@ ListDownloadTab::ListDownloadTab(const contentType type, const nlohmann::ordered
{
this->setDescription();
this->createList(this->type);
this->createList();
if (this->type == contentType::cheats) {
brls::Label* cheatsLabel = new brls::Label(
@ -29,24 +29,24 @@ ListDownloadTab::ListDownloadTab(const contentType type, const nlohmann::ordered
"menus/cheats/cheats_label"_i18n,
true);
this->addView(cheatsLabel);
creategbatempItem();
createCheatSlipItem();
this->creategbatempItem();
this->createCheatSlipItem();
}
if (this->type == contentType::bootloaders) {
brls::Label* payloadsLabel = new brls::Label(
brls::LabelStyle::DESCRIPTION,
fmt::format("menus/main/payloads_label"_i18n, BOOTLOADER_PL_PATH),
true);
this->addView(payloadsLabel);
createList(contentType::payloads);
this->setDescription(contentType::payloads);
this->createList(contentType::payloads);
}
}
void ListDownloadTab::createList() {
ListDownloadTab::createList(this->type);
}
void ListDownloadTab::createList(contentType type)
{
std::vector<std::pair<std::string, std::string>> links;
if (this->type == contentType::cheats && this->newCheatsVer != "")
if (type == contentType::cheats && this->newCheatsVer != "")
links.push_back(std::make_pair(fmt::format("{}{})", "menus/main/get_cheats"_i18n, this->newCheatsVer), CurrentCfw::running_cfw == CFW::sxos ? CHEATS_URL_TITLES : CHEATS_URL_CONTENTS));
else
links = download::getLinksFromJson(util::getValueFromKey(this->nxlinks, contentTypeNames[(int)type].data()));
@ -58,15 +58,15 @@ void ListDownloadTab::createList(contentType type)
const std::string text("menus/common/download"_i18n + link.first + "menus/common/from"_i18n + url);
listItem = new brls::ListItem(link.first);
listItem->setHeight(LISTITEM_HEIGHT);
listItem->getClickEvent()->subscribe([this, text, url, title, type](brls::View* view) {
listItem->getClickEvent()->subscribe([this, type, text, url, title](brls::View* view) {
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
stagedFrame->setTitle(fmt::format("menus/main/getting"_i18n, contentTypeNames[(int)type].data()));
stagedFrame->addStage(new ConfirmPage(stagedFrame, text));
if (type != contentType::payloads) {
if (type != contentType::cheats || this->newCheatsVer != this->currentCheatsVer || !std::filesystem::exists(CHEATS_ZIP_PATH)) {
stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [type, url]() { util::downloadArchive(url, type); }));
stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [this, type, url]() { util::downloadArchive(url, type); }));
}
stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [type]() { util::extractArchive(type); }));
stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [this, type]() { util::extractArchive(type); }));
}
else {
fs::createTree(BOOTLOADER_PL_PATH);
@ -121,13 +121,17 @@ void ListDownloadTab::displayNotFound()
}
void ListDownloadTab::setDescription()
{
this->setDescription(this->type);
}
void ListDownloadTab::setDescription(contentType type)
{
brls::Label* description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true);
switch (this->type) {
switch (type) {
case contentType::sigpatches:
description->setText(
"menus/main/sigpatches_text"_i18n);
description->setText("menus/main/sigpatches_text"_i18n);
break;
case contentType::fw: {
SetSysFirmwareVersion ver;
@ -139,11 +143,13 @@ void ListDownloadTab::setDescription()
"menus/main/bootloaders_text"_i18n);
break;
case contentType::cheats:
this->newCheatsVer = util::downloadFileToString(CHEATS_URL_VERSION);
this->currentCheatsVer = util::readVersion(CHEATS_VERSION);
description->setText("menus/main/cheats_text"_i18n + this->currentCheatsVer);
break;
case contentType::payloads:
description->setText("menus/main/payloads_label"_i18n);
break;
default:
break;
}
@ -153,7 +159,7 @@ void ListDownloadTab::setDescription()
void ListDownloadTab::createCheatSlipItem()
{
cheatslipsItem = new brls::ListItem("menus/cheats/get_cheatslips"_i18n);
brls::ListItem* cheatslipsItem = new brls::ListItem("menus/cheats/get_cheatslips"_i18n);
cheatslipsItem->setHeight(LISTITEM_HEIGHT);
cheatslipsItem->getClickEvent()->subscribe([](brls::View* view) {
if (std::filesystem::exists(TOKEN_PATH)) {
@ -196,7 +202,7 @@ void ListDownloadTab::createCheatSlipItem()
void ListDownloadTab::creategbatempItem()
{
gbatempItem = new brls::ListItem("menus/cheats/get_gbatemp"_i18n);
brls::ListItem* gbatempItem = new brls::ListItem("menus/cheats/get_gbatemp"_i18n);
gbatempItem->setHeight(LISTITEM_HEIGHT);
gbatempItem->getClickEvent()->subscribe([](brls::View* view) {
brls::Application::pushView(new AppPage_Gbatemp());