Fix Crashes when touching non existing entry positions.

This commit is contained in:
StackZ
2019-12-24 01:03:43 +01:00
parent c092c63efe
commit 71e4ff0939
3 changed files with 23 additions and 24 deletions
+10 -10
View File
@@ -45,12 +45,12 @@ std::string maxScripts;
void fixInfo(nlohmann::json &json) {
for(uint i=0;i<json.size();i++) {
if(!json[i].contains("title")) json[i]["title"] = "TITLE";
if(!json[i].contains("author")) json[i]["author"] = "AUTHOR";
if(!json[i].contains("title")) json[i]["title"] = "TITLE";
if(!json[i].contains("author")) json[i]["author"] = "AUTHOR";
if(!json[i].contains("shortDesc")) json[i]["shortDesc"] = "SHORTDESC";
if(!json[i].contains("revision")) json[i]["revision"] = 0;
if(!json[i].contains("curRevision")) json[i]["curRevision"] = 0;
if(!json[i].contains("version")) json[i]["revision"] = 0;
if(!json[i].contains("revision")) json[i]["revision"] = 0;
if(!json[i].contains("curRevision")) json[i]["curRevision"] = 0;
if(!json[i].contains("version")) json[i]["revision"] = 0;
}
}
@@ -227,7 +227,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH) {
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN;i++) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)infoJson.size();i++) {
if(touch.py > (i+1)*57 && touch.py < (i+2)*57) {
if (infoJson.size() != 0) {
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPos + i]["title"]);
@@ -241,11 +241,11 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
downloadToFile(infoJson[screenPos + i]["url"], Config::ScriptPath + titleFix + ".json");
infoJson[screenPos + i]["curRevision"] = infoJson[screenPos + i]["revision"];
}
}
}
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST;i++) {
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)infoJson.size();i++) {
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (infoJson.size() != 0) {
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPosList + i]["title"]);
std::string titleFix = infoJson[screenPosList + i]["title"];
@@ -258,7 +258,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
downloadToFile(infoJson[screenPosList + i]["url"], Config::ScriptPath + titleFix + ".json");
infoJson[screenPosList + i]["curRevision"] = infoJson[screenPosList + i]["revision"];
}
}
}
}
}
}
+9 -9
View File
@@ -84,7 +84,7 @@ void checkForValidate(void) {
nlohmann::json openScriptFile() {
FILE* file = fopen(currentFile.c_str(), "rt");
nlohmann::json jsonFile;
if(file) jsonFile = nlohmann::json::parse(file, nullptr, false);
if(file) jsonFile = nlohmann::json::parse(file, nullptr, false);
fclose(file);
return jsonFile;
}
@@ -123,7 +123,7 @@ void runFunctions(nlohmann::json &json) {
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;
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);
@@ -167,7 +167,7 @@ void runFunctions(nlohmann::json &json) {
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;
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);
@@ -351,7 +351,7 @@ void ScriptList::DrawSingleObject(void) const {
info = fileInfo2[screenPos2 + i];
if(screenPos2 + i == selection2) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, selected);
} else {
} else {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, unselected);
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, TextColor, info, 320);
@@ -362,7 +362,7 @@ void ScriptList::DrawSingleObject(void) const {
info = fileInfo2[screenPosList2 + i];
if(screenPosList2 + i == selection2) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, selected);
} else {
} else {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, unselected);
}
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, TextColor, info, 320);
@@ -403,7 +403,7 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH) {
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN; i++) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)fileInfo.size(); i++) {
if(touch.py > (i+1)*57 && touch.py < (i+2)*57) {
if (dirContents[screenPos + i].isDirectory) {
} else if (fileInfo.size() != 0) {
@@ -424,7 +424,7 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST; i++) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)fileInfo.size(); i++) {
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (dirContents[screenPosList + i].isDirectory) {
} else if (fileInfo.size() != 0) {
@@ -541,7 +541,7 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH) {
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN; i++) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)fileInfo2.size(); i++) {
if(touch.py > (i+1)*57 && touch.py < (i+2)*57) {
if (fileInfo2.size() != 0) {
choice = fileInfo2[screenPos2 + i];
@@ -550,7 +550,7 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST; i++) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)fileInfo2.size(); i++) {
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (fileInfo2.size() != 0) {
choice = fileInfo2[screenPosList2 + i];
+4 -5
View File
@@ -77,7 +77,6 @@ TinyDB::TinyDB() {
selectedOption = tinyDBList[0];
}
// To-Do.
void TinyDB::Draw(void) const {
std::string info;
Gui::setDraw(top);
@@ -228,7 +227,7 @@ void TinyDB::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH) {
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN;i++) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)tinyDBList.size();i++) {
if(touch.py > (i+1)*57 && touch.py < (i+2)*57) {
selection = screenPos + i;
selectedOption = tinyDBList[screenPos + i];
@@ -236,7 +235,7 @@ void TinyDB::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST;i++) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)tinyDBList.size();i++) {
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
selection = screenPosList + i;
selectedOption = tinyDBList[screenPosList + i];
@@ -258,7 +257,7 @@ void TinyDB::execute() {
bool missing = false;
std::string file, message;
if(tinyDBJson.at(selectedOption).at("script").at(i).contains("file")) file = tinyDBJson.at(selectedOption).at("script").at(i).at("file");
else missing = true;
else missing = true;
if(tinyDBJson.at(selectedOption).at("script").at(i).contains("message")) message = tinyDBJson.at(selectedOption).at("script").at(i).at("message");
if(!missing) ScriptHelper::removeFile(file, message);
@@ -276,7 +275,7 @@ void TinyDB::execute() {
bool missing = false;
std::string file, message;
if(tinyDBJson.at(selectedOption).at("script").at(i).contains("file")) file = tinyDBJson.at(selectedOption).at("script").at(i).at("file");
else missing = true;
else missing = true;
if(tinyDBJson.at(selectedOption).at("script").at(i).contains("message")) message = tinyDBJson.at(selectedOption).at("script").at(i).at("message");
if(!missing) ScriptHelper::installFile(file, message);
}