diff --git a/include/download/download.hpp b/include/download/download.hpp index 4b679d5..77ff864 100644 --- a/include/download/download.hpp +++ b/include/download/download.hpp @@ -39,8 +39,8 @@ enum DownloadError { DL_ERROR_GIT, }; -Result downloadToFile(std::string url, std::string path, bool downloadToRAM); -Result downloadFromRelease(std::string url, std::string asset, std::string path, bool includePrereleases, bool downloadToRAM); +Result downloadToFile(std::string url, std::string path); +Result downloadFromRelease(std::string url, std::string asset, std::string path, bool includePrereleases); void displayProgressBar(); @@ -69,7 +69,7 @@ void doneMsg(void); * item is that to get from the API. (Ex. "tag_name") * @return the string from the API. */ -std::string getLatestRelease(std::string repo, std::string item, bool downloadToRAM); +std::string getLatestRelease(std::string repo, std::string item); /** * Get info from the GitHub API about a Commit. @@ -77,7 +77,7 @@ std::string getLatestRelease(std::string repo, std::string item, bool downloadTo * item is that to get from the API. (Ex. "sha") * @return the string from the API. */ -std::string getLatestCommit(std::string repo, std::string item, bool downloadToRAM); +std::string getLatestCommit(std::string repo, std::string item); /** * Get info from the GitHub API about a Commit. @@ -86,4 +86,4 @@ std::string getLatestCommit(std::string repo, std::string item, bool downloadToR * item is that to get from the API. (Ex. "message") * @return the string from the API. */ -std::string getLatestCommit(std::string repo, std::string array, std::string item, bool downloadToRAM); \ No newline at end of file +std::string getLatestCommit(std::string repo, std::string array, std::string item); \ No newline at end of file diff --git a/include/screens/ftpScreen.hpp b/include/screens/ftpScreen.hpp index 4cece6b..87b5003 100644 --- a/include/screens/ftpScreen.hpp +++ b/include/screens/ftpScreen.hpp @@ -26,6 +26,8 @@ #include "screens/screen.hpp" +#include "utils/structs.hpp" + class FTPScreen : public screen { public: @@ -34,4 +36,7 @@ public: private: int ftpEnabled = 1; + std::vector arrowPos = { + {0, 215, 25, 25, -1}, // Back Arrow. + }; }; \ No newline at end of file diff --git a/include/screens/mainMenu.hpp b/include/screens/mainMenu.hpp index 3ceb9ba..f6bc41e 100644 --- a/include/screens/mainMenu.hpp +++ b/include/screens/mainMenu.hpp @@ -50,6 +50,7 @@ private: {170, 100, 140, 35, -1}, // ScriptCreator. {10, 160, 140, 35, -1}, // Language. {170, 160, 140, 35, -1}, // Colors. + {0, 215, 25, 25, -1}, // Back Arrow. }; }; diff --git a/include/screens/scriptBrowse.hpp b/include/screens/scriptBrowse.hpp index 0f8385f..090e20f 100644 --- a/include/screens/scriptBrowse.hpp +++ b/include/screens/scriptBrowse.hpp @@ -51,6 +51,7 @@ private: std::vector arrowPos = { {295, 0, 25, 25, -1}, // Arrow Up. {295, 215, 25, 25, -1}, // Arrow Down. + {0, 215, 25, 25, -1}, // Back Arrow. }; }; diff --git a/include/screens/scriptlist.hpp b/include/screens/scriptlist.hpp index ea01aa2..011ee4a 100644 --- a/include/screens/scriptlist.hpp +++ b/include/screens/scriptlist.hpp @@ -62,6 +62,7 @@ private: std::vector arrowPos = { {295, 0, 25, 25, -1}, // Arrow Up. {295, 215, 25, 25, -1}, // Arrow Down. + {0, 215, 25, 25, -1}, // Back Arrow. }; }; diff --git a/include/screens/settings.hpp b/include/screens/settings.hpp index 7a766e4..11e136e 100644 --- a/include/screens/settings.hpp +++ b/include/screens/settings.hpp @@ -84,7 +84,13 @@ private: }; std::vector barPos = { - {0, 215, 320, 25, -1}, + {100, 215, 100, 25, -1}, + }; + + std::vector arrowPos = { + {0, 0, 25, 25, -1}, // Previous Arrow. + {295, 0, 25, 25, -1}, // Next Arrow. + {0, 215, 25, 25, -1}, // Back Arrow. }; }; diff --git a/include/screens/tinyDB.hpp b/include/screens/tinyDB.hpp index 26e01b7..77fde15 100644 --- a/include/screens/tinyDB.hpp +++ b/include/screens/tinyDB.hpp @@ -49,6 +49,7 @@ private: std::vector arrowPos = { {295, 0, 25, 25, -1}, // Arrow Up. {295, 215, 25, 25, -1}, // Arrow Down. + {0, 215, 25, 25, -1}, // Back Arrow. }; }; diff --git a/include/utils/scriptHelper.hpp b/include/utils/scriptHelper.hpp index fcefd93..0ced401 100644 --- a/include/utils/scriptHelper.hpp +++ b/include/utils/scriptHelper.hpp @@ -35,8 +35,8 @@ namespace ScriptHelper { int getNum(nlohmann::json json, const std::string &key, const std::string &key2); // Script Functions. - void downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, bool downloadToRAM, std::string message); - void downloadFile(std::string file, std::string output, bool downloadToRAM, std::string message); + void downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, std::string message); + void downloadFile(std::string file, std::string output, std::string message); void removeFile(std::string file, std::string message); void installFile(std::string file, std::string message); diff --git a/source/download/download.cpp b/source/download/download.cpp index 9fb7fca..5a0138d 100644 --- a/source/download/download.cpp +++ b/source/download/download.cpp @@ -161,11 +161,12 @@ static Result setupContextForDirectToFileDownload(CURL *hnd, const char * url) return 0; } -Result downloadToFile(std::string url, std::string path, bool downloadToRAM) +Result downloadToFile(std::string url, std::string path) { Result ret = 0; u64 offset = 0; u32 bytesWritten = 0; + bool isDownloadToRAM = true; printf("Downloading from:\n%s\nto:\n%s\n", url.c_str(), path.c_str()); void *socubuf = memalign(0x1000, 0x100000); @@ -198,11 +199,12 @@ Result downloadToFile(std::string url, std::string path, bool downloadToRAM) result_fileHandle = &fileHandle; CURL *hnd = curl_easy_init(); - if (downloadToRAM == true) { - ret = setupContext(hnd, url.c_str()); - } else { + ret = setupContext(hnd, url.c_str()); + if (downloadTotal > 30000000) { ret = setupContextForDirectToFileDownload(hnd, url.c_str()); + isDownloadToRAM = false; } + if (ret != 0) { socExit(); free(result_buf); @@ -232,7 +234,7 @@ Result downloadToFile(std::string url, std::string path, bool downloadToRAM) FSFILE_Close(fileHandle); return -1; } - if (downloadToRAM == true) { + if (isDownloadToRAM == true) { FSFILE_Write(fileHandle, &bytesWritten, offset, result_buf, result_written, 0); } @@ -251,7 +253,7 @@ Result downloadToFile(std::string url, std::string path, bool downloadToRAM) return 0; } -Result downloadFromRelease(std::string url, std::string asset, std::string path, bool includePrereleases, bool downloadToRAM) +Result downloadFromRelease(std::string url, std::string asset, std::string path, bool includePrereleases) { Result ret = 0; void *socubuf = memalign(0x1000, 0x100000); @@ -335,7 +337,7 @@ Result downloadFromRelease(std::string url, std::string asset, std::string path, if (assetUrl.empty()) ret = DL_ERROR_GIT; else - ret = downloadToFile(assetUrl, path, downloadToRAM); + ret = downloadToFile(assetUrl, path); return ret; } @@ -383,7 +385,7 @@ void notConnectedMsg(void) { } } -std::string getLatestRelease(std::string repo, std::string item, bool downloadToRAM) +std::string getLatestRelease(std::string repo, std::string item) { Result ret = 0; void *socubuf = memalign(0x1000, 0x100000); @@ -404,13 +406,7 @@ std::string getLatestRelease(std::string repo, std::string item, bool downloadTo std::string apiurl = apiurlStream.str(); CURL *hnd = curl_easy_init(); - - if (downloadToRAM == true) { - ret = setupContext(hnd, apiurl.c_str()); - } else { - ret = setupContextForDirectToFileDownload(hnd, apiurl.c_str()); - } - + ret = setupContext(hnd, apiurl.c_str()); if (ret != 0) { socExit(); free(result_buf); @@ -453,7 +449,7 @@ std::string getLatestRelease(std::string repo, std::string item, bool downloadTo return jsonItem; } -std::string getLatestCommit(std::string repo, std::string item, bool downloadToRAM) +std::string getLatestCommit(std::string repo, std::string item) { Result ret = 0; void *socubuf = memalign(0x1000, 0x100000); @@ -474,11 +470,7 @@ std::string getLatestCommit(std::string repo, std::string item, bool downloadToR std::string apiurl = apiurlStream.str(); CURL *hnd = curl_easy_init(); - if (downloadToRAM == true) { - ret = setupContext(hnd, apiurl.c_str()); - } else { - ret = setupContextForDirectToFileDownload(hnd, apiurl.c_str()); - } + ret = setupContext(hnd, apiurl.c_str()); if (ret != 0) { socExit(); free(result_buf); @@ -521,7 +513,7 @@ std::string getLatestCommit(std::string repo, std::string item, bool downloadToR return jsonItem; } -std::string getLatestCommit(std::string repo, std::string array, std::string item, bool downloadToRAM) +std::string getLatestCommit(std::string repo, std::string array, std::string item) { Result ret = 0; void *socubuf = memalign(0x1000, 0x100000); @@ -542,11 +534,7 @@ std::string getLatestCommit(std::string repo, std::string array, std::string ite std::string apiurl = apiurlStream.str(); CURL *hnd = curl_easy_init(); - if (downloadToRAM == true) { - ret = setupContext(hnd, apiurl.c_str()); - } else { - ret = setupContextForDirectToFileDownload(hnd, apiurl.c_str()); - } + ret = setupContext(hnd, apiurl.c_str()); if (ret != 0) { socExit(); free(result_buf); diff --git a/source/screens/ftpScreen.cpp b/source/screens/ftpScreen.cpp index 82f4868..3db91d2 100644 --- a/source/screens/ftpScreen.cpp +++ b/source/screens/ftpScreen.cpp @@ -39,6 +39,9 @@ extern "C" { #include "ftp.h" } +extern bool touching(touchPosition touch, Structs::ButtonPos button); +extern touchPosition touch; + void FTPScreen::Draw(void) const { ftp_init(); @@ -54,6 +57,7 @@ void FTPScreen::Draw(void) const Gui::DrawTop(); Gui::DrawString((400-Gui::GetStringWidth(0.8f, Lang::get("FTP_MODE")))/2, 0, 0.8f, Config::TxtColor, Lang::get("FTP_MODE"), 400); Gui::DrawBottom(); + Gui::DrawArrow(0, 242, 270.0); ret = ACU_GetWifiStatus(&wifiStatus); if ((wifiStatus != 0) && R_SUCCEEDED(ret)) { @@ -77,10 +81,13 @@ void FTPScreen::Draw(void) const Gui::clearTextBufs(); C3D_FrameEnd(0); hidScanInput(); + hidTouchRead(&touch); u32 hDown = hidKeysDown(); if (hDown & KEY_B) break; + if (hDown & KEY_TOUCH && touching(touch, arrowPos[0])) + break; } memset(ftp_accepted_connection, 0, 20); // Empty accepted connection address. memset(ftp_file_transfer, 0, 50); // Empty transfer status. diff --git a/source/screens/mainMenu.cpp b/source/screens/mainMenu.cpp index 3010b67..71ba7c5 100644 --- a/source/screens/mainMenu.cpp +++ b/source/screens/mainMenu.cpp @@ -54,6 +54,7 @@ void MainMenu::Draw(void) const { Gui::DrawString(397-Gui::GetStringWidth(0.5f, V_STRING), 237-Gui::GetStringHeight(0.5f, V_STRING), 0.5f, Config::TxtColor, V_STRING); if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, fadealpha)); // Fade in out effect Gui::DrawBottom(); + Gui::DrawArrow(0, 242, 270.0); for (int i = 0; i < 6; i++) { if (Selection == i) { @@ -186,6 +187,8 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } else { notConnectedMsg(); } + } else if (touching(touch, mainButtons[6])) { + exiting = true; } } } \ No newline at end of file diff --git a/source/screens/scriptBrowse.cpp b/source/screens/scriptBrowse.cpp index 166846f..e5b9270 100644 --- a/source/screens/scriptBrowse.cpp +++ b/source/screens/scriptBrowse.cpp @@ -99,7 +99,7 @@ ScriptBrowse::ScriptBrowse() { DisplayMsg(Lang::get("GETTING_SCRIPT_LIST")); // Get repo info - downloadToFile("https://github.com/Universal-Team/extras/raw/scripts/info/scriptInfo.json", metaFile, true); + downloadToFile("https://github.com/Universal-Team/extras/raw/scripts/info/scriptInfo.json", metaFile); FILE* file = fopen(metaFile, "r"); if(file) infoJson = nlohmann::json::parse(file, nullptr, false); fclose(file); @@ -128,8 +128,10 @@ void ScriptBrowse::Draw(void) const { Gui::DrawBottom(); Gui::DrawArrow(295, 0); Gui::DrawArrow(315, 240, 180.0); - Gui::sprite(sprites_search_idx, -3, 0); - Gui::DrawString(7.5, 1.5, 0.72f, BLACK, "\uE003"); +// Gui::sprite(sprites_search_idx, -3, 0); +// Gui::DrawString(7.5, 1.5, 0.72f, BLACK, "\uE003"); + + Gui::DrawArrow(0, 242, 270.0); Gui::DrawStringCentered(-23, 3, 0.6f, Config::TxtColor, std::to_string(selection + 1) + " / " + maxScripts); if (Config::viewMode == 0) { @@ -191,6 +193,12 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } } + if (hDown & KEY_TOUCH && touching(touch, arrowPos[2])) { + infoJson.clear(); + Screen::back(); + return; + } + if (hHeld & KEY_DOWN && !keyRepeatDelay) { if (selection < (int)infoJson.size()-1) { selection++; @@ -230,7 +238,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } } DisplayMsg(fileName); - downloadToFile(infoJson[screenPos + i]["url"], Config::ScriptPath + titleFix + ".json", true); + downloadToFile(infoJson[screenPos + i]["url"], Config::ScriptPath + titleFix + ".json"); infoJson[screenPos + i]["curRevision"] = infoJson[screenPos + i]["revision"]; } } @@ -247,7 +255,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } } DisplayMsg(fileName); - downloadToFile(infoJson[screenPosList + i]["url"], Config::ScriptPath + titleFix + ".json", true); + downloadToFile(infoJson[screenPosList + i]["url"], Config::ScriptPath + titleFix + ".json"); infoJson[screenPosList + i]["curRevision"] = infoJson[screenPosList + i]["revision"]; } } @@ -267,7 +275,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } DisplayMsg(fileName); - downloadToFile(infoJson[selection]["url"], Config::ScriptPath + titleFix + ".json", true); + downloadToFile(infoJson[selection]["url"], Config::ScriptPath + titleFix + ".json"); infoJson[selection]["curRevision"] = infoJson[selection]["revision"]; } } @@ -315,7 +323,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } } DisplayMsg(fileName + " " + std::to_string(current) + " / " + std::to_string(total)); - downloadToFile(infoJson[i]["url"], Config::ScriptPath + titleFix + ".json", true); + downloadToFile(infoJson[i]["url"], Config::ScriptPath + titleFix + ".json"); infoJson[i]["curRevision"] = infoJson[i]["revision"]; } } diff --git a/source/screens/scriptlist.cpp b/source/screens/scriptlist.cpp index e1f434d..1a88d89 100644 --- a/source/screens/scriptlist.cpp +++ b/source/screens/scriptlist.cpp @@ -128,19 +128,17 @@ void runFunctions(nlohmann::json &json) { if(!missing) ScriptHelper::removeFile(file, message); } else if(type == "downloadFile") { - bool missing = false, downloadToRAM = false; + bool missing = false; std::string file, output, message; if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file"); else missing = true; if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output"); else missing = true; - if(json.at(choice).at(i).contains("downloadToRAM") && json.at(choice).at(i).at("downloadToRAM").is_boolean()) - downloadToRAM = json.at(choice).at(i).at("downloadToRAM"); if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message"); - if(!missing) ScriptHelper::downloadFile(file, output, downloadToRAM, message); + if(!missing) ScriptHelper::downloadFile(file, output, message); } else if(type == "downloadRelease") { - bool missing = false, includePrereleases = false, downloadToRAM = false; + bool missing = false, includePrereleases = false; std::string repo, file, output, message; if(json.at(choice).at(i).contains("repo")) repo = json.at(choice).at(i).at("repo"); else missing = true; @@ -150,10 +148,8 @@ void runFunctions(nlohmann::json &json) { else missing = true; if(json.at(choice).at(i).contains("includePrereleases") && json.at(choice).at(i).at("includePrereleases").is_boolean()) includePrereleases = json.at(choice).at(i).at("includePrereleases"); - if(json.at(choice).at(i).contains("downloadToRAM") && json.at(choice).at(i).at("downloadToRAM").is_boolean()) - downloadToRAM = json.at(choice).at(i).at("downloadToRAM"); if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message"); - if(!missing) ScriptHelper::downloadRelease(repo, file, output, includePrereleases, downloadToRAM, message); + if(!missing) ScriptHelper::downloadRelease(repo, file, output, includePrereleases, message); } else if(type == "extractFile") { bool missing = false; @@ -290,7 +286,7 @@ void ScriptList::DrawList(void) const { Gui::DrawBottom(); Gui::DrawArrow(295, 0); Gui::DrawArrow(315, 240, 180.0); - + Gui::DrawArrow(0, 242, 270.0); if (Config::viewMode == 0) { for(int i=0;i 0) colorMode--; + } + if (hDown & KEY_L || hDown & KEY_LEFT) { if(colorMode > 0) colorMode--; } + if (hDown & KEY_TOUCH && touching(touch, arrowPos[1])) { + if(colorMode < 6) colorMode++; + } + if (hDown & KEY_R || hDown & KEY_RIGHT) { if(colorMode < 6) colorMode++; } @@ -349,6 +378,8 @@ void Settings::CreditsLogic(u32 hDown, touchPosition touch) { if (hDown & KEY_TOUCH) { if (touching(touch, barPos[0])) { DisplayMode = 2; + } else if (touching(touch, arrowPos[2])) { + mode = 0; } } if (hDown & KEY_B) { @@ -357,6 +388,8 @@ void Settings::CreditsLogic(u32 hDown, touchPosition touch) { } else if (DisplayMode == 2) { if (hDown & KEY_B) { DisplayMode = 1; + } else if (hDown & KEY_TOUCH && touching(touch, arrowPos[2])) { + DisplayMode = 1; } } } diff --git a/source/screens/tinyDB.cpp b/source/screens/tinyDB.cpp index 6c79de4..b4de89a 100644 --- a/source/screens/tinyDB.cpp +++ b/source/screens/tinyDB.cpp @@ -72,7 +72,7 @@ std::vector tinyDBList; TinyDB::TinyDB() { DisplayMsg(Lang::get("TINYDB_DOWNLOADING")); - downloadToFile("https://tinydb.eiphax.tech/api/universal-updater.json?raw=true", tinyDBFile, true); + downloadToFile("https://tinydb.eiphax.tech/api/universal-updater.json?raw=true", tinyDBFile); tinyDBList = parseObjects(); selectedOption = tinyDBList[0]; } @@ -107,9 +107,10 @@ void TinyDB::Draw(void) const { Gui::DrawArrow(295, 0); Gui::DrawArrow(315, 240, 180.0); + Gui::DrawArrow(0, 242, 270.0); // Search Icon. - Gui::sprite(sprites_search_idx, -3, 0); - Gui::DrawString(7.5, 1.5, 0.72f, BLACK, "\uE003"); +// Gui::sprite(sprites_search_idx, -3, 0); +// Gui::DrawString(7.5, 1.5, 0.72f, BLACK, "\uE003"); if (Config::viewMode == 0) { for(int i=0;i 0) { selection--; @@ -256,18 +262,14 @@ void TinyDB::execute() { if(!missing) ScriptHelper::removeFile(file, message); } else if(type == "downloadFile") { - bool missing = false, downloadToRAM = false; + bool missing = false; std::string file, output, message; if(tinyDBJson.at(selectedOption).at("script").at(i).contains("file")) file = tinyDBJson.at(selectedOption).at("script").at(i).at("file"); else missing = true; if(tinyDBJson.at(selectedOption).at("script").at(i).contains("output")) output = tinyDBJson.at(selectedOption).at("script").at(i).at("output"); else missing = true; if(tinyDBJson.at(selectedOption).at("script").at(i).contains("message")) message = tinyDBJson.at(selectedOption).at("script").at(i).at("message"); - - if (int64_t(tinyDBJson[selectedOption]["info"]["fileSize"]) < 30000000) { - downloadToRAM = true; - } - if(!missing) ScriptHelper::downloadFile(file, output, downloadToRAM, message); + if(!missing) ScriptHelper::downloadFile(file, output, message); } else if(type == "installCia") { bool missing = false; diff --git a/source/utils/scriptHelper.cpp b/source/utils/scriptHelper.cpp index b10bcd3..f2f6dfa 100644 --- a/source/utils/scriptHelper.cpp +++ b/source/utils/scriptHelper.cpp @@ -67,12 +67,12 @@ int ScriptHelper::getNum(nlohmann::json json, const std::string &key, const std: } // Download from a Github Release. -void ScriptHelper::downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, bool downloadToRAM, std::string message) { +void ScriptHelper::downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, std::string message) { snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str()); showProgressBar = true; progressBarType = 0; Threads::create((ThreadFunc)displayProgressBar); - if (downloadFromRelease("https://github.com/" + repo, file, output, includePrereleases, downloadToRAM) != 0) { + if (downloadFromRelease("https://github.com/" + repo, file, output, includePrereleases) != 0) { showProgressBar = false; downloadFailed(); return; @@ -81,12 +81,12 @@ void ScriptHelper::downloadRelease(std::string repo, std::string file, std::stri } // Download a File from everywhere. -void ScriptHelper::downloadFile(std::string file, std::string output, bool downloadToRAM, std::string message) { +void ScriptHelper::downloadFile(std::string file, std::string output, std::string message) { snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str()); showProgressBar = true; progressBarType = 0; Threads::create((ThreadFunc)displayProgressBar); - if (downloadToFile(file, output, downloadToRAM) != 0) { + if (downloadToFile(file, output) != 0) { showProgressBar = false; downloadFailed(); return;