mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-07 08:49:08 +00:00
Improve Extracting & Add progressbar.
This commit is contained in:
@@ -31,8 +31,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Animation {
|
namespace Animation {
|
||||||
// Draw Progressbar.
|
// Downloading Progressbar.
|
||||||
void DrawProgressBar(float currentProgress, float totalProgress, int mode);
|
void DrawProgressBar(float currentProgress, float totalProgress, int mode);
|
||||||
|
// Extracting progressbar.
|
||||||
|
void DrawProgressBarExtract(u64 currentProgress, u64 totalProgress, int mode);
|
||||||
// Draw Button.
|
// Draw Button.
|
||||||
void Button(int x, int y, float speed = .030);
|
void Button(int x, int y, float speed = .030);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ private:
|
|||||||
int dropSelection = 0;
|
int dropSelection = 0;
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
bool dropDownMenu = false;
|
bool dropDownMenu = false;
|
||||||
|
bool loaded = false;
|
||||||
|
|
||||||
// Draws.
|
// Draws.
|
||||||
void DrawBrowse(void) const;
|
void DrawBrowse(void) const;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"DONE": "Done!",
|
"DONE": "Done!",
|
||||||
"CONNECT_WIFI": "Please Connect to WiFi.",
|
"CONNECT_WIFI": "Please Connect to WiFi.",
|
||||||
"DOWNLOADING": "Downloading: ",
|
"DOWNLOADING": "Downloading: ",
|
||||||
"CURRENTLY_EXTRACTING": "\nCurrently extracting:\n",
|
"CURRENTLY_EXTRACTING": "Currently extracting:\n",
|
||||||
"FILE_EXTRACTED": "file extracted.",
|
"FILE_EXTRACTED": "file extracted.",
|
||||||
"FILES_EXTRACTED": "files extracted.",
|
"FILES_EXTRACTED": "files extracted.",
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ void Animation::DrawProgressBar(float currentProgress, float totalProgress, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animation::DrawProgressBarExtract(u64 currentProgress, u64 totalProgress, int mode) {
|
||||||
|
if (mode == 1) {
|
||||||
|
Gui::Draw_Rect(31, 141, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, progressBar);
|
||||||
|
} else {
|
||||||
|
Gui::Draw_Rect(31, 141, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, Config::progressbarColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Animation::Button(int x, int y, float speed)
|
void Animation::Button(int x, int y, float speed)
|
||||||
{
|
{
|
||||||
static float timer = 0.0f;
|
static float timer = 0.0f;
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ char progressBarMsg[128] = "";
|
|||||||
bool showProgressBar = false;
|
bool showProgressBar = false;
|
||||||
bool progressBarType = 0; // 0 = Download | 1 = Extract
|
bool progressBarType = 0; // 0 = Download | 1 = Extract
|
||||||
|
|
||||||
|
// That are our extract Progressbar variables.
|
||||||
|
extern u64 extractSize;
|
||||||
|
extern u64 writeOffset;
|
||||||
|
|
||||||
#define TIME_IN_US 1
|
#define TIME_IN_US 1
|
||||||
#define TIMETYPE curl_off_t
|
#define TIMETYPE curl_off_t
|
||||||
#define TIMEOPT CURLINFO_TOTAL_TIME_T
|
#define TIMEOPT CURLINFO_TOTAL_TIME_T
|
||||||
@@ -878,8 +882,24 @@ void displayProgressBar() {
|
|||||||
|
|
||||||
// Display 'Currently Extracting: <Filename>'.
|
// Display 'Currently Extracting: <Filename>'.
|
||||||
if (progressBarType == 1) {
|
if (progressBarType == 1) {
|
||||||
Gui::DrawStringCentered(0, 140, 0.6f, TextColor, str, 400);
|
// Text.
|
||||||
Gui::DrawStringCentered(0, 60, 0.6f, TextColor, Lang::get("CURRENTLY_EXTRACTING") + extractingFile, 400);
|
if (isScriptSelected == true) {
|
||||||
|
Gui::DrawStringCentered(0, 100, 0.6f, TextColor, str, 400);
|
||||||
|
Gui::DrawStringCentered(0, 180, 0.6f, TextColor, formatBytes(writeOffset) + " / " + formatBytes(extractSize), 400);
|
||||||
|
Gui::DrawStringCentered(0, 40, 0.6f, TextColor, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
|
||||||
|
} else {
|
||||||
|
Gui::DrawStringCentered(0, 100, 0.6f, Config::TxtColor, str, 400);
|
||||||
|
Gui::DrawStringCentered(0, 180, 0.6f, Config::TxtColor, formatBytes(writeOffset) + " / " + formatBytes(extractSize), 400);
|
||||||
|
Gui::DrawStringCentered(0, 40, 0.6f, Config::TxtColor, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
|
||||||
|
}
|
||||||
|
// Outline of progressbar.
|
||||||
|
Gui::Draw_Rect(30, 140, 340, 30, BLACK);
|
||||||
|
// Progressbar.
|
||||||
|
if (isScriptSelected == true) {
|
||||||
|
Animation::DrawProgressBarExtract(writeOffset, extractSize, 1);
|
||||||
|
} else {
|
||||||
|
Animation::DrawProgressBarExtract(writeOffset, extractSize, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only display this by downloading.
|
// Only display this by downloading.
|
||||||
@@ -889,7 +909,7 @@ void displayProgressBar() {
|
|||||||
} else {
|
} else {
|
||||||
Gui::DrawStringCentered(0, 80, 0.6f, Config::TxtColor, str, 400);
|
Gui::DrawStringCentered(0, 80, 0.6f, Config::TxtColor, str, 400);
|
||||||
}
|
}
|
||||||
|
// Outline of progressbar.
|
||||||
Gui::Draw_Rect(30, 120, 340, 30, BLACK);
|
Gui::Draw_Rect(30, 120, 340, 30, BLACK);
|
||||||
if (isScriptSelected == true) {
|
if (isScriptSelected == true) {
|
||||||
Animation::DrawProgressBar(downloadNow, downloadTotal, 1);
|
Animation::DrawProgressBar(downloadNow, downloadTotal, 1);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern bool touching(touchPosition touch, Structs::ButtonPos button);
|
extern bool touching(touchPosition touch, Structs::ButtonPos button);
|
||||||
|
extern void downloadFailed();
|
||||||
|
|
||||||
void fixInfo(nlohmann::json &json) {
|
void fixInfo(nlohmann::json &json) {
|
||||||
for(uint i=0;i<json.size();i++) {
|
for(uint i=0;i<json.size();i++) {
|
||||||
@@ -89,27 +90,46 @@ ScriptBrowse::ScriptBrowse() {
|
|||||||
Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST"));
|
Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST"));
|
||||||
|
|
||||||
// Get repo info
|
// Get repo info
|
||||||
downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile);
|
if (downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile) != 0) {
|
||||||
|
downloadFailed();
|
||||||
|
loaded = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
FILE* file = fopen(metaFile, "r");
|
FILE* file = fopen(metaFile, "r");
|
||||||
if(file) infoJson = nlohmann::json::parse(file, nullptr, false);
|
if(file) {
|
||||||
|
infoJson = nlohmann::json::parse(file, nullptr, false);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
fixInfo(infoJson);
|
fixInfo(infoJson);
|
||||||
findExistingFiles(infoJson);
|
findExistingFiles(infoJson);
|
||||||
maxScripts = infoJson.size();
|
maxScripts = infoJson.size();
|
||||||
|
loaded = true;
|
||||||
|
// File is not able to be parsed, go screen back.
|
||||||
|
} else {
|
||||||
|
loaded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptBrowse::refresh() {
|
void ScriptBrowse::refresh() {
|
||||||
if (checkWifiStatus() == true) {
|
if (checkWifiStatus() == true) {
|
||||||
if (Msg::promptMsg(Lang::get("REFRESH_SCRIPTBROWSE_PROMPT"))) {
|
if (Msg::promptMsg(Lang::get("REFRESH_SCRIPTBROWSE_PROMPT"))) {
|
||||||
Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST"));
|
Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST"));
|
||||||
downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile);
|
if (downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile) != 0) {
|
||||||
|
downloadFailed();
|
||||||
|
loaded = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
FILE* file = fopen(metaFile, "r");
|
FILE* file = fopen(metaFile, "r");
|
||||||
if(file) infoJson = nlohmann::json::parse(file, nullptr, false);
|
if(file) {
|
||||||
|
infoJson = nlohmann::json::parse(file, nullptr, false);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
fixInfo(infoJson);
|
fixInfo(infoJson);
|
||||||
findExistingFiles(infoJson);
|
findExistingFiles(infoJson);
|
||||||
maxScripts = infoJson.size();
|
maxScripts = infoJson.size();
|
||||||
Selection = 0;
|
Selection = 0;
|
||||||
|
loaded = true;
|
||||||
|
} else {
|
||||||
|
loaded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
notConnectedMsg();
|
notConnectedMsg();
|
||||||
@@ -125,6 +145,7 @@ void ScriptBrowse::Draw(void) const {
|
|||||||
|
|
||||||
void ScriptBrowse::DrawBrowse(void) const {
|
void ScriptBrowse::DrawBrowse(void) const {
|
||||||
GFX::DrawTop();
|
GFX::DrawTop();
|
||||||
|
if (loaded) {
|
||||||
std::string revision = std::to_string(int64_t(infoJson[Selection]["curRevision"]));
|
std::string revision = std::to_string(int64_t(infoJson[Selection]["curRevision"]));
|
||||||
revision += " | ";
|
revision += " | ";
|
||||||
revision += std::to_string(int64_t(infoJson[Selection]["revision"]));
|
revision += std::to_string(int64_t(infoJson[Selection]["revision"]));
|
||||||
@@ -224,11 +245,15 @@ void ScriptBrowse::DrawBrowse(void) const {
|
|||||||
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, Config::TxtColor, Lang::get("REFRESH_BROWSE_DDM"), 100);
|
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, Config::TxtColor, Lang::get("REFRESH_BROWSE_DDM"), 100);
|
||||||
Gui::DrawString(dropPos[2].x+30, dropPos[2].y+5, 0.4f, Config::TxtColor, Lang::get("VIEW_DDM"), 100);
|
Gui::DrawString(dropPos[2].x+30, dropPos[2].y+5, 0.4f, Config::TxtColor, Lang::get("VIEW_DDM"), 100);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
GFX::DrawBottom();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptBrowse::DrawGlossary(void) const {
|
void ScriptBrowse::DrawGlossary(void) const {
|
||||||
GFX::DrawTop();
|
GFX::DrawTop();
|
||||||
|
if (loaded) {
|
||||||
if (Config::UseBars == true) {
|
if (Config::UseBars == true) {
|
||||||
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
|
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
|
||||||
} else {
|
} else {
|
||||||
@@ -266,9 +291,14 @@ void ScriptBrowse::DrawGlossary(void) const {
|
|||||||
GFX::DrawSpriteBlend(sprites_update_idx, 20, 195);
|
GFX::DrawSpriteBlend(sprites_update_idx, 20, 195);
|
||||||
Gui::DrawString(50, 197, 0.6f, Config::TxtColor, Lang::get("REFRESH_SCRIPTBROWSE"), 260);
|
Gui::DrawString(50, 197, 0.6f, Config::TxtColor, Lang::get("REFRESH_SCRIPTBROWSE"), 260);
|
||||||
GFX::DrawArrow(0, 218, 0, 1);
|
GFX::DrawArrow(0, 218, 0, 1);
|
||||||
|
} else {
|
||||||
|
GFX::DrawBottom();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptBrowse::DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
void ScriptBrowse::DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||||
|
if (loaded) {
|
||||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||||
dropDownMenu = false;
|
dropDownMenu = false;
|
||||||
}
|
}
|
||||||
@@ -317,6 +347,7 @@ void ScriptBrowse::DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptBrowse::downloadAll() {
|
void ScriptBrowse::downloadAll() {
|
||||||
if (infoJson.size() != 0) {
|
if (infoJson.size() != 0) {
|
||||||
@@ -338,6 +369,7 @@ void ScriptBrowse::downloadAll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||||
|
if (loaded) {
|
||||||
if (keyRepeatDelay) keyRepeatDelay--;
|
if (keyRepeatDelay) keyRepeatDelay--;
|
||||||
if (dropDownMenu) {
|
if (dropDownMenu) {
|
||||||
DropDownLogic(hDown, hHeld, touch);
|
DropDownLogic(hDown, hHeld, touch);
|
||||||
@@ -461,4 +493,10 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
|||||||
else mode = 0;
|
else mode = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (hDown & KEY_B) {
|
||||||
|
Gui::screenBack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "extract.hpp"
|
#include "extract.hpp"
|
||||||
|
#include "logging.hpp"
|
||||||
|
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
#include <archive_entry.h>
|
#include <archive_entry.h>
|
||||||
@@ -33,7 +34,14 @@
|
|||||||
int filesExtracted = 0;
|
int filesExtracted = 0;
|
||||||
std::string extractingFile = "";
|
std::string extractingFile = "";
|
||||||
|
|
||||||
|
// That are our File Progressbar variable.
|
||||||
|
u64 extractSize = 0;
|
||||||
|
u64 writeOffset = 0;
|
||||||
|
|
||||||
Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath) {
|
Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath) {
|
||||||
|
extractSize = 0;
|
||||||
|
writeOffset = 0;
|
||||||
|
|
||||||
archive_entry *entry;
|
archive_entry *entry;
|
||||||
|
|
||||||
archive *a = archive_read_new();
|
archive *a = archive_read_new();
|
||||||
@@ -41,6 +49,7 @@ Result extractArchive(std::string archivePath, std::string wantedFile, std::stri
|
|||||||
archive_read_support_format_raw(a);
|
archive_read_support_format_raw(a);
|
||||||
|
|
||||||
if(archive_read_open_filename(a, archivePath.c_str(), 0x4000) != ARCHIVE_OK) {
|
if(archive_read_open_filename(a, archivePath.c_str(), 0x4000) != ARCHIVE_OK) {
|
||||||
|
Logging::writeToLog("EXTRACT_ERROR_ARCHIVE");
|
||||||
return EXTRACT_ERROR_ARCHIVE;
|
return EXTRACT_ERROR_ARCHIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,45 +66,48 @@ Result extractArchive(std::string archivePath, std::string wantedFile, std::stri
|
|||||||
int substrPos = 1;
|
int substrPos = 1;
|
||||||
while(out.find("/", substrPos)) {
|
while(out.find("/", substrPos)) {
|
||||||
mkdir(out.substr(0, substrPos).c_str(), 0777);
|
mkdir(out.substr(0, substrPos).c_str(), 0777);
|
||||||
|
Logging::writeToLog(out.substr(0, substrPos));
|
||||||
substrPos = out.find("/", substrPos)+1;
|
substrPos = out.find("/", substrPos)+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle fileHandle;
|
Handle fileHandle;
|
||||||
Result res = openFile(&fileHandle, (outputPath + match.suffix().str()).c_str(), true);
|
Result res = openFile(&fileHandle, (outputPath + match.suffix().str()).c_str(), true);
|
||||||
if (R_FAILED(res)) {
|
if (R_FAILED(res)) {
|
||||||
|
Logging::writeToLog("EXTRACT_ERROR_OPENFILE");
|
||||||
ret = EXTRACT_ERROR_OPENFILE;
|
ret = EXTRACT_ERROR_OPENFILE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 fileSize = archive_entry_size(entry);
|
u64 fileSize = archive_entry_size(entry);
|
||||||
u32 toRead = 0x4000;
|
extractSize = fileSize; // Get Size.
|
||||||
u8 * buf = (u8 *)malloc(toRead);
|
u32 toRead = 0x30000;
|
||||||
|
u8 * buf = (u8 *)memalign(0x1000, toRead);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
|
Logging::writeToLog("EXTRACT_ERROR_ALLOC");
|
||||||
ret = EXTRACT_ERROR_ALLOC;
|
ret = EXTRACT_ERROR_ALLOC;
|
||||||
FSFILE_Close(fileHandle);
|
FSFILE_Close(fileHandle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 bytesWritten = 0;
|
u32 bytesWritten = 0;
|
||||||
u64 offset = 0;
|
writeOffset = 0;
|
||||||
do {
|
do {
|
||||||
if (toRead > fileSize) toRead = fileSize;
|
if (toRead > fileSize) toRead = fileSize;
|
||||||
ssize_t size = archive_read_data(a, buf, toRead);
|
ssize_t size = archive_read_data(a, buf, toRead);
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
|
Logging::writeToLog("EXTRACT_ERROR_READFILE");
|
||||||
ret = EXTRACT_ERROR_READFILE;
|
ret = EXTRACT_ERROR_READFILE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
res = FSFILE_Write(fileHandle, &bytesWritten, writeOffset, buf, toRead, 0);
|
||||||
res = FSFILE_Write(fileHandle, &bytesWritten, offset, buf, toRead, 0);
|
|
||||||
if (R_FAILED(res)) {
|
if (R_FAILED(res)) {
|
||||||
|
Logging::writeToLog("EXTRACT_ERROR_WRITEFILE");
|
||||||
ret = EXTRACT_ERROR_WRITEFILE;
|
ret = EXTRACT_ERROR_WRITEFILE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += bytesWritten;
|
writeOffset += bytesWritten;
|
||||||
fileSize -= bytesWritten;
|
fileSize -= bytesWritten;
|
||||||
} while(fileSize);
|
} while(fileSize);
|
||||||
|
|
||||||
FSFILE_Close(fileHandle);
|
FSFILE_Close(fileHandle);
|
||||||
free(buf);
|
free(buf);
|
||||||
filesExtracted++;
|
filesExtracted++;
|
||||||
@@ -103,6 +115,5 @@ Result extractArchive(std::string archivePath, std::string wantedFile, std::stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
archive_read_free(a);
|
archive_read_free(a);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user