1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-08 11:31:43 +00:00

Added information about download progress.

This commit is contained in:
flb 2021-03-11 18:42:10 +01:00
parent 7511637f8d
commit cc9e74386e
6 changed files with 38 additions and 4 deletions

View file

@ -22,7 +22,7 @@ DATA := data
INCLUDES := include lib/zipper/include
APP_TITLE := All-in-One Switch Updater
APP_AUTHOR := HamletDuFromage
APP_VERSION := 2.4.0
APP_VERSION := 2.4.1
TARGET := $(notdir $(CURDIR))
ROMFS := resources

View file

@ -5,6 +5,9 @@ private:
ProgressEvent() {}
int _current = 0;
int _max = 60;
double _now = 0;
double _total = 0;
double _speed = 0;
public:
ProgressEvent(const ProgressEvent&) = delete;
@ -20,11 +23,20 @@ public:
void reset() {
_current = 0;
_max = 60;
_now = 0;
_total = 0;
_speed = 0;
}
inline void setTotalSteps(int steps) { _max = steps; }
inline void setTotalCount(double total) { _total = total; }
inline void setSpeed(double speed) { _speed = speed; }
inline void setStep(int step) { _current = step; }
inline void setNow(double now) { _now = now; }
inline int getStep() { return _current; }
inline double getNow() { return _now; }
inline bool finished() { return (_current == _max) ; }
inline int getMax() { return _max; }
inline double getTotal() { return _total; }
inline double getSpeed() { return _speed; }
};

View file

@ -3,7 +3,6 @@
#include <borealis.hpp>
#include <thread>
typedef std::function<void()> worker_func_t;
class WorkerPage : public brls::View
@ -13,6 +12,7 @@ class WorkerPage : public brls::View
brls::StagedAppletFrame* frame;
brls::Button* button;
brls::Label* label;
std::string text;
int progressValue = 0;
bool workStarted = false;
std::thread* workerThread;

View file

@ -118,6 +118,9 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true)
verTitles.push_back("v2.4.0");
changes.push_back("\uE016 Added option to extract the entire gbatemp cheats archive.\n\uE016 Shortened load times.\n\uE016 Added German localisation (thanks to github.com/Slluxx).\n\uE016 Added option to disable sysmodules prior to updating.\n\uE016 Improved Japanese localisation (thanks to github.com/yyoossk).\n\uE016 Added current AMS version display.");
verTitles.push_back("v2.4.1");
changes.push_back("\uE016 Added information about download progress.");
for(int i = verTitles.size() -1 ; i >= 0; i--){
listItem = new brls::ListItem(verTitles[i]);
change = changes[i];

View file

@ -4,6 +4,7 @@
#include <time.h>
#include <math.h>
#include <curl/curl.h>
#include <chrono>
#include <string>
#include <regex>
@ -16,6 +17,9 @@
using json = nlohmann::json;
std::chrono::_V2::steady_clock::time_point time_old;
double dlold;
typedef struct
{
char *memory;
@ -54,6 +58,15 @@ int download_progress(void *p, double dltotal, double dlnow, double ultotal, dou
double fractionDownloaded = dlnow / dltotal;
int counter = (int) (fractionDownloaded * ProgressEvent::instance().getMax()); //20 is the number of increments
ProgressEvent::instance().setStep(std::min(ProgressEvent::instance().getMax() - 1, counter));
ProgressEvent::instance().setNow(dlnow);
ProgressEvent::instance().setTotalCount(dltotal);
auto time_now = std::chrono::steady_clock::now();
double elasped_time = ((std::chrono::duration<double>) (time_now - time_old)).count();
if(elasped_time > 1.0f) {
ProgressEvent::instance().setSpeed((dlnow - dlold) / elasped_time);
dlold = dlnow;
time_old = time_now;
}
return 0;
}
@ -62,6 +75,8 @@ std::vector<std::uint8_t> downloadFile(const char *url, const char *output, int
ProgressEvent::instance().reset();
CURL *curl = curl_easy_init();
ntwrk_struct_t chunk = {0};
time_old = std::chrono::steady_clock::now();
dlold = 0.0f;
if (curl)
{
FILE *fp = fopen(output, "wb");
@ -84,7 +99,6 @@ std::vector<std::uint8_t> downloadFile(const char *url, const char *output, int
if (api == OFF)
{
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
//curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &prog);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, download_progress);
}
curl_easy_perform(curl);

View file

@ -8,7 +8,8 @@
#include "constants.hpp"
#include "progress_event.hpp"
WorkerPage::WorkerPage(brls::StagedAppletFrame* frame, const std::string& text, worker_func_t worker_func): frame(frame), workerFunc(worker_func)
WorkerPage::WorkerPage(brls::StagedAppletFrame* frame, const std::string& text, worker_func_t worker_func): frame(frame), workerFunc(worker_func), text(text)
{
this->progressDisp = new brls::ProgressDisplay();
this->progressDisp->setParent(this);
@ -43,6 +44,10 @@ void WorkerPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned hei
{
this->progressDisp->setProgress(ProgressEvent::instance().getStep(), ProgressEvent::instance().getMax());
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);
}
}