diff --git a/include/colors.hpp b/include/colors.hpp index 1e5b708..6d8007c 100644 --- a/include/colors.hpp +++ b/include/colors.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/download/download.hpp b/include/download/download.hpp index f4b5f14..72ece2a 100644 --- a/include/download/download.hpp +++ b/include/download/download.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ enum DownloadError { DL_ERROR_GIT, }; -struct ThemeEntry { +struct ListEntry { std::string downloadUrl; std::string name; std::string path; @@ -101,13 +101,4 @@ std::string getLatestCommit(std::string repo, std::string array, std::string ite * path is the path within the repo (Ex. "contents/_nds/TWiLightMenu/dsimenu/themes") * @return the string from the API. */ -std::vector getThemeList(std::string repo, std::string path); - -namespace download { - void downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, std::string message); - void downloadFile(std::string file, std::string output, std::string message); - void deleteFileList(std::string file, std::string message); - void installFileList(std::string file, std::string message); - void extractFileList(std::string file, std::string input, std::string output, std::string message); - void displayTimeMsg(std::string message, int seconds); -} \ No newline at end of file +std::vector getList(std::string repo, std::string path); \ No newline at end of file diff --git a/include/gui.hpp b/include/gui.hpp index ce1e14c..59f9867 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/screens/ftpScreen.hpp b/include/screens/ftpScreen.hpp index a871cee..f34a059 100644 --- a/include/screens/ftpScreen.hpp +++ b/include/screens/ftpScreen.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/screens/mainMenu.hpp b/include/screens/mainMenu.hpp index bcd7931..789f2f8 100644 --- a/include/screens/mainMenu.hpp +++ b/include/screens/mainMenu.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ * or requiring that modified versions of such material be marked in * reasonable ways as different from the original version. */ + #ifndef MAINMENU_HPP #define MAINMENU_HPP diff --git a/include/screens/screenCommon.hpp b/include/screens/screenCommon.hpp index 6931d31..e7f0dec 100644 --- a/include/screens/screenCommon.hpp +++ b/include/screens/screenCommon.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/screens/scriptBrowse.hpp b/include/screens/scriptBrowse.hpp index 5c710c4..b14df79 100644 --- a/include/screens/scriptBrowse.hpp +++ b/include/screens/scriptBrowse.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ * or requiring that modified versions of such material be marked in * reasonable ways as different from the original version. */ + #ifndef SCRIPTBROWSE_HPP #define SCRIPTBROWSE_HPP @@ -47,4 +48,5 @@ private: int keyRepeatDelay = 0; int fastMode = false; }; + #endif \ No newline at end of file diff --git a/include/screens/scriptCreator.hpp b/include/screens/scriptCreator.hpp index e7ed9cc..3b6e442 100644 --- a/include/screens/scriptCreator.hpp +++ b/include/screens/scriptCreator.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ * or requiring that modified versions of such material be marked in * reasonable ways as different from the original version. */ + #ifndef SCRIPTCREATOR_HPP #define SCRIPTCREATOR_HPP diff --git a/include/screens/scriptlist.hpp b/include/screens/scriptlist.hpp index e83d696..2cca130 100644 --- a/include/screens/scriptlist.hpp +++ b/include/screens/scriptlist.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ * or requiring that modified versions of such material be marked in * reasonable ways as different from the original version. */ + #ifndef SCRIPTLIST_HPP #define SCRIPTLIST_HPP @@ -58,5 +59,4 @@ private: int fastMode = false; }; -Result createFile(const char * path); #endif \ No newline at end of file diff --git a/include/screens/settings.hpp b/include/screens/settings.hpp index 42ab939..13c9965 100644 --- a/include/screens/settings.hpp +++ b/include/screens/settings.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ * or requiring that modified versions of such material be marked in * reasonable ways as different from the original version. */ + #ifndef SETTINGS_HPP #define SETTINGS_HPP diff --git a/include/screens/tinyDB.hpp b/include/screens/tinyDB.hpp index 9965909..48327d8 100644 --- a/include/screens/tinyDB.hpp +++ b/include/screens/tinyDB.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ * or requiring that modified versions of such material be marked in * reasonable ways as different from the original version. */ + #ifndef TINYDB_HPP #define TINYDB_HPP diff --git a/include/utils/common.hpp b/include/utils/common.hpp index 819acea..b598a45 100644 --- a/include/utils/common.hpp +++ b/include/utils/common.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/utils/config.hpp b/include/utils/config.hpp index c481ae7..add7431 100644 --- a/include/utils/config.hpp +++ b/include/utils/config.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/utils/extract.hpp b/include/utils/extract.hpp index 878b3ae..6ed8166 100644 --- a/include/utils/extract.hpp +++ b/include/utils/extract.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/utils/formatting.hpp b/include/utils/formatting.hpp index e7d4f5d..1b8c538 100644 --- a/include/utils/formatting.hpp +++ b/include/utils/formatting.hpp @@ -1,3 +1,29 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + #pragma once std::string formatBytes(int bytes); \ No newline at end of file diff --git a/include/utils/scriptHelper.hpp b/include/utils/scriptHelper.hpp new file mode 100644 index 0000000..48482c5 --- /dev/null +++ b/include/utils/scriptHelper.hpp @@ -0,0 +1,48 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#ifndef SCRIPTHELPER_HPP +#define SCRIPTHELPER_HPP + +#include + +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, std::string message); + void 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); + void extractFile(std::string file, std::string input, std::string output, std::string message); + Result createFile(const char * path); + void displayTimeMsg(std::string message, int seconds); +} + +#endif \ No newline at end of file diff --git a/include/utils/structs.hpp b/include/utils/structs.hpp index 72f2d81..7fa304a 100644 --- a/include/utils/structs.hpp +++ b/include/utils/structs.hpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index 5bf6d6a..c7b270e 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -59,7 +59,7 @@ "CREDITS": "Credits", "DEVELOPED_BY": "Developed by: Universal-Team.", - "MAIN_DEV": "Main Developer: VoltZ", + "MAIN_DEV": "Main Developer: StackZ", "CURRENT_VERSION": "Current version: ", "MANY_THANKS": "Many Thanks to:", "TRANSLATORS": "All our Translators", diff --git a/source/colors.cpp b/source/colors.cpp index 3bc8522..caef0ec 100644 --- a/source/colors.cpp +++ b/source/colors.cpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/source/download/download.cpp b/source/download/download.cpp index 3e0a903..48e6002 100644 --- a/source/download/download.cpp +++ b/source/download/download.cpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,20 +33,11 @@ #include "screens/screenCommon.hpp" #include "utils/config.hpp" -#include "utils/extract.hpp" -#include "utils/fileBrowse.h" -#include "utils/thread.hpp" #include "utils/formatting.hpp" -#include -#include #include #include -extern "C" { - #include "utils/cia.h" -} - #define USER_AGENT APP_TITLE "-" VERSION_STRING static char* result_buf = NULL; @@ -574,11 +565,11 @@ std::string getLatestCommit(std::string repo, std::string array, std::string ite return jsonItem; } -std::vector getThemeList(std::string repo, std::string path) +std::vector getList(std::string repo, std::string path) { Result ret = 0; void *socubuf = memalign(0x1000, 0x100000); - std::vector emptyVector; + std::vector emptyVector; if (!socubuf) { return emptyVector; @@ -625,27 +616,27 @@ std::vector getThemeList(std::string repo, std::string path) return emptyVector; } - std::vector jsonItems; + std::vector jsonItems; json parsedAPI = json::parse(result_buf); for(uint i=0;i getThemeList(std::string repo, std::string path) return jsonItems; } -void downloadTheme(std::string path) { - std::vector themeContents = getThemeList("Universal-Team/extras", path); - for(uint i=0;i #include @@ -53,25 +54,6 @@ std::string selectedTitle; std::string Desc = ""; nlohmann::json jsonFile; -std::string get(nlohmann::json json, const std::string &key, const std::string &key2) { - if(!json.contains(key)) return "MISSING: " + key; - if(!json.at(key).is_object()) return "NOT OBJECT: " + key; - - if(!json.at(key).contains(key2)) return "MISSING: " + key + "." + key2; - if(!json.at(key).at(key2).is_string()) return "NOT STRING: " + key + "." + key2; - - return json.at(key).at(key2).get_ref(); -} - -int getNum(nlohmann::json json, const std::string &key, const std::string &key2) { - if(!json.contains(key)) return 0; - if(!json.at(key).is_object()) return 0; - - if(!json.at(key).contains(key2)) return 0; - if(!json.at(key).at(key2).is_number()) return 0; - return json.at(key).at(key2).get_ref(); -} - Info parseInfo(std::string fileName) { FILE* file = fopen(fileName.c_str(), "rt"); if(!file) { @@ -83,9 +65,9 @@ Info parseInfo(std::string fileName) { fclose(file); Info info; - info.title = get(json, "info", "title"); - info.author = get(json, "info", "author"); - info.shortDesc = get(json, "info", "shortDesc"); + info.title = ScriptHelper::getString(json, "info", "title"); + info.author = ScriptHelper::getString(json, "info", "author"); + info.shortDesc = ScriptHelper::getString(json, "info", "shortDesc"); return info; } @@ -93,10 +75,7 @@ void checkForValidate(void) { FILE* file = fopen(currentFile.c_str(), "rt"); nlohmann::json json = nlohmann::json::parse(file, nullptr, false); fclose(file); - - std::string version; - version = get(json, "info", "version"); - int ver = getNum(json, "info", "version"); + int ver = ScriptHelper::getNum(json, "info", "version"); if (ver < SCRIPT_VERSION || ver > SCRIPT_VERSION) { Gui::DisplayWarnMsg(Lang::get("INCOMPATIBLE_SCRIPT")); } @@ -137,14 +116,6 @@ std::string Description(nlohmann::json &json) { return out; } -// Because we need `#include `. -Result createFile(const char * path) { - std::ofstream ofstream; - ofstream.open(path, std::ofstream::out | std::ofstream::app); - ofstream.close(); - return 0; -} - void runFunctions(nlohmann::json &json) { for(int i=0;i<(int)json.at(choice).size();i++) { std::string type = json.at(choice).at(i).at("type"); @@ -155,7 +126,7 @@ void runFunctions(nlohmann::json &json) { 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) download::deleteFileList(file, message); + if(!missing) ScriptHelper::removeFile(file, message); } else if(type == "downloadFile") { bool missing = false; @@ -165,7 +136,7 @@ void runFunctions(nlohmann::json &json) { 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) download::downloadFile(file, output, message); + if(!missing) ScriptHelper::downloadFile(file, output, message); } else if(type == "downloadRelease") { bool missing = false, includePrereleases = false; @@ -179,7 +150,7 @@ void runFunctions(nlohmann::json &json) { 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("message")) message = json.at(choice).at(i).at("message"); - if(!missing) download::downloadRelease(repo, file, output, includePrereleases, message); + if(!missing) ScriptHelper::downloadRelease(repo, file, output, includePrereleases, message); } else if(type == "extractFile") { bool missing = false; @@ -191,7 +162,7 @@ void runFunctions(nlohmann::json &json) { 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) download::extractFileList(file, input, output, message); + if(!missing) ScriptHelper::extractFile(file, input, output, message); } else if(type == "installCia") { bool missing = false; @@ -199,7 +170,7 @@ void runFunctions(nlohmann::json &json) { 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) download::installFileList(file, message); + if(!missing) ScriptHelper::installFile(file, message); } else if (type == "mkdir") { bool missing = false; @@ -225,7 +196,7 @@ void runFunctions(nlohmann::json &json) { std::string file; if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file"); else missing = true; - if(!missing) createFile(file.c_str()); + if(!missing) ScriptHelper::createFile(file.c_str()); } else if (type == "timeMsg") { bool missing = false; @@ -236,7 +207,7 @@ void runFunctions(nlohmann::json &json) { 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) download::displayTimeMsg(message, seconds); + if(!missing) ScriptHelper::displayTimeMsg(message, seconds); } } doneMsg(); @@ -270,25 +241,25 @@ u32 progressBar; void loadColors(nlohmann::json &json) { u32 colorTemp; - colorTemp = getColor(get(json, "info", "barColor")); + colorTemp = getColor(ScriptHelper::getString(json, "info", "barColor")); barColor = colorTemp == 0 ? Config::Color1 : colorTemp; - colorTemp = getColor(get(json, "info", "bgTopColor")); + colorTemp = getColor(ScriptHelper::getString(json, "info", "bgTopColor")); bgTopColor = colorTemp == 0 ? Config::Color2 : colorTemp; - colorTemp = getColor(get(json, "info", "bgBottomColor")); + colorTemp = getColor(ScriptHelper::getString(json, "info", "bgBottomColor")); bgBottomColor = colorTemp == 0 ? Config::Color3 : colorTemp; - colorTemp = getColor(get(json, "info", "textColor")); + colorTemp = getColor(ScriptHelper::getString(json, "info", "textColor")); TextColor = colorTemp == 0 ? Config::TxtColor : colorTemp; - colorTemp = getColor(get(json, "info", "selectedColor")); + colorTemp = getColor(ScriptHelper::getString(json, "info", "selectedColor")); selected = colorTemp == 0 ? Config::SelectedColor : colorTemp; - colorTemp = getColor(get(json, "info", "unselectedColor")); + colorTemp = getColor(ScriptHelper::getString(json, "info", "unselectedColor")); unselected = colorTemp == 0 ? Config::UnselectedColor : colorTemp; - colorTemp = getColor(get(json, "info", "progressbarColor")); + colorTemp = getColor(ScriptHelper::getString(json, "info", "progressbarColor")); progressBar = colorTemp == 0 ? Config::progressbarColor : colorTemp; } diff --git a/source/screens/settings.cpp b/source/screens/settings.cpp index 5d7b950..3877847 100644 --- a/source/screens/settings.cpp +++ b/source/screens/settings.cpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/source/screens/tinyDB.cpp b/source/screens/tinyDB.cpp index 2aaffdf..b9ccefb 100644 --- a/source/screens/tinyDB.cpp +++ b/source/screens/tinyDB.cpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ #include "utils/fileBrowse.h" #include "utils/json.hpp" #include "utils/formatting.hpp" +#include "utils/scriptHelper.hpp" #define ENTRIES_PER_SCREEN 3 #define ENTRIES_PER_LIST 7 @@ -45,7 +46,6 @@ extern C2D_SpriteSheet sprites; #define tinyDBFile "sdmc:/3ds/Universal-Updater/TinyDB.json" -extern std::string get(nlohmann::json json, const std::string &key, const std::string &key2); std::string maxEntries; // Parse the Objects. @@ -211,7 +211,7 @@ void TinyDB::execute() { if(tinyDBJson.at(selectedOption).at("script").at(i).contains("file")) file = tinyDBJson.at(selectedOption).at("script").at(i).at("file"); 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) download::deleteFileList(file, message); + if(!missing) ScriptHelper::removeFile(file, message); } else if(type == "downloadFile") { bool missing = false; @@ -221,7 +221,7 @@ void TinyDB::execute() { if(tinyDBJson.at(selectedOption).at("script").at(i).contains("output")) output = tinyDBJson.at(selectedOption).at("script").at(i).at("output"); 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) download::downloadFile(file, output, message); + if(!missing) ScriptHelper::downloadFile(file, output, message); } else if(type == "installCia") { bool missing = false; @@ -229,7 +229,7 @@ void TinyDB::execute() { if(tinyDBJson.at(selectedOption).at("script").at(i).contains("file")) file = tinyDBJson.at(selectedOption).at("script").at(i).at("file"); 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) download::installFileList(file, message); + if(!missing) ScriptHelper::installFile(file, message); } } doneMsg(); diff --git a/source/utils/config.cpp b/source/utils/config.cpp index c295ffb..cd0e9fa 100644 --- a/source/utils/config.cpp +++ b/source/utils/config.cpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/source/utils/extract.cpp b/source/utils/extract.cpp index 08cead4..3c15aa7 100644 --- a/source/utils/extract.cpp +++ b/source/utils/extract.cpp @@ -1,6 +1,6 @@ /* * This file is part of Universal-Updater -* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/source/utils/formatting.cpp b/source/utils/formatting.cpp index d9aaee6..22c25a6 100644 --- a/source/utils/formatting.cpp +++ b/source/utils/formatting.cpp @@ -1,4 +1,31 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + #include + #include "utils/formatting.hpp" // adapted from GM9i's byte parsing. diff --git a/source/utils/scriptHelper.cpp b/source/utils/scriptHelper.cpp new file mode 100644 index 0000000..ca51903 --- /dev/null +++ b/source/utils/scriptHelper.cpp @@ -0,0 +1,134 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include "gui.hpp" + +#include "download/download.hpp" + +#include "utils/extract.hpp" +#include "utils/scriptHelper.hpp" +#include "utils/thread.hpp" + +#include + +extern "C" { + #include "utils/cia.h" +} + +extern bool showProgressBar; +extern bool progressBarType; +extern char progressBarMsg[128]; +extern int filesExtracted; + +extern void downloadFailed(); + +// Get String of the Script. +std::string ScriptHelper::getString(nlohmann::json json, const std::string &key, const std::string &key2) { + if(!json.contains(key)) return "MISSING: " + key; + if(!json.at(key).is_object()) return "NOT OBJECT: " + key; + + if(!json.at(key).contains(key2)) return "MISSING: " + key + "." + key2; + if(!json.at(key).at(key2).is_string()) return "NOT STRING: " + key + "." + key2; + + return json.at(key).at(key2).get_ref(); +} + +// Get int of the Script. +int ScriptHelper::getNum(nlohmann::json json, const std::string &key, const std::string &key2) { + if(!json.contains(key)) return 0; + if(!json.at(key).is_object()) return 0; + + if(!json.at(key).contains(key2)) return 0; + if(!json.at(key).at(key2).is_number()) return 0; + return json.at(key).at(key2).get_ref(); +} + +// Download from a Github Release. +void ScriptHelper::downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, std::string message) { + snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str()); + showProgressBar = true; + progressBarType = 0; + Threads::create((ThreadFunc)displayProgressBar); + if (downloadFromRelease("https://github.com/" + repo, file, output, includePrereleases) != 0) { + showProgressBar = false; + downloadFailed(); + return; + } + showProgressBar = false; +} + +// Download a File from everywhere. +void ScriptHelper::downloadFile(std::string file, std::string output, std::string message) { + snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str()); + showProgressBar = true; + progressBarType = 0; + Threads::create((ThreadFunc)displayProgressBar); + if (downloadToFile(file, output) != 0) { + showProgressBar = false; + downloadFailed(); + return; + } + showProgressBar = false; +} + +// Remove a File. +void ScriptHelper::removeFile(std::string file, std::string message) { + DisplayMsg(message); + deleteFile(file.c_str()); +} + +// Install a file. +void ScriptHelper::installFile(std::string file, std::string message) { + DisplayMsg(message); + installCia(file.c_str()); +} + +// Extract Files. +void ScriptHelper::extractFile(std::string file, std::string input, std::string output, std::string message) { + snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str()); + showProgressBar = true; + filesExtracted = 0; + progressBarType = 1; + Threads::create((ThreadFunc)displayProgressBar); + extractArchive(file, input, output); + showProgressBar = false; +} + +// Create an empty file. +Result ScriptHelper::createFile(const char * path) { + std::ofstream ofstream; + ofstream.open(path, std::ofstream::out | std::ofstream::app); + ofstream.close(); + return 0; +} + +// Display a Message for a specific amount of time. +void ScriptHelper::displayTimeMsg(std::string message, int seconds) { + DisplayMsg(message); + for (int i = 0; i < 60*seconds; i++) { + gspWaitForVBlank(); + } +} \ No newline at end of file