diff --git a/include/progress_event.hpp b/include/progress_event.hpp index 92f83a8..b2b1f8a 100644 --- a/include/progress_event.hpp +++ b/include/progress_event.hpp @@ -32,6 +32,7 @@ public: inline void setTotalCount(double total) { _total = total; } inline void setSpeed(double speed) { _speed = speed; } inline void setStep(int step) { _current = step; } + inline void incrementStep(int increment) {_current += increment; } inline void setNow(double now) { _now = now; } inline int getStep() { return _current; } inline double getNow() { return _now; } diff --git a/include/utils.hpp b/include/utils.hpp index 6f6ff53..cf72bf1 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -1,11 +1,11 @@ #pragma once +#include "constants.hpp" #include #include #include #include #include -#include "constants.hpp" namespace util { @@ -27,6 +27,7 @@ namespace util { std::string formatApplicationId(u64 ApplicationId); std::vector fetchPayloads(); void shutDown(bool reboot = false); + void rebootToPayload(const std::string& path); int showDialogBox(std::string text, std::string opt); int showDialogBox(std::string text, std::string opt1, std::string opt2); std::string getLatestTag(const std::string& url); diff --git a/source/changelog_page.cpp b/source/changelog_page.cpp index 13b7812..26182ad 100644 --- a/source/changelog_page.cpp +++ b/source/changelog_page.cpp @@ -151,7 +151,6 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true) verTitles.push_back("v2.5.1"); changes.push_back("\uE016 Fixed bug copying Mariko payloads on Erista."); - for(int i = verTitles.size() -1 ; i >= 0; i--){ listItem = new brls::ListItem(verTitles[i]); change = changes[i]; diff --git a/source/confirm_page.cpp b/source/confirm_page.cpp index 3abe7c0..7959a7a 100644 --- a/source/confirm_page.cpp +++ b/source/confirm_page.cpp @@ -2,7 +2,7 @@ #include "utils.hpp" #include "main_frame.hpp" #include "fs.hpp" -#include "reboot_payload.h" +#include "utils.hpp" #include #include #include @@ -22,7 +22,7 @@ ConfirmPage::ConfirmPage(brls::StagedAppletFrame* frame, std::string text, bool } else if (this->reboot) { if(this->erista) { - reboot_to_payload(RCM_PAYLOAD_PATH); + util::rebootToPayload(RCM_PAYLOAD_PATH); } else { if(std::filesystem::exists(UPDATE_BIN_PATH)) { diff --git a/source/dialogue_page.cpp b/source/dialogue_page.cpp index 7fc87e7..8712c32 100644 --- a/source/dialogue_page.cpp +++ b/source/dialogue_page.cpp @@ -1,6 +1,5 @@ #include "dialogue_page.hpp" #include "utils.hpp" -#include "reboot_payload.h" #include "main_frame.hpp" #include "fs.hpp" #include @@ -24,7 +23,7 @@ DialoguePage::DialoguePage(brls::StagedAppletFrame* frame, std::string text, boo this->button2->getClickEvent()->subscribe([frame, this](View* view) { if(this->erista) { - reboot_to_payload(RCM_PAYLOAD_PATH); + util::rebootToPayload(RCM_PAYLOAD_PATH); } else { if(std::filesystem::exists(UPDATE_BIN_PATH)) { diff --git a/source/extract.cpp b/source/extract.cpp index f3e4e68..93fcd85 100644 --- a/source/extract.cpp +++ b/source/extract.cpp @@ -30,46 +30,30 @@ void extract(const std::string& filename, const std::string& workingPath, int o ProgressEvent::instance().setStep(1); chdir(workingPath.c_str()); std::set ignoreList = fs::readLineByLine(FILES_IGNORE); - std::set::iterator it; zipper::Unzipper unzipper(filename); std::vector entries = unzipper.entries(); - int k = -1; - bool isIgnored; ProgressEvent::instance().setTotalSteps(entries.size() + 1); - for (int i = 0; i < (int) entries.size(); i++){ - isIgnored = false; - it = ignoreList.begin(); - if(overwriteInis == 0 && entries[i].name.substr(entries[i].name.length() - 4) == ".ini"){ - if(!std::filesystem::exists("/" + entries[i].name)){ - unzipper.extractEntry(entries[i].name); - } - continue; - } - while (it != ignoreList.end() ){ - k = ("/" + entries[i].name).find((*it)); - if(k == 0 || k == 1){ - isIgnored = true; - if(!std::filesystem::exists("/" + entries[i].name)){ - unzipper.extractEntry(entries[i].name); - } - break; - } - it++; - } - if(!isIgnored){ - if(entries[i].name == "sept/payload.bin" || entries[i].name == "atmosphere/fusee-secondary.bin" || entries[i].name == "atmosphere/stratosphere.romfs"){ - std::ofstream readonlyFile(entries[i].name + ".aio"); - unzipper.extractEntryToStream(entries[i].name, readonlyFile); - } - else { - unzipper.extractEntry(entries[i].name); - if(entries[i].name.substr(0, 13) == "hekate_ctcaer") { - fs::copyFile("/" + entries[i].name, UPDATE_BIN_PATH); - } + for (const auto& entry : entries) { + if((overwriteInis == 0 && entry.name.substr(entry.name.length() - 4) == ".ini") + || find_if(ignoreList.begin(), ignoreList.end(), [entry](std::string ignoreList) { + u8 res = ("/" + entry.name).find(ignoreList); + return (res == 0 || res == 1); }) != ignoreList.end()) + { + if(!std::filesystem::exists("/" + entry.name)) { + unzipper.extractEntry(entry.name); } } - - ProgressEvent::instance().setStep(i); + else if(entry.name == "sept/payload.bin" || entry.name == "atmosphere/fusee-secondary.bin" || entry.name == "atmosphere/stratosphere.romfs"){ + std::ofstream readonlyFile(entry.name + ".aio"); + unzipper.extractEntryToStream(entry.name, readonlyFile); + } + else { + unzipper.extractEntry(entry.name); + if(entry.name.substr(0, 13) == "hekate_ctcaer") { + fs::copyFile("/" + entry.name, UPDATE_BIN_PATH); + } + } + ProgressEvent::instance().incrementStep(1); } unzipper.close(); ProgressEvent::instance().setStep(ProgressEvent::instance().getMax()); @@ -81,31 +65,22 @@ void extract(const std::string& filename, const std::string& workingPath, const chdir(workingPath.c_str()); std::set ignoreList = fs::readLineByLine(FILES_IGNORE); ignoreList.insert(toExclude); - std::set::iterator it; zipper::Unzipper unzipper(filename); std::vector entries = unzipper.entries(); - int k = -1; - bool isIgnored; ProgressEvent::instance().setTotalSteps(entries.size() + 1); - for (int i = 0; i < (int) entries.size(); i++){ - isIgnored = false; - it = ignoreList.begin(); - while (it != ignoreList.end()){ - k = ("/" + entries[i].name).find((*it)); - if(k == 0 || k == 1){ - isIgnored = true; - if(!std::filesystem::exists("/" + entries[i].name)){ - unzipper.extractEntry(entries[i].name); - } - break; + for (const auto& entry : entries) { + if(find_if(ignoreList.begin(), ignoreList.end(), [entry](std::string ignoreList) { + u8 res = ("/" + entry.name).find(ignoreList); + return (res == 0 || res == 1); }) != ignoreList.end()) + { + if(!std::filesystem::exists("/" + entry.name)){ + unzipper.extractEntry(entry.name); } - it++; } - if(!isIgnored) { - unzipper.extractEntry(entries[i].name); + else { + unzipper.extractEntry(entry.name); } - - ProgressEvent::instance().setStep(i); + ProgressEvent::instance().incrementStep(1); } unzipper.close(); ProgressEvent::instance().setStep(ProgressEvent::instance().getMax()); @@ -146,7 +121,6 @@ std::vector getInstalledTitlesNs(){ std::vector excludeTitles(const std::string& path, std::vector listedTitles){ std::vector titles; std::ifstream file(path); - int total = 0; std::string name; if (file.is_open()) { @@ -172,7 +146,6 @@ std::vector excludeTitles(const std::string& path, std::vector titles, CFW cfw, bool credits){ - //TODO: REWRITE WITH SETS INSTEAD OF VECTORS ProgressEvent::instance().reset(); zipper::Unzipper unzipper(zipPath); std::vector entries = unzipper.entries(); @@ -211,7 +184,6 @@ void extractCheats(const std::string& zipPath, std::vector titles, std::vector> children; std::vector tempChildren; - size_t k = 0; while(k < entriesNames.size()){ if(entriesNames[k].length() == (size_t) (offset + 17)){ @@ -289,11 +261,11 @@ void extractAllCheats(const std::string& zipPath, CFW cfw){ break; } ProgressEvent::instance().setTotalSteps(entries.size()); - for(size_t j = 0; j < entries.size(); j++){ - if(((int) entries[j].name.size() == offset + 16 + 4) && (isBID(entries[j].name.substr(offset, 16)))) { - unzipper.extractEntry(entries[j].name); + for(const auto& entry : entries) { + if(((int) entry.name.size() == offset + 16 + 4) && (isBID(entry.name.substr(offset, 16)))) { + unzipper.extractEntry(entry.name); } - ProgressEvent::instance().setStep(j); + ProgressEvent::instance().incrementStep(1); } unzipper.close(); auto cheatsVerVec = download::downloadFile(CHEATS_URL_VERSION); @@ -337,7 +309,6 @@ void removeCheats(CFW cfw){ } ProgressEvent::instance().reset(); ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator())); - int c = 0; for (const auto & entry : std::filesystem::directory_iterator(path)){ std::string cheatsPath = entry.path().string() + "/cheats"; if(std::filesystem::exists(cheatsPath)){ @@ -349,7 +320,7 @@ void removeCheats(CFW cfw){ rmdir(entry.path().string().c_str()); } } - ProgressEvent::instance().setStep(c++); + ProgressEvent::instance().incrementStep(1); } std::filesystem::remove(UPDATED_TITLES_PATH); std::filesystem::remove(CHEATS_VERSION); diff --git a/source/main_frame.cpp b/source/main_frame.cpp index 6c3adb7..eb6d9f8 100644 --- a/source/main_frame.cpp +++ b/source/main_frame.cpp @@ -3,10 +3,10 @@ #include "list_download_tab.hpp" #include "ams_tab.hpp" #include "tools_tab.hpp" -#include -#include #include "utils.hpp" #include "fs.hpp" +#include +#include namespace i18n = brls::i18n; using namespace i18n::literals; diff --git a/source/payload_page.cpp b/source/payload_page.cpp index 723058e..2e3f443 100644 --- a/source/payload_page.cpp +++ b/source/payload_page.cpp @@ -1,6 +1,5 @@ #include "payload_page.hpp" #include "utils.hpp" -#include "reboot_payload.h" #include "current_cfw.hpp" #include "utils.hpp" #include "fs.hpp" @@ -23,7 +22,7 @@ PayloadPage::PayloadPage() : AppletFrame(true, true) std::string payload_path = payload; listItem = new brls::ListItem(payload_path); listItem->getClickEvent()->subscribe([&, payload](brls::View* view) { - reboot_to_payload(payload.c_str()); + util::rebootToPayload(payload); brls::Application::popView(); }); if(CurrentCfw::running_cfw == CFW::ams){ diff --git a/source/reboot_payload.c b/source/reboot_payload.c index ab9acd4..59dee54 100644 --- a/source/reboot_payload.c +++ b/source/reboot_payload.c @@ -10,7 +10,7 @@ static alignas(0x1000) u8 g_work_page[0x1000]; void do_iram_dram_copy(void *buf, uintptr_t iram_addr, size_t size, int option) { memcpy(g_work_page, buf, size); - + SecmonArgs args = {0}; args.X[0] = 0xF0000201; /* smcAmsIramCopy */ args.X[1] = (uintptr_t)g_work_page; /* DRAM Address */ @@ -62,6 +62,8 @@ int reboot_to_payload(const char* path){ printf("injecting payload"); inject_payload(); } - if (can_reboot) splExit(); + if (can_reboot) + splExit(); + return 0; } diff --git a/source/utils.cpp b/source/utils.cpp index 9b74a9f..5fbf7fe 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,11 +1,13 @@ +#include #include "utils.hpp" #include "fs.hpp" #include "current_cfw.hpp" -#include #include "download.hpp" #include "extract.hpp" #include "progress_event.hpp" #include "main_frame.hpp" +#include "reboot_payload.h" +#include "unistd.h" #include #include @@ -207,12 +209,18 @@ std::vector fetchPayloads(){ } void shutDown(bool reboot){ + //sync(); bpcInitialize(); if(reboot) bpcRebootSystem(); else bpcShutdownSystem(); bpcExit(); } +void rebootToPayload(const std::string& path) { + //sync(); + reboot_to_payload(path.c_str()); +} + std::string getLatestTag(const std::string& url){ nlohmann::json tag = download::getRequest(url, {"accept: application/vnd.github.v3+json"}); if(tag.find("tag_name") != tag.end()) @@ -222,10 +230,8 @@ std::string getLatestTag(const std::string& url){ } void saveVersion(std::string version, const std::string& path){ - std::fstream newVersion; - newVersion.open(path, std::fstream::out | std::fstream::trunc); + std::ofstream newVersion(path); newVersion << version << std::endl; - newVersion.close(); } std::string readVersion(const std::string& path){