diff --git a/include/gui.hpp b/include/gui.hpp index d21b0fd..2226f5f 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -70,6 +70,7 @@ namespace Gui void DrawBottom(void); void DisplayWarnMsg(std::string Text); + bool promptMsg(std::string promptMsg); } void DisplayMsg(std::string text); diff --git a/include/screens/scriptlist.hpp b/include/screens/scriptlist.hpp index c3421e8..395fa34 100644 --- a/include/screens/scriptlist.hpp +++ b/include/screens/scriptlist.hpp @@ -56,4 +56,5 @@ private: int fastMode = false; }; +Result createFile(const char * path); #endif \ No newline at end of file diff --git a/include/utils/common.hpp b/include/utils/common.hpp index e1b19bc..1d1415a 100644 --- a/include/utils/common.hpp +++ b/include/utils/common.hpp @@ -58,5 +58,5 @@ using json = nlohmann::json; extern char * arg0; -#define WORKING_DIR "/3ds/" +#define WORKING_DIR "/" #define SCRIPTS_PATH "/3ds/Universal-Updater/scripts/" // The Scripts will be here. \ No newline at end of file diff --git a/include/utils/files.h b/include/utils/files.h index 95ed050..1415624 100644 --- a/include/utils/files.h +++ b/include/utils/files.h @@ -28,5 +28,8 @@ #include "common.hpp" +Result makeDirs(const char * path); Result openFile(Handle* fileHandle, const char * path, bool write); -Result deleteFile(const char * path); \ No newline at end of file +Result deleteFile(const char * path); +Result removeDir(const char * path); +Result removeDirRecursive(const char * path); \ No newline at end of file diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index 6ae1a43..eb0deba 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -27,5 +27,8 @@ "ENTER_BLUE_RGB": "Enter the Blue RGB.", "WHAT_DO_YOU_TRY": "What are you trying to do? :P", - "INCOMPATIBLE_SCRIPT": "You have an incompatible script." + "INCOMPATIBLE_SCRIPT": "You have an incompatible script.", + + "DELETE_PROMPT": "Are you sure you want to delete this Directory?", + "CONFIRM_OR_CANCEL": "Press A to confirm, B to cancel." } diff --git a/source/gui.cpp b/source/gui.cpp index 02732ae..be3abc7 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -173,4 +173,28 @@ void Gui::DrawBottom(void) { Gui::Draw_Rect(0, 0, 320, 30, Config::Color1); Gui::Draw_Rect(0, 30, 320, 180, Config::Color3); Gui::Draw_Rect(0, 210, 320, 30, Config::Color1); +} + +// Display a Message, which needs to be confirmed with A/B. +bool Gui::promptMsg(std::string promptMsg) +{ + Gui::clearTextBufs(); + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + C2D_TargetClear(top, BLACK); + C2D_TargetClear(bottom, BLACK); + Gui::DrawTop(); + Gui::DrawString((400-Gui::GetStringWidth(0.6f, promptMsg.c_str()))/2, 100, 0.6f, Config::TxtColor, promptMsg.c_str(), 400); + Gui::DrawString((400-Gui::GetStringWidth(0.72f, Lang::get("CONFIRM_OR_CANCEL")))/2, 214, 0.72f, Config::TxtColor, Lang::get("CONFIRM_OR_CANCEL"), 400); + Gui::DrawBottom(); + C3D_FrameEnd(0); + while(1) + { + gspWaitForVBlank(); + hidScanInput(); + if(hidKeysDown() & KEY_A) { + return true; + } else if(hidKeysDown() & KEY_B) { + return false; + } + } } \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 49167b6..a997249 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -68,7 +68,6 @@ int main() Config::saveConfig(); } Lang::load(1); - Gui::setScreen(std::make_unique()); osSetSpeedupEnable(true); // Enable speed-up for New 3DS users diff --git a/source/screens/scriptlist.cpp b/source/screens/scriptlist.cpp index bbc3125..4946940 100644 --- a/source/screens/scriptlist.cpp +++ b/source/screens/scriptlist.cpp @@ -45,6 +45,7 @@ struct Info { }; std::string choice; std::string currentFile; +std::string selectedTitle; Info parseInfo(std::string fileName) { FILE* file = fopen(fileName.c_str(), "rt"); @@ -95,6 +96,14 @@ std::vector parseObjects(std::string fileName) { return objs; } +// Because we need `#include `. +Result createFile(const char * path) { + std::ofstream ofstream; + ofstream.open(path, std::ofstream::out | std::ofstream::app); + ofstream.close(); + return 0; +} + void runFunctions(void) { FILE* file = fopen(currentFile.c_str(), "rt"); nlohmann::json json = nlohmann::json::parse(file, nullptr, false); @@ -151,6 +160,32 @@ void runFunctions(void) { else missing = true; if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message"); if(!missing) download::installFileList(file, message); + + } else if (type == "mkdir") { + bool missing = false; + std::string directory, message; + if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory"); + else missing = true; + if(!missing) makeDirs(directory.c_str()); + + } else if (type == "rmdir") { + bool missing = false; + std::string directory, message, promptmsg; + if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory"); + else missing = true; + promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory; + if(!missing) { + if (Gui::promptMsg(promptmsg)) { + removeDirRecursive(directory.c_str()); + } + } + + } else if (type == "mkfile") { + bool missing = false; + std::string file; + if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file"); + else missing = true; + if(!missing) createFile(file.c_str()); } } doneMsg(); @@ -201,6 +236,7 @@ void ScriptList::DrawSingleObject(void) const { std::string info; Gui::DrawTop(); Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400); + Gui::DrawStringCentered(0, 214, 0.7f, Config::TxtColor, selectedTitle, 400); Gui::DrawBottom(); for(int i=0;i