mirror of
https://github.com/HamletDuFromage/aio-switch-updater.git
synced 2024-12-29 10:56:01 +00:00
added option to cancel downloads/extraction https://github.com/HamletDuFromage/aio-switch-updater/issues/140 https://github.com/HamletDuFromage/aio-switch-updater/issues/125
This commit is contained in:
parent
5259a461c4
commit
2d74f465f8
5 changed files with 32 additions and 12 deletions
|
@ -10,6 +10,7 @@ private:
|
|||
double _total = 0;
|
||||
double _speed = 0;
|
||||
long _status_code = 0;
|
||||
bool _interupt = false;
|
||||
|
||||
public:
|
||||
ProgressEvent(const ProgressEvent&) = delete;
|
||||
|
@ -31,6 +32,7 @@ public:
|
|||
_total = 0;
|
||||
_speed = 0;
|
||||
_status_code = 0;
|
||||
_interupt = false;
|
||||
}
|
||||
|
||||
inline void setTotalSteps(int steps) { _max = steps; }
|
||||
|
@ -47,4 +49,6 @@ public:
|
|||
inline double getTotal() { return _total; }
|
||||
inline double getSpeed() { return _speed; }
|
||||
inline double getStatusCode() { return _status_code; }
|
||||
inline void setInterupt(bool interupt) { _interupt = interupt; }
|
||||
inline bool getInterupt() { return _interupt; }
|
||||
};
|
||||
|
|
|
@ -155,7 +155,6 @@ namespace JC {
|
|||
{
|
||||
hiddbgInitialize();
|
||||
hidsysInitialize();
|
||||
ProgressEvent::instance().reset();
|
||||
ProgressEvent::instance().setStep(1);
|
||||
int res = setColor(values);
|
||||
if (res != 0) {
|
||||
|
@ -170,7 +169,6 @@ namespace JC {
|
|||
{
|
||||
hiddbgInitialize();
|
||||
hidsysInitialize();
|
||||
ProgressEvent::instance().reset();
|
||||
ProgressEvent::instance().setStep(1);
|
||||
json backup;
|
||||
json profiles;
|
||||
|
@ -306,7 +304,6 @@ namespace PC {
|
|||
{
|
||||
hiddbgInitialize();
|
||||
hidsysInitialize();
|
||||
ProgressEvent::instance().reset();
|
||||
ProgressEvent::instance().setStep(1);
|
||||
int res = setColor(values);
|
||||
if (res != 0) {
|
||||
|
@ -321,7 +318,6 @@ namespace PC {
|
|||
{
|
||||
hiddbgInitialize();
|
||||
hidsysInitialize();
|
||||
ProgressEvent::instance().reset();
|
||||
ProgressEvent::instance().setStep(1);
|
||||
json backup;
|
||||
json profiles;
|
||||
|
|
|
@ -45,6 +45,9 @@ namespace download {
|
|||
|
||||
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;
|
||||
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)
|
||||
{
|
||||
ProgressEvent::instance().reset();
|
||||
CURL* curl = curl_easy_init();
|
||||
ntwrk_struct_t chunk = {0};
|
||||
long status_code;
|
||||
|
|
|
@ -46,7 +46,6 @@ namespace extract {
|
|||
brls::Application::quit();
|
||||
}
|
||||
}
|
||||
ProgressEvent::instance().reset();
|
||||
ProgressEvent::instance().setStep(1);
|
||||
ProgressEvent::instance().setTotalSteps(entries.size() + 1);
|
||||
}
|
||||
|
@ -56,9 +55,14 @@ namespace extract {
|
|||
{
|
||||
zipper::Unzipper unzipper(filename);
|
||||
std::vector<zipper::ZipEntry> entries;
|
||||
|
||||
preWork(unzipper, workingPath, entries);
|
||||
std::set<std::string> ignoreList = fs::readLineByLine(FILES_IGNORE);
|
||||
|
||||
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) {
|
||||
u8 res = ("/" + entry.name).find(ignored);
|
||||
return (res == 0 || res == 1); }) != ignoreList.end()) {
|
||||
|
@ -87,9 +91,14 @@ namespace extract {
|
|||
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()) {
|
||||
|
@ -172,7 +181,6 @@ namespace extract {
|
|||
|
||||
void extractCheats(const std::string& zipPath, std::vector<std::string> titles, CFW cfw, bool credits)
|
||||
{
|
||||
ProgressEvent::instance().reset();
|
||||
zipper::Unzipper unzipper(zipPath);
|
||||
std::vector<zipper::ZipEntry> entries = unzipper.entries();
|
||||
//std::set<std::string> extractedTitles;
|
||||
|
@ -238,6 +246,9 @@ namespace extract {
|
|||
std::string id;
|
||||
ProgressEvent::instance().setTotalSteps(titles.size());
|
||||
for (size_t j = 0; j < titles.size(); j++) {
|
||||
if (ProgressEvent::instance().getInterupt()) {
|
||||
break;
|
||||
}
|
||||
for (size_t l = lastL; l < parents.size(); l++) {
|
||||
if (strcasecmp((titles[j]).c_str(), parents[l].substr(offset, 16).c_str()) == 0) {
|
||||
unzipper.extractEntry(parents[l]);
|
||||
|
@ -261,10 +272,9 @@ namespace extract {
|
|||
|
||||
void extractAllCheats(const std::string& zipPath, CFW cfw)
|
||||
{
|
||||
ProgressEvent::instance().reset();
|
||||
zipper::Unzipper unzipper(zipPath);
|
||||
std::vector<zipper::ZipEntry> entries = unzipper.entries();
|
||||
//std::set<std::string> extractedTitles;
|
||||
|
||||
int offset = 0;
|
||||
switch (cfw) {
|
||||
case CFW::ams:
|
||||
|
@ -288,6 +298,9 @@ namespace extract {
|
|||
}
|
||||
ProgressEvent::instance().setTotalSteps(entries.size());
|
||||
for (const auto& entry : entries) {
|
||||
if (ProgressEvent::instance().getInterupt()) {
|
||||
break;
|
||||
}
|
||||
if (((int)entry.name.size() == offset + 16 + 4) && (isBID(entry.name.substr(offset, 16)))) {
|
||||
//extractedTitles.insert(util::upperCase(entry.name.substr(offset - 24, 16)));
|
||||
unzipper.extractEntry(entry.name);
|
||||
|
@ -325,7 +338,6 @@ namespace extract {
|
|||
void removeCheats()
|
||||
{
|
||||
std::string path = util::getContentsPath();
|
||||
ProgressEvent::instance().reset();
|
||||
ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator()));
|
||||
for (const auto& entry : std::filesystem::directory_iterator(path)) {
|
||||
removeCheatsDirectory(entry.path().string());
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "constants.hpp"
|
||||
#include "download.hpp"
|
||||
#include "extract.hpp"
|
||||
#include "main_frame.hpp"
|
||||
#include "progress_event.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->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; });
|
||||
}
|
||||
|
||||
|
@ -44,6 +48,9 @@ void WorkerPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned hei
|
|||
this->draw_page = false;
|
||||
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 {
|
||||
ProgressEvent::instance().setStatusCode(0);
|
||||
frame->nextStage();
|
||||
|
@ -54,7 +61,6 @@ void WorkerPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned hei
|
|||
this->progressDisp->frame(ctx);
|
||||
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 - MB/s)", text, ProgressEvent::instance().getNow() / 0x100000, ProgressEvent::instance().getTotal() / 0x100000));
|
||||
}
|
||||
this->label->frame(ctx);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue