mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
Begin to add checks for Scripts.
This commit is contained in:
@@ -51,7 +51,7 @@ private:
|
||||
nlohmann::json openScriptFile();
|
||||
void checkForValidate(void);
|
||||
void loadDesc(void);
|
||||
void runFunctions(nlohmann::json &json);
|
||||
Result runFunctions(nlohmann::json &json);
|
||||
|
||||
// Draw Functions.
|
||||
void DrawSubMenu(void) const;
|
||||
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
void GitHubLogic(u32 hDown, u32 hHeld, touchPosition touch);
|
||||
|
||||
|
||||
void execute();
|
||||
Result execute();
|
||||
void descript();
|
||||
void updateStore(int selectedStore);
|
||||
void deleteStore(int selectedStore);
|
||||
|
||||
@@ -47,14 +47,21 @@ struct StoreInfo {
|
||||
std::string sheetURL;
|
||||
};
|
||||
|
||||
enum ScriptState {
|
||||
NONE = 0,
|
||||
FAILED_DOWNLOAD,
|
||||
SCRIPT_CANCELED,
|
||||
SYNTAX_ERROR,
|
||||
};
|
||||
|
||||
namespace ScriptHelper {
|
||||
// Get stuff from a JSON.
|
||||
std::string getString(nlohmann::json json, const std::string &key, const std::string &key2);
|
||||
int getNum(nlohmann::json json, const std::string &key, const std::string &key2);
|
||||
|
||||
// Script Functions.
|
||||
void downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, bool showVersions, std::string message);
|
||||
void downloadFile(std::string file, std::string output, std::string message);
|
||||
Result downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, bool showVersions, std::string message);
|
||||
Result downloadFile(std::string file, std::string output, std::string message);
|
||||
|
||||
void removeFile(std::string file, std::string message);
|
||||
void installFile(std::string file, std::string message);
|
||||
@@ -66,6 +73,8 @@ namespace ScriptHelper {
|
||||
|
||||
void deleteTitle(const std::string TitleID, bool isNAND, std::string message);
|
||||
void bootTitle(const std::string TitleID, bool isNAND, std::string message);
|
||||
|
||||
Result prompt(std::string message);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -167,5 +167,8 @@
|
||||
"PUBLISHED_AT": "Published at: ",
|
||||
"FETCHING_RELEASES": "Fetching Releases... please wait.",
|
||||
"VERSION_SELECT": "Select the Release you want to download.",
|
||||
"IS_PRERELEASE": "PreRelease: "
|
||||
"IS_PRERELEASE": "PreRelease: ",
|
||||
"DOWNLOAD_ERROR": "Download Error!",
|
||||
"SCRIPT_CANCELED": "Script Canceled!",
|
||||
"SYNTAX_ERROR": "Syntax Error!"
|
||||
}
|
||||
|
||||
+134
-113
@@ -884,128 +884,149 @@ void ScriptList::DrawGlossary(void) const {
|
||||
}
|
||||
|
||||
// Execute | run the script.
|
||||
void ScriptList::runFunctions(nlohmann::json &json) {
|
||||
Result ScriptList::runFunctions(nlohmann::json &json) {
|
||||
Result ret = NONE; // No Error as of yet.
|
||||
for(int i=0;i<(int)json.at(choice).size();i++) {
|
||||
std::string type = json.at(choice).at(i).at("type");
|
||||
if (ret == NONE) {
|
||||
std::string type = json.at(choice).at(i).at("type");
|
||||
|
||||
if(type == "deleteFile") {
|
||||
bool missing = false;
|
||||
std::string file, message;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
if(!missing) ScriptHelper::removeFile(file, message);
|
||||
if(type == "deleteFile") {
|
||||
bool missing = false;
|
||||
std::string file, message;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).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(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
if(!missing) ScriptHelper::downloadFile(file, output, message);
|
||||
} else if(type == "downloadFile") {
|
||||
bool missing = false;
|
||||
std::string file, output, message;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).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(json.at(choice).at(i).contains("repo")) repo = json.at(choice).at(i).at("repo");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("includePrereleases") && json.at(choice).at(i).at("includePrereleases").is_boolean())
|
||||
includePrereleases = json.at(choice).at(i).at("includePrereleases");
|
||||
if(json.at(choice).at(i).contains("showVersions") && json.at(choice).at(i).at("showVersions").is_boolean())
|
||||
showVersions = json.at(choice).at(i).at("showVersions");
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
if(!missing) ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
|
||||
|
||||
} else if(type == "extractFile") {
|
||||
bool missing = false;
|
||||
std::string file, input, output, message;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("input")) input = json.at(choice).at(i).at("input");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
if(!missing) ScriptHelper::extractFile(file, input, output, message);
|
||||
} else if(type == "downloadRelease") {
|
||||
bool missing = false, includePrereleases = false, showVersions = false;
|
||||
std::string repo, file, output, message;
|
||||
if(json.at(choice).at(i).contains("repo")) repo = json.at(choice).at(i).at("repo");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("includePrereleases") && json.at(choice).at(i).at("includePrereleases").is_boolean())
|
||||
includePrereleases = json.at(choice).at(i).at("includePrereleases");
|
||||
if(json.at(choice).at(i).contains("showVersions") && json.at(choice).at(i).at("showVersions").is_boolean())
|
||||
showVersions = json.at(choice).at(i).at("showVersions");
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
if(!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
|
||||
|
||||
} else if(type == "installCia") {
|
||||
bool missing = false;
|
||||
std::string file, message;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
if(!missing) ScriptHelper::installFile(file, message);
|
||||
} else if(type == "extractFile") {
|
||||
bool missing = false;
|
||||
std::string file, input, output, message;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("input")) input = json.at(choice).at(i).at("input");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
if(!missing) ScriptHelper::extractFile(file, input, output, message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "mkdir") {
|
||||
bool missing = false;
|
||||
std::string directory, message;
|
||||
if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory");
|
||||
else missing = true;
|
||||
if(!missing) makeDirs(directory.c_str());
|
||||
} else if(type == "installCia") {
|
||||
bool missing = false;
|
||||
std::string file, message;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
if(!missing) ScriptHelper::installFile(file, message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "rmdir") {
|
||||
bool missing = false;
|
||||
std::string directory, message, promptmsg;
|
||||
if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).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 == "mkdir") {
|
||||
bool missing = false;
|
||||
std::string directory, message;
|
||||
if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).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(json.at(choice).at(i).contains("directory")) directory = json.at(choice).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(json.at(choice).at(i).contains("file")) file = json.at(choice).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(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("seconds") && json.at(choice).at(i).at("seconds").is_number())
|
||||
seconds = json.at(choice).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 == "deleteTitle") {
|
||||
std::string TitleID = "";
|
||||
std::string message = "";
|
||||
bool isNAND = false, missing = false;
|
||||
if(json.at(choice).at(i).contains("TitleID")) TitleID = json.at(choice).at(i).at("TitleID");
|
||||
else missing = true;
|
||||
if (json.at(choice).at(i).contains("NAND") && json.at(choice).at(i).at("NAND").is_boolean()) isNAND = json.at(choice).at(i).at("NAND");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).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(json.at(choice).at(i).contains("TitleID")) TitleID = json.at(choice).at(i).at("TitleID");
|
||||
else missing = true;
|
||||
if (json.at(choice).at(i).contains("NAND") && json.at(choice).at(i).at("NAND").is_boolean()) isNAND = json.at(choice).at(i).at("NAND");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).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(json.at(choice).at(i).contains("message")) Message = json.at(choice).at(i).at("message");
|
||||
ret = ScriptHelper::prompt(Message);
|
||||
}
|
||||
|
||||
} else if (type == "mkfile") {
|
||||
bool missing = false;
|
||||
std::string file;
|
||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).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(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("seconds") && json.at(choice).at(i).at("seconds").is_number())
|
||||
seconds = json.at(choice).at(i).at("seconds");
|
||||
else missing = true;
|
||||
if(!missing) ScriptHelper::displayTimeMsg(message, seconds);
|
||||
|
||||
} else if (type == "saveConfig") {
|
||||
Config::save();
|
||||
|
||||
} else if (type == "deleteTitle") {
|
||||
std::string TitleID = "";
|
||||
std::string message = "";
|
||||
bool isNAND = false, missing = false;
|
||||
if(json.at(choice).at(i).contains("TitleID")) TitleID = json.at(choice).at(i).at("TitleID");
|
||||
else missing = true;
|
||||
if (json.at(choice).at(i).contains("NAND") && json.at(choice).at(i).at("NAND").is_boolean()) isNAND = json.at(choice).at(i).at("NAND");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).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(json.at(choice).at(i).contains("TitleID")) TitleID = json.at(choice).at(i).at("TitleID");
|
||||
else missing = true;
|
||||
if (json.at(choice).at(i).contains("NAND") && json.at(choice).at(i).at("NAND").is_boolean()) isNAND = json.at(choice).at(i).at("NAND");
|
||||
else missing = true;
|
||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).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;
|
||||
}
|
||||
+137
-111
@@ -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;
|
||||
}
|
||||
@@ -34,7 +34,7 @@
|
||||
#include <fstream>
|
||||
|
||||
extern "C" {
|
||||
#include "cia.h"
|
||||
#include "cia.h"
|
||||
}
|
||||
|
||||
extern bool showProgressBar;
|
||||
@@ -66,17 +66,21 @@ int ScriptHelper::getNum(nlohmann::json json, const std::string &key, const std:
|
||||
}
|
||||
|
||||
// Download from a Github Release.
|
||||
void ScriptHelper::downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, bool showVersions, std::string message) {
|
||||
Result ScriptHelper::downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, bool showVersions, std::string message) {
|
||||
Result ret = NONE;
|
||||
if (downloadFromRelease("https://github.com/" + repo, file, output, message, includePrereleases, showVersions) != 0) {
|
||||
showProgressBar = false;
|
||||
downloadFailed();
|
||||
return;
|
||||
ret = FAILED_DOWNLOAD;
|
||||
return ret;
|
||||
}
|
||||
showProgressBar = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Download a File from everywhere.
|
||||
void ScriptHelper::downloadFile(std::string file, std::string output, std::string message) {
|
||||
Result ScriptHelper::downloadFile(std::string file, std::string output, std::string message) {
|
||||
Result ret = NONE;
|
||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||
showProgressBar = true;
|
||||
progressBarType = 0;
|
||||
@@ -84,9 +88,11 @@ void ScriptHelper::downloadFile(std::string file, std::string output, std::strin
|
||||
if (downloadToFile(file, output) != 0) {
|
||||
showProgressBar = false;
|
||||
downloadFailed();
|
||||
return;
|
||||
ret = FAILED_DOWNLOAD;
|
||||
return ret;
|
||||
}
|
||||
showProgressBar = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Remove a File.
|
||||
@@ -180,4 +186,12 @@ void ScriptHelper::bootTitle(const std::string TitleID, bool isNAND, std::string
|
||||
CIA_LaunchTitle(ID, MEDIATYPE_SD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Result ScriptHelper::prompt(std::string message) {
|
||||
Result ret = NONE;
|
||||
if (!Msg::promptMsg(message)) {
|
||||
ret = SCRIPT_CANCELED;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user