Do Download Speed optional.

Cause I cannot properly fix that now.
This commit is contained in:
StackZ 2020-06-29 19:28:52 +02:00
commit 85a18eb031
5 changed files with 38 additions and 18 deletions

View file

@ -44,6 +44,7 @@ namespace GFX {
void DrawSpriteBlend(int img, int x, int y, float ScaleX = 1, float ScaleY = 1);
void DrawButton(int x, int y, std::string ButtonText = "", u32 color = config->buttonColor());
void TextFormatted(float x, float y, float size, const char *format, ...);
}
#endif

View file

@ -120,7 +120,10 @@ public:
// Use ScriptColors.
bool useScriptColor() { return this->v_useScriptColor; }
void useScriptColor(bool v) { this->v_useScriptColor = v; if (!this->changesMade) this->changesMade = true; }
// Show Downloadspeed.
bool showSpeed() { return this->v_showSpeed; }
void showSpeed(bool v) { this->v_showSpeed = v; if (!this->changesMade) this->changesMade = true; }
// Mainly helper.
bool getBool(const std::string &key);
void setBool(const std::string &key, bool v);
@ -138,7 +141,7 @@ private:
v_outdatedColor, v_uptodateColor, v_notfoundColor, v_futureColor;
std::string v_scriptPath, v_musicPath, v_storePath, v_autobootFile, v_language;
int v_langPath, v_viewMode, v_autoboot, v_keyDelay;
bool v_logging, v_useBars, v_screenFade, v_progressDisplay, v_firstStartup, v_useScriptColor;
bool v_logging, v_useBars, v_screenFade, v_progressDisplay, v_firstStartup, v_useScriptColor, v_showSpeed;
};
#endif

View file

@ -851,22 +851,10 @@ void displayProgressBar() {
downloadTotal = downloadNow;
}
if (!curlResult) {
curl_off_t speed;
curlResult = curl_easy_getinfo(hnd, CURLINFO_SPEED_DOWNLOAD_T, &speed);
if (!curlResult) {
snprintf(str, sizeof(str), "%s / %s (%.2f%%) \n\n\n\n\n %s %lld %s",
formatBytes(downloadNow).c_str(),
formatBytes(downloadTotal).c_str(),
((float)downloadNow/(float)downloadTotal) * 100.0f,
Lang::get("DOWNLOAD_SPEED").c_str(), (speed / 1000), Lang::get("KB_PER_SECOND").c_str());
} else {
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
formatBytes(downloadNow).c_str(),
formatBytes(downloadTotal).c_str(),
((float)downloadNow/(float)downloadTotal) * 100.0f);
}
}
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
formatBytes(downloadNow).c_str(),
formatBytes(downloadTotal).c_str(),
((float)downloadNow/(float)downloadTotal) * 100.0f);
break;
case ProgressBar::Extracting:
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
@ -893,6 +881,16 @@ void displayProgressBar() {
switch(progressbarType) {
case ProgressBar::Downloading:
Gui::DrawStringCentered(0, 80, 0.6f, isScriptSelected ? TextColor : config->textColor(), str, 400);
if (!curlResult && hnd != nullptr && config->showSpeed()) {
curl_off_t speed = 0;
curlResult = curl_easy_getinfo(hnd, CURLINFO_SPEED_DOWNLOAD_T, &speed);
if (!curlResult) {
GFX::TextFormatted(0, 170, 0.6f, "%s %lld %s", Lang::get("DOWNLOAD_SPEED").c_str(), (speed / 1000), Lang::get("KB_PER_SECOND").c_str());
} else {
Gui::DrawStringCentered(0, 170, 0.6f, isScriptSelected ? TextColor : config->textColor(), Lang::get("DOWNLOAD_SPEED") + "?");
}
}
Animation::DrawProgressBar(downloadNow, downloadTotal);
break;
case ProgressBar::Extracting:

View file

@ -98,4 +98,14 @@ void GFX::DrawButton(int x, int y, std::string ButtonText, u32 color) {
C2D_SetImageTint(&tint, C2D_BotRight, color, 0.5);
C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, sprites_button_idx), x, y, 0.5f, &tint);
Gui::DrawStringCentered(- (158/2) + x, y + (61/2) - (Gui::GetStringHeight(0.6f, ButtonText) / 2), 0.6f, isScriptSelected ? TextColor : config->textColor(), ButtonText, 145, 30);
}
void GFX::TextFormatted(float x, float y, float size, const char *format, ...) {
char str[512];
va_list va;
va_start(va, format);
vsnprintf(str, 512, format, va);
va_end(va);
char * Text = strtok(str, "\n");
Gui::DrawStringCentered(x, y, size, isScriptSelected ? TextColor : config->textColor(), Text);
}

View file

@ -68,6 +68,7 @@ void Config::initialize() {
this->setString("LANGUAGE", "en");
this->setBool("FIRST_STARTUP", true);
this->setBool("USE_SCRIPT_COLORS", true);
this->setBool("SHOW_SPEED", false);
this->setInt("VERSION", this->configVersion);
// Write to file.
@ -258,6 +259,12 @@ Config::Config() {
this->useScriptColor(this->getBool("USE_SCRIPT_COLORS"));
}
if (!this->json.contains("SHOW_SPEED")) {
this->showSpeed(false);
} else {
this->showSpeed(this->getBool("SHOW_SPEED"));
}
this->changesMade = false; // No changes made yet.
}
@ -294,6 +301,7 @@ void Config::save() {
this->setString("LANGUAGE", this->language());
this->setBool("FIRST_STARTUP", this->firstStartup());
this->setBool("USE_SCRIPT_COLORS", this->useScriptColor());
this->setBool("SHOW_SPEED", this->showSpeed());
// Write changes to file.
fwrite(this->json.dump(1, '\t').c_str(), 1, this->json.dump(1, '\t').size(), file);
fclose(file);