Begin to add checks for Scripts.

This commit is contained in:
StackZ
2020-03-21 03:49:21 +01:00
parent 23aab6ada9
commit 73c495db4f
7 changed files with 307 additions and 234 deletions
+137 -111
View File
@@ -1217,126 +1217,152 @@ void UniStore::DrawGlossary(void) const {
}
// Execute Entry.
void UniStore::execute() {
Result UniStore::execute() {
Result ret = NONE; // No Error has been occured now.
for(int i=0;i<(int)appStoreJson.at("storeContent").at(Selection).at("script").size();i++) {
std::string type = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("type");
if(type == "deleteFile") {
bool missing = false;
std::string file, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::removeFile(file, message);
if (ret == NONE) {
std::string type = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("type");
if(type == "deleteFile") {
bool missing = false;
std::string file, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::removeFile(file, message);
else ret = SYNTAX_ERROR;
} else if(type == "downloadFile") {
bool missing = false;
std::string file, output, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::downloadFile(file, output, message);
} else if(type == "downloadFile") {
bool missing = false;
std::string file, output, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ret = ScriptHelper::downloadFile(file, output, message);
else ret = SYNTAX_ERROR;
} else if(type == "downloadRelease") {
bool missing = false, includePrereleases = false, showVersions = false;
std::string repo, file, output, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("repo")) repo = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("repo");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("includePrereleases") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("includePrereleases").is_boolean())
includePrereleases = appStoreJson.at(Selection).at("script").at(i).at("includePrereleases");
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("showVersions") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("showVersions").is_boolean())
showVersions = appStoreJson.at(Selection).at("script").at(i).at("showVersions");
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
} else if(type == "downloadRelease") {
bool missing = false, includePrereleases = false, showVersions = false;
std::string repo, file, output, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("repo")) repo = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("repo");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("includePrereleases") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("includePrereleases").is_boolean())
includePrereleases = appStoreJson.at(Selection).at("script").at(i).at("includePrereleases");
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("showVersions") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("showVersions").is_boolean())
showVersions = appStoreJson.at(Selection).at("script").at(i).at("showVersions");
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
else ret = SYNTAX_ERROR;
} else if(type == "extractFile") {
bool missing = false;
std::string file, input, output, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("input")) input = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("input");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::extractFile(file, input, output, message);
} else if(type == "extractFile") {
bool missing = false;
std::string file, input, output, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("input")) input = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("input");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::extractFile(file, input, output, message);
else ret = SYNTAX_ERROR;
} else if(type == "installCia") {
bool missing = false;
std::string file, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::installFile(file, message);
} else if(type == "installCia") {
bool missing = false;
std::string file, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::installFile(file, message);
else ret = SYNTAX_ERROR;
} else if (type == "mkdir") {
bool missing = false;
std::string directory, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
else missing = true;
if(!missing) makeDirs(directory.c_str());
} else if (type == "mkdir") {
bool missing = false;
std::string directory, message;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
else missing = true;
if(!missing) makeDirs(directory.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "rmdir") {
bool missing = false;
std::string directory, message, promptmsg;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
else missing = true;
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
if(!missing) {
if (Msg::promptMsg(promptmsg)) {
removeDirRecursive(directory.c_str());
} else if (type == "rmdir") {
bool missing = false;
std::string directory, message, promptmsg;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
else missing = true;
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
if(!missing) {
if (Msg::promptMsg(promptmsg)) {
removeDirRecursive(directory.c_str());
}
}
else ret = SYNTAX_ERROR;
} else if (type == "mkfile") {
bool missing = false;
std::string file;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(!missing) ScriptHelper::createFile(file.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "timeMsg") {
bool missing = false;
std::string message;
int seconds;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("seconds") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("seconds").is_number())
seconds = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("seconds");
else missing = true;
if(!missing) ScriptHelper::displayTimeMsg(message, seconds);
else ret = SYNTAX_ERROR;
} else if (type == "saveConfig") {
Config::save();
} else if (type == "notImplemented") {
notImplemented();
} else if (type == "deleteTitle") {
std::string TitleID = "";
std::string message = "";
bool isNAND = false, missing = false;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("TitleID")) TitleID = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("TitleID");
else missing = true;
if (appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("NAND") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND").is_boolean()) isNAND = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if(!missing) ScriptHelper::deleteTitle(TitleID, isNAND, message);
else ret = SYNTAX_ERROR;
} else if (type == "bootTitle") {
std::string TitleID = "";
std::string message = "";
bool isNAND = false, missing = false;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("TitleID")) TitleID = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("TitleID");
else missing = true;
if (appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("NAND") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND").is_boolean()) isNAND = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if(!missing) ScriptHelper::bootTitle(TitleID, isNAND, message);
else ret = SYNTAX_ERROR;
} else if (type == "promptMessage") {
std::string Message = "";
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
ret = ScriptHelper::prompt(Message);
}
} else if (type == "mkfile") {
bool missing = false;
std::string file;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(!missing) ScriptHelper::createFile(file.c_str());
} else if (type == "timeMsg") {
bool missing = false;
std::string message;
int seconds;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("seconds") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("seconds").is_number())
seconds = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("seconds");
else missing = true;
if(!missing) ScriptHelper::displayTimeMsg(message, seconds);
} else if (type == "saveConfig") {
Config::save();
} else if (type == "notImplemented") {
notImplemented();
} else if (type == "deleteTitle") {
std::string TitleID = "";
std::string message = "";
bool isNAND = false, missing = false;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("TitleID")) TitleID = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("TitleID");
else missing = true;
if (appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("NAND") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND").is_boolean()) isNAND = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if(!missing) ScriptHelper::deleteTitle(TitleID, isNAND, message);
} else if (type == "bootTitle") {
std::string TitleID = "";
std::string message = "";
bool isNAND = false, missing = false;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("TitleID")) TitleID = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("TitleID");
else missing = true;
if (appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("NAND") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND").is_boolean()) isNAND = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND");
else missing = true;
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if(!missing) ScriptHelper::bootTitle(TitleID, isNAND, message);
}
}
doneMsg();
if (ret == NONE) doneMsg();
else if (ret == FAILED_DOWNLOAD) Msg::DisplayWarnMsg(Lang::get("DOWNLOAD_ERROR"));
else if (ret == SCRIPT_CANCELED) Msg::DisplayWarnMsg(Lang::get("SCRIPT_CANCELED"));
else Msg::DisplayWarnMsg(Lang::get("SYNTAX_ERROR"));
return ret;
}