1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-12-29 10:56:01 +00:00
flb 2021-09-22 21:01:45 +02:00
parent 5259a461c4
commit 2d74f465f8
5 changed files with 32 additions and 12 deletions

View file

@ -10,6 +10,7 @@ private:
double _total = 0; double _total = 0;
double _speed = 0; double _speed = 0;
long _status_code = 0; long _status_code = 0;
bool _interupt = false;
public: public:
ProgressEvent(const ProgressEvent&) = delete; ProgressEvent(const ProgressEvent&) = delete;
@ -31,6 +32,7 @@ public:
_total = 0; _total = 0;
_speed = 0; _speed = 0;
_status_code = 0; _status_code = 0;
_interupt = false;
} }
inline void setTotalSteps(int steps) { _max = steps; } inline void setTotalSteps(int steps) { _max = steps; }
@ -47,4 +49,6 @@ public:
inline double getTotal() { return _total; } inline double getTotal() { return _total; }
inline double getSpeed() { return _speed; } inline double getSpeed() { return _speed; }
inline double getStatusCode() { return _status_code; } inline double getStatusCode() { return _status_code; }
inline void setInterupt(bool interupt) { _interupt = interupt; }
inline bool getInterupt() { return _interupt; }
}; };

View file

@ -155,7 +155,6 @@ namespace JC {
{ {
hiddbgInitialize(); hiddbgInitialize();
hidsysInitialize(); hidsysInitialize();
ProgressEvent::instance().reset();
ProgressEvent::instance().setStep(1); ProgressEvent::instance().setStep(1);
int res = setColor(values); int res = setColor(values);
if (res != 0) { if (res != 0) {
@ -170,7 +169,6 @@ namespace JC {
{ {
hiddbgInitialize(); hiddbgInitialize();
hidsysInitialize(); hidsysInitialize();
ProgressEvent::instance().reset();
ProgressEvent::instance().setStep(1); ProgressEvent::instance().setStep(1);
json backup; json backup;
json profiles; json profiles;
@ -306,7 +304,6 @@ namespace PC {
{ {
hiddbgInitialize(); hiddbgInitialize();
hidsysInitialize(); hidsysInitialize();
ProgressEvent::instance().reset();
ProgressEvent::instance().setStep(1); ProgressEvent::instance().setStep(1);
int res = setColor(values); int res = setColor(values);
if (res != 0) { if (res != 0) {
@ -321,7 +318,6 @@ namespace PC {
{ {
hiddbgInitialize(); hiddbgInitialize();
hidsysInitialize(); hidsysInitialize();
ProgressEvent::instance().reset();
ProgressEvent::instance().setStep(1); ProgressEvent::instance().setStep(1);
json backup; json backup;
json profiles; json profiles;

View file

@ -45,6 +45,9 @@ namespace download {
static size_t WriteMemoryCallback(void* contents, size_t size, size_t num_files, void* userp) static size_t WriteMemoryCallback(void* contents, size_t size, size_t num_files, void* userp)
{ {
if (ProgressEvent::instance().getInterupt()) {
return 0;
}
ntwrk_struct_t* data_struct = (ntwrk_struct_t*)userp; ntwrk_struct_t* data_struct = (ntwrk_struct_t*)userp;
size_t realsize = size * num_files; size_t realsize = size * num_files;
@ -132,7 +135,6 @@ namespace download {
long downloadFile(const std::string& url, std::vector<std::uint8_t>& res, const char* output, int api) long downloadFile(const std::string& url, std::vector<std::uint8_t>& res, const char* output, int api)
{ {
ProgressEvent::instance().reset();
CURL* curl = curl_easy_init(); CURL* curl = curl_easy_init();
ntwrk_struct_t chunk = {0}; ntwrk_struct_t chunk = {0};
long status_code; long status_code;

View file

@ -46,7 +46,6 @@ namespace extract {
brls::Application::quit(); brls::Application::quit();
} }
} }
ProgressEvent::instance().reset();
ProgressEvent::instance().setStep(1); ProgressEvent::instance().setStep(1);
ProgressEvent::instance().setTotalSteps(entries.size() + 1); ProgressEvent::instance().setTotalSteps(entries.size() + 1);
} }
@ -56,9 +55,14 @@ namespace extract {
{ {
zipper::Unzipper unzipper(filename); zipper::Unzipper unzipper(filename);
std::vector<zipper::ZipEntry> entries; std::vector<zipper::ZipEntry> entries;
preWork(unzipper, workingPath, entries); preWork(unzipper, workingPath, entries);
std::set<std::string> ignoreList = fs::readLineByLine(FILES_IGNORE); std::set<std::string> ignoreList = fs::readLineByLine(FILES_IGNORE);
for (const auto& entry : entries) { for (const auto& entry : entries) {
if (ProgressEvent::instance().getInterupt()) {
break;
}
if ((overwriteInis == 0 && entry.name.substr(entry.name.length() - 4) == ".ini") || find_if(ignoreList.begin(), ignoreList.end(), [&entry](std::string ignored) { if ((overwriteInis == 0 && entry.name.substr(entry.name.length() - 4) == ".ini") || find_if(ignoreList.begin(), ignoreList.end(), [&entry](std::string ignored) {
u8 res = ("/" + entry.name).find(ignored); u8 res = ("/" + entry.name).find(ignored);
return (res == 0 || res == 1); }) != ignoreList.end()) { return (res == 0 || res == 1); }) != ignoreList.end()) {
@ -87,9 +91,14 @@ namespace extract {
zipper::Unzipper unzipper(filename); zipper::Unzipper unzipper(filename);
std::vector<zipper::ZipEntry> entries; std::vector<zipper::ZipEntry> entries;
preWork(unzipper, workingPath, entries); preWork(unzipper, workingPath, entries);
std::set<std::string> ignoreList = fs::readLineByLine(FILES_IGNORE); std::set<std::string> ignoreList = fs::readLineByLine(FILES_IGNORE);
ignoreList.insert(toExclude); ignoreList.insert(toExclude);
for (const auto& entry : entries) { for (const auto& entry : entries) {
if (ProgressEvent::instance().getInterupt()) {
break;
}
if (find_if(ignoreList.begin(), ignoreList.end(), [&entry](std::string ignored) { if (find_if(ignoreList.begin(), ignoreList.end(), [&entry](std::string ignored) {
u8 res = ("/" + entry.name).find(ignored); u8 res = ("/" + entry.name).find(ignored);
return (res == 0 || res == 1); }) != ignoreList.end()) { return (res == 0 || res == 1); }) != ignoreList.end()) {
@ -172,7 +181,6 @@ namespace extract {
void extractCheats(const std::string& zipPath, std::vector<std::string> titles, CFW cfw, bool credits) void extractCheats(const std::string& zipPath, std::vector<std::string> titles, CFW cfw, bool credits)
{ {
ProgressEvent::instance().reset();
zipper::Unzipper unzipper(zipPath); zipper::Unzipper unzipper(zipPath);
std::vector<zipper::ZipEntry> entries = unzipper.entries(); std::vector<zipper::ZipEntry> entries = unzipper.entries();
//std::set<std::string> extractedTitles; //std::set<std::string> extractedTitles;
@ -238,6 +246,9 @@ namespace extract {
std::string id; std::string id;
ProgressEvent::instance().setTotalSteps(titles.size()); ProgressEvent::instance().setTotalSteps(titles.size());
for (size_t j = 0; j < titles.size(); j++) { for (size_t j = 0; j < titles.size(); j++) {
if (ProgressEvent::instance().getInterupt()) {
break;
}
for (size_t l = lastL; l < parents.size(); l++) { for (size_t l = lastL; l < parents.size(); l++) {
if (strcasecmp((titles[j]).c_str(), parents[l].substr(offset, 16).c_str()) == 0) { if (strcasecmp((titles[j]).c_str(), parents[l].substr(offset, 16).c_str()) == 0) {
unzipper.extractEntry(parents[l]); unzipper.extractEntry(parents[l]);
@ -261,10 +272,9 @@ namespace extract {
void extractAllCheats(const std::string& zipPath, CFW cfw) void extractAllCheats(const std::string& zipPath, CFW cfw)
{ {
ProgressEvent::instance().reset();
zipper::Unzipper unzipper(zipPath); zipper::Unzipper unzipper(zipPath);
std::vector<zipper::ZipEntry> entries = unzipper.entries(); std::vector<zipper::ZipEntry> entries = unzipper.entries();
//std::set<std::string> extractedTitles;
int offset = 0; int offset = 0;
switch (cfw) { switch (cfw) {
case CFW::ams: case CFW::ams:
@ -288,6 +298,9 @@ namespace extract {
} }
ProgressEvent::instance().setTotalSteps(entries.size()); ProgressEvent::instance().setTotalSteps(entries.size());
for (const auto& entry : entries) { for (const auto& entry : entries) {
if (ProgressEvent::instance().getInterupt()) {
break;
}
if (((int)entry.name.size() == offset + 16 + 4) && (isBID(entry.name.substr(offset, 16)))) { if (((int)entry.name.size() == offset + 16 + 4) && (isBID(entry.name.substr(offset, 16)))) {
//extractedTitles.insert(util::upperCase(entry.name.substr(offset - 24, 16))); //extractedTitles.insert(util::upperCase(entry.name.substr(offset - 24, 16)));
unzipper.extractEntry(entry.name); unzipper.extractEntry(entry.name);
@ -325,7 +338,6 @@ namespace extract {
void removeCheats() void removeCheats()
{ {
std::string path = util::getContentsPath(); std::string path = util::getContentsPath();
ProgressEvent::instance().reset();
ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator())); ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator()));
for (const auto& entry : std::filesystem::directory_iterator(path)) { for (const auto& entry : std::filesystem::directory_iterator(path)) {
removeCheatsDirectory(entry.path().string()); removeCheatsDirectory(entry.path().string());

View file

@ -6,6 +6,7 @@
#include "constants.hpp" #include "constants.hpp"
#include "download.hpp" #include "download.hpp"
#include "extract.hpp" #include "extract.hpp"
#include "main_frame.hpp"
#include "progress_event.hpp" #include "progress_event.hpp"
#include "utils.hpp" #include "utils.hpp"
@ -24,7 +25,10 @@ WorkerPage::WorkerPage(brls::StagedAppletFrame* frame, const std::string& text,
this->button = new brls::Button(brls::ButtonStyle::REGULAR); this->button = new brls::Button(brls::ButtonStyle::REGULAR);
this->button->setParent(this); this->button->setParent(this);
this->registerAction("", brls::Key::B, [this] { return true; }); this->registerAction("menus/common/cancel"_i18n, brls::Key::B, [this] {
ProgressEvent::instance().setInterupt(true);
return true;
});
this->registerAction("", brls::Key::A, [this] { return true; }); this->registerAction("", brls::Key::A, [this] { return true; });
} }
@ -44,6 +48,9 @@ void WorkerPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned hei
this->draw_page = false; this->draw_page = false;
brls::Application::crash(fmt::format("menus/errors/error_message"_i18n, util::getErrorMessage(ProgressEvent::instance().getStatusCode()))); brls::Application::crash(fmt::format("menus/errors/error_message"_i18n, util::getErrorMessage(ProgressEvent::instance().getStatusCode())));
} }
if (ProgressEvent::instance().getInterupt()) {
brls::Application::pushView(new MainFrame());
}
else { else {
ProgressEvent::instance().setStatusCode(0); ProgressEvent::instance().setStatusCode(0);
frame->nextStage(); frame->nextStage();
@ -54,7 +61,6 @@ void WorkerPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned hei
this->progressDisp->frame(ctx); this->progressDisp->frame(ctx);
if (ProgressEvent::instance().getTotal()) { if (ProgressEvent::instance().getTotal()) {
this->label->setText(fmt::format("{0} ({1:.1f} MB of {2:.1f} MB - {3:.1f} MB/s)", text, ProgressEvent::instance().getNow() / 0x100000, ProgressEvent::instance().getTotal() / 0x100000, ProgressEvent::instance().getSpeed() / 0x100000)); this->label->setText(fmt::format("{0} ({1:.1f} MB of {2:.1f} MB - {3:.1f} MB/s)", text, ProgressEvent::instance().getNow() / 0x100000, ProgressEvent::instance().getTotal() / 0x100000, ProgressEvent::instance().getSpeed() / 0x100000));
//this->label->setText(fmt::format("{0} ({1:.1f}MB of {2:.1f}MB - MB/s)", text, ProgressEvent::instance().getNow() / 0x100000, ProgressEvent::instance().getTotal() / 0x100000));
} }
this->label->frame(ctx); this->label->frame(ctx);
} }