TinyDB Screen work!

Display much more informations! :)
This commit is contained in:
VoltZ
2019-11-13 21:46:11 +01:00
parent 1a50afbbed
commit c71c3c2c66
2 changed files with 51 additions and 17 deletions
+11 -6
View File
@@ -40,12 +40,12 @@
"GET_SCRIPTS": "Get Scripts", "GET_SCRIPTS": "Get Scripts",
"INSTALLED_REV": "Installed revision: ", "INSTALLED_REV": "Installed revision: ",
"CURRENT_REV": "Current revision: ", "CURRENT_REV": "Current revision: ",
"AUTHOR": "author: ", "AUTHOR": "Author: ",
"TITLE": "title: ", "TITLE": "Title: ",
"FUTURE_SCRIPT": "This Script is a Future Script.", "FUTURE_SCRIPT": "This script is a future script.",
"OUTDATED_SCRIPT": "This Script is outdated.", "OUTDATED_SCRIPT": "This script is outdated.",
"UP-TO-DATE": "This Script is Up-To-Date.", "UP-TO-DATE": "This script is up-to-date.",
"FTP_MODE": "FTP Mode", "FTP_MODE": "FTP Mode",
"FTP_INITIALIZED": "FTP Initialized.", "FTP_INITIALIZED": "FTP Initialized.",
@@ -69,5 +69,10 @@
"SHOW_QR": "Click here to show the QR Code.", "SHOW_QR": "Click here to show the QR Code.",
"LINK": "Join our Discord: https://discord.gg/KDJCfGF", "LINK": "Join our Discord: https://discord.gg/KDJCfGF",
"TINYDB_DOWNLOADING": "Downloading database of available titles from TinyDB..." "TINYDB_DOWNLOADING": "Downloading database of available titles from TinyDB...",
"RELEASE_TAG": "Release Tag: ",
"DESC": "Desc: ",
"RELEASE_ID": "Release ID: ",
"TITLE_ID": "Title ID: ",
"FILE_SIZE": "File size: "
} }
+40 -11
View File
@@ -66,10 +66,28 @@ std::vector<std::string> parseObjects() {
std::vector<std::string> tinyDBList; std::vector<std::string> tinyDBList;
// adapted from GM9i's byte parsing.
std::string parseBytes(int bytes) {
char out[32];
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);
return out;
}
TinyDB::TinyDB() { TinyDB::TinyDB() {
DisplayMsg(Lang::get("TINYDB_DOWNLOADING")); DisplayMsg(Lang::get("TINYDB_DOWNLOADING"));
downloadToFile("https://tinydb.eiphax.tech/api/universal.json?raw=true", tinyDBFile); downloadToFile("https://tinydb.eiphax.tech/api/universal-updater.json?raw=true", tinyDBFile);
tinyDBList = parseObjects(); tinyDBList = parseObjects();
selectedOption = tinyDBList[0];
} }
// To-Do. // To-Do.
@@ -80,6 +98,14 @@ void TinyDB::Draw(void) const {
Gui::Draw_Rect(0, 30, 400, 180, C2D_Color32(140, 140, 140, 255)); Gui::Draw_Rect(0, 30, 400, 180, C2D_Color32(140, 140, 140, 255));
Gui::Draw_Rect(0, 210, 400, 30, C2D_Color32(63, 81, 181, 255)); Gui::Draw_Rect(0, 210, 400, 30, C2D_Color32(63, 81, 181, 255));
if (selection != 0) {
Gui::DrawStringCentered(0, 35, 0.6f, Config::TxtColor, Lang::get("AUTHOR") + std::string(tinyDBJson[selectedOption]["info"]["author"]), 400);
Gui::DrawStringCentered(0, 65, 0.6f, Config::TxtColor, Lang::get("DESC") + std::string(tinyDBJson[selectedOption]["info"]["description"]), 400);
Gui::DrawStringCentered(0, 95, 0.6f, Config::TxtColor, Lang::get("RELEASE_TAG") + std::string(tinyDBJson[selectedOption]["info"]["releaseTag"]), 400);
Gui::DrawStringCentered(0, 125, 0.6f, Config::TxtColor, Lang::get("RELEASE_ID") + std::string(tinyDBJson[selectedOption]["info"]["releaseId"]), 400);
Gui::DrawStringCentered(0, 155, 0.6f, Config::TxtColor, Lang::get("TITLE_ID") + std::string(tinyDBJson[selectedOption]["info"]["titleid"]), 400);
Gui::DrawStringCentered(0, 185, 0.6f, Config::TxtColor, Lang::get("FILE_SIZE") + parseBytes(int64_t(tinyDBJson[selectedOption]["info"]["fileSize"])), 400);
}
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "TinyDB", 400); Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "TinyDB", 400);
std::string entryAmount = std::to_string(selection+1) + " / " + std::to_string(tinyDBList.size()); std::string entryAmount = std::to_string(selection+1) + " / " + std::to_string(tinyDBList.size());
Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), 237-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, Config::TxtColor, entryAmount); Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), 237-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, Config::TxtColor, entryAmount);
@@ -133,8 +159,10 @@ void TinyDB::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hHeld & KEY_UP && !keyRepeatDelay) { if (hHeld & KEY_UP && !keyRepeatDelay) {
if (selection > 0) { if (selection > 0) {
selection--; selection--;
selectedOption = tinyDBList[selection];
} else { } else {
selection = (int)tinyDBList.size()-1; selection = (int)tinyDBList.size()-1;
selectedOption = tinyDBList[selection];
} }
if (fastMode == true) { if (fastMode == true) {
keyRepeatDelay = 3; keyRepeatDelay = 3;
@@ -146,8 +174,10 @@ void TinyDB::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hHeld & KEY_DOWN && !keyRepeatDelay) { if (hHeld & KEY_DOWN && !keyRepeatDelay) {
if (selection < (int)tinyDBList.size()-1) { if (selection < (int)tinyDBList.size()-1) {
selection++; selection++;
selectedOption = tinyDBList[selection];
} else { } else {
selection = 0; selection = 0;
selectedOption = tinyDBList[selection];
} }
if (fastMode == true) { if (fastMode == true) {
keyRepeatDelay = 3; keyRepeatDelay = 3;
@@ -179,38 +209,37 @@ void TinyDB::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
} }
if (hDown & KEY_A) { if (hDown & KEY_A) {
selectedOption = tinyDBList[selection];
execute(); execute();
} }
} }
void TinyDB::execute() { void TinyDB::execute() {
for(int i=0;i<(int)tinyDBJson.at(selectedOption).size();i++) { for(int i=0;i<(int)tinyDBJson.at(selectedOption).size();i++) {
std::string type = tinyDBJson.at(selectedOption).at(i).at("type"); std::string type = tinyDBJson.at(selectedOption).at("script").at(i).at("type");
if(type == "deleteFile") { if(type == "deleteFile") {
bool missing = false; bool missing = false;
std::string file, message; std::string file, message;
if(tinyDBJson.at(selectedOption).at(i).contains("file")) file = tinyDBJson.at(selectedOption).at(i).at("file"); if(tinyDBJson.at(selectedOption).at("script").at(i).contains("file")) file = tinyDBJson.at(selectedOption).at("script").at(i).at("file");
else missing = true; else missing = true;
if(tinyDBJson.at(selectedOption).at(i).contains("message")) message = tinyDBJson.at(selectedOption).at(i).at("message"); if(tinyDBJson.at(selectedOption).at("script").at(i).contains("message")) message = tinyDBJson.at(selectedOption).at("script").at(i).at("message");
if(!missing) download::deleteFileList(file, message); if(!missing) download::deleteFileList(file, message);
} else if(type == "downloadFile") { } else if(type == "downloadFile") {
bool missing = false; bool missing = false;
std::string file, output, message; std::string file, output, message;
if(tinyDBJson.at(selectedOption).at(i).contains("file")) file = tinyDBJson.at(selectedOption).at(i).at("file"); if(tinyDBJson.at(selectedOption).at("script").at(i).contains("file")) file = tinyDBJson.at(selectedOption).at("script").at(i).at("file");
else missing = true; else missing = true;
if(tinyDBJson.at(selectedOption).at(i).contains("output")) output = tinyDBJson.at(selectedOption).at(i).at("output"); if(tinyDBJson.at(selectedOption).at("script").at(i).contains("output")) output = tinyDBJson.at(selectedOption).at("script").at(i).at("output");
else missing = true; else missing = true;
if(tinyDBJson.at(selectedOption).at(i).contains("message")) message = tinyDBJson.at(selectedOption).at(i).at("message"); if(tinyDBJson.at(selectedOption).at("script").at(i).contains("message")) message = tinyDBJson.at(selectedOption).at("script").at(i).at("message");
if(!missing) download::downloadFile(file, output, message); if(!missing) download::downloadFile(file, output, message);
} else if(type == "installCia") { } else if(type == "installCia") {
bool missing = false; bool missing = false;
std::string file, message; std::string file, message;
if(tinyDBJson.at(selectedOption).at(i).contains("file")) file = tinyDBJson.at(selectedOption).at(i).at("file"); if(tinyDBJson.at(selectedOption).at("script").at(i).contains("file")) file = tinyDBJson.at(selectedOption).at("script").at(i).at("file");
else missing = true; else missing = true;
if(tinyDBJson.at(selectedOption).at(i).contains("message")) message = tinyDBJson.at(selectedOption).at(i).at("message"); if(tinyDBJson.at(selectedOption).at("script").at(i).contains("message")) message = tinyDBJson.at(selectedOption).at("script").at(i).at("message");
if(!missing) download::installFileList(file, message); if(!missing) download::installFileList(file, message);
} }
} }