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.
This commit is contained in:
StackZ
2019-12-17 19:22:39 +01:00
committed by GitHub
parent 5d80ec6111
commit 0a308c43e8
27 changed files with 847 additions and 361 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
trigger:
branches:
include: ['*']
exclude: [translation]
exclude: [translation, script-creator-experimental]
tags:
include: ['*']
+1 -14
View File
@@ -32,27 +32,14 @@
#include "screens/screen.hpp"
#include <3ds.h>
#include <citro2d.h>
#include <citro3d.h>
#include <random>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <wchar.h>
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> 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);
+48
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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 <fstream>
#include <stdarg.h>
#include <string>
#include <time.h>
#include <unistd.h>
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
+1 -1
View File
@@ -26,7 +26,7 @@
#include "screens/screen.hpp"
class FTPScreen : public Screen
class FTPScreen : public screen
{
public:
void Draw(void) const override;
+55 -53
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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 <vector>
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<Structs::ButtonPos> 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 <http://www.gnu.org/licenses/>.
*
* 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 <vector>
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<DirEntry> dirContents; // To return Script state.
std::vector<Structs::ButtonPos> 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
+35 -2
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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 <memory>
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<screen> screen2);
void fade(std::unique_ptr<screen> screen2, bool fadeout = true);
void back(void);
void loop(u32 hDown, u32 hHeld, touchPosition touch);
}
#endif
+1 -1
View File
@@ -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;
+40 -3
View File
@@ -35,21 +35,45 @@
#include <vector>
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<Structs::ButtonPos> mainButtons = {
{90, 40, 140, 35, -1}, // New Script.
{90, 100, 140, 35, -1}, // Existing Script.
};
// Creator Button Pos.
std::vector<Structs::ButtonPos> 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
+1 -1
View File
@@ -32,7 +32,7 @@
#include "utils/fileBrowse.h"
class ScriptList : public Screen
class ScriptList : public screen
{
public:
void Draw(void) const override;
+1 -1
View File
@@ -34,7 +34,7 @@
#include <vector>
class Settings : public Screen
class Settings : public screen
{
public:
void Draw(void) const override;
+1 -1
View File
@@ -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;
+1
View File
@@ -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();
+3 -1
View File
@@ -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!"
}
+16 -16
View File
@@ -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();
}
}
+3 -29
View File
@@ -30,18 +30,10 @@
#include "utils/config.hpp"
#include <3ds.h>
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <stack>
C3D_RenderTarget* top;
C3D_RenderTarget* bottom;
C2D_TextBuf sizeBuf;
std::stack<std::unique_ptr<Screen>> 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> 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);
+2 -2
View File
@@ -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();
+72
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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 <memory>
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<char, decltype(free)*> 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();
}
}
+8 -14
View File
@@ -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<MainMenu>());
if (Config::Logging == true) {
Logging::createLogFile();
}
Screen::set(std::make_unique<MainMenu>());
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) {
+1 -1
View File
@@ -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;
}
+190 -166
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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<ScriptList>());
break;
case 1:
if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<ScriptBrowse>());
} else {
notConnectedMsg();
}
break;
case 2:
if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<TinyDB>());
} else {
notConnectedMsg();
}
break;
case 3:
if (isTesting == true) {
Gui::setScreen(std::make_unique<ScriptCreator>());
} else {
notImplemented();
}
break;
case 4:
Gui::setScreen(std::make_unique<Settings>());
break;
case 5:
if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<FTPScreen>());
} else {
notConnectedMsg();
}
break;
}
}
if (hDown & KEY_X) {
if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<FTPScreen>());
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
Gui::setScreen(std::make_unique<ScriptList>());
} else if (touching(touch, mainButtons[1])) {
if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<ScriptBrowse>());
} else {
notConnectedMsg();
}
} else if (touching(touch, mainButtons[2])) {
if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<TinyDB>());
} else {
notConnectedMsg();
}
} else if (touching(touch, mainButtons[3])) {
if (isTesting == true) {
Gui::setScreen(std::make_unique<ScriptCreator>());
} else {
notImplemented();
}
} else if (touching(touch, mainButtons[4])) {
Gui::setScreen(std::make_unique<Settings>());
} else if (touching(touch, mainButtons[5])) {
if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<FTPScreen>());
} 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 <http://www.gnu.org/licenses/>.
*
* 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 <unistd.h>
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<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, {"json"});
for(uint i=0;i<dirContentsTemp.size();i++) {
dirContents.push_back(dirContentsTemp[i]);
}
if (dirContents.size() == 0) {
return false;
}
return true;
}
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:
if (returnScriptState() == true) {
Screen::set(std::make_unique<ScriptList>());
} else {
Gui::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST"));
}
break;
case 1:
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<ScriptBrowse>());
} else {
notConnectedMsg();
}
break;
case 2:
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<TinyDB>());
} else {
notConnectedMsg();
}
break;
case 3:
if (isTesting == true) {
Screen::set(std::make_unique<ScriptCreator>());
} else {
notImplemented();
}
break;
case 4:
Screen::set(std::make_unique<Settings>());
break;
case 5:
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<FTPScreen>());
} else {
notConnectedMsg();
}
break;
}
}
if (hDown & KEY_X) {
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<FTPScreen>());
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
if (returnScriptState() == true) {
Screen::set(std::make_unique<ScriptList>());
} else {
Gui::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST"));
}
} else if (touching(touch, mainButtons[1])) {
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<ScriptBrowse>());
} else {
notConnectedMsg();
}
} else if (touching(touch, mainButtons[2])) {
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<TinyDB>());
} else {
notConnectedMsg();
}
} else if (touching(touch, mainButtons[3])) {
if (isTesting == true) {
Screen::set(std::make_unique<ScriptCreator>());
} else {
notImplemented();
}
} else if (touching(touch, mainButtons[4])) {
Screen::set(std::make_unique<Settings>());
} else if (touching(touch, mainButtons[5])) {
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<FTPScreen>());
} else {
notConnectedMsg();
}
}
}
}
+73
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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 <stack>
// Fade stuff.
int fadealpha = 255;
bool fadein = true;
std::stack<std::unique_ptr<screen>> screens;
// Set a specific Screen.
void Screen::set(std::unique_ptr<screen> screen2)
{
screens.push(std::move(screen2));
}
// Fade into another Screen, but first do a fadeout.
void Screen::fade(std::unique_ptr<screen> 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;
}
}
}
+11 -11
View File
@@ -43,14 +43,14 @@ nlohmann::json infoJson;
std::string maxScripts;
void fixInfo(nlohmann::json &json) {
for(uint i=0;i<json.size();i++) {
if(!json[i].contains("title")) json[i]["title"] = "TITLE";
if(!json[i].contains("author")) json[i]["author"] = "AUTHOR";
for(uint i=0;i<json.size();i++) {
if(!json[i].contains("title")) json[i]["title"] = "TITLE";
if(!json[i].contains("author")) json[i]["author"] = "AUTHOR";
if(!json[i].contains("shortDesc")) json[i]["shortDesc"] = "SHORTDESC";
if(!json[i].contains("revision")) json[i]["revision"] = 0;
if(!json[i].contains("curRevision")) json[i]["curRevision"] = 0;
if(!json[i].contains("version")) json[i]["revision"] = 0;
}
if(!json[i].contains("revision")) json[i]["revision"] = 0;
if(!json[i].contains("curRevision")) json[i]["curRevision"] = 0;
if(!json[i].contains("version")) json[i]["revision"] = 0;
}
}
nlohmann::json infoFromScript(const std::string &path) {
@@ -169,7 +169,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
if (hDown & KEY_B) {
infoJson.clear();
Gui::screenBack();
Screen::back();
return;
}
@@ -205,9 +205,9 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
std::string titleFix = infoJson[selection]["title"];
for (int i = 0; i < (int)titleFix.size(); i++) {
if (titleFix[i] == '/') {
titleFix[i] = '-';
}
if (titleFix[i] == '/') {
titleFix[i] = '-';
}
}
DisplayMsg(fileName);
+267 -38
View File
@@ -25,12 +25,14 @@
*/
#include "keyboard.hpp"
#include "logging.hpp"
#include "screens/scriptCreator.hpp"
#include "utils/config.hpp"
#include <fstream>
#include <unistd.h>
// 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);
}
}
+1 -1
View File
@@ -365,7 +365,7 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld) {
if (hDown & KEY_B) {
fileInfo.clear();
Gui::screenBack();
Screen::back();
return;
}
+1 -1
View File
@@ -232,7 +232,7 @@ void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
if (hDown & KEY_B) {
Gui::screenBack();
Screen::back();
return;
}
}
+3 -3
View File
@@ -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;
}
+10
View File
@@ -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);