mirror of
https://github.com/HamletDuFromage/aio-switch-updater.git
synced 2024-12-29 10:56:01 +00:00
code cleanup
This commit is contained in:
parent
5d4a4622db
commit
de93c13d10
10 changed files with 57 additions and 79 deletions
|
@ -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; }
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "constants.hpp"
|
||||
#include <regex>
|
||||
#include <set>
|
||||
#include <switch.h>
|
||||
#include <borealis.hpp>
|
||||
#include <json.hpp>
|
||||
#include "constants.hpp"
|
||||
|
||||
namespace util {
|
||||
|
||||
|
@ -27,6 +27,7 @@ namespace util {
|
|||
std::string formatApplicationId(u64 ApplicationId);
|
||||
std::vector<std::string> 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);
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "utils.hpp"
|
||||
#include "main_frame.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "reboot_payload.h"
|
||||
#include "utils.hpp"
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
@ -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)) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "dialogue_page.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "reboot_payload.h"
|
||||
#include "main_frame.hpp"
|
||||
#include "fs.hpp"
|
||||
#include <filesystem>
|
||||
|
@ -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)) {
|
||||
|
|
|
@ -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<std::string> ignoreList = fs::readLineByLine(FILES_IGNORE);
|
||||
std::set<std::string>::iterator it;
|
||||
zipper::Unzipper unzipper(filename);
|
||||
std::vector<zipper::ZipEntry> 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<std::string> ignoreList = fs::readLineByLine(FILES_IGNORE);
|
||||
ignoreList.insert(toExclude);
|
||||
std::set<std::string>::iterator it;
|
||||
zipper::Unzipper unzipper(filename);
|
||||
std::vector<zipper::ZipEntry> 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<std::string> getInstalledTitlesNs(){
|
|||
std::vector<std::string> excludeTitles(const std::string& path, std::vector<std::string> listedTitles){
|
||||
std::vector<std::string> titles;
|
||||
std::ifstream file(path);
|
||||
int total = 0;
|
||||
std::string name;
|
||||
|
||||
if (file.is_open()) {
|
||||
|
@ -172,7 +146,6 @@ std::vector<std::string> excludeTitles(const std::string& path, std::vector<std:
|
|||
}
|
||||
|
||||
void extractCheats(const std::string& zipPath, std::vector<std::string> titles, CFW cfw, bool credits){
|
||||
//TODO: REWRITE WITH SETS INSTEAD OF VECTORS
|
||||
ProgressEvent::instance().reset();
|
||||
zipper::Unzipper unzipper(zipPath);
|
||||
std::vector<zipper::ZipEntry> entries = unzipper.entries();
|
||||
|
@ -211,7 +184,6 @@ void extractCheats(const std::string& zipPath, std::vector<std::string> titles,
|
|||
std::vector<std::vector<std::string>> children;
|
||||
std::vector<std::string> 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);
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
#include "list_download_tab.hpp"
|
||||
#include "ams_tab.hpp"
|
||||
#include "tools_tab.hpp"
|
||||
#include <json.hpp>
|
||||
#include <fstream>
|
||||
#include "utils.hpp"
|
||||
#include "fs.hpp"
|
||||
#include <json.hpp>
|
||||
#include <fstream>
|
||||
|
||||
namespace i18n = brls::i18n;
|
||||
using namespace i18n::literals;
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#include <switch.h>
|
||||
#include "utils.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "current_cfw.hpp"
|
||||
#include <switch.h>
|
||||
#include "download.hpp"
|
||||
#include "extract.hpp"
|
||||
#include "progress_event.hpp"
|
||||
#include "main_frame.hpp"
|
||||
#include "reboot_payload.h"
|
||||
#include "unistd.h"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
|
@ -207,12 +209,18 @@ std::vector<std::string> 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){
|
||||
|
|
Loading…
Reference in a new issue