mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-06 08:39:07 +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.",
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -35,9 +35,17 @@ extern C2D_SpriteSheet sprites;
|
|||||||
// Draws a Rectangle as the progressbar.
|
// Draws a Rectangle as the progressbar.
|
||||||
void Animation::DrawProgressBar(float currentProgress, float totalProgress, int mode) {
|
void Animation::DrawProgressBar(float currentProgress, float totalProgress, int mode) {
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress/(float)totalProgress) * 338.0f), 28, progressBar);
|
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, progressBar);
|
||||||
} else {
|
} else {
|
||||||
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress/(float)totalProgress) * 338.0f), 28, Config::progressbarColor);
|
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, Config::progressbarColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,10 +52,14 @@ char progressBarMsg[128] = "";
|
|||||||
bool showProgressBar = false;
|
bool showProgressBar = false;
|
||||||
bool progressBarType = 0; // 0 = Download | 1 = Extract
|
bool progressBarType = 0; // 0 = Download | 1 = Extract
|
||||||
|
|
||||||
#define TIME_IN_US 1
|
// That are our extract Progressbar variables.
|
||||||
|
extern u64 extractSize;
|
||||||
|
extern u64 writeOffset;
|
||||||
|
|
||||||
|
#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
|
||||||
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3000000
|
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3000000
|
||||||
|
|
||||||
extern u32 progressBar;
|
extern u32 progressBar;
|
||||||
extern bool isScriptSelected;
|
extern bool isScriptSelected;
|
||||||
@@ -178,7 +182,7 @@ Result downloadToFile(std::string url, std::string path) {
|
|||||||
hnd = curl_easy_init();
|
hnd = curl_easy_init();
|
||||||
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, FILE_ALLOC_SIZE);
|
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, FILE_ALLOC_SIZE);
|
||||||
curl_easy_setopt(hnd, CURLOPT_URL, url.c_str());
|
curl_easy_setopt(hnd, CURLOPT_URL, url.c_str());
|
||||||
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
|
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
|
||||||
curl_easy_setopt(hnd, CURLOPT_USERAGENT, USER_AGENT);
|
curl_easy_setopt(hnd, CURLOPT_USERAGENT, USER_AGENT);
|
||||||
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
|
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
curl_easy_setopt(hnd, CURLOPT_FAILONERROR, 1L);
|
curl_easy_setopt(hnd, CURLOPT_FAILONERROR, 1L);
|
||||||
@@ -853,12 +857,12 @@ void displayProgressBar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (progressBarType) {
|
if (progressBarType) {
|
||||||
snprintf(str, sizeof(str), "%i %s",
|
snprintf(str, sizeof(str), "%i %s",
|
||||||
filesExtracted,
|
filesExtracted,
|
||||||
(filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED")).c_str())
|
(filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED")).c_str())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
|
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
|
||||||
formatBytes(downloadNow).c_str(),
|
formatBytes(downloadNow).c_str(),
|
||||||
formatBytes(downloadTotal).c_str(),
|
formatBytes(downloadTotal).c_str(),
|
||||||
((float)downloadNow/(float)downloadTotal) * 100.0f
|
((float)downloadNow/(float)downloadTotal) * 100.0f
|
||||||
@@ -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);
|
||||||
|
|||||||
+334
-296
@@ -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) {
|
||||||
fclose(file);
|
infoJson = nlohmann::json::parse(file, nullptr, false);
|
||||||
fixInfo(infoJson);
|
fclose(file);
|
||||||
findExistingFiles(infoJson);
|
fixInfo(infoJson);
|
||||||
maxScripts = infoJson.size();
|
findExistingFiles(infoJson);
|
||||||
|
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) {
|
||||||
fclose(file);
|
infoJson = nlohmann::json::parse(file, nullptr, false);
|
||||||
fixInfo(infoJson);
|
fclose(file);
|
||||||
findExistingFiles(infoJson);
|
fixInfo(infoJson);
|
||||||
maxScripts = infoJson.size();
|
findExistingFiles(infoJson);
|
||||||
Selection = 0;
|
maxScripts = infoJson.size();
|
||||||
|
Selection = 0;
|
||||||
|
loaded = true;
|
||||||
|
} else {
|
||||||
|
loaded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
notConnectedMsg();
|
notConnectedMsg();
|
||||||
@@ -125,195 +145,206 @@ void ScriptBrowse::Draw(void) const {
|
|||||||
|
|
||||||
void ScriptBrowse::DrawBrowse(void) const {
|
void ScriptBrowse::DrawBrowse(void) const {
|
||||||
GFX::DrawTop();
|
GFX::DrawTop();
|
||||||
std::string revision = std::to_string(int64_t(infoJson[Selection]["curRevision"]));
|
if (loaded) {
|
||||||
revision += " | ";
|
std::string revision = std::to_string(int64_t(infoJson[Selection]["curRevision"]));
|
||||||
revision += std::to_string(int64_t(infoJson[Selection]["revision"]));
|
revision += " | ";
|
||||||
|
revision += std::to_string(int64_t(infoJson[Selection]["revision"]));
|
||||||
|
|
||||||
if (Config::UseBars == true) {
|
if (Config::UseBars == true) {
|
||||||
Gui::DrawString(397-Gui::GetStringWidth(0.6f, revision), 239-Gui::GetStringHeight(0.6f, revision), 0.6f, Config::TxtColor, revision);
|
Gui::DrawString(397-Gui::GetStringWidth(0.6f, revision), 239-Gui::GetStringHeight(0.6f, revision), 0.6f, Config::TxtColor, revision);
|
||||||
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, std::string(infoJson[Selection]["title"]), 400);
|
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, std::string(infoJson[Selection]["title"]), 400);
|
||||||
|
} else {
|
||||||
|
Gui::DrawString(397-Gui::GetStringWidth(0.6f, revision), 237-Gui::GetStringHeight(0.6f, revision), 0.6f, Config::TxtColor, revision);
|
||||||
|
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, std::string(infoJson[Selection]["title"]), 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(infoJson[Selection]["shortDesc"]), 400);
|
||||||
|
if (infoJson[Selection]["curRevision"] == -1) {
|
||||||
|
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("SCRIPT_NOT_FOUND"), 370);
|
||||||
|
} else if(infoJson[Selection]["curRevision"] < infoJson[Selection]["revision"]) {
|
||||||
|
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("OUTDATED_SCRIPT"), 370);
|
||||||
|
} else if(infoJson[Selection]["curRevision"] == infoJson[Selection]["revision"]) {
|
||||||
|
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("UP-TO-DATE"), 370);
|
||||||
|
} else if(infoJson[Selection]["curRevision"] > infoJson[Selection]["revision"]) {
|
||||||
|
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 370);
|
||||||
|
}
|
||||||
|
GFX::DrawBottom();
|
||||||
|
GFX::DrawArrow(295, -1);
|
||||||
|
GFX::DrawArrow(315, 240, 180.0);
|
||||||
|
GFX::DrawArrow(0, 218, 0, 1);
|
||||||
|
|
||||||
|
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
|
||||||
|
|
||||||
|
Gui::DrawStringCentered(0, 1, 0.6f, Config::TxtColor, std::to_string(Selection + 1) + " | " + std::to_string(maxScripts));
|
||||||
|
|
||||||
|
if (Config::viewMode == 0) {
|
||||||
|
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)infoJson.size();i++) {
|
||||||
|
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
|
||||||
|
if(screenPos + i == Selection) {
|
||||||
|
if (!dropDownMenu) {
|
||||||
|
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (infoJson[screenPos+i]["curRevision"] == -1) {
|
||||||
|
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::notFound);
|
||||||
|
} else if(infoJson[screenPos+i]["curRevision"] < infoJson[screenPos+i]["revision"]) {
|
||||||
|
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::outdated);
|
||||||
|
} else if(infoJson[screenPos+i]["curRevision"] == infoJson[screenPos+i]["revision"]) {
|
||||||
|
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::uptodate);
|
||||||
|
} else if(infoJson[screenPos+i]["curRevision"] > infoJson[screenPos+i]["revision"]) {
|
||||||
|
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::future);
|
||||||
|
}
|
||||||
|
|
||||||
|
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, Config::TxtColor, infoJson[screenPos+i]["title"], 317);
|
||||||
|
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, Config::TxtColor, infoJson[screenPos+i]["author"], 317);
|
||||||
|
}
|
||||||
|
} else if (Config::viewMode == 1) {
|
||||||
|
for(int i=0;i<ENTRIES_PER_LIST && i<(int)infoJson.size();i++) {
|
||||||
|
Gui::Draw_Rect(0, (i+1)*27, 320, 25, Config::UnselectedColor);
|
||||||
|
if(screenPosList + i == Selection) {
|
||||||
|
if (!dropDownMenu) {
|
||||||
|
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, Config::SelectedColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Script not found.
|
||||||
|
if (infoJson[screenPosList+i]["curRevision"] == -1) {
|
||||||
|
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::notFound);
|
||||||
|
// Script outdaed.
|
||||||
|
} else if(infoJson[screenPosList+i]["curRevision"] < infoJson[screenPosList+i]["revision"]) {
|
||||||
|
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::outdated);
|
||||||
|
// Script up-to-date.
|
||||||
|
} else if(infoJson[screenPosList+i]["curRevision"] == infoJson[screenPosList+i]["revision"]) {
|
||||||
|
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::uptodate);
|
||||||
|
// Future script.
|
||||||
|
} else if(infoJson[screenPosList+i]["curRevision"] > infoJson[screenPosList+i]["revision"]) {
|
||||||
|
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::future);
|
||||||
|
}
|
||||||
|
|
||||||
|
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, Config::TxtColor, infoJson[screenPosList+i]["title"], 317);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DropDown Menu.
|
||||||
|
if (dropDownMenu) {
|
||||||
|
// Draw Operation Box.
|
||||||
|
Gui::Draw_Rect(0, 25, 140, 130, Config::Color1);
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (dropSelection == i) {
|
||||||
|
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, Config::SelectedColor);
|
||||||
|
} else {
|
||||||
|
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, Config::UnselectedColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Draw Dropdown Icons.
|
||||||
|
GFX::DrawSpriteBlend(sprites_download_all_idx, dropPos[0].x, dropPos[0].y);
|
||||||
|
GFX::DrawSpriteBlend(sprites_update_idx, dropPos[1].x, dropPos[1].y);
|
||||||
|
GFX::DrawSpriteBlend(sprites_view_idx, dropPos[2].x, dropPos[2].y);
|
||||||
|
// Dropdown Text.
|
||||||
|
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, Config::TxtColor, Lang::get("DOWNLOAD_ALL_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);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Gui::DrawString(397-Gui::GetStringWidth(0.6f, revision), 237-Gui::GetStringHeight(0.6f, revision), 0.6f, Config::TxtColor, revision);
|
GFX::DrawBottom();
|
||||||
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, std::string(infoJson[Selection]["title"]), 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(infoJson[Selection]["shortDesc"]), 400);
|
|
||||||
if (infoJson[Selection]["curRevision"] == -1) {
|
|
||||||
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("SCRIPT_NOT_FOUND"), 370);
|
|
||||||
} else if(infoJson[Selection]["curRevision"] < infoJson[Selection]["revision"]) {
|
|
||||||
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("OUTDATED_SCRIPT"), 370);
|
|
||||||
} else if(infoJson[Selection]["curRevision"] == infoJson[Selection]["revision"]) {
|
|
||||||
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("UP-TO-DATE"), 370);
|
|
||||||
} else if(infoJson[Selection]["curRevision"] > infoJson[Selection]["revision"]) {
|
|
||||||
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 370);
|
|
||||||
}
|
|
||||||
GFX::DrawBottom();
|
|
||||||
GFX::DrawArrow(295, -1);
|
|
||||||
GFX::DrawArrow(315, 240, 180.0);
|
|
||||||
GFX::DrawArrow(0, 218, 0, 1);
|
|
||||||
|
|
||||||
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
|
|
||||||
|
|
||||||
Gui::DrawStringCentered(0, 1, 0.6f, Config::TxtColor, std::to_string(Selection + 1) + " | " + std::to_string(maxScripts));
|
|
||||||
|
|
||||||
if (Config::viewMode == 0) {
|
|
||||||
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)infoJson.size();i++) {
|
|
||||||
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
|
|
||||||
if(screenPos + i == Selection) {
|
|
||||||
if (!dropDownMenu) {
|
|
||||||
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (infoJson[screenPos+i]["curRevision"] == -1) {
|
|
||||||
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::notFound);
|
|
||||||
} else if(infoJson[screenPos+i]["curRevision"] < infoJson[screenPos+i]["revision"]) {
|
|
||||||
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::outdated);
|
|
||||||
} else if(infoJson[screenPos+i]["curRevision"] == infoJson[screenPos+i]["revision"]) {
|
|
||||||
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::uptodate);
|
|
||||||
} else if(infoJson[screenPos+i]["curRevision"] > infoJson[screenPos+i]["revision"]) {
|
|
||||||
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::future);
|
|
||||||
}
|
|
||||||
|
|
||||||
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, Config::TxtColor, infoJson[screenPos+i]["title"], 317);
|
|
||||||
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, Config::TxtColor, infoJson[screenPos+i]["author"], 317);
|
|
||||||
}
|
|
||||||
} else if (Config::viewMode == 1) {
|
|
||||||
for(int i=0;i<ENTRIES_PER_LIST && i<(int)infoJson.size();i++) {
|
|
||||||
Gui::Draw_Rect(0, (i+1)*27, 320, 25, Config::UnselectedColor);
|
|
||||||
if(screenPosList + i == Selection) {
|
|
||||||
if (!dropDownMenu) {
|
|
||||||
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, Config::SelectedColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Script not found.
|
|
||||||
if (infoJson[screenPosList+i]["curRevision"] == -1) {
|
|
||||||
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::notFound);
|
|
||||||
// Script outdaed.
|
|
||||||
} else if(infoJson[screenPosList+i]["curRevision"] < infoJson[screenPosList+i]["revision"]) {
|
|
||||||
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::outdated);
|
|
||||||
// Script up-to-date.
|
|
||||||
} else if(infoJson[screenPosList+i]["curRevision"] == infoJson[screenPosList+i]["revision"]) {
|
|
||||||
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::uptodate);
|
|
||||||
// Future script.
|
|
||||||
} else if(infoJson[screenPosList+i]["curRevision"] > infoJson[screenPosList+i]["revision"]) {
|
|
||||||
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::future);
|
|
||||||
}
|
|
||||||
|
|
||||||
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, Config::TxtColor, infoJson[screenPosList+i]["title"], 317);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DropDown Menu.
|
|
||||||
if (dropDownMenu) {
|
|
||||||
// Draw Operation Box.
|
|
||||||
Gui::Draw_Rect(0, 25, 140, 130, Config::Color1);
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
if (dropSelection == i) {
|
|
||||||
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, Config::SelectedColor);
|
|
||||||
} else {
|
|
||||||
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, Config::UnselectedColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Draw Dropdown Icons.
|
|
||||||
GFX::DrawSpriteBlend(sprites_download_all_idx, dropPos[0].x, dropPos[0].y);
|
|
||||||
GFX::DrawSpriteBlend(sprites_update_idx, dropPos[1].x, dropPos[1].y);
|
|
||||||
GFX::DrawSpriteBlend(sprites_view_idx, dropPos[2].x, dropPos[2].y);
|
|
||||||
// Dropdown Text.
|
|
||||||
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, Config::TxtColor, Lang::get("DOWNLOAD_ALL_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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptBrowse::DrawGlossary(void) const {
|
void ScriptBrowse::DrawGlossary(void) const {
|
||||||
GFX::DrawTop();
|
GFX::DrawTop();
|
||||||
if (Config::UseBars == true) {
|
if (loaded) {
|
||||||
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
|
if (Config::UseBars == true) {
|
||||||
|
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
|
||||||
|
} else {
|
||||||
|
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
Gui::Draw_Rect(20, 30, 30, 30, Config::notFound);
|
||||||
|
Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("SCRIPT_NOT_FOUND"), 300);
|
||||||
|
|
||||||
|
Gui::Draw_Rect(20, 70, 30, 30, Config::outdated);
|
||||||
|
Gui::DrawString(65, 75, 0.7f, Config::TxtColor, Lang::get("OUTDATED_SCRIPT"), 300);
|
||||||
|
|
||||||
|
Gui::Draw_Rect(20, 110, 30, 30, Config::uptodate);
|
||||||
|
Gui::DrawString(65, 115, 0.7f, Config::TxtColor, Lang::get("UP-TO-DATE"), 300);
|
||||||
|
|
||||||
|
Gui::Draw_Rect(20, 150, 30, 30, Config::future);
|
||||||
|
Gui::DrawString(65, 155, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 300);
|
||||||
|
|
||||||
|
Gui::DrawString(15, 185, 0.7f, Config::TxtColor, std::to_string(int64_t(infoJson[Selection]["curRevision"])) + " | " + std::to_string(int64_t(infoJson[Selection]["revision"])), 40);
|
||||||
|
Gui::DrawString(65, 185, 0.7f, Config::TxtColor, Lang::get("REVISION"), 300);
|
||||||
|
|
||||||
|
GFX::DrawBottom();
|
||||||
|
GFX::DrawSpriteBlend(sprites_download_all_idx, 20, 25);
|
||||||
|
Gui::DrawString(50, 27, 0.6f, Config::TxtColor, Lang::get("DOWNLOAD_ALL"), 260);
|
||||||
|
GFX::DrawSpriteBlend(sprites_view_idx, 20, 55);
|
||||||
|
Gui::DrawString(50, 57, 0.6f, Config::TxtColor, Lang::get("CHANGE_VIEW_MODE"), 260);
|
||||||
|
GFX::DrawArrow(20, 85);
|
||||||
|
Gui::DrawString(50, 87, 0.6f, Config::TxtColor, Lang::get("ENTRY_UP"), 260);
|
||||||
|
GFX::DrawArrow(42, 140, 180.0);
|
||||||
|
Gui::DrawString(50, 117, 0.6f, Config::TxtColor, Lang::get("ENTRY_DOWN"), 260);
|
||||||
|
GFX::DrawArrow(20, 145, 0, 1);
|
||||||
|
Gui::DrawString(50, 147, 0.6f, Config::TxtColor, Lang::get("GO_BACK"), 260);
|
||||||
|
Gui::DrawString(10, 177, 0.6f, Config::TxtColor, std::to_string(Selection + 1) + " | " + std::to_string(maxScripts), 35);
|
||||||
|
Gui::DrawString(50, 177, 0.6f, Config::TxtColor, Lang::get("ENTRY"), 260);
|
||||||
|
GFX::DrawSpriteBlend(sprites_update_idx, 20, 195);
|
||||||
|
Gui::DrawString(50, 197, 0.6f, Config::TxtColor, Lang::get("REFRESH_SCRIPTBROWSE"), 260);
|
||||||
|
GFX::DrawArrow(0, 218, 0, 1);
|
||||||
} else {
|
} else {
|
||||||
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
|
GFX::DrawBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
Gui::Draw_Rect(20, 30, 30, 30, Config::notFound);
|
|
||||||
Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("SCRIPT_NOT_FOUND"), 300);
|
|
||||||
|
|
||||||
Gui::Draw_Rect(20, 70, 30, 30, Config::outdated);
|
|
||||||
Gui::DrawString(65, 75, 0.7f, Config::TxtColor, Lang::get("OUTDATED_SCRIPT"), 300);
|
|
||||||
|
|
||||||
Gui::Draw_Rect(20, 110, 30, 30, Config::uptodate);
|
|
||||||
Gui::DrawString(65, 115, 0.7f, Config::TxtColor, Lang::get("UP-TO-DATE"), 300);
|
|
||||||
|
|
||||||
Gui::Draw_Rect(20, 150, 30, 30, Config::future);
|
|
||||||
Gui::DrawString(65, 155, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 300);
|
|
||||||
|
|
||||||
Gui::DrawString(15, 185, 0.7f, Config::TxtColor, std::to_string(int64_t(infoJson[Selection]["curRevision"])) + " | " + std::to_string(int64_t(infoJson[Selection]["revision"])), 40);
|
|
||||||
Gui::DrawString(65, 185, 0.7f, Config::TxtColor, Lang::get("REVISION"), 300);
|
|
||||||
|
|
||||||
GFX::DrawBottom();
|
|
||||||
GFX::DrawSpriteBlend(sprites_download_all_idx, 20, 25);
|
|
||||||
Gui::DrawString(50, 27, 0.6f, Config::TxtColor, Lang::get("DOWNLOAD_ALL"), 260);
|
|
||||||
GFX::DrawSpriteBlend(sprites_view_idx, 20, 55);
|
|
||||||
Gui::DrawString(50, 57, 0.6f, Config::TxtColor, Lang::get("CHANGE_VIEW_MODE"), 260);
|
|
||||||
GFX::DrawArrow(20, 85);
|
|
||||||
Gui::DrawString(50, 87, 0.6f, Config::TxtColor, Lang::get("ENTRY_UP"), 260);
|
|
||||||
GFX::DrawArrow(42, 140, 180.0);
|
|
||||||
Gui::DrawString(50, 117, 0.6f, Config::TxtColor, Lang::get("ENTRY_DOWN"), 260);
|
|
||||||
GFX::DrawArrow(20, 145, 0, 1);
|
|
||||||
Gui::DrawString(50, 147, 0.6f, Config::TxtColor, Lang::get("GO_BACK"), 260);
|
|
||||||
Gui::DrawString(10, 177, 0.6f, Config::TxtColor, std::to_string(Selection + 1) + " | " + std::to_string(maxScripts), 35);
|
|
||||||
Gui::DrawString(50, 177, 0.6f, Config::TxtColor, Lang::get("ENTRY"), 260);
|
|
||||||
GFX::DrawSpriteBlend(sprites_update_idx, 20, 195);
|
|
||||||
Gui::DrawString(50, 197, 0.6f, Config::TxtColor, Lang::get("REFRESH_SCRIPTBROWSE"), 260);
|
|
||||||
GFX::DrawArrow(0, 218, 0, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptBrowse::DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
void ScriptBrowse::DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
if (loaded) {
|
||||||
dropDownMenu = false;
|
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||||
}
|
dropDownMenu = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (hDown & KEY_DOWN) {
|
if (hDown & KEY_DOWN) {
|
||||||
if (dropSelection < 2) dropSelection++;
|
if (dropSelection < 2) dropSelection++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hDown & KEY_UP) {
|
if (hDown & KEY_UP) {
|
||||||
if (dropSelection > 0) dropSelection--;
|
if (dropSelection > 0) dropSelection--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hDown & KEY_A) {
|
if (hDown & KEY_A) {
|
||||||
switch(dropSelection) {
|
switch(dropSelection) {
|
||||||
case 0:
|
case 0:
|
||||||
|
downloadAll();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
refresh();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (Config::viewMode == 0) {
|
||||||
|
Config::viewMode = 1;
|
||||||
|
} else {
|
||||||
|
Config::viewMode = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dropDownMenu = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hDown & KEY_TOUCH) {
|
||||||
|
if (touching(touch, dropPos2[0])) {
|
||||||
downloadAll();
|
downloadAll();
|
||||||
break;
|
dropDownMenu = false;
|
||||||
case 1:
|
} else if (touching(touch, dropPos2[1])) {
|
||||||
refresh();
|
refresh();
|
||||||
break;
|
dropDownMenu = false;
|
||||||
case 2:
|
} else if (touching(touch, dropPos2[2])) {
|
||||||
if (Config::viewMode == 0) {
|
if (Config::viewMode == 0) {
|
||||||
Config::viewMode = 1;
|
Config::viewMode = 1;
|
||||||
} else {
|
} else {
|
||||||
Config::viewMode = 0;
|
Config::viewMode = 0;
|
||||||
}
|
}
|
||||||
break;
|
dropDownMenu = false;
|
||||||
}
|
|
||||||
dropDownMenu = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hDown & KEY_TOUCH) {
|
|
||||||
if (touching(touch, dropPos2[0])) {
|
|
||||||
downloadAll();
|
|
||||||
dropDownMenu = false;
|
|
||||||
} else if (touching(touch, dropPos2[1])) {
|
|
||||||
refresh();
|
|
||||||
dropDownMenu = false;
|
|
||||||
} else if (touching(touch, dropPos2[2])) {
|
|
||||||
if (Config::viewMode == 0) {
|
|
||||||
Config::viewMode = 1;
|
|
||||||
} else {
|
|
||||||
Config::viewMode = 0;
|
|
||||||
}
|
}
|
||||||
dropDownMenu = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -338,127 +369,134 @@ void ScriptBrowse::downloadAll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||||
if (keyRepeatDelay) keyRepeatDelay--;
|
if (loaded) {
|
||||||
if (dropDownMenu) {
|
if (keyRepeatDelay) keyRepeatDelay--;
|
||||||
DropDownLogic(hDown, hHeld, touch);
|
if (dropDownMenu) {
|
||||||
|
DropDownLogic(hDown, hHeld, touch);
|
||||||
|
} else {
|
||||||
|
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
||||||
|
infoJson.clear();
|
||||||
|
Gui::screenBack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mode == 0) {
|
||||||
|
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
|
||||||
|
if (Selection < (int)infoJson.size()-1) {
|
||||||
|
Selection++;
|
||||||
|
} else {
|
||||||
|
Selection = 0;
|
||||||
|
}
|
||||||
|
if (fastMode == true) {
|
||||||
|
keyRepeatDelay = 3;
|
||||||
|
} else if (fastMode == false){
|
||||||
|
keyRepeatDelay = 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||||
|
dropDownMenu = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
|
||||||
|
if (Selection > 0) {
|
||||||
|
Selection--;
|
||||||
|
} else {
|
||||||
|
Selection = (int)infoJson.size()-1;
|
||||||
|
}
|
||||||
|
if (fastMode == true) {
|
||||||
|
keyRepeatDelay = 3;
|
||||||
|
} else if (fastMode == false){
|
||||||
|
keyRepeatDelay = 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hDown & KEY_TOUCH) {
|
||||||
|
if (Config::viewMode == 0) {
|
||||||
|
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)infoJson.size();i++) {
|
||||||
|
if(touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
|
||||||
|
if (infoJson.size() != 0) {
|
||||||
|
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPos + i]["title"]);
|
||||||
|
std::string titleFix = infoJson[screenPos + i]["title"];
|
||||||
|
for (int l = 0; l < (int)titleFix.size(); l++) {
|
||||||
|
if (titleFix[l] == '/') {
|
||||||
|
titleFix[l] = '-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Msg::DisplayMsg(fileName);
|
||||||
|
downloadToFile(infoJson[screenPos + i]["url"], Config::ScriptPath + titleFix + ".json");
|
||||||
|
infoJson[screenPos + i]["curRevision"] = infoJson[screenPos + i]["revision"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (Config::viewMode == 1) {
|
||||||
|
for(int i=0;i<ENTRIES_PER_LIST && i<(int)infoJson.size();i++) {
|
||||||
|
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
|
||||||
|
if (infoJson.size() != 0) {
|
||||||
|
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPosList + i]["title"]);
|
||||||
|
std::string titleFix = infoJson[screenPosList + i]["title"];
|
||||||
|
for (int l = 0; l < (int)titleFix.size(); l++) {
|
||||||
|
if (titleFix[l] == '/') {
|
||||||
|
titleFix[l] = '-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Msg::DisplayMsg(fileName);
|
||||||
|
downloadToFile(infoJson[screenPosList + i]["url"], Config::ScriptPath + titleFix + ".json");
|
||||||
|
infoJson[screenPosList + i]["curRevision"] = infoJson[screenPosList + i]["revision"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hDown & KEY_A) {
|
||||||
|
if (infoJson.size() != 0) {
|
||||||
|
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[Selection]["title"]);
|
||||||
|
|
||||||
|
std::string titleFix = infoJson[Selection]["title"];
|
||||||
|
for (int i = 0; i < (int)titleFix.size(); i++) {
|
||||||
|
if (titleFix[i] == '/') {
|
||||||
|
titleFix[i] = '-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Msg::DisplayMsg(fileName);
|
||||||
|
|
||||||
|
downloadToFile(infoJson[Selection]["url"], Config::ScriptPath + titleFix + ".json");
|
||||||
|
infoJson[Selection]["curRevision"] = infoJson[Selection]["revision"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hDown & KEY_R) {
|
||||||
|
fastMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hDown & KEY_L) {
|
||||||
|
fastMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Config::viewMode == 0) {
|
||||||
|
if(Selection < screenPos) {
|
||||||
|
screenPos = Selection;
|
||||||
|
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
|
||||||
|
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
|
||||||
|
}
|
||||||
|
} else if (Config::viewMode == 1) {
|
||||||
|
if(Selection < screenPosList) {
|
||||||
|
screenPosList = Selection;
|
||||||
|
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
|
||||||
|
screenPosList = Selection - ENTRIES_PER_LIST + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Switch to Glossary and back.
|
||||||
|
if (hDown & KEY_RIGHT || hDown & KEY_LEFT) {
|
||||||
|
if (mode == 0) mode = 1;
|
||||||
|
else mode = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
if (hDown & KEY_B) {
|
||||||
infoJson.clear();
|
|
||||||
Gui::screenBack();
|
Gui::screenBack();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mode == 0) {
|
|
||||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
|
|
||||||
if (Selection < (int)infoJson.size()-1) {
|
|
||||||
Selection++;
|
|
||||||
} else {
|
|
||||||
Selection = 0;
|
|
||||||
}
|
|
||||||
if (fastMode == true) {
|
|
||||||
keyRepeatDelay = 3;
|
|
||||||
} else if (fastMode == false){
|
|
||||||
keyRepeatDelay = 6;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
|
||||||
dropDownMenu = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
|
|
||||||
if (Selection > 0) {
|
|
||||||
Selection--;
|
|
||||||
} else {
|
|
||||||
Selection = (int)infoJson.size()-1;
|
|
||||||
}
|
|
||||||
if (fastMode == true) {
|
|
||||||
keyRepeatDelay = 3;
|
|
||||||
} else if (fastMode == false){
|
|
||||||
keyRepeatDelay = 6;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hDown & KEY_TOUCH) {
|
|
||||||
if (Config::viewMode == 0) {
|
|
||||||
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)infoJson.size();i++) {
|
|
||||||
if(touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
|
|
||||||
if (infoJson.size() != 0) {
|
|
||||||
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPos + i]["title"]);
|
|
||||||
std::string titleFix = infoJson[screenPos + i]["title"];
|
|
||||||
for (int l = 0; l < (int)titleFix.size(); l++) {
|
|
||||||
if (titleFix[l] == '/') {
|
|
||||||
titleFix[l] = '-';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Msg::DisplayMsg(fileName);
|
|
||||||
downloadToFile(infoJson[screenPos + i]["url"], Config::ScriptPath + titleFix + ".json");
|
|
||||||
infoJson[screenPos + i]["curRevision"] = infoJson[screenPos + i]["revision"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (Config::viewMode == 1) {
|
|
||||||
for(int i=0;i<ENTRIES_PER_LIST && i<(int)infoJson.size();i++) {
|
|
||||||
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
|
|
||||||
if (infoJson.size() != 0) {
|
|
||||||
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPosList + i]["title"]);
|
|
||||||
std::string titleFix = infoJson[screenPosList + i]["title"];
|
|
||||||
for (int l = 0; l < (int)titleFix.size(); l++) {
|
|
||||||
if (titleFix[l] == '/') {
|
|
||||||
titleFix[l] = '-';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Msg::DisplayMsg(fileName);
|
|
||||||
downloadToFile(infoJson[screenPosList + i]["url"], Config::ScriptPath + titleFix + ".json");
|
|
||||||
infoJson[screenPosList + i]["curRevision"] = infoJson[screenPosList + i]["revision"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hDown & KEY_A) {
|
|
||||||
if (infoJson.size() != 0) {
|
|
||||||
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[Selection]["title"]);
|
|
||||||
|
|
||||||
std::string titleFix = infoJson[Selection]["title"];
|
|
||||||
for (int i = 0; i < (int)titleFix.size(); i++) {
|
|
||||||
if (titleFix[i] == '/') {
|
|
||||||
titleFix[i] = '-';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Msg::DisplayMsg(fileName);
|
|
||||||
|
|
||||||
downloadToFile(infoJson[Selection]["url"], Config::ScriptPath + titleFix + ".json");
|
|
||||||
infoJson[Selection]["curRevision"] = infoJson[Selection]["revision"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hDown & KEY_R) {
|
|
||||||
fastMode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hDown & KEY_L) {
|
|
||||||
fastMode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::viewMode == 0) {
|
|
||||||
if(Selection < screenPos) {
|
|
||||||
screenPos = Selection;
|
|
||||||
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
|
|
||||||
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
|
|
||||||
}
|
|
||||||
} else if (Config::viewMode == 1) {
|
|
||||||
if(Selection < screenPosList) {
|
|
||||||
screenPosList = Selection;
|
|
||||||
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
|
|
||||||
screenPosList = Selection - ENTRIES_PER_LIST + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Switch to Glossary and back.
|
|
||||||
if (hDown & KEY_RIGHT || hDown & KEY_LEFT) {
|
|
||||||
if (mode == 0) mode = 1;
|
|
||||||
else mode = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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