*Only* open valid Scripts.

This commit is contained in:
SuperSaiyajinStackZ
2019-12-22 17:49:23 +01:00
parent 11e7664706
commit 3ebdb7e95d
5 changed files with 29 additions and 15 deletions
+2
View File
@@ -43,6 +43,8 @@ namespace ScriptHelper {
void extractFile(std::string file, std::string input, std::string output, std::string message); void extractFile(std::string file, std::string input, std::string output, std::string message);
Result createFile(const char * path); Result createFile(const char * path);
void displayTimeMsg(std::string message, int seconds); void displayTimeMsg(std::string message, int seconds);
bool checkIfValid(std::string scriptFile);
} }
#endif #endif
-1
View File
@@ -59,7 +59,6 @@ nlohmann::json infoFromScript(const std::string &path) {
FILE* file = fopen(path.c_str(), "r"); FILE* file = fopen(path.c_str(), "r");
if(!file) { if(!file) {
fclose(file);
return out; return out;
} }
in = nlohmann::json::parse(file, nullptr, false); in = nlohmann::json::parse(file, nullptr, false);
+13 -13
View File
@@ -59,7 +59,6 @@ Info parseInfo(std::string fileName) {
FILE* file = fopen(fileName.c_str(), "rt"); FILE* file = fopen(fileName.c_str(), "rt");
if(!file) { if(!file) {
printf("File not found\n"); printf("File not found\n");
fclose(file);
return {"", ""}; return {"", ""};
} }
nlohmann::json json = nlohmann::json::parse(file, nullptr, false); nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
@@ -95,7 +94,6 @@ std::vector<std::string> parseObjects(std::string fileName) {
FILE* file = fopen(fileName.c_str(), "rt"); FILE* file = fopen(fileName.c_str(), "rt");
if(!file) { if(!file) {
printf("File not found\n"); printf("File not found\n");
fclose(file);
return {{""}}; return {{""}};
} }
nlohmann::json json = nlohmann::json::parse(file, nullptr, false); nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
@@ -425,17 +423,19 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_A) { if (hDown & KEY_A) {
if (dirContents[selection].isDirectory) { if (dirContents[selection].isDirectory) {
} else if (fileInfo.size() != 0) { } else if (fileInfo.size() != 0) {
currentFile = dirContents[selection].name; if (ScriptHelper::checkIfValid(dirContents[selection].name) == true) {
selectedTitle = fileInfo[selection].title; currentFile = dirContents[selection].name;
jsonFile = openScriptFile(); selectedTitle = fileInfo[selection].title;
Desc = Description(jsonFile); jsonFile = openScriptFile();
checkForValidate(); Desc = Description(jsonFile);
fileInfo2 = parseObjects(currentFile); checkForValidate();
loadColors(jsonFile); fileInfo2 = parseObjects(currentFile);
loadDesc(); loadColors(jsonFile);
isScriptSelected = true; loadDesc();
selection = 0; isScriptSelected = true;
mode = 1; selection = 0;
mode = 1;
}
} }
} }
-1
View File
@@ -54,7 +54,6 @@ std::vector<std::string> parseObjects() {
FILE* file = fopen(tinyDBFile, "rt"); FILE* file = fopen(tinyDBFile, "rt");
if(!file) { if(!file) {
printf("File not found\n"); printf("File not found\n");
fclose(file);
return {{""}}; return {{""}};
} }
tinyDBJson = nlohmann::json::parse(file, nullptr, false); tinyDBJson = nlohmann::json::parse(file, nullptr, false);
+14
View File
@@ -132,3 +132,17 @@ void ScriptHelper::displayTimeMsg(std::string message, int seconds) {
gspWaitForVBlank(); gspWaitForVBlank();
} }
} }
bool ScriptHelper::checkIfValid(std::string scriptFile) {
FILE* file = fopen(scriptFile.c_str(), "rt");
if(!file) {
printf("File not found\n");
return false;
}
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
fclose(file);
if (!json.contains("info")) return false;
return true;
}