*Only* open valid Scripts.

This commit is contained in:
SuperSaiyajinStackZ 2019-12-22 17:49:23 +01:00
commit 3ebdb7e95d
5 changed files with 29 additions and 15 deletions

View file

@ -43,6 +43,8 @@ namespace ScriptHelper {
void extractFile(std::string file, std::string input, std::string output, std::string message);
Result createFile(const char * path);
void displayTimeMsg(std::string message, int seconds);
bool checkIfValid(std::string scriptFile);
}
#endif

View file

@ -59,7 +59,6 @@ nlohmann::json infoFromScript(const std::string &path) {
FILE* file = fopen(path.c_str(), "r");
if(!file) {
fclose(file);
return out;
}
in = nlohmann::json::parse(file, nullptr, false);

View file

@ -59,7 +59,6 @@ Info parseInfo(std::string fileName) {
FILE* file = fopen(fileName.c_str(), "rt");
if(!file) {
printf("File not found\n");
fclose(file);
return {"", ""};
}
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");
if(!file) {
printf("File not found\n");
fclose(file);
return {{""}};
}
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 (dirContents[selection].isDirectory) {
} else if (fileInfo.size() != 0) {
currentFile = dirContents[selection].name;
selectedTitle = fileInfo[selection].title;
jsonFile = openScriptFile();
Desc = Description(jsonFile);
checkForValidate();
fileInfo2 = parseObjects(currentFile);
loadColors(jsonFile);
loadDesc();
isScriptSelected = true;
selection = 0;
mode = 1;
if (ScriptHelper::checkIfValid(dirContents[selection].name) == true) {
currentFile = dirContents[selection].name;
selectedTitle = fileInfo[selection].title;
jsonFile = openScriptFile();
Desc = Description(jsonFile);
checkForValidate();
fileInfo2 = parseObjects(currentFile);
loadColors(jsonFile);
loadDesc();
isScriptSelected = true;
selection = 0;
mode = 1;
}
}
}

View file

@ -54,7 +54,6 @@ std::vector<std::string> parseObjects() {
FILE* file = fopen(tinyDBFile, "rt");
if(!file) {
printf("File not found\n");
fclose(file);
return {{""}};
}
tinyDBJson = nlohmann::json::parse(file, nullptr, false);

View file

@ -131,4 +131,18 @@ void ScriptHelper::displayTimeMsg(std::string message, int seconds) {
for (int i = 0; i < 60*seconds; i++) {
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;
}