From 0a308c43e87c768fc8c578c16031c5aadcb65cd8 Mon Sep 17 00:00:00 2001 From: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com> Date: Tue, 17 Dec 2019 19:22:39 +0100 Subject: [PATCH] A little Script Creator work and little checks. (#9) * No builds allowed here. * Try something. * Next work. * Add some Logging stuff for testing purpose. * Ok, this should log it priperly. * Replace MainMenu with Screen Selection. * Redo Screen Logic. * Switch back to old MainMenu. * Only access Scriptlist, when Scripts are found. Hopefully avoid crashes with that. * Remove unused String, because we use the MainMenu again. --- azure-pipelines.yml | 2 +- include/gui.hpp | 15 +- include/logging.hpp | 48 ++++ include/screens/ftpScreen.hpp | 2 +- include/screens/mainMenu.hpp | 108 ++++----- include/screens/screen.hpp | 37 +++- include/screens/scriptBrowse.hpp | 2 +- include/screens/scriptCreator.hpp | 43 +++- include/screens/scriptlist.hpp | 2 +- include/screens/settings.hpp | 2 +- include/screens/tinyDB.hpp | 2 +- include/utils/config.hpp | 1 + romfs/lang/en/app.json | 4 +- source/download/download.cpp | 32 +-- source/gui.cpp | 32 +-- source/keyboard.cpp | 4 +- source/logging.cpp | 72 ++++++ source/main.cpp | 22 +- source/screens/ftpScreen.cpp | 2 +- source/screens/mainMenu.cpp | 356 ++++++++++++++++-------------- source/screens/screen.cpp | 73 ++++++ source/screens/scriptBrowse.cpp | 22 +- source/screens/scriptCreator.cpp | 305 +++++++++++++++++++++---- source/screens/scriptlist.cpp | 2 +- source/screens/settings.cpp | 2 +- source/screens/tinyDB.cpp | 6 +- source/utils/config.cpp | 10 + 27 files changed, 847 insertions(+), 361 deletions(-) create mode 100644 include/logging.hpp create mode 100644 source/logging.cpp create mode 100644 source/screens/screen.cpp diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6619261..119af5a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,7 +1,7 @@ trigger: branches: include: ['*'] - exclude: [translation] + exclude: [translation, script-creator-experimental] tags: include: ['*'] diff --git a/include/gui.hpp b/include/gui.hpp index 59f9867..804e9c1 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -32,27 +32,14 @@ #include "screens/screen.hpp" -#include <3ds.h> -#include -#include -#include -#include -#include -#include -#include - namespace Gui { // Init and Exit of the GUI. Result init(void); void exit(void); - // Screen and MainLoops. - void mainLoop(u32 hDown, u32 hHeld, touchPosition touch); - void setScreen(std::unique_ptr screen); - void screenBack(void); C3D_RenderTarget* target(gfxScreen_t t); - void ScreenDraw(C3D_RenderTarget * screen); + void setDraw(C3D_RenderTarget * screen); // Clear Text. void clearTextBufs(void); diff --git a/include/logging.hpp b/include/logging.hpp new file mode 100644 index 0000000..f7f1b18 --- /dev/null +++ b/include/logging.hpp @@ -0,0 +1,48 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#ifndef LOGGING_HPP +#define LOGGING_HPP + +#include +#include +#include +#include +#include + +namespace Logging { + // Create the Log File. + void createLogFile(void); + + // Write to the Log. + void writeToLog(std::string debugText); + + // Other needed stuff. ;P + std::string logDate(void); + std::string format(const std::string& fmt_str, ...); +} + +#endif \ No newline at end of file diff --git a/include/screens/ftpScreen.hpp b/include/screens/ftpScreen.hpp index f34a059..4cece6b 100644 --- a/include/screens/ftpScreen.hpp +++ b/include/screens/ftpScreen.hpp @@ -26,7 +26,7 @@ #include "screens/screen.hpp" -class FTPScreen : public Screen +class FTPScreen : public screen { public: void Draw(void) const override; diff --git a/include/screens/mainMenu.hpp b/include/screens/mainMenu.hpp index 789f2f8..3ceb9ba 100644 --- a/include/screens/mainMenu.hpp +++ b/include/screens/mainMenu.hpp @@ -1,54 +1,56 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* Additional Terms 7.b and 7.c of GPLv3 apply to this file: -* * Requiring preservation of specified reasonable legal notices or -* author attributions in that material or in the Appropriate Legal -* Notices displayed by works containing it. -* * Prohibiting misrepresentation of the origin of that material, -* or requiring that modified versions of such material be marked in -* reasonable ways as different from the original version. -*/ - -#ifndef MAINMENU_HPP -#define MAINMENU_HPP - -#include "screens/screen.hpp" - -#include "utils/structs.hpp" - -#include - -class MainMenu : public Screen -{ -public: - void Draw(void) const override; - void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; -private: - int Selection = 0; - - std::vector mainButtons = { - {10, 40, 140, 35, -1}, // Scriptlist. - {170, 40, 140, 35, -1}, // ScriptBrowse. - {10, 100, 140, 35, -1}, // TinyDB. - {170, 100, 140, 35, -1}, // ScriptCreator. - {10, 160, 140, 35, -1}, // Language. - {170, 160, 140, 35, -1}, // Colors. - }; -}; - +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#ifndef MAINMENU_HPP +#define MAINMENU_HPP + +#include "screens/screen.hpp" + +#include "utils/fileBrowse.h" +#include "utils/structs.hpp" + +#include + +class MainMenu : public screen +{ +public: + void Draw(void) const override; + void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; +private: + bool returnScriptState(); + int Selection = 0; + std::vector dirContents; // To return Script state. + std::vector mainButtons = { + {10, 40, 140, 35, -1}, // Scriptlist. + {170, 40, 140, 35, -1}, // ScriptBrowse. + {10, 100, 140, 35, -1}, // TinyDB. + {170, 100, 140, 35, -1}, // ScriptCreator. + {10, 160, 140, 35, -1}, // Language. + {170, 160, 140, 35, -1}, // Colors. + }; +}; + #endif \ No newline at end of file diff --git a/include/screens/screen.hpp b/include/screens/screen.hpp index 4d8023f..e16474d 100644 --- a/include/screens/screen.hpp +++ b/include/screens/screen.hpp @@ -1,16 +1,49 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + #ifndef SCREEN_HPP #define SCREEN_HPP #include <3ds.h> #include -class Screen +class screen { public: - virtual ~Screen() {} + virtual ~screen() {} virtual void Logic(u32 hDown, u32 hHeld, touchPosition touch) = 0; virtual void Draw() const = 0; private: }; +namespace Screen { + void set(std::unique_ptr screen2); + void fade(std::unique_ptr screen2, bool fadeout = true); + void back(void); + void loop(u32 hDown, u32 hHeld, touchPosition touch); +} + #endif \ No newline at end of file diff --git a/include/screens/scriptBrowse.hpp b/include/screens/scriptBrowse.hpp index b14df79..7206282 100644 --- a/include/screens/scriptBrowse.hpp +++ b/include/screens/scriptBrowse.hpp @@ -33,7 +33,7 @@ #include "utils/config.hpp" #include "utils/fileBrowse.h" -class ScriptBrowse : public Screen +class ScriptBrowse : public screen { public: void Draw(void) const override; diff --git a/include/screens/scriptCreator.hpp b/include/screens/scriptCreator.hpp index 3b6e442..479dad1 100644 --- a/include/screens/scriptCreator.hpp +++ b/include/screens/scriptCreator.hpp @@ -35,21 +35,45 @@ #include -class ScriptCreator : public Screen +class ScriptCreator : public screen { public: void Draw(void) const override; void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; - ScriptCreator(); private: + // Screen draws. + void DrawSubMenu(void) const; + void DrawScriptScreen(void) const; + + void SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch); + void scriptLogic(u32 hDown, u32 hHeld, touchPosition touch); + + // Selection + Mode. int Selection = 0; + int mode = 0; + int page = 0; + + // Functions. void openJson(std::string fileName); void createNewJson(std::string fileName); void save(); void setInfoStuff(void); - void createDownloadRelease(); + // Creating Functions. -> Page 1. + void createDownloadRelease(); + void createDownloadFile(); + void createDeleteFile(); + void createExtractFile(); + void createInstallCia(); + void createMkDir(); + + // Creating Functions. -> Page 2. + void createRmDir(); + void createMkFile(); + void createTimeMsg(); + + // void setBool(const std::string &object, const std::string &key, bool v); void setBool2(const std::string &object, const std::string &key, const std::string &key2, bool v); @@ -61,10 +85,23 @@ private: void createEntry(const std::string &Entryname); + std::string jsonFileName; + // Main Pos. std::vector mainButtons = { {90, 40, 140, 35, -1}, // New Script. {90, 100, 140, 35, -1}, // Existing Script. }; + + // Creator Button Pos. + std::vector creatorButtons = { + {10, 40, 140, 35, -1}, + {170, 40, 140, 35, -1}, + {10, 100, 140, 35, -1}, + {170, 100, 140, 35, -1}, + {10, 160, 140, 35, -1}, + {170, 160, 140, 35, -1}, + }; + }; #endif \ No newline at end of file diff --git a/include/screens/scriptlist.hpp b/include/screens/scriptlist.hpp index 2cca130..4914444 100644 --- a/include/screens/scriptlist.hpp +++ b/include/screens/scriptlist.hpp @@ -32,7 +32,7 @@ #include "utils/fileBrowse.h" -class ScriptList : public Screen +class ScriptList : public screen { public: void Draw(void) const override; diff --git a/include/screens/settings.hpp b/include/screens/settings.hpp index 13c9965..7a766e4 100644 --- a/include/screens/settings.hpp +++ b/include/screens/settings.hpp @@ -34,7 +34,7 @@ #include -class Settings : public Screen +class Settings : public screen { public: void Draw(void) const override; diff --git a/include/screens/tinyDB.hpp b/include/screens/tinyDB.hpp index 48327d8..d79660a 100644 --- a/include/screens/tinyDB.hpp +++ b/include/screens/tinyDB.hpp @@ -30,7 +30,7 @@ #include "screens/screen.hpp" #include "screens/screenCommon.hpp" -class TinyDB : public Screen +class TinyDB : public screen { public: void Draw(void) const override; diff --git a/include/utils/config.hpp b/include/utils/config.hpp index add7431..65ba280 100644 --- a/include/utils/config.hpp +++ b/include/utils/config.hpp @@ -32,6 +32,7 @@ namespace Config { extern int lang, Color1, Color2, Color3, TxtColor, SelectedColor, UnselectedColor, viewMode, ColorKeys, progressbarColor; extern std::string ScriptPath, MusicPath; + extern bool Logging; void load(); void save(); diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index c7b270e..7d8332f 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -75,5 +75,7 @@ "DESC": "Desc: ", "RELEASE_ID": "Release ID: ", "TITLE_ID": "Title ID: ", - "FILE_SIZE": "File size: " + "FILE_SIZE": "File size: ", + + "GET_SCRIPTS_FIRST": "Get some Scripts first!" } diff --git a/source/download/download.cpp b/source/download/download.cpp index 48e6002..d0b0f80 100644 --- a/source/download/download.cpp +++ b/source/download/download.cpp @@ -119,13 +119,13 @@ curl_off_t downloadTotal = 1; //Dont initialize with 0 to avoid division by zero curl_off_t downloadNow = 0; static int curlProgress(CURL *hnd, - curl_off_t dltotal, curl_off_t dlnow, - curl_off_t ultotal, curl_off_t ulnow) + curl_off_t dltotal, curl_off_t dlnow, + curl_off_t ultotal, curl_off_t ulnow) { - downloadTotal = dltotal; - downloadNow = dlnow; - - return 0; + downloadTotal = dltotal; + downloadNow = dlnow; + + return 0; } static Result setupContext(CURL *hnd, const char * url) @@ -673,21 +673,21 @@ void displayProgressBar() { } Gui::clearTextBufs(); - C3D_FrameBegin(C3D_FRAME_SYNCDRAW); - C2D_TargetClear(top, BLACK); - C2D_TargetClear(bottom, BLACK); - Gui::DrawTop(); - Gui::DrawStringCentered(0, 1, 0.7f, Config::TxtColor, progressBarMsg, 400); + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + C2D_TargetClear(top, BLACK); + C2D_TargetClear(bottom, BLACK); + Gui::DrawTop(); + Gui::DrawStringCentered(0, 1, 0.7f, Config::TxtColor, progressBarMsg, 400); - Gui::DrawStringCentered(0, 80, 0.6f, Config::TxtColor, str, 400); - Gui::Draw_Rect(30, 120, 340, 30, BLACK); + Gui::DrawStringCentered(0, 80, 0.6f, Config::TxtColor, str, 400); + Gui::Draw_Rect(30, 120, 340, 30, BLACK); if (isScriptSelected == true) { - Gui::Draw_Rect(31, 121, (int)(((float)downloadNow/(float)downloadTotal) * 338.0f), 28, progressBar); + Gui::Draw_Rect(31, 121, (int)(((float)downloadNow/(float)downloadTotal) * 338.0f), 28, progressBar); } else { Gui::Draw_Rect(31, 121, (int)(((float)downloadNow/(float)downloadTotal) * 338.0f), 28, Config::progressbarColor); } - Gui::DrawBottom(); - C3D_FrameEnd(0); + Gui::DrawBottom(); + C3D_FrameEnd(0); gspWaitForVBlank(); } } \ No newline at end of file diff --git a/source/gui.cpp b/source/gui.cpp index 675bba0..4d8af4e 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -30,18 +30,10 @@ #include "utils/config.hpp" -#include <3ds.h> -#include -#include -#include -#include -#include - C3D_RenderTarget* top; C3D_RenderTarget* bottom; C2D_TextBuf sizeBuf; -std::stack> screens; C2D_SpriteSheet sprites; bool currentScreen = false; extern bool isScriptSelected; @@ -162,33 +154,15 @@ bool Gui::Draw_Rect(float x, float y, float w, float h, u32 color) { return C2D_DrawRectSolid(x, y, 0.5f, w, h, color); } -// Mainloop the GUI. -void Gui::mainLoop(u32 hDown, u32 hHeld, touchPosition touch) { - screens.top()->Draw(); - screens.top()->Logic(hDown, hHeld, touch); -} - -// Set the current Screen. -void Gui::setScreen(std::unique_ptr screen) -{ - screens.push(std::move(screen)); -} - -// Go a Screen back. -void Gui::screenBack() -{ - screens.pop(); -} - // Select, on which Screen should be drawn. -void Gui::ScreenDraw(C3D_RenderTarget * screen) +void Gui::setDraw(C3D_RenderTarget * screen) { C2D_SceneBegin(screen); currentScreen = screen == top ? 1 : 0; } void Gui::DrawTop(void) { - Gui::ScreenDraw(top); + Gui::setDraw(top); if (isScriptSelected == false) { Gui::Draw_Rect(0, 0, 400, 25, Config::Color1); Gui::Draw_Rect(0, 25, 400, 190, Config::Color2); @@ -205,7 +179,7 @@ void Gui::DrawTop(void) { } void Gui::DrawBottom(void) { - Gui::ScreenDraw(bottom); + Gui::setDraw(bottom); if (isScriptSelected == false) { Gui::Draw_Rect(0, 0, 320, 25, Config::Color1); Gui::Draw_Rect(0, 25, 320, 190, Config::Color3); diff --git a/source/keyboard.cpp b/source/keyboard.cpp index 6e47583..0f32e0e 100644 --- a/source/keyboard.cpp +++ b/source/keyboard.cpp @@ -121,10 +121,10 @@ std::string Input::Numpad(uint maxLength, std::string Text) C2D_TargetClear(top, BLACK); C2D_TargetClear(bottom, BLACK); Gui::DrawTop(); - Gui::DrawString((400-Gui::GetStringWidth(0.8f, Text))/2, 2, 0.8f, WHITE, Text, 400); + Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, WHITE, Text, 400); Gui::DrawString(180, 212, 0.8, WHITE, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 400); if(cursorBlink < -20) cursorBlink = 20; - Gui::ScreenDraw(bottom); + Gui::setDraw(bottom); Gui::Draw_Rect(0, 0, 320, 240, Config::Color3); DrawNumpad(); scanKeys(); diff --git a/source/logging.cpp b/source/logging.cpp new file mode 100644 index 0000000..e39d874 --- /dev/null +++ b/source/logging.cpp @@ -0,0 +1,72 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include "logging.hpp" + +#include "utils/config.hpp" + +#include + +std::string Logging::format(const std::string& fmt_str, ...) +{ + va_list ap; + char* fp = NULL; + va_start(ap, fmt_str); + vasprintf(&fp, fmt_str.c_str(), ap); + va_end(ap); + std::unique_ptr formatted(fp, free); + return std::string(formatted.get()); +} + +std::string Logging::logDate(void) +{ + time_t unixTime; + struct tm timeStruct; + time(&unixTime); + localtime_r(&unixTime, &timeStruct); + return format("%04i-%02i-%02i %02i:%02i:%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1, timeStruct.tm_mday, timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec); +} + +void Logging::createLogFile(void) { + if((access("sdmc:/3ds/Universal-Updater/Log.log", F_OK) != 0)) { + FILE* logFile = fopen(("sdmc:/3ds/Universal-Updater/Log.log"), "w"); + fclose(logFile); + } +} + +// Only write to the Log, if it is enabled in the Settings File! +void Logging::writeToLog(std::string debugText) { + if (Config::getBool("LOGGING") == true) { + std::ofstream logFile; + logFile.open(("sdmc:/3ds/Universal-Updater/Log.log"), std::ofstream::app); + std::string writeDebug = "[ "; + writeDebug += logDate(); + writeDebug += " ] "; + writeDebug += debugText.c_str(); + logFile << writeDebug << std::endl; + logFile.close(); + } +} \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 6972561..94eb92a 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -25,6 +25,7 @@ */ #include "gui.hpp" +#include "logging.hpp" #include "lang/lang.hpp" @@ -45,9 +46,6 @@ touchPosition touch; sound *bgm = NULL; bool songIsFound = false; -int fadealpha = 255; -bool fadein = true; - // If button Position pressed -> Do something. bool touching(touchPosition touch, Structs::ButtonPos button) { if (touch.px >= button.x && touch.px <= (button.x + button.w) && touch.py >= button.y && touch.py <= (button.y + button.h)) @@ -97,7 +95,12 @@ int main() } Config::load(); Lang::load(Config::lang); - Gui::setScreen(std::make_unique()); + + if (Config::Logging == true) { + Logging::createLogFile(); + } + + Screen::set(std::make_unique()); osSetSpeedupEnable(true); // Enable speed-up for New 3DS users if( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 ) { @@ -107,7 +110,6 @@ int main() playMusic(); } - // Loop as long as the status is not exit while (aptMainLoop() && !exiting) { @@ -119,17 +121,9 @@ int main() C2D_TargetClear(top, BLACK); C2D_TargetClear(bottom, BLACK); Gui::clearTextBufs(); - Gui::mainLoop(hDown, hHeld, touch); + Screen::loop(hDown, hHeld, touch); C3D_FrameEnd(0); gspWaitForVBlank(); - - if (fadein == true) { - fadealpha -= 3; - if (fadealpha < 0) { - fadealpha = 0; - fadein = false; - } - } } if (songIsFound == true) { diff --git a/source/screens/ftpScreen.cpp b/source/screens/ftpScreen.cpp index e693340..82f4868 100644 --- a/source/screens/ftpScreen.cpp +++ b/source/screens/ftpScreen.cpp @@ -86,7 +86,7 @@ void FTPScreen::Draw(void) const memset(ftp_file_transfer, 0, 50); // Empty transfer status. ftp_exit(); - Gui::screenBack(); + Screen::back(); return; } diff --git a/source/screens/mainMenu.cpp b/source/screens/mainMenu.cpp index 37de25e..3010b67 100644 --- a/source/screens/mainMenu.cpp +++ b/source/screens/mainMenu.cpp @@ -1,167 +1,191 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* Additional Terms 7.b and 7.c of GPLv3 apply to this file: -* * Requiring preservation of specified reasonable legal notices or -* author attributions in that material or in the Appropriate Legal -* Notices displayed by works containing it. -* * Prohibiting misrepresentation of the origin of that material, -* or requiring that modified versions of such material be marked in -* reasonable ways as different from the original version. -*/ - -#include "download/download.hpp" - -#include "screens/ftpScreen.hpp" -#include "screens/mainMenu.hpp" -#include "screens/scriptBrowse.hpp" -#include "screens/scriptCreator.hpp" -#include "screens/scriptlist.hpp" -#include "screens/settings.hpp" -#include "screens/tinyDB.hpp" - -#include "utils/config.hpp" - -extern bool exiting; -extern bool touching(touchPosition touch, Structs::ButtonPos button); -extern bool checkWifiStatus(void); -extern int fadealpha; -extern bool fadein; -extern void notImplemented(void); - -// This is for the Script Creator, so no one can access it for now, until it is stable or so. -bool isTesting = false; - -void MainMenu::Draw(void) const { - Gui::DrawTop(); - Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400); - 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(); - - for (int i = 0; i < 6; i++) { - if (Selection == i) { - Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::SelectedColor); - } else { - Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::UnselectedColor); - } - } - - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTLIST")))/2-150+70, mainButtons[0].y+10, 0.6f, Config::TxtColor, Lang::get("SCRIPTLIST"), 140); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("GET_SCRIPTS")))/2+150-70, mainButtons[1].y+10, 0.6f, Config::TxtColor, Lang::get("GET_SCRIPTS"), 140); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, "TinyDB"))/2-150+70, mainButtons[2].y+10, 0.6f, Config::TxtColor, "TinyDB", 140); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTCREATOR")))/2+150-70, mainButtons[3].y+10, 0.6f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 140); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SETTINGS")))/2-150+70, mainButtons[4].y+10, 0.6f, Config::TxtColor, Lang::get("SETTINGS"), 140); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, "FTP"))/2+150-70, mainButtons[5].y+10, 0.6f, Config::TxtColor, "FTP", 140); - if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, fadealpha)); // Fade in out effect -} - - -void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { - if (hDown & KEY_START) { - exiting = true; - } - if (hDown & KEY_UP) { - if(Selection > 1) Selection -= 2; - } - if (hDown & KEY_DOWN) { - if(Selection < 4) Selection += 2; - } - if (hDown & KEY_LEFT) { - if (Selection%2) Selection--; - } - if (hDown & KEY_RIGHT) { - if (!(Selection%2)) Selection++; - } - - if (hDown & KEY_A) { - switch(Selection) { - case 0: - Gui::setScreen(std::make_unique()); - break; - case 1: - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } else { - notConnectedMsg(); - } - break; - case 2: - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } else { - notConnectedMsg(); - } - break; - case 3: - if (isTesting == true) { - Gui::setScreen(std::make_unique()); - } else { - notImplemented(); - } - break; - case 4: - Gui::setScreen(std::make_unique()); - break; - case 5: - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } else { - notConnectedMsg(); - } - break; - } - } - - if (hDown & KEY_X) { - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } - } - - if (hDown & KEY_TOUCH) { - if (touching(touch, mainButtons[0])) { - Gui::setScreen(std::make_unique()); - } else if (touching(touch, mainButtons[1])) { - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } else { - notConnectedMsg(); - } - } else if (touching(touch, mainButtons[2])) { - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } else { - notConnectedMsg(); - } - } else if (touching(touch, mainButtons[3])) { - if (isTesting == true) { - Gui::setScreen(std::make_unique()); - } else { - notImplemented(); - } - } else if (touching(touch, mainButtons[4])) { - Gui::setScreen(std::make_unique()); - } else if (touching(touch, mainButtons[5])) { - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } else { - notConnectedMsg(); - } - } - } +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include "download/download.hpp" + +#include "screens/ftpScreen.hpp" +#include "screens/mainMenu.hpp" +#include "screens/scriptBrowse.hpp" +#include "screens/scriptCreator.hpp" +#include "screens/scriptlist.hpp" +#include "screens/settings.hpp" +#include "screens/tinyDB.hpp" + +#include "utils/config.hpp" + +#include + +extern bool exiting; +extern bool touching(touchPosition touch, Structs::ButtonPos button); +extern bool checkWifiStatus(void); +extern int fadealpha; +extern bool fadein; +extern void notImplemented(void); + +// This is for the Script Creator, so no one can access it for now, until it is stable or so. +bool isTesting = false; + +void MainMenu::Draw(void) const { + Gui::DrawTop(); + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400); + 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(); + + for (int i = 0; i < 6; i++) { + if (Selection == i) { + Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::SelectedColor); + } else { + Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::UnselectedColor); + } + } + + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTLIST")))/2-150+70, mainButtons[0].y+10, 0.6f, Config::TxtColor, Lang::get("SCRIPTLIST"), 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("GET_SCRIPTS")))/2+150-70, mainButtons[1].y+10, 0.6f, Config::TxtColor, Lang::get("GET_SCRIPTS"), 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "TinyDB"))/2-150+70, mainButtons[2].y+10, 0.6f, Config::TxtColor, "TinyDB", 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTCREATOR")))/2+150-70, mainButtons[3].y+10, 0.6f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SETTINGS")))/2-150+70, mainButtons[4].y+10, 0.6f, Config::TxtColor, Lang::get("SETTINGS"), 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "FTP"))/2+150-70, mainButtons[5].y+10, 0.6f, Config::TxtColor, "FTP", 140); + if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, fadealpha)); // Fade in out effect +} + +bool MainMenu::returnScriptState() { + dirContents.clear(); + chdir(Config::ScriptPath.c_str()); + std::vector dirContentsTemp; + getDirectoryContents(dirContentsTemp, {"json"}); + for(uint i=0;i 1) Selection -= 2; + } + if (hDown & KEY_DOWN) { + if(Selection < 4) Selection += 2; + } + if (hDown & KEY_LEFT) { + if (Selection%2) Selection--; + } + if (hDown & KEY_RIGHT) { + if (!(Selection%2)) Selection++; + } + + if (hDown & KEY_A) { + switch(Selection) { + case 0: + if (returnScriptState() == true) { + Screen::set(std::make_unique()); + } else { + Gui::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST")); + } + break; + case 1: + if (checkWifiStatus() == true) { + Screen::set(std::make_unique()); + } else { + notConnectedMsg(); + } + break; + case 2: + if (checkWifiStatus() == true) { + Screen::set(std::make_unique()); + } else { + notConnectedMsg(); + } + break; + case 3: + if (isTesting == true) { + Screen::set(std::make_unique()); + } else { + notImplemented(); + } + break; + case 4: + Screen::set(std::make_unique()); + break; + case 5: + if (checkWifiStatus() == true) { + Screen::set(std::make_unique()); + } else { + notConnectedMsg(); + } + break; + } + } + + if (hDown & KEY_X) { + if (checkWifiStatus() == true) { + Screen::set(std::make_unique()); + } + } + + if (hDown & KEY_TOUCH) { + if (touching(touch, mainButtons[0])) { + if (returnScriptState() == true) { + Screen::set(std::make_unique()); + } else { + Gui::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST")); + } + } else if (touching(touch, mainButtons[1])) { + if (checkWifiStatus() == true) { + Screen::set(std::make_unique()); + } else { + notConnectedMsg(); + } + } else if (touching(touch, mainButtons[2])) { + if (checkWifiStatus() == true) { + Screen::set(std::make_unique()); + } else { + notConnectedMsg(); + } + } else if (touching(touch, mainButtons[3])) { + if (isTesting == true) { + Screen::set(std::make_unique()); + } else { + notImplemented(); + } + } else if (touching(touch, mainButtons[4])) { + Screen::set(std::make_unique()); + } else if (touching(touch, mainButtons[5])) { + if (checkWifiStatus() == true) { + Screen::set(std::make_unique()); + } else { + notConnectedMsg(); + } + } + } } \ No newline at end of file diff --git a/source/screens/screen.cpp b/source/screens/screen.cpp new file mode 100644 index 0000000..59d4542 --- /dev/null +++ b/source/screens/screen.cpp @@ -0,0 +1,73 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include "screens/screen.hpp" + +#include + +// Fade stuff. +int fadealpha = 255; +bool fadein = true; + +std::stack> screens; + +// Set a specific Screen. +void Screen::set(std::unique_ptr screen2) +{ + screens.push(std::move(screen2)); +} + +// Fade into another Screen, but first do a fadeout. +void Screen::fade(std::unique_ptr screen2, bool fadeout) { + if (fadeout) { + fadealpha += 6; + if (fadealpha > 255) { + fadealpha = 255; + screens.push(std::move(screen2)); + fadein = true; + fadeout = false; + } + } +} + +// Go a Screen back. +void Screen::back() +{ + screens.pop(); +} + +// For the Mainloop. +void Screen::loop(u32 hDown, u32 hHeld, touchPosition touch) { + screens.top()->Draw(); + screens.top()->Logic(hDown, hHeld, touch); + if (fadein == true) { + fadealpha -= 6; + if (fadealpha < 0) { + fadealpha = 0; + fadein = false; + } + } +} \ No newline at end of file diff --git a/source/screens/scriptBrowse.cpp b/source/screens/scriptBrowse.cpp index 95496cc..debbcfc 100644 --- a/source/screens/scriptBrowse.cpp +++ b/source/screens/scriptBrowse.cpp @@ -43,14 +43,14 @@ nlohmann::json infoJson; std::string maxScripts; void fixInfo(nlohmann::json &json) { - for(uint i=0;i +#include // The to editing script. nlohmann::json editScript; @@ -68,6 +70,14 @@ void ScriptCreator::setString2(const std::string &object, const std::string &key } void ScriptCreator::Draw(void) const { + if (mode == 0) { + DrawSubMenu(); + } else if (mode == 1) { + DrawScriptScreen(); + } +} + +void ScriptCreator::DrawSubMenu(void) const { Gui::DrawTop(); Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 400); Gui::DrawBottom(); @@ -84,7 +94,47 @@ void ScriptCreator::Draw(void) const { Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("EXISTING_SCRIPT")))/2, mainButtons[1].y+10, 0.6f, Config::TxtColor, Lang::get("EXISTING_SCRIPT"), 140); } -std::string jsonFileName; +void ScriptCreator::DrawScriptScreen(void) const { + Gui::DrawTop(); + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 400); + Gui::DrawBottom(); + + // Draw Page. + for (int i = 0; i < 2; i++) { + if (i == page) { + Gui::DrawString(260, 3, 0.6f, Config::TxtColor, std::to_string(i+1) + " / 2", 140); + } + } + + if (page == 0) { + for (int i = 0; i < 6; i++) { + if (Selection == i) { + Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, Config::SelectedColor); + } else { + Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, Config::UnselectedColor); + } + } + + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "downloadRelease"))/2-150+70, creatorButtons[0].y+10, 0.6f, Config::TxtColor, "downloadRelease", 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "downloadFile"))/2+150-70, creatorButtons[1].y+10, 0.6f, Config::TxtColor, "downloadFile", 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "deleteFile"))/2-150+70, creatorButtons[2].y+10, 0.6f, Config::TxtColor, "deleteFile", 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "extractFile"))/2+150-70, creatorButtons[3].y+10, 0.6f, Config::TxtColor, "extractFile", 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "installCia"))/2-150+70, creatorButtons[4].y+10, 0.6f, Config::TxtColor, "installCia", 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "mkdir"))/2+150-70, creatorButtons[5].y+10, 0.6f, Config::TxtColor, "mkdir", 140); + } else if (page == 1) { + for (int i = 0; i < 3; i++) { + if (Selection == i) { + Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, Config::SelectedColor); + } else { + Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, Config::UnselectedColor); + } + } + + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "rmdir"))/2-150+70, creatorButtons[0].y+10, 0.6f, Config::TxtColor, "rmdir", 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "mkfile"))/2+150-70, creatorButtons[1].y+10, 0.6f, Config::TxtColor, "mkfile", 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "TimeMsg"))/2-150+70, creatorButtons[2].y+10, 0.6f, Config::TxtColor, "TimeMsg", 140); + } +} void ScriptCreator::createNewJson(std::string fileName) { std::ofstream ofstream; @@ -94,6 +144,8 @@ void ScriptCreator::createNewJson(std::string fileName) { // Test. void ScriptCreator::createDownloadRelease() { + // Entry name. + std::string entryname = Input::getString(50, "Enter the name of the Entry."); // Repo. std::string repo = Input::getString(50, "Enter the name of the Owner."); repo += "/"; @@ -107,62 +159,121 @@ void ScriptCreator::createDownloadRelease() { // Message. std::string message = Input::getString(50, "Enter the Message."); - editScript["Test"] = { {{"type", "downloadRelease"}, {"repo", repo}, {"file", file}, {"output", output}, {"includePrerelease", prerelease}, {"message", message}} }; + editScript[entryname] = { {{"type", "downloadRelease"}, {"repo", repo}, {"file", file}, {"output", output}, {"includePrerelease", prerelease}, {"message", message}} }; + Logging::writeToLog("Execute 'ScriptCreator::createDownloadRelease();'."); } // To-Do. -/* -void ScriptCreator::createDownloadFile(const std::string &Entryname, const std::string &file, const std::string output, const std::string &message) { - editScript[Entryname] = { {{"type", "downloadFile"}, {"file", file}, {"output", output}, {"message", message}} }; + +void ScriptCreator::createDownloadFile() { + // Entry name. + std::string entryname = Input::getString(50, "Enter the name of the Entry."); + // URL of the file. + std::string file = Input::getString(50, "Enter the URL of the file."); + // Output. + std::string output = Input::getString(50, "Enter the name of the Output path."); + // Message. + std::string message = Input::getString(50, "Enter the Message."); + + editScript[entryname] = { {{"type", "downloadFile"}, {"file", file}, {"output", output}, {"message", message}} }; + Logging::writeToLog("Execute 'ScriptCreator::createDownloadFile();'."); } -void ScriptCreator::createDeleteFile(const std::string &Entryname, const std::string &file, const std::string &message) { - editScript[Entryname] = { {{"type", "deleteFile"}, {"file", file}, {"message", message}} }; + +void ScriptCreator::createDeleteFile() { + // Entry name. + std::string entryname = Input::getString(50, "Enter the name of the Entry."); + // URL of the file. + std::string file = Input::getString(50, "Enter the path to the file."); + // Message. + std::string message = Input::getString(50, "Enter the Message."); + + editScript[entryname] = { {{"type", "deleteFile"}, {"file", file}, {"message", message}} }; + Logging::writeToLog("Execute 'ScriptCreator::createDeleteFile();'."); } -void ScriptCreator::createExtractFile(const std::string &Entryname, const std::string &file, const std::string &input, const std::string &output, const std::string &message) { - editScript[Entryname] = { {{"type", "extractFile"}, {"file", file}, {"input", input}, {"output", output}, {"message", message}} }; + +void ScriptCreator::createExtractFile() { + // Entry name. + std::string entryname = Input::getString(50, "Enter the name of the Entry."); + // File path. + std::string file = Input::getString(50, "Enter the path to the file."); + // Input of the archive. + std::string input = Input::getString(50, "Enter the Input of what should be extracted."); + // Output path. + std::string output = Input::getString(50, "Enter the output path."); + // Message. + std::string message = Input::getString(50, "Enter the Message."); + + editScript[entryname] = { {{"type", "extractFile"}, {"file", file}, {"input", input}, {"output", output}, {"message", message}} }; + Logging::writeToLog("Execute 'ScriptCreator::createExtractFile();'."); } -void ScriptCreator::createInstallCia(const std::string &Entryname, const std::string &file, const std::string &message) { - editScript[Entryname] = { {{"type", "installCia"}, {"file", file}, {"message", message}} }; + +void ScriptCreator::createInstallCia() { + // Entry name. + std::string entryname = Input::getString(50, "Enter the name of the Entry."); + // File path. + std::string file = Input::getString(50, "Enter the path to the CIA File."); + // Message. + std::string message = Input::getString(50, "Enter the Message."); + + editScript[entryname] = { {{"type", "installCia"}, {"file", file}, {"message", message}} }; + Logging::writeToLog("Execute 'ScriptCreator::createInstallCia();'."); } -void ScriptCreator::createMkDir(const std::string &Entryname, const std::string &directory) { - editScript[Entryname] = { {{"type", "mkdir"}, {"directory", directory}} }; + +void ScriptCreator::createMkDir() { + // Entry name. + std::string entryname = Input::getString(50, "Enter the name of the Entry."); + // Directory path. + std::string directory = Input::getString(50, "Enter the directory path."); + + editScript[entryname] = { {{"type", "mkdir"}, {"directory", directory}} }; + Logging::writeToLog("Execute 'ScriptCreator::createMkDir();'."); } -void ScriptCreator::createRmDir(const std::string &Entryname, const std::string &directory) { - editScript[Entryname] = { {{"type", "rmdir"}, {"directory", directory}} }; +void ScriptCreator::createRmDir() { + // Entry name. + std::string entryname = Input::getString(50, "Enter the name of the Entry."); + // Directory path. + std::string directory = Input::getString(50, "Enter the directory path."); + + editScript[entryname] = { {{"type", "rmdir"}, {"directory", directory}} }; + Logging::writeToLog("Execute 'ScriptCreator::createRmDir();'."); } -void ScriptCreator::createMkFile(const std::string &Entryname, const std::string &file) { - editScript[Entryname] = { {{"type", "mkfile"}, {"file", file}} }; +void ScriptCreator::createMkFile() { + // Entry name. + std::string entryname = Input::getString(50, "Enter the name of the Entry."); + // File path. + std::string file = Input::getString(50, "Enter the path to the new File."); + + editScript[entryname] = { {{"type", "mkfile"}, {"file", file}} }; + Logging::writeToLog("Execute 'ScriptCreator::createMkFile();'."); } -void ScriptCreator::createTimeMsg(const std::string &Entryname, const std::string &message, int seconds) { - editScript[Entryname] = { {{"type", "rmdir"}, {"message", message}, {"seconds", seconds}} }; -} -*/ +void ScriptCreator::createTimeMsg() { + // Entry name. + std::string entryname = Input::getString(50, "Enter the name of the Entry."); + // Message. + std::string message = Input::getString(50, "Enter the Message."); + // Seconds. + int seconds = Input::getUint(999, "Enter the Seconds for the Message to display."); -// Testing purpose for now. -ScriptCreator::ScriptCreator() { - jsonFileName = Config::ScriptPath; - jsonFileName += Input::getString(20, "Enter the name of the JSON file."); - if (jsonFileName != "") { - jsonFileName += ".json"; - createNewJson(jsonFileName); - openJson(jsonFileName); - } + editScript[entryname] = { {{"type", "timeMsg"}, {"message", message}, {"seconds", seconds}} }; + Logging::writeToLog("Execute 'ScriptCreator::createTimeMsg();'."); } + void ScriptCreator::save() { FILE* file = fopen(jsonFileName.c_str(), "w"); if(file) fwrite(editScript.dump(1, '\t').c_str(), 1, editScript.dump(1, '\t').size(), file); fclose(file); + Logging::writeToLog("Execute 'ScriptCreator::save();'."); } -// Importaant to make Scripts valid. +// Important to make Scripts valid. void ScriptCreator::setInfoStuff(void) { // Get needed things. const std::string &test = Input::getString(50, "Enter the Title of the script."); @@ -180,14 +291,38 @@ void ScriptCreator::setInfoStuff(void) { } - -void ScriptCreator::Logic(u32 hDown, u32 hHeld, touchPosition touch) { +void ScriptCreator::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { if (hDown & KEY_B) { - save(); - Gui::screenBack(); + Screen::back(); return; } + if (hDown & KEY_A) { + switch(Selection) { + case 0: + jsonFileName = Config::ScriptPath; + jsonFileName += Input::getString(20, "Enter the name of the JSON file."); + if (jsonFileName != "") { + jsonFileName += ".json"; + createNewJson(jsonFileName); + openJson(jsonFileName); + Selection = 0; + mode = 1; + } + break; + case 1: + jsonFileName = Config::ScriptPath; + jsonFileName += Input::getString(20, "Enter the name of the JSON file."); + if(access(jsonFileName.c_str(), F_OK) != -1 ) { + openJson(jsonFileName); + Selection = 0; + mode = 1; + } + break; + } + } + + if (hDown & KEY_UP) { if(Selection == 1) Selection = 0; } @@ -195,12 +330,106 @@ void ScriptCreator::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if (hDown & KEY_DOWN) { if(Selection == 0) Selection = 1; } +} - if (hDown & KEY_Y) { - setInfoStuff(); +void ScriptCreator::scriptLogic(u32 hDown, u32 hHeld, touchPosition touch) { + if (hDown & KEY_B) { + save(); + Selection = 0; + mode = 0; + } + + // Page 1. + if (page == 0) { + if (hDown & KEY_UP) { + if(Selection > 1) Selection -= 2; + } + if (hDown & KEY_DOWN) { + if(Selection < 4) Selection += 2; + } + if (hDown & KEY_LEFT) { + if (Selection%2) Selection--; + } + if (hDown & KEY_RIGHT) { + if (!(Selection%2)) Selection++; + } + } else if (page == 1) { + if (hDown & KEY_UP) { + if (Selection == 2) Selection = 0; + } + if (hDown & KEY_RIGHT) { + if (Selection == 0) Selection = 1; + } + if (hDown & KEY_LEFT) { + if (Selection == 1) Selection = 0; + } + if (hDown & KEY_DOWN) { + if (Selection == 0) Selection = 2; + } + } + + // Page 2. + + if (hDown & KEY_R) { + if (page == 0) { + page = 1; + Selection = 0; + } + } + + if (hDown & KEY_L) { + if (page == 1) { + page = 0; + Selection = 0; + } + } + + if (hDown & KEY_A) { + if (page == 0) { + switch(Selection) { + case 0: + createDownloadRelease(); + break; + case 1: + createDownloadFile(); + break; + case 2: + createDeleteFile(); + break; + case 3: + createExtractFile(); + break; + case 4: + createInstallCia(); + break; + case 5: + createMkDir(); + break; + } + } else if (page == 1) { + switch(Selection) { + case 0: + createRmDir(); + break; + case 1: + createMkFile(); + break; + case 2: + createTimeMsg(); + break; + } + } } if (hDown & KEY_X) { - createDownloadRelease(); + setInfoStuff(); + } +} + +void ScriptCreator::Logic(u32 hDown, u32 hHeld, touchPosition touch) { + if (mode == 0) { + SubMenuLogic(hDown, hHeld, touch); + } else if (mode == 1) { + scriptLogic(hDown, hHeld, touch); } } \ No newline at end of file diff --git a/source/screens/scriptlist.cpp b/source/screens/scriptlist.cpp index b8c0240..0769107 100644 --- a/source/screens/scriptlist.cpp +++ b/source/screens/scriptlist.cpp @@ -365,7 +365,7 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld) { if (hDown & KEY_B) { fileInfo.clear(); - Gui::screenBack(); + Screen::back(); return; } diff --git a/source/screens/settings.cpp b/source/screens/settings.cpp index 3877847..224acd1 100644 --- a/source/screens/settings.cpp +++ b/source/screens/settings.cpp @@ -232,7 +232,7 @@ void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_B) { - Gui::screenBack(); + Screen::back(); return; } } diff --git a/source/screens/tinyDB.cpp b/source/screens/tinyDB.cpp index b9ccefb..3cd05bf 100644 --- a/source/screens/tinyDB.cpp +++ b/source/screens/tinyDB.cpp @@ -80,7 +80,7 @@ TinyDB::TinyDB() { // To-Do. void TinyDB::Draw(void) const { std::string info; - Gui::ScreenDraw(top); + Gui::setDraw(top); Gui::Draw_Rect(0, 0, 400, 25, C2D_Color32(63, 81, 181, 255)); Gui::Draw_Rect(0, 25, 400, 190, C2D_Color32(140, 140, 140, 255)); Gui::Draw_Rect(0, 215, 400, 25, C2D_Color32(63, 81, 181, 255)); @@ -98,7 +98,7 @@ void TinyDB::Draw(void) const { Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), 237-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, Config::TxtColor, entryAmount); - Gui::ScreenDraw(bottom); + Gui::setDraw(bottom); Gui::Draw_Rect(0, 0, 320, 25, C2D_Color32(63, 81, 181, 255)); Gui::Draw_Rect(0, 25, 320, 190, C2D_Color32(140, 140, 140, 255)); Gui::Draw_Rect(0, 215, 320, 25, C2D_Color32(63, 81, 181, 255)); @@ -133,7 +133,7 @@ void TinyDB::Draw(void) const { void TinyDB::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if (keyRepeatDelay) keyRepeatDelay--; if (hDown & KEY_B) { - Gui::screenBack(); + Screen::back(); return; } diff --git a/source/utils/config.cpp b/source/utils/config.cpp index cd0e9fa..303be65 100644 --- a/source/utils/config.cpp +++ b/source/utils/config.cpp @@ -45,6 +45,7 @@ int Config::ColorKeys; int Config::progressbarColor; std::string Config::ScriptPath; std::string Config::MusicPath; +bool Config::Logging; nlohmann::json configJson; void Config::load() { @@ -124,6 +125,12 @@ void Config::load() { Config::MusicPath = getString("MUSICPATH"); } + if(!configJson.contains("LOGGING")) { + Config::Logging = false; + } else { + Config::Logging = getBool("LOGGING"); + } + fclose(file); } else { Config::Color1 = BarColor; @@ -138,6 +145,7 @@ void Config::load() { Config::ColorKeys = C2D_Color32(0, 0, 200, 255); Config::progressbarColor = WHITE; Config::MusicPath = MUSIC_PATH; + Config::Logging = false; } } @@ -154,6 +162,7 @@ void Config::save() { Config::setInt("COLORKEYS", Config::ColorKeys); Config::setInt("PROGRESSBARCOLOR", Config::progressbarColor); Config::setString("MUSICPATH", Config::MusicPath); + Config::setBool("LOGGING", Config::Logging); FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w"); if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file); fclose(file); @@ -174,6 +183,7 @@ void Config::initializeNewConfig() { Config::setInt("COLORKEYS", C2D_Color32(0, 0, 200, 255)); Config::setInt("PROGRESSBARCOLOR", WHITE); Config::setString("MUSICPATH", MUSIC_PATH); + Config::setBool("LOGGING", false); if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file); fclose(file);