mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user