mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-04 16:49:06 +00:00
Begin to add checks for Scripts.
This commit is contained in:
@@ -51,7 +51,7 @@ private:
|
|||||||
nlohmann::json openScriptFile();
|
nlohmann::json openScriptFile();
|
||||||
void checkForValidate(void);
|
void checkForValidate(void);
|
||||||
void loadDesc(void);
|
void loadDesc(void);
|
||||||
void runFunctions(nlohmann::json &json);
|
Result runFunctions(nlohmann::json &json);
|
||||||
|
|
||||||
// Draw Functions.
|
// Draw Functions.
|
||||||
void DrawSubMenu(void) const;
|
void DrawSubMenu(void) const;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ private:
|
|||||||
void GitHubLogic(u32 hDown, u32 hHeld, touchPosition touch);
|
void GitHubLogic(u32 hDown, u32 hHeld, touchPosition touch);
|
||||||
|
|
||||||
|
|
||||||
void execute();
|
Result execute();
|
||||||
void descript();
|
void descript();
|
||||||
void updateStore(int selectedStore);
|
void updateStore(int selectedStore);
|
||||||
void deleteStore(int selectedStore);
|
void deleteStore(int selectedStore);
|
||||||
|
|||||||
@@ -47,14 +47,21 @@ struct StoreInfo {
|
|||||||
std::string sheetURL;
|
std::string sheetURL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ScriptState {
|
||||||
|
NONE = 0,
|
||||||
|
FAILED_DOWNLOAD,
|
||||||
|
SCRIPT_CANCELED,
|
||||||
|
SYNTAX_ERROR,
|
||||||
|
};
|
||||||
|
|
||||||
namespace ScriptHelper {
|
namespace ScriptHelper {
|
||||||
// Get stuff from a JSON.
|
// Get stuff from a JSON.
|
||||||
std::string getString(nlohmann::json json, const std::string &key, const std::string &key2);
|
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);
|
int getNum(nlohmann::json json, const std::string &key, const std::string &key2);
|
||||||
|
|
||||||
// Script Functions.
|
// Script Functions.
|
||||||
void downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, bool showVersions, std::string message);
|
Result 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 downloadFile(std::string file, std::string output, std::string message);
|
||||||
|
|
||||||
void removeFile(std::string file, std::string message);
|
void removeFile(std::string file, std::string message);
|
||||||
void installFile(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 deleteTitle(const std::string TitleID, bool isNAND, std::string message);
|
||||||
void bootTitle(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
|
#endif
|
||||||
@@ -167,5 +167,8 @@
|
|||||||
"PUBLISHED_AT": "Published at: ",
|
"PUBLISHED_AT": "Published at: ",
|
||||||
"FETCHING_RELEASES": "Fetching Releases... please wait.",
|
"FETCHING_RELEASES": "Fetching Releases... please wait.",
|
||||||
"VERSION_SELECT": "Select the Release you want to download.",
|
"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!"
|
||||||
}
|
}
|
||||||
|
|||||||
+133
-112
@@ -884,128 +884,149 @@ void ScriptList::DrawGlossary(void) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute | run the script.
|
// 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++) {
|
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") {
|
if(type == "deleteFile") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string file, message;
|
std::string file, message;
|
||||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||||
if(!missing) ScriptHelper::removeFile(file, message);
|
if(!missing) ScriptHelper::removeFile(file, message);
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if(type == "downloadFile") {
|
} else if(type == "downloadFile") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string file, output, message;
|
std::string file, output, message;
|
||||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||||
if(!missing) ScriptHelper::downloadFile(file, output, message);
|
if(!missing) ret = ScriptHelper::downloadFile(file, output, message);
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if(type == "downloadRelease") {
|
} else if(type == "downloadRelease") {
|
||||||
bool missing = false, includePrereleases = false, showVersions = false;
|
bool missing = false, includePrereleases = false, showVersions = false;
|
||||||
std::string repo, file, output, message;
|
std::string repo, file, output, message;
|
||||||
if(json.at(choice).at(i).contains("repo")) repo = json.at(choice).at(i).at("repo");
|
if(json.at(choice).at(i).contains("repo")) repo = json.at(choice).at(i).at("repo");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("includePrereleases") && json.at(choice).at(i).at("includePrereleases").is_boolean())
|
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");
|
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())
|
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");
|
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(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);
|
if(!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
|
||||||
|
|
||||||
} else if(type == "extractFile") {
|
} else if(type == "extractFile") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string file, input, output, message;
|
std::string file, input, output, message;
|
||||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("input")) input = json.at(choice).at(i).at("input");
|
if(json.at(choice).at(i).contains("input")) input = json.at(choice).at(i).at("input");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||||
if(!missing) ScriptHelper::extractFile(file, input, output, message);
|
if(!missing) ScriptHelper::extractFile(file, input, output, message);
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if(type == "installCia") {
|
} else if(type == "installCia") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string file, message;
|
std::string file, message;
|
||||||
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||||
if(!missing) ScriptHelper::installFile(file, message);
|
if(!missing) ScriptHelper::installFile(file, message);
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if (type == "mkdir") {
|
} else if (type == "mkdir") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string directory, message;
|
std::string directory, message;
|
||||||
if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory");
|
if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
if(!missing) makeDirs(directory.c_str());
|
if(!missing) makeDirs(directory.c_str());
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if (type == "rmdir") {
|
} else if (type == "rmdir") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string directory, message, promptmsg;
|
std::string directory, message, promptmsg;
|
||||||
if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory");
|
if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
|
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
|
||||||
if(!missing) {
|
if(!missing) {
|
||||||
if (Msg::promptMsg(promptmsg)) {
|
if (Msg::promptMsg(promptmsg)) {
|
||||||
removeDirRecursive(directory.c_str());
|
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.
|
// 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++) {
|
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 (ret == NONE) {
|
||||||
if(type == "deleteFile") {
|
std::string type = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("type");
|
||||||
bool missing = false;
|
if(type == "deleteFile") {
|
||||||
std::string file, message;
|
bool missing = false;
|
||||||
if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file");
|
std::string file, message;
|
||||||
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");
|
||||||
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::removeFile(file, 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");
|
||||||
|
if(!missing) ScriptHelper::removeFile(file, message);
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if(type == "downloadFile") {
|
} else if(type == "downloadFile") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string file, output, message;
|
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");
|
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;
|
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");
|
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;
|
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(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);
|
if(!missing) ret = ScriptHelper::downloadFile(file, output, message);
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if(type == "downloadRelease") {
|
} else if(type == "downloadRelease") {
|
||||||
bool missing = false, includePrereleases = false, showVersions = false;
|
bool missing = false, includePrereleases = false, showVersions = false;
|
||||||
std::string repo, file, output, message;
|
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");
|
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;
|
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");
|
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;
|
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");
|
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;
|
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())
|
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");
|
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())
|
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");
|
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(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);
|
if(!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if(type == "extractFile") {
|
} else if(type == "extractFile") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string file, input, output, message;
|
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");
|
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;
|
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");
|
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;
|
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");
|
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;
|
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(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);
|
if(!missing) ScriptHelper::extractFile(file, input, output, message);
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if(type == "installCia") {
|
} else if(type == "installCia") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string file, message;
|
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");
|
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;
|
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(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);
|
if(!missing) ScriptHelper::installFile(file, message);
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if (type == "mkdir") {
|
} else if (type == "mkdir") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string directory, message;
|
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");
|
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;
|
else missing = true;
|
||||||
if(!missing) makeDirs(directory.c_str());
|
if(!missing) makeDirs(directory.c_str());
|
||||||
|
else ret = SYNTAX_ERROR;
|
||||||
|
|
||||||
} else if (type == "rmdir") {
|
} else if (type == "rmdir") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
std::string directory, message, promptmsg;
|
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");
|
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;
|
else missing = true;
|
||||||
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
|
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
|
||||||
if(!missing) {
|
if(!missing) {
|
||||||
if (Msg::promptMsg(promptmsg)) {
|
if (Msg::promptMsg(promptmsg)) {
|
||||||
removeDirRecursive(directory.c_str());
|
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>
|
#include <fstream>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "cia.h"
|
#include "cia.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
extern bool showProgressBar;
|
extern bool showProgressBar;
|
||||||
@@ -66,17 +66,21 @@ int ScriptHelper::getNum(nlohmann::json json, const std::string &key, const std:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Download from a Github Release.
|
// 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) {
|
if (downloadFromRelease("https://github.com/" + repo, file, output, message, includePrereleases, showVersions) != 0) {
|
||||||
showProgressBar = false;
|
showProgressBar = false;
|
||||||
downloadFailed();
|
downloadFailed();
|
||||||
return;
|
ret = FAILED_DOWNLOAD;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
showProgressBar = false;
|
showProgressBar = false;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download a File from everywhere.
|
// 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());
|
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||||
showProgressBar = true;
|
showProgressBar = true;
|
||||||
progressBarType = 0;
|
progressBarType = 0;
|
||||||
@@ -84,9 +88,11 @@ void ScriptHelper::downloadFile(std::string file, std::string output, std::strin
|
|||||||
if (downloadToFile(file, output) != 0) {
|
if (downloadToFile(file, output) != 0) {
|
||||||
showProgressBar = false;
|
showProgressBar = false;
|
||||||
downloadFailed();
|
downloadFailed();
|
||||||
return;
|
ret = FAILED_DOWNLOAD;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
showProgressBar = false;
|
showProgressBar = false;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a File.
|
// Remove a File.
|
||||||
@@ -181,3 +187,11 @@ void ScriptHelper::bootTitle(const std::string TitleID, bool isNAND, std::string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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