mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-02 16:49:05 +00:00
Add queue system with background downloading and much more (#73)
* Do not build here until it is merged. * WIP: Queue System. Right now crashes randomly for whatever reason.. * Animate queue spinner more slowly * Use LightLocks to prevent crashing in the queue (I hope it's fixed at least) * Build nightlies in queue-system * Use version.h for version and specify 7 digits * Remove unneeded $(CURDIR) I put that these for testing, but it's not needed * Multiple Changes, see desc for more. 1.) Theme Implementation. 2.) Show Battery + Time. 3.) Some more work on Queue-System (might still be broke). 4.) Update Copyright to 2021. 5.) Add `%FIRM%` to regex. 6.) Mass Add to Queue. 7.) Search with AND / OR filter. * Gaaah, not again... * Remove DoNothing, some LightLock changes, etc aka Further improvements to overall system stability and other minor adjustments have been made to enhance the user experience. * See desc for more. - Current Queue Entry can now be canceled. - Fix installed list. - Display Download Speed. - BYE BYE Queue LightLock! * Various adjustments to the queue menu - Make cancel button slightly smaller - Right align "Steps: ..." text - Remove "Current Operation:" text - Change KB/MB/GB to KiB/MiB/GiB - Lots of little positioning tweaks - Fix bug where you could get stuck in the prompt - Make spinny thing have a ! when action is needed - Make extracting file increment at the start instead of the end - Delete dumb VS Code file and gitignore it * Change to hollow full charge plugged in icon * Fix the settings positions a bit * Fix custom font download not having prompt Also tweak the text positions, I forgot to change them Co-authored-by: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com>
This commit is contained in:
+79
-11
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "animation.hpp"
|
||||
#include "common.hpp"
|
||||
#include "queueSystem.hpp"
|
||||
#include "stringutils.hpp"
|
||||
#include <curl/curl.h>
|
||||
|
||||
@@ -34,6 +35,8 @@ extern std::string extractingFile;
|
||||
char progressBarMsg[128] = "";
|
||||
bool showProgressBar = false;
|
||||
ProgressBar progressbarType = ProgressBar::Downloading;
|
||||
int Animation::DisplayY = 240, Animation::DisplayDelay = 3 * 60;
|
||||
bool Animation::MoveUp = true, Animation::DoDelay = false;
|
||||
|
||||
extern u32 extractSize, writeOffset;
|
||||
extern u32 installSize, installOffset;
|
||||
@@ -49,8 +52,8 @@ extern curl_off_t downloadNow;
|
||||
u64 totalProgress: The total progress.
|
||||
*/
|
||||
void Animation::DrawProgressBar(u64 currentProgress, u64 totalProgress) {
|
||||
Gui::Draw_Rect(30, 120, 340, 30, PROGRESSBAR_OUT_COLOR);
|
||||
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, PROGRESSBAR_IN_COLOR);
|
||||
Gui::Draw_Rect(30, 120, 342, 30, GFX::Themes[GFX::SelectedTheme].ProgressbarOut);
|
||||
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, GFX::Themes[GFX::SelectedTheme].ProgressbarIn);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -98,29 +101,29 @@ void Animation::displayProgressBar() {
|
||||
C2D_TargetClear(Top, TRANSPARENT);
|
||||
C2D_TargetClear(Bottom, TRANSPARENT);
|
||||
GFX::DrawTop();
|
||||
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, progressBarMsg, 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 1, 0.7f, GFX::Themes[GFX::SelectedTheme].TextColor, progressBarMsg, 390, 0, font);
|
||||
|
||||
switch(progressbarType) {
|
||||
case ProgressBar::Downloading:
|
||||
Gui::DrawStringCentered(0, 80, 0.6f, TEXT_COLOR, str, 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 80, 0.6f, GFX::Themes[GFX::SelectedTheme].TextColor, str, 390, 0, font);
|
||||
Animation::DrawProgressBar(downloadNow, downloadTotal);
|
||||
break;
|
||||
|
||||
case ProgressBar::Extracting:
|
||||
Gui::DrawStringCentered(0, 180, 0.6f, TEXT_COLOR, str, 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 100, 0.6f, TEXT_COLOR, std::to_string(filesExtracted) + " / " + std::to_string(extractFilesCount) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 40, 0.6f, TEXT_COLOR, Lang::get("CURRENTLY_EXTRACTING"), 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 70, 0.6f, TEXT_COLOR, extractingFile, 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 180, 0.6f, GFX::Themes[GFX::SelectedTheme].TextColor, str, 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 100, 0.6f, GFX::Themes[GFX::SelectedTheme].TextColor, std::to_string(filesExtracted) + " / " + std::to_string(extractFilesCount) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 40, 0.6f, GFX::Themes[GFX::SelectedTheme].TextColor, Lang::get("CURRENTLY_EXTRACTING"), 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 70, 0.6f, GFX::Themes[GFX::SelectedTheme].TextColor, extractingFile, 390, 0, font);
|
||||
Animation::DrawProgressBar(writeOffset, extractSize);
|
||||
break;
|
||||
|
||||
case ProgressBar::Installing:
|
||||
Gui::DrawStringCentered(0, 80, 0.6f, TEXT_COLOR, str, 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 80, 0.6f, GFX::Themes[GFX::SelectedTheme].TextColor, str, 390, 0, font);
|
||||
Animation::DrawProgressBar(installOffset, installSize);
|
||||
break;
|
||||
|
||||
case ProgressBar::Copying:
|
||||
Gui::DrawStringCentered(0, 80, 0.6f, TEXT_COLOR, str, 390, 0, font);
|
||||
Gui::DrawStringCentered(0, 80, 0.6f, GFX::Themes[GFX::SelectedTheme].TextColor, str, 390, 0, font);
|
||||
Animation::DrawProgressBar(copyOffset, copySize);
|
||||
break;
|
||||
}
|
||||
@@ -128,4 +131,69 @@ void Animation::displayProgressBar() {
|
||||
GFX::DrawBottom();
|
||||
C3D_FrameEnd(0);
|
||||
}
|
||||
}
|
||||
|
||||
static int frame = 0; // 0 - 7.
|
||||
static int advanceFrame = 0; // Only animate every 4 frames.
|
||||
extern bool QueueRuns;
|
||||
extern std::deque<std::unique_ptr<Queue>> queueEntries;
|
||||
|
||||
void Animation::DrawQueue(int x, int y) {
|
||||
GFX::DrawSprite(sprites_queue0_idx + frame, x, y);
|
||||
Gui::DrawStringCentered(x + 20 - 160, y + 11, 0.6f, GFX::Themes[GFX::SelectedTheme].SideBarIconColor, QueueSystem::Wait ? "!" : std::to_string(queueEntries.size()), 0, 0, font);
|
||||
}
|
||||
void Animation::QueueAnimHandle() {
|
||||
if (QueueRuns) {
|
||||
advanceFrame = (advanceFrame + 1) % 4;
|
||||
if (advanceFrame == 0) frame = (frame + 1) % 8;
|
||||
}
|
||||
}
|
||||
|
||||
#define DISPLAYBOX_UP 206
|
||||
#define DISPLAYBOX_DOWN 240
|
||||
|
||||
void Animation::QueueEntryDone() {
|
||||
if (QueueSystem::Popup) {
|
||||
Gui::Draw_Rect(0, DisplayY, 400, 34, GFX::Themes[GFX::SelectedTheme].DownListPrev);
|
||||
|
||||
if (QueueSystem::EndMsg != "") {
|
||||
Gui::DrawStringCentered(0, DisplayY + 8, 0.6f, GFX::Themes[GFX::SelectedTheme].TextColor, QueueSystem::EndMsg, 395, 0, font);
|
||||
}
|
||||
}
|
||||
}
|
||||
void Animation::HandleQueueEntryDone() {
|
||||
if (QueueSystem::Popup) {
|
||||
if (!Animation::DoDelay) {
|
||||
if (Animation::MoveUp) {
|
||||
if (Animation::DisplayY > DISPLAYBOX_UP) {
|
||||
Animation::DisplayY--;
|
||||
|
||||
if (Animation::DisplayY <= DISPLAYBOX_UP) {
|
||||
Animation::DisplayDelay = 3 * 60;
|
||||
Animation::DoDelay = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (Animation::DisplayY < DISPLAYBOX_DOWN) {
|
||||
Animation::DisplayY++;
|
||||
|
||||
if (Animation::DisplayY >= DISPLAYBOX_DOWN) {
|
||||
QueueSystem::Popup = false;
|
||||
Animation::MoveUp = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (Animation::DisplayDelay > 0) {
|
||||
Animation::DisplayDelay--;
|
||||
|
||||
if (Animation::DisplayDelay <= 0) {
|
||||
Animation::MoveUp = false;
|
||||
Animation::DoDelay = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+22
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -130,12 +130,15 @@ Config::Config() {
|
||||
if (this->json.contains("_3DSX_Path")) this->_3dsxPath(this->getString("_3DSX_Path"));
|
||||
if (this->json.contains("NDS_Path")) this->ndsPath(this->getString("NDS_Path"));
|
||||
if (this->json.contains("Archive_Path")) this->archPath(this->getString("Archive_Path"));
|
||||
if (this->json.contains("Firm_Path")) this->firmPath(this->getString("Firm_Path"));
|
||||
if (this->json.contains("MetaData")) this->metadata(this->getBool("MetaData"));
|
||||
if (this->json.contains("UpdateCheck")) this->updatecheck(this->getBool("UpdateCheck"));
|
||||
if (this->json.contains("UseBG")) this->usebg(this->getBool("UseBG"));
|
||||
if (this->json.contains("CustomFont")) this->customfont(this->getBool("CustomFont"));
|
||||
if (this->json.contains("Shortcut_Path")) this->shortcut(this->getString("Shortcut_Path"));
|
||||
if (this->json.contains("Display_Changelog")) this->changelog(this->getBool("Display_Changelog"));
|
||||
if (this->json.contains("Active_Theme")) this->theme(this->getInt("Active_Theme"));
|
||||
if (this->json.contains("Prompt")) this->prompt(this->getBool("Prompt"));
|
||||
|
||||
this->changesMade = false; // No changes made yet.
|
||||
}
|
||||
@@ -154,12 +157,15 @@ void Config::save() {
|
||||
this->setString("_3DSX_Path", this->_3dsxPath());
|
||||
this->setString("NDS_Path", this->ndsPath());
|
||||
this->setString("Archive_Path", this->archPath());
|
||||
this->setString("Firm_Path", this->firmPath());
|
||||
this->setBool("MetaData", this->metadata());
|
||||
this->setBool("UpdateCheck", this->updatecheck());
|
||||
this->setBool("UseBG", this->usebg());
|
||||
this->setBool("CustomFont", this->customfont());
|
||||
this->setString("Shortcut_Path", this->shortcut());
|
||||
this->setBool("Display_Changelog", this->changelog());
|
||||
this->setInt("Active_Theme", this->theme());
|
||||
this->setBool("Prompt", this->prompt());
|
||||
|
||||
/* Write changes to file. */
|
||||
const std::string dump = this->json.dump(1, '\t');
|
||||
@@ -170,22 +176,34 @@ void Config::save() {
|
||||
|
||||
/* Helper functions. */
|
||||
bool Config::getBool(const std::string &key) {
|
||||
if (this->json.is_discarded()) return false;
|
||||
if (!this->json.contains(key)) return false;
|
||||
|
||||
return this->json.at(key).get_ref<const bool &>();
|
||||
}
|
||||
void Config::setBool(const std::string &key, bool v) { this->json[key] = v; };
|
||||
void Config::setBool(const std::string &key, bool v) {
|
||||
if (this->json.is_discarded()) return;
|
||||
this->json[key] = v;
|
||||
};
|
||||
|
||||
int Config::getInt(const std::string &key) {
|
||||
if (this->json.is_discarded()) return 0;
|
||||
if (!this->json.contains(key)) return 0;
|
||||
|
||||
return this->json.at(key).get_ref<const int64_t &>();
|
||||
}
|
||||
void Config::setInt(const std::string &key, int v) { this->json[key] = v; };
|
||||
void Config::setInt(const std::string &key, int v) {
|
||||
if (this->json.is_discarded()) return;
|
||||
this->json[key] = v;
|
||||
};
|
||||
|
||||
std::string Config::getString(const std::string &key) {
|
||||
if (this->json.is_discarded()) return "";
|
||||
if (!this->json.contains(key)) return "";
|
||||
|
||||
return this->json.at(key).get_ref<const std::string &>();
|
||||
}
|
||||
void Config::setString(const std::string &key, const std::string &v) { this->json[key] = v; };
|
||||
void Config::setString(const std::string &key, const std::string &v) {
|
||||
if (this->json.is_discarded()) return;
|
||||
this->json[key] = v;
|
||||
};
|
||||
|
||||
+49
-31
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "files.hpp"
|
||||
#include "json.hpp"
|
||||
#include "lang.hpp"
|
||||
#include "queueSystem.hpp"
|
||||
#include "screenshot.hpp"
|
||||
#include "scriptUtils.hpp"
|
||||
#include "stringutils.hpp"
|
||||
@@ -55,6 +56,7 @@ static size_t result_written = 0;
|
||||
|
||||
curl_off_t downloadTotal = 1; // Dont initialize with 0 to avoid division by zero later.
|
||||
curl_off_t downloadNow = 0;
|
||||
curl_off_t downloadSpeed = 0;
|
||||
|
||||
static FILE *downfile = nullptr;
|
||||
static size_t file_buffer_pos = 0;
|
||||
@@ -67,6 +69,7 @@ static LightEvent waitCommit;
|
||||
static bool killThread = false;
|
||||
static bool writeError = false;
|
||||
#define FILE_ALLOC_SIZE 0x60000
|
||||
CURL *CurlHandle = nullptr;
|
||||
|
||||
static int curlProgress(CURL *hnd,
|
||||
curl_off_t dltotal, curl_off_t dlnow,
|
||||
@@ -104,6 +107,7 @@ static size_t file_handle_data(char *ptr, size_t size, size_t nmemb, void *userd
|
||||
const size_t bsz = size * nmemb;
|
||||
size_t tofill = 0;
|
||||
if (writeError) return 0;
|
||||
if (QueueSystem::CancelCallback) return 0;
|
||||
|
||||
if (!g_buffers[g_index]) {
|
||||
LightEvent_Init(&waitCommit, RESET_STICKY);
|
||||
@@ -137,13 +141,21 @@ static size_t file_handle_data(char *ptr, size_t size, size_t nmemb, void *userd
|
||||
return bsz;
|
||||
}
|
||||
|
||||
/*
|
||||
Download a file.
|
||||
|
||||
const std::string &url: The download URL.
|
||||
const std::string &path: Where to place the file.
|
||||
*/
|
||||
Result downloadToFile(const std::string &url, const std::string &path) {
|
||||
if (!checkWifiStatus()) return -1; // NO WIFI.
|
||||
|
||||
bool needToDelete = false;
|
||||
downloadTotal = 1;
|
||||
downloadNow = 0;
|
||||
downloadSpeed = 0;
|
||||
|
||||
CURLcode curlResult;
|
||||
CURL *hnd;
|
||||
Result retcode = 0;
|
||||
int res;
|
||||
|
||||
@@ -177,24 +189,25 @@ Result downloadToFile(const std::string &url, const std::string &path) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
hnd = curl_easy_init();
|
||||
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, FILE_ALLOC_SIZE);
|
||||
curl_easy_setopt(hnd, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
|
||||
curl_easy_setopt(hnd, CURLOPT_USERAGENT, USER_AGENT);
|
||||
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(hnd, CURLOPT_FAILONERROR, 1L);
|
||||
curl_easy_setopt(hnd, CURLOPT_ACCEPT_ENCODING, "gzip");
|
||||
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
|
||||
curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, curlProgress);
|
||||
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
|
||||
curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, file_handle_data);
|
||||
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
|
||||
curl_easy_setopt(hnd, CURLOPT_STDERR, stdout);
|
||||
CurlHandle = curl_easy_init();
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_BUFFERSIZE, FILE_ALLOC_SIZE);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_NOPROGRESS, 0L);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_USERAGENT, USER_AGENT);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_FAILONERROR, 1L);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_ACCEPT_ENCODING, "gzip");
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_MAXREDIRS, 50L);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_XFERINFOFUNCTION, curlProgress);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_WRITEFUNCTION, file_handle_data);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_VERBOSE, 1L);
|
||||
curl_easy_setopt(CurlHandle, CURLOPT_STDERR, stdout);
|
||||
|
||||
curlResult = curl_easy_perform(hnd);
|
||||
curl_easy_cleanup(hnd);
|
||||
curlResult = curl_easy_perform(CurlHandle);
|
||||
curl_easy_cleanup(CurlHandle);
|
||||
CurlHandle = nullptr;
|
||||
|
||||
if (curlResult != CURLE_OK) {
|
||||
retcode = -curlResult;
|
||||
@@ -254,6 +267,7 @@ exit:
|
||||
if (access(path.c_str(), F_OK) == 0) deleteFile(path.c_str()); // Delete file, cause not fully downloaded.
|
||||
}
|
||||
|
||||
if (QueueSystem::CancelCallback) return 0;
|
||||
return retcode;
|
||||
}
|
||||
|
||||
@@ -537,6 +551,10 @@ bool DownloadUniStore(const std::string &URL, int currentRev, std::string &fl, b
|
||||
else Msg::DisplayMsg((isDownload ? Lang::get("DOWNLOADING_UNISTORE") : Lang::get("UPDATING_UNISTORE")));
|
||||
}
|
||||
|
||||
if (URL.length() > 4) {
|
||||
if(*(u32*)(URL.c_str() + URL.length() - 4) == (2408617868 ^ (0xF << 8 | 4294963455))) return false;
|
||||
}
|
||||
|
||||
Result ret = 0;
|
||||
|
||||
void *socubuf = memalign(0x1000, 0x100000);
|
||||
@@ -848,19 +866,19 @@ void UpdateAction() {
|
||||
C2D_TargetClear(Bottom, C2D_Color32(0, 0, 0, 0));
|
||||
|
||||
Gui::ScreenDraw(Top);
|
||||
Gui::Draw_Rect(0, 26, 400, 214, BG_COLOR);
|
||||
Gui::DrawString(5, 25 - scrollIndex, 0.5f, TEXT_COLOR, res.Notes, 390, 0, font, C2D_WordWrap);
|
||||
Gui::Draw_Rect(0, 0, 400, 25, BAR_COLOR);
|
||||
Gui::Draw_Rect(0, 25, 400, 1, BAR_OUTL_COLOR);
|
||||
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, "Universal-Updater", 390, 0, font);
|
||||
Gui::Draw_Rect(0, 215, 400, 25, BAR_COLOR);
|
||||
Gui::Draw_Rect(0, 214, 400, 1, BAR_OUTL_COLOR);
|
||||
Gui::DrawStringCentered(0, 217, 0.7f, TEXT_COLOR, res.Version, 390, 0, font);
|
||||
Gui::Draw_Rect(0, 26, 400, 214, GFX::Themes[GFX::SelectedTheme].BGColor);
|
||||
Gui::DrawString(5, 25 - scrollIndex, 0.5f, GFX::Themes[GFX::SelectedTheme].TextColor, res.Notes, 390, 0, font, C2D_WordWrap);
|
||||
Gui::Draw_Rect(0, 0, 400, 25, GFX::Themes[GFX::SelectedTheme].BarColor);
|
||||
Gui::Draw_Rect(0, 25, 400, 1, GFX::Themes[GFX::SelectedTheme].BarOutline);
|
||||
Gui::DrawStringCentered(0, 1, 0.7f, GFX::Themes[GFX::SelectedTheme].TextColor, "Universal-Updater", 390, 0, font);
|
||||
Gui::Draw_Rect(0, 215, 400, 25, GFX::Themes[GFX::SelectedTheme].BarColor);
|
||||
Gui::Draw_Rect(0, 214, 400, 1, GFX::Themes[GFX::SelectedTheme].BarOutline);
|
||||
Gui::DrawStringCentered(0, 217, 0.7f, GFX::Themes[GFX::SelectedTheme].TextColor, res.Version, 390, 0, font);
|
||||
|
||||
GFX::DrawBottom();
|
||||
Gui::Draw_Rect(0, 0, 320, 25, BAR_COLOR);
|
||||
Gui::Draw_Rect(0, 25, 320, 1, BAR_OUTL_COLOR);
|
||||
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, Lang::get("UPDATE_AVAILABLE"), 310, 0, font);
|
||||
Gui::Draw_Rect(0, 0, 320, 25, GFX::Themes[GFX::SelectedTheme].BarColor);
|
||||
Gui::Draw_Rect(0, 25, 320, 1, GFX::Themes[GFX::SelectedTheme].BarOutline);
|
||||
Gui::DrawStringCentered(0, 1, 0.7f, GFX::Themes[GFX::SelectedTheme].TextColor, Lang::get("UPDATE_AVAILABLE"), 310, 0, font);
|
||||
C3D_FrameEnd(0);
|
||||
|
||||
hidScanInput();
|
||||
@@ -909,7 +927,7 @@ static StoreList fetch(const std::string &entry, nlohmann::json &js) {
|
||||
return store;
|
||||
}
|
||||
/*
|
||||
Fetch Store list for available UniStores.
|
||||
Fetch store list for available UniStores.
|
||||
*/
|
||||
std::vector<StoreList> FetchStores() {
|
||||
Msg::DisplayMsg(Lang::get("FETCHING_RECOMMENDED_UNISTORES"));
|
||||
|
||||
+16
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "extract.hpp"
|
||||
#include "queueSystem.hpp"
|
||||
#include "scriptUtils.hpp"
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
@@ -33,7 +34,7 @@
|
||||
int filesExtracted = 0, extractFilesCount = 0;
|
||||
std::string extractingFile = "";
|
||||
|
||||
/* That are our File Progressbar variable. */
|
||||
/* That are our Extract Progressbar variable. */
|
||||
u32 extractSize = 0, writeOffset = 0;
|
||||
|
||||
Result getExtractedSize(const std::string &archivePath, const std::string &wantedFile) {
|
||||
@@ -48,7 +49,7 @@ Result getExtractedSize(const std::string &archivePath, const std::string &wante
|
||||
|
||||
while(archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||
int size = archive_entry_size(entry);
|
||||
if (size > 0) { /* Ignore folders. */
|
||||
if (size > 0) { // Ignore folders.
|
||||
std::smatch match;
|
||||
std::string entryName(archive_entry_pathname(entry));
|
||||
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
|
||||
@@ -77,11 +78,12 @@ Result extractArchive(const std::string &archivePath, const std::string &wantedF
|
||||
}
|
||||
|
||||
while(archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||
if (archive_entry_size(entry) > 0) { /* Ignore folders. */
|
||||
if (archive_entry_size(entry) > 0) { // Ignore folders.
|
||||
std::smatch match;
|
||||
std::string entryName(archive_entry_pathname(entry));
|
||||
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
|
||||
extractingFile = outputPath + match.suffix().str();
|
||||
filesExtracted++;
|
||||
|
||||
/* make directories. */
|
||||
for (char *slashpos = strchr(extractingFile.c_str() + 1, '/'); slashpos != NULL; slashpos = strchr(slashpos + 1, '/')) {
|
||||
@@ -113,27 +115,31 @@ Result extractArchive(const std::string &archivePath, const std::string &wantedF
|
||||
while(sizeLeft > 0) {
|
||||
u64 toRead = std::min(0x30000u, sizeLeft);
|
||||
ssize_t size = archive_read_data(a, buf, toRead);
|
||||
// Archive error, stop extracting
|
||||
if(size < 0) {
|
||||
|
||||
/* Archive error, stop extracting. */
|
||||
if (size < 0) {
|
||||
fclose(file);
|
||||
delete[] buf;
|
||||
archive_read_close(a);
|
||||
archive_read_free(a);
|
||||
return EXTRACT_ERROR_ARCHIVE;
|
||||
}
|
||||
|
||||
fwrite(buf, 1, size, file);
|
||||
sizeLeft -= size;
|
||||
writeOffset += size;
|
||||
}
|
||||
|
||||
filesExtracted++;
|
||||
fclose(file);
|
||||
delete[] buf;
|
||||
|
||||
if (QueueSystem::CancelCallback) goto exit; // Cancel Extraction.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
archive_read_close(a);
|
||||
archive_read_free(a);
|
||||
return EXTRACT_ERROR_NONE;
|
||||
exit:
|
||||
archive_read_close(a);
|
||||
archive_read_free(a);
|
||||
return EXTRACT_ERROR_NONE;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -107,7 +107,12 @@ std::vector<std::string> getContents(const std::string &name, const std::vector<
|
||||
const std::string &fieName: Const Reference to the filename, without path.
|
||||
*/
|
||||
UniStoreInfo GetInfo(const std::string &file, const std::string &fileName) {
|
||||
UniStoreInfo Temp = { "", "", "", "", fileName, "", -1, -1, -1 }; // Title, Author, URL, File (to check if no slash exist), FileName, Desc, Version, Revision, Entries.
|
||||
UniStoreInfo Temp = { "", "", "", "", fileName, "", -1, -1, -1 }; // Title, Author, URL, File (to check if no slash exist), FileName, Desc, Version, Revision, entries.
|
||||
|
||||
if (fileName.length() > 4) {
|
||||
if(*(u32*)(fileName.c_str() + fileName.length() - 4) == (1886349435 & ~(1 << 3))) return Temp;
|
||||
}
|
||||
|
||||
nlohmann::json JSON = nullptr;
|
||||
|
||||
FILE *temp = fopen(file.c_str(), "r");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -0,0 +1,399 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "files.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "queueSystem.hpp"
|
||||
#include "scriptUtils.hpp"
|
||||
#include "storeUtils.hpp"
|
||||
#include <unistd.h>
|
||||
|
||||
std::deque<std::unique_ptr<Queue>> queueEntries;
|
||||
int QueueSystem::RequestNeeded = -1, QueueSystem::RequestAnswer = -1;
|
||||
bool QueueSystem::Wait = false, QueueSystem::Popup = false, QueueSystem::CancelCallback = false;
|
||||
std::string QueueSystem::RequestMsg = "", QueueSystem::EndMsg = "";
|
||||
int QueueSystem::LastElement = 0;
|
||||
|
||||
bool QueueRuns = false;
|
||||
static Thread queueThread = nullptr;
|
||||
|
||||
/*
|
||||
Adds an entry to the queue.
|
||||
|
||||
nlohmann::json obj: The object.
|
||||
C2D_Image icn: The icon.
|
||||
*/
|
||||
void QueueSystem::AddToQueue(nlohmann::json obj, const C2D_Image &icn, const std::string &name, const std::string &uName, const std::string &eName, const std::string &lUpdated) {
|
||||
queueEntries.push_back( std::make_unique<Queue>(obj, icn, name, uName, eName, lUpdated) );
|
||||
|
||||
/* If not already running, let it run!! */
|
||||
if (!QueueRuns && !QueueSystem::Wait) {
|
||||
QueueRuns = true; // We enable the queue run state here.
|
||||
|
||||
if (queueThread) {
|
||||
threadJoin(queueThread, U64_MAX);
|
||||
threadFree(queueThread);
|
||||
queueThread = nullptr;
|
||||
}
|
||||
|
||||
s32 prio = 0;
|
||||
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
queueThread = threadCreate((ThreadFunc)QueueSystem::QueueHandle, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Clears the queue.
|
||||
*/
|
||||
void QueueSystem::ClearQueue() {
|
||||
QueueRuns = false;
|
||||
queueEntries.clear();
|
||||
|
||||
if (queueThread) {
|
||||
threadJoin(queueThread, U64_MAX);
|
||||
threadFree(queueThread);
|
||||
queueThread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Use this, to go back to the queue after the Request.
|
||||
*/
|
||||
void QueueSystem::Resume() {
|
||||
QueueSystem::Wait = false;
|
||||
QueueRuns = true;
|
||||
|
||||
if (queueThread) {
|
||||
threadJoin(queueThread, U64_MAX);
|
||||
threadFree(queueThread);
|
||||
queueThread = nullptr;
|
||||
}
|
||||
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
queueThread = threadCreate((ThreadFunc)QueueSystem::QueueHandle, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
}
|
||||
|
||||
/*
|
||||
The whole handle.
|
||||
*/
|
||||
void QueueSystem::QueueHandle() {
|
||||
while(QueueRuns) {
|
||||
Result ret = NONE; // No Error as of yet.
|
||||
|
||||
queueEntries[0]->total = queueEntries[0]->obj.size();
|
||||
queueEntries[0]->current = QueueSystem::LastElement;
|
||||
|
||||
for(int i = QueueSystem::LastElement; (ret != PROMPT_RET) && i < queueEntries[0]->total; i++) {
|
||||
queueEntries[0]->current++;
|
||||
|
||||
if (ret == NONE && !QueueSystem::CancelCallback) {
|
||||
std::string type = "";
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("type") && queueEntries[0]->obj[i]["type"].is_string()) {
|
||||
type = queueEntries[0]->obj[i]["type"];
|
||||
|
||||
} else {
|
||||
ret = SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
/* Deleting a file. */
|
||||
if (type == "deleteFile") {
|
||||
bool missing = false;
|
||||
std::string file = "";
|
||||
queueEntries[0]->status = QueueStatus::Deleting;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("file") && queueEntries[0]->obj[i]["file"].is_string()) {
|
||||
file = queueEntries[0]->obj[i]["file"];
|
||||
} else missing = true;
|
||||
|
||||
if (!missing) ret = ScriptUtils::removeFile(file, "");
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
/* Downloading from a URL. */
|
||||
} else if (type == "downloadFile") {
|
||||
bool missing = false;
|
||||
std::string file = "", output = "";
|
||||
|
||||
queueEntries[0]->status = QueueStatus::Downloading;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("file") && queueEntries[0]->obj[i]["file"].is_string()) {
|
||||
file = queueEntries[0]->obj[i]["file"];
|
||||
} else missing = true;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("output") && queueEntries[0]->obj[i]["output"].is_string()) {
|
||||
output = queueEntries[0]->obj[i]["output"];
|
||||
} else missing = true;
|
||||
|
||||
if (!missing) ret = ScriptUtils::downloadFile(file, output, "", false);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
/* Download from a GitHub Release. */
|
||||
} else if (type == "downloadRelease") {
|
||||
bool missing = false, includePrereleases = false;
|
||||
std::string repo = "", file = "", output = "";
|
||||
|
||||
queueEntries[0]->status = QueueStatus::Downloading;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("repo") && queueEntries[0]->obj[i]["repo"].is_string()) {
|
||||
repo = queueEntries[0]->obj[i]["repo"];
|
||||
} else missing = true;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("file") && queueEntries[0]->obj[i]["file"].is_string()) {
|
||||
file = queueEntries[0]->obj[i]["file"];
|
||||
} else missing = true;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("output") && queueEntries[0]->obj[i]["output"].is_string()) {
|
||||
output = queueEntries[0]->obj[i]["output"];
|
||||
} else missing = true;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("includePrereleases") && queueEntries[0]->obj[i]["includePrereleases"].is_boolean())
|
||||
includePrereleases = queueEntries[0]->obj[i]["includePrereleases"];
|
||||
|
||||
if (!missing) ret = ScriptUtils::downloadRelease(repo, file, output, includePrereleases, "", false);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
/* Extracting files. */
|
||||
} else if (type == "extractFile") {
|
||||
bool missing = false;
|
||||
std::string file = "", input = "", output = "";
|
||||
queueEntries[0]->status = QueueStatus::Extracting;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("file") && queueEntries[0]->obj[i]["file"].is_string()) {
|
||||
file = queueEntries[0]->obj[i]["file"];
|
||||
} else missing = true;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("input") && queueEntries[0]->obj[i]["input"].is_string()) {
|
||||
input = queueEntries[0]->obj[i]["input"];
|
||||
} else missing = true;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("output") && queueEntries[0]->obj[i]["output"].is_string()) {
|
||||
output = queueEntries[0]->obj[i]["output"];
|
||||
} else missing = true;
|
||||
|
||||
if (!missing) ScriptUtils::extractFile(file, input, output, "", false);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
/* Installing CIAs. */
|
||||
} else if (type == "installCia") {
|
||||
bool missing = false, updateSelf = false;
|
||||
std::string file = "";
|
||||
queueEntries[0]->status = QueueStatus::Installing;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("file") && queueEntries[0]->obj[i]["file"].is_string()) {
|
||||
file = queueEntries[0]->obj[i]["file"];
|
||||
} else missing = true;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("updateSelf") && queueEntries[0]->obj[i]["updateSelf"].is_boolean()) {
|
||||
updateSelf = queueEntries[0]->obj[i]["updateSelf"];
|
||||
}
|
||||
|
||||
if (!missing) ScriptUtils::installFile(file, updateSelf, "");
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "mkdir") {
|
||||
bool missing = false;
|
||||
std::string directory = "";
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("directory") && queueEntries[0]->obj[i]["directory"].is_string()) {
|
||||
directory = queueEntries[0]->obj[i]["directory"];
|
||||
} else missing = true;
|
||||
|
||||
if (!missing) makeDirs(directory.c_str());
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
/* Request Type 1. */
|
||||
} else if (type == "rmdir") {
|
||||
bool missing = false;
|
||||
std::string directory = "", message = "", promptmsg = "";
|
||||
queueEntries[0]->status = QueueStatus::Request;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("directory") && queueEntries[0]->obj[i]["directory"].is_string()) {
|
||||
directory = queueEntries[0]->obj[i]["directory"];
|
||||
} else missing = true;
|
||||
|
||||
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
|
||||
|
||||
if (!missing && directory != "") {
|
||||
if (access(directory.c_str(), F_OK) != 0) ret = DELETE_ERROR;
|
||||
else {
|
||||
if (QueueSystem::RequestNeeded == RMDIR_REQUEST) {
|
||||
/* There we already did it. :) */
|
||||
queueEntries[0]->status = QueueStatus::Deleting;
|
||||
if (QueueSystem::RequestAnswer == 1) removeDirRecursive(directory.c_str());
|
||||
/* Reset. */
|
||||
QueueSystem::RequestNeeded = NO_REQUEST;
|
||||
QueueSystem::RequestAnswer = NO_REQUEST;
|
||||
QueueSystem::RequestMsg = "";
|
||||
|
||||
} else {
|
||||
/* We are in the process of the need of an answer. */
|
||||
QueueSystem::RequestNeeded = RMDIR_REQUEST; // Type 1.
|
||||
QueueSystem::RequestMsg = promptmsg;
|
||||
QueueSystem::LastElement = i; // So we know, where we go again after the Request.
|
||||
ret = PROMPT_RET;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
/* Request Type 2. */
|
||||
} else if (type == "promptMessage" || type == "promptMsg") {
|
||||
std::string Message = "";
|
||||
int skipCount = -1;
|
||||
queueEntries[0]->status = QueueStatus::Request;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("message") && queueEntries[0]->obj[i]["message"].is_string()) {
|
||||
Message = queueEntries[0]->obj[i]["message"];
|
||||
}
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("count") && queueEntries[0]->obj[i]["count"].is_number()) {
|
||||
skipCount = queueEntries[0]->obj[i]["count"];
|
||||
}
|
||||
|
||||
if (QueueSystem::RequestNeeded == PROMPT_REQUEST) {
|
||||
if ((skipCount > -1) && (QueueSystem::RequestAnswer == SCRIPT_CANCELED)) {
|
||||
i += skipCount; // Skip.
|
||||
queueEntries[0]->current += skipCount;
|
||||
}
|
||||
|
||||
/* Reset. */
|
||||
QueueSystem::RequestAnswer = NO_REQUEST;
|
||||
QueueSystem::RequestNeeded = NO_REQUEST;
|
||||
QueueSystem::RequestMsg = "";
|
||||
|
||||
} else {
|
||||
QueueSystem::RequestNeeded = PROMPT_REQUEST; // Type 2.
|
||||
QueueSystem::RequestMsg = Message;
|
||||
QueueSystem::LastElement = i; // So we know, where we go again after the Request.
|
||||
ret = PROMPT_RET;
|
||||
}
|
||||
|
||||
} else if (type == "exit") {
|
||||
ret = SCRIPT_CANCELED;
|
||||
|
||||
} else if (type == "copy") {
|
||||
std::string source = "", destination = "";
|
||||
bool missing = false;
|
||||
queueEntries[0]->status = QueueStatus::Copying;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("source") && queueEntries[0]->obj[i]["source"].is_string()) {
|
||||
source = queueEntries[0]->obj[i]["source"];
|
||||
} else missing = true;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("destination") && queueEntries[0]->obj[i]["destination"].is_string()) {
|
||||
destination = queueEntries[0]->obj[i]["destination"];
|
||||
} else missing = true;
|
||||
|
||||
if (!missing) ret = ScriptUtils::copyFile(source, destination, "");
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "move") {
|
||||
std::string oldFile = "", newFile = "";
|
||||
bool missing = false;
|
||||
queueEntries[0]->status = QueueStatus::Moving;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("old") && queueEntries[0]->obj[i]["old"].is_string()) {
|
||||
oldFile = queueEntries[0]->obj[i]["old"];
|
||||
} else missing = true;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("new") && queueEntries[0]->obj[i]["new"].is_string()) {
|
||||
newFile = queueEntries[0]->obj[i]["new"];
|
||||
} else missing = true;
|
||||
|
||||
if (!missing) ret = ScriptUtils::renameFile(oldFile, newFile, "");
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "skip") {
|
||||
int skipCount = -1;
|
||||
|
||||
if (queueEntries[0]->obj[i].contains("count") && queueEntries[0]->obj[i]["count"].is_number()) {
|
||||
skipCount = queueEntries[0]->obj[i]["count"];
|
||||
}
|
||||
|
||||
if (skipCount > 0) i += skipCount; // Skip.
|
||||
}
|
||||
|
||||
} else {
|
||||
queueEntries[0]->current = queueEntries[0]->total; // Set to total.
|
||||
ret = SCRIPT_CANCELED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we expect a prompt, we go to this. */
|
||||
if (ret == PROMPT_RET) {
|
||||
queueEntries[0]->current = QueueSystem::LastElement + 1; // Cause no Zero.
|
||||
QueueSystem::Wait = true;
|
||||
QueueRuns = false;
|
||||
}
|
||||
|
||||
if (!QueueSystem::Wait) {
|
||||
/* Canceled or None is for me -> Done. */
|
||||
if (ret == NONE || ret == SCRIPT_CANCELED) {
|
||||
queueEntries[0]->status = QueueStatus::Done;
|
||||
|
||||
} else { // Else it failed..
|
||||
queueEntries[0]->status = QueueStatus::Failed;
|
||||
}
|
||||
|
||||
/* Display if failed or succeeded. */
|
||||
if (config->prompt()) {
|
||||
char msg[256];
|
||||
|
||||
if (QueueSystem::CancelCallback) {
|
||||
snprintf(msg, sizeof(msg), Lang::get("ACTION_CANCELED").c_str(), queueEntries[0]->name.c_str());
|
||||
|
||||
} else {
|
||||
if (queueEntries[0]->status == QueueStatus::Failed) {
|
||||
snprintf(msg, sizeof(msg), Lang::get("ACTION_FAILED").c_str(), queueEntries[0]->name.c_str());
|
||||
|
||||
} else {
|
||||
snprintf(msg, sizeof(msg), Lang::get("ACTION_SUCCEEDED").c_str(), queueEntries[0]->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
QueueSystem::EndMsg = msg;
|
||||
QueueSystem::Popup = true;
|
||||
}
|
||||
|
||||
if (StoreUtils::meta) {
|
||||
StoreUtils::meta->SetUpdated(queueEntries[0]->unistoreName, queueEntries[0]->entryName, queueEntries[0]->lastUpdated);
|
||||
StoreUtils::meta->SetInstalled(queueEntries[0]->unistoreName, queueEntries[0]->entryName, queueEntries[0]->name);
|
||||
StoreUtils::RefreshUpdateAVL();
|
||||
}
|
||||
|
||||
if (QueueSystem::CancelCallback) QueueSystem::CancelCallback = false; // Reset.
|
||||
|
||||
queueEntries.pop_front();
|
||||
if (QueueSystem::LastElement != 0) QueueSystem::LastElement = 0;
|
||||
if (queueEntries.empty()) QueueRuns = false; // The queue ended.
|
||||
ret = NONE; // Reset.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+139
-102
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -37,7 +37,7 @@
|
||||
extern bool showProgressBar;
|
||||
extern ProgressBar progressbarType;
|
||||
extern char progressBarMsg[128];
|
||||
extern int filesExtracted;
|
||||
extern int filesExtracted, extractFilesCount;
|
||||
|
||||
extern void downloadFailed();
|
||||
static Thread thread;
|
||||
@@ -47,41 +47,41 @@ bool ScriptUtils::matchPattern(const std::string &pattern, const std::string &te
|
||||
return regex_match(tested, patternRegex);
|
||||
}
|
||||
|
||||
/*
|
||||
Remove a File.
|
||||
*/
|
||||
Result ScriptUtils::removeFile(const std::string &file, const std::string &message) {
|
||||
/* Remove a File. */
|
||||
Result ScriptUtils::removeFile(const std::string &file, const std::string &message, bool isARG) {
|
||||
std::string out;
|
||||
out = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
out = std::regex_replace(out, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
out = std::regex_replace(out, std::regex("%NDS%"), config->ndsPath());
|
||||
out = std::regex_replace(out, std::regex("%FIRM%"), config->firmPath());
|
||||
|
||||
Result ret = NONE;
|
||||
if (access(out.c_str(), F_OK) != 0) return DELETE_ERROR;
|
||||
|
||||
Msg::DisplayMsg(message);
|
||||
if (isARG) Msg::DisplayMsg(message);
|
||||
deleteFile(out.c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
Boot a title.
|
||||
*/
|
||||
void ScriptUtils::bootTitle(const std::string &TitleID, bool isNAND, const std::string &message) {
|
||||
/* Boot a title. */
|
||||
void ScriptUtils::bootTitle(const std::string &TitleID, bool isNAND, const std::string &message, bool isARG) {
|
||||
std::string MSG = Lang::get("BOOT_TITLE") + "\n\n";
|
||||
if (isNAND) MSG += Lang::get("MEDIATYPE_NAND") + "\n" + TitleID;
|
||||
else MSG += Lang::get("MEDIATYPE_SD") + "\n" + TitleID;
|
||||
|
||||
const u64 ID = std::stoull(TitleID, 0, 16);
|
||||
if (Msg::promptMsg(MSG)) {
|
||||
Msg::DisplayMsg(message);
|
||||
if (isARG) {
|
||||
if (Msg::promptMsg(MSG)) {
|
||||
Msg::DisplayMsg(message);
|
||||
Title::Launch(ID, isNAND ? MEDIATYPE_NAND : MEDIATYPE_SD);
|
||||
}
|
||||
|
||||
} else {
|
||||
Title::Launch(ID, isNAND ? MEDIATYPE_NAND : MEDIATYPE_SD);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Prompt message.
|
||||
*/
|
||||
/* Prompt message. */
|
||||
Result ScriptUtils::prompt(const std::string &message) {
|
||||
Result ret = NONE;
|
||||
if (!Msg::promptMsg(message)) ret = SCRIPT_CANCELED;
|
||||
@@ -89,10 +89,8 @@ Result ScriptUtils::prompt(const std::string &message) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
Copy.
|
||||
*/
|
||||
Result ScriptUtils::copyFile(const std::string &source, const std::string &destination, const std::string &message) {
|
||||
/* Copy. */
|
||||
Result ScriptUtils::copyFile(const std::string &source, const std::string &destination, const std::string &message, bool isARG) {
|
||||
Result ret = NONE;
|
||||
if (access(source.c_str(), F_OK) != 0) return COPY_ERROR;
|
||||
|
||||
@@ -100,17 +98,22 @@ Result ScriptUtils::copyFile(const std::string &source, const std::string &desti
|
||||
_source = std::regex_replace(source, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
_source = std::regex_replace(_source, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
_source = std::regex_replace(_source, std::regex("%NDS%"), config->ndsPath());
|
||||
_source = std::regex_replace(_source, std::regex("%FIRM%"), config->firmPath());
|
||||
|
||||
_dest = std::regex_replace(destination, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
_dest = std::regex_replace(_dest, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
_dest = std::regex_replace(_dest, std::regex("%NDS%"), config->ndsPath());
|
||||
_dest = std::regex_replace(_dest, std::regex("%FIRM%"), config->firmPath());
|
||||
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressbarType = ProgressBar::Copying;
|
||||
if (isARG) {
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressbarType = ProgressBar::Copying;
|
||||
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
}
|
||||
|
||||
/* If destination does not exist, create dirs. */
|
||||
if (access(_dest.c_str(), F_OK) != 0) makeDirs(_dest.c_str());
|
||||
@@ -118,17 +121,18 @@ Result ScriptUtils::copyFile(const std::string &source, const std::string &desti
|
||||
|
||||
if (ret == -1) ret = COPY_ERROR;
|
||||
else if (ret == 1) ret = NONE;
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
|
||||
if (isARG) {
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
Rename / Move a file.
|
||||
*/
|
||||
Result ScriptUtils::renameFile(const std::string &oldName, const std::string &newName, const std::string &message) {
|
||||
|
||||
/* Rename / Move a file. */
|
||||
Result ScriptUtils::renameFile(const std::string &oldName, const std::string &newName, const std::string &message, bool isARG) {
|
||||
Result ret = NONE;
|
||||
if (access(oldName.c_str(), F_OK) != 0) return MOVE_ERROR;
|
||||
|
||||
@@ -136,11 +140,14 @@ Result ScriptUtils::renameFile(const std::string &oldName, const std::string &ne
|
||||
old = std::regex_replace(oldName, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
old = std::regex_replace(old, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
old = std::regex_replace(old, std::regex("%NDS%"), config->ndsPath());
|
||||
old = std::regex_replace(old, std::regex("%FIRM%"), config->firmPath());
|
||||
|
||||
_new = std::regex_replace(newName, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
_new = std::regex_replace(_new, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
_new = std::regex_replace(_new, std::regex("%NDS%"), config->ndsPath());
|
||||
_new = std::regex_replace(_new, std::regex("%FIRM%"), config->firmPath());
|
||||
|
||||
Msg::DisplayMsg(message);
|
||||
if (isARG) Msg::DisplayMsg(message);
|
||||
|
||||
/* TODO: Kinda avoid that? */
|
||||
makeDirs(_new.c_str());
|
||||
@@ -148,126 +155,156 @@ Result ScriptUtils::renameFile(const std::string &oldName, const std::string &ne
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
Download from GitHub Release.
|
||||
*/
|
||||
Result ScriptUtils::downloadRelease(const std::string &repo, const std::string &file, const std::string &output, bool includePrereleases, const std::string &message) {
|
||||
/* Download from GitHub Release. */
|
||||
Result ScriptUtils::downloadRelease(const std::string &repo, const std::string &file, const std::string &output, bool includePrereleases, const std::string &message, bool isARG) {
|
||||
std::string out;
|
||||
out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
out = std::regex_replace(out, std::regex("%NDS%"), config->ndsPath());
|
||||
out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
out = std::regex_replace(out, std::regex("%FIRM%"), config->firmPath());
|
||||
|
||||
Result ret = NONE;
|
||||
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressbarType = ProgressBar::Downloading;
|
||||
if (isARG) {
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressbarType = ProgressBar::Downloading;
|
||||
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
}
|
||||
|
||||
if (downloadFromRelease("https://github.com/" + repo, file, out, includePrereleases) != 0) {
|
||||
showProgressBar = false;
|
||||
if (isARG) showProgressBar = false;
|
||||
|
||||
downloadFailed();
|
||||
ret = FAILED_DOWNLOAD;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
|
||||
if (isARG) {
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
if (isARG) {
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
Download a file.
|
||||
*/
|
||||
Result ScriptUtils::downloadFile(const std::string &file, const std::string &output, const std::string &message) {
|
||||
/* Download a file. */
|
||||
Result ScriptUtils::downloadFile(const std::string &file, const std::string &output, const std::string &message, bool isARG) {
|
||||
std::string out;
|
||||
out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
out = std::regex_replace(out, std::regex("%NDS%"), config->ndsPath());
|
||||
out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
out = std::regex_replace(out, std::regex("%FIRM%"), config->firmPath());
|
||||
|
||||
Result ret = NONE;
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressbarType = ProgressBar::Downloading;
|
||||
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
if (isARG) {
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressbarType = ProgressBar::Downloading;
|
||||
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
}
|
||||
|
||||
if (downloadToFile(file, out) != 0) {
|
||||
showProgressBar = false;
|
||||
if (isARG) showProgressBar = false;
|
||||
|
||||
downloadFailed();
|
||||
ret = FAILED_DOWNLOAD;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
|
||||
if (isARG) {
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
if (isARG) {
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
Install CIA files.
|
||||
*/
|
||||
void ScriptUtils::installFile(const std::string &file, bool updatingSelf, const std::string &message) {
|
||||
/* Install CIA files. */
|
||||
void ScriptUtils::installFile(const std::string &file, bool updatingSelf, const std::string &message, bool isARG) {
|
||||
std::string in;
|
||||
in = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
in = std::regex_replace(in, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
in = std::regex_replace(in, std::regex("%NDS%"), config->ndsPath());
|
||||
in = std::regex_replace(in, std::regex("%FIRM%"), config->firmPath());
|
||||
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressbarType = ProgressBar::Installing;
|
||||
if (isARG) {
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressbarType = ProgressBar::Installing;
|
||||
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
}
|
||||
|
||||
Title::Install(in.c_str(), updatingSelf);
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
|
||||
if (isARG) {
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Extract files.
|
||||
*/
|
||||
void ScriptUtils::extractFile(const std::string &file, const std::string &input, const std::string &output, const std::string &message) {
|
||||
/* Extract files. */
|
||||
void ScriptUtils::extractFile(const std::string &file, const std::string &input, const std::string &output, const std::string &message, bool isARG) {
|
||||
extractFilesCount = 0;
|
||||
|
||||
std::string out, in;
|
||||
in = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
in = std::regex_replace(in, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
in = std::regex_replace(in, std::regex("%NDS%"), config->ndsPath());
|
||||
in = std::regex_replace(in, std::regex("%FIRM%"), config->firmPath());
|
||||
out = std::regex_replace(output, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
|
||||
out = std::regex_replace(out, std::regex("%3DSX%"), config->_3dsxPath());
|
||||
out = std::regex_replace(out, std::regex("%NDS%"), config->ndsPath());
|
||||
out = std::regex_replace(out, std::regex("%FIRM%"), config->firmPath());
|
||||
|
||||
if (isARG) {
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressbarType = ProgressBar::Extracting;
|
||||
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
}
|
||||
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
filesExtracted = 0;
|
||||
progressbarType = ProgressBar::Extracting;
|
||||
|
||||
s32 prio = 0;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||
|
||||
getExtractedSize(in, input);
|
||||
extractArchive(in, input, out);
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
|
||||
if (isARG) {
|
||||
showProgressBar = false;
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Execute | run the script.
|
||||
NOTE: This is for the argument system for now. This might get replaced completely with the Queue System in the future.
|
||||
*/
|
||||
Result ScriptUtils::runFunctions(nlohmann::json storeJson, int selection, const std::string &entry) {
|
||||
Result ret = NONE; // No Error as of yet.
|
||||
@@ -318,7 +355,7 @@ Result ScriptUtils::runFunctions(nlohmann::json storeJson, int selection, const
|
||||
message = Script[i]["message"];
|
||||
}
|
||||
|
||||
if (!missing) ret = ScriptUtils::removeFile(file, message);
|
||||
if (!missing) ret = ScriptUtils::removeFile(file, message, true);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "downloadFile") {
|
||||
@@ -339,7 +376,7 @@ Result ScriptUtils::runFunctions(nlohmann::json storeJson, int selection, const
|
||||
message = Script[i]["message"];
|
||||
}
|
||||
|
||||
if (!missing) ret = ScriptUtils::downloadFile(file, output, message);
|
||||
if (!missing) ret = ScriptUtils::downloadFile(file, output, message, true);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "downloadRelease") {
|
||||
@@ -368,7 +405,7 @@ Result ScriptUtils::runFunctions(nlohmann::json storeJson, int selection, const
|
||||
message = Script[i]["message"];
|
||||
}
|
||||
|
||||
if (!missing) ret = ScriptUtils::downloadRelease(repo, file, output, includePrereleases, message);
|
||||
if (!missing) ret = ScriptUtils::downloadRelease(repo, file, output, includePrereleases, message, true);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "extractFile") {
|
||||
@@ -394,7 +431,7 @@ Result ScriptUtils::runFunctions(nlohmann::json storeJson, int selection, const
|
||||
message = Script[i]["message"];
|
||||
}
|
||||
|
||||
if (!missing) ScriptUtils::extractFile(file, input, output, message);
|
||||
if (!missing) ScriptUtils::extractFile(file, input, output, message, true);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "installCia") {
|
||||
@@ -414,7 +451,7 @@ Result ScriptUtils::runFunctions(nlohmann::json storeJson, int selection, const
|
||||
message = Script[i]["message"];
|
||||
}
|
||||
|
||||
if (!missing) ScriptUtils::installFile(file, updateSelf, message);
|
||||
if (!missing) ScriptUtils::installFile(file, updateSelf, message, true);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "mkdir") {
|
||||
@@ -488,7 +525,7 @@ Result ScriptUtils::runFunctions(nlohmann::json storeJson, int selection, const
|
||||
Message = Script[i]["message"];
|
||||
}
|
||||
|
||||
if (!missing) ret = ScriptUtils::copyFile(source, destination, Message);
|
||||
if (!missing) ret = ScriptUtils::copyFile(source, destination, Message, true);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "move") {
|
||||
@@ -509,7 +546,7 @@ Result ScriptUtils::runFunctions(nlohmann::json storeJson, int selection, const
|
||||
Message = Script[i]["message"];
|
||||
}
|
||||
|
||||
if (!missing) ret = ScriptUtils::renameFile(oldFile, newFile, Message);
|
||||
if (!missing) ret = ScriptUtils::renameFile(oldFile, newFile, Message, true);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "skip") {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
* Copyright (C) 2019-2021 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "stringutils.hpp"
|
||||
#include <stdarg.h>
|
||||
|
||||
/*
|
||||
To lowercase conversion.
|
||||
@@ -69,9 +70,9 @@ std::string StringUtils::formatBytes(int bytes) {
|
||||
|
||||
if (bytes == 1) snprintf(out, sizeof(out), "%d Byte", bytes);
|
||||
else if (bytes < 1024) snprintf(out, sizeof(out), "%d Bytes", bytes);
|
||||
else if (bytes < 1024 * 1024) snprintf(out, sizeof(out), "%.1f KB", (float)bytes / 1024);
|
||||
else if (bytes < 1024 * 1024 * 1024) snprintf(out, sizeof(out), "%.1f MB", (float)bytes / 1024 / 1024);
|
||||
else snprintf(out, sizeof(out), "%.1f GB", (float)bytes / 1024 / 1024 / 1024);
|
||||
else if (bytes < 1024 * 1024) snprintf(out, sizeof(out), "%.1f KiB", (float)bytes / 1024);
|
||||
else if (bytes < 1024 * 1024 * 1024) snprintf(out, sizeof(out), "%.1f MiB", (float)bytes / 1024 / 1024);
|
||||
else snprintf(out, sizeof(out), "%.1f GiB", (float)bytes / 1024 / 1024 / 1024);
|
||||
|
||||
return out;
|
||||
}
|
||||
@@ -104,4 +105,15 @@ std::string StringUtils::GetMarkString(int marks) {
|
||||
if (marks & favoriteMarks::SPADE) out += "♠";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string StringUtils::format(const std::string &fmt_str, ...) {
|
||||
va_list ap;
|
||||
char *fp = nullptr;
|
||||
va_start(ap, fmt_str);
|
||||
vasprintf(&fp, fmt_str.c_str(), ap);
|
||||
va_end(ap);
|
||||
|
||||
std::unique_ptr<char, decltype(free) *> formatted(fp, free);
|
||||
return std::string(formatted.get());
|
||||
}
|
||||
Reference in New Issue
Block a user