From 3cf43a5445b42c5d177b4b5f63847ef15a2985d8 Mon Sep 17 00:00:00 2001 From: flb Date: Fri, 12 Feb 2021 23:20:16 +0100 Subject: [PATCH] Added tool to automatically copy files --- Makefile | 2 +- include/app_page.hpp | 2 +- include/constants.hpp | 1 + include/current_cfw.hpp | 2 +- include/list_download_tab.hpp | 2 +- include/tools_tab.hpp | 3 +- move_files.json | 4 ++ resources/i18n/en-US/menus.json | 6 ++- source/app_page.cpp | 2 +- source/list_download_tab.cpp | 2 +- source/main.cpp | 2 +- source/tools_tab.cpp | 93 ++++++++++++++++++++++++--------- source/utils.cpp | 4 +- 13 files changed, 89 insertions(+), 36 deletions(-) create mode 100644 move_files.json diff --git a/Makefile b/Makefile index 30fe815..f8d4637 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ DATA := data INCLUDES := include lib/zipper/include APP_TITLE := All-in-One Switch Updater APP_AUTHOR := HamletDuFromage -APP_VERSION := 2.2.1 +APP_VERSION := 2.3.0 TARGET := $(notdir $(CURDIR)) ROMFS := resources diff --git a/include/app_page.hpp b/include/app_page.hpp index 446d4f3..3eafc6a 100644 --- a/include/app_page.hpp +++ b/include/app_page.hpp @@ -18,5 +18,5 @@ class AppPage : public brls::AppletFrame std::set titles; public: - AppPage(bool cheatSlips = false); + AppPage(const bool cheatSlips = false); }; \ No newline at end of file diff --git a/include/constants.hpp b/include/constants.hpp index b549cda..386fb6f 100644 --- a/include/constants.hpp +++ b/include/constants.hpp @@ -76,6 +76,7 @@ #define FW_DIRECTORY_PATH "/firmware/" #define HIDE_TABS_JSON "/config/aio-switch-updater/hide_tabs.json" +#define MOVE_FILES_JSON "/config/aio-switch-updater/move_files.json" #define ROMFS_FORWARDER "romfs:/aiosu-forwarder.nro" #define FORWARDER_PATH "/config/aio-switch-updater/aiosu-forwarder.nro" diff --git a/include/current_cfw.hpp b/include/current_cfw.hpp index 964886b..9818266 100644 --- a/include/current_cfw.hpp +++ b/include/current_cfw.hpp @@ -4,4 +4,4 @@ bool isServiceRunning(const char *serviceName); CFW getCFW(); -extern CFW running_cfw; \ No newline at end of file +const extern CFW running_cfw; \ No newline at end of file diff --git a/include/list_download_tab.hpp b/include/list_download_tab.hpp index 318102f..88ebd48 100644 --- a/include/list_download_tab.hpp +++ b/include/list_download_tab.hpp @@ -12,6 +12,6 @@ class ListDownloadTab : public brls::List brls::Label *description; brls::Label *cheatSlipLabel; public: - ListDownloadTab(archiveType type); + ListDownloadTab(const archiveType type); ~ListDownloadTab(); }; \ No newline at end of file diff --git a/include/tools_tab.hpp b/include/tools_tab.hpp index efaf9e5..50128f2 100644 --- a/include/tools_tab.hpp +++ b/include/tools_tab.hpp @@ -16,8 +16,9 @@ class ToolsTab : public brls::List brls::ListItem* language; brls::ListItem* cleanUp; brls::ListItem* hideTabs; - brls::ListItem* ntcp; + //brls::ListItem* ntcp; brls::ListItem* netSettings; + brls::ListItem* moveFiles; brls::ListItem* browser; brls::StagedAppletFrame* stagedFrame; diff --git a/move_files.json b/move_files.json new file mode 100644 index 0000000..515f170 --- /dev/null +++ b/move_files.json @@ -0,0 +1,4 @@ +{ + /* "source/path/to/file": "/destination/path/to/file", */ + "/atmosphere/reboot_payload.bin": "/bootloader/payloads/payload.bin" +} \ No newline at end of file diff --git a/resources/i18n/en-US/menus.json b/resources/i18n/en-US/menus.json index 893f348..e1842fe 100644 --- a/resources/i18n/en-US/menus.json +++ b/resources/i18n/en-US/menus.json @@ -229,7 +229,11 @@ "net_settings": "Internet settings", "go_back" : "Go back", "Confirm_button" : "Confirm", - "Cancel_button" : "Cancel" + "Cancel_button" : "Cancel", + + "tool_copyFiles": "Batch copy files", + "files_not_found": "The following files were not found and couldn't be copied:\n", + "move_files_not_found": "" diff --git a/source/app_page.cpp b/source/app_page.cpp index 4dc73ef..4e89e03 100644 --- a/source/app_page.cpp +++ b/source/app_page.cpp @@ -10,7 +10,7 @@ namespace i18n = brls::i18n; using namespace i18n::literals; -AppPage::AppPage(bool cheatSlips) : AppletFrame(true, true) +AppPage::AppPage(const bool cheatSlips) : AppletFrame(true, true) { this->setTitle(cheatSlips ? "menus/cheastlips_title"_i18n : "menus/app_title"_i18n ); list = new brls::List(); diff --git a/source/list_download_tab.cpp b/source/list_download_tab.cpp index 85662be..9aa2e88 100644 --- a/source/list_download_tab.cpp +++ b/source/list_download_tab.cpp @@ -13,7 +13,7 @@ namespace i18n = brls::i18n; using namespace i18n::literals; -ListDownloadTab::ListDownloadTab(archiveType type) : +ListDownloadTab::ListDownloadTab(const archiveType type) : brls::List() { std::vector> links; diff --git a/source/main.cpp b/source/main.cpp index 30eec1f..93104ca 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -13,7 +13,7 @@ using namespace i18n::literals; //TimeServiceType __nx_time_service_type = TimeServiceType_System; -CFW running_cfw = getCFW(); +const CFW running_cfw = getCFW(); int main(int argc, char* argv[]) { diff --git a/source/tools_tab.cpp b/source/tools_tab.cpp index f93c66f..e0526d6 100644 --- a/source/tools_tab.cpp +++ b/source/tools_tab.cpp @@ -11,12 +11,41 @@ #include "extract.hpp" #include "utils.hpp" #include "hide_tabs_page.hpp" +#include "json.hpp" #include +#include +#include namespace i18n = brls::i18n; using namespace i18n::literals; +using json = nlohmann::json; + ToolsTab::ToolsTab(std::string tag) : brls::List() { + if(!tag.empty() && tag != APP_VERSION){ + updateApp = new brls::ListItem("menus/tool_update"_i18n + tag +")"); + std::string text("menus/tool_DownLoad"_i18n + std::string(APP_URL)); + updateApp->getClickEvent()->subscribe([&, text, tag](brls::View* view) { + brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); + stagedFrame->setTitle("menus/tool_updating"_i18n ); + stagedFrame->addStage( + new ConfirmPage(stagedFrame, text) + ); + stagedFrame->addStage( + new WorkerPage(stagedFrame, "menus/tool_downloading"_i18n , [](){downloadArchive(APP_URL, app);}) + ); + stagedFrame->addStage( + new WorkerPage(stagedFrame, "menus/tool_extracting"_i18n , [tag](){extractArchive(app, tag);}) + ); + stagedFrame->addStage( + new ConfirmPage(stagedFrame, "menus/tool_all_done"_i18n , true) + ); + brls::Application::pushView(stagedFrame); + }); + updateApp->setHeight(LISTITEM_HEIGHT); + this->addView(updateApp); + } + cheats = new brls::ListItem("menus/tool_cheats"_i18n ); cheats->getClickEvent()->subscribe([&](brls::View* view){ brls::Application::pushView(new CheatsPage()); @@ -121,6 +150,45 @@ ToolsTab::ToolsTab(std::string tag) : brls::List() browser->setHeight(LISTITEM_HEIGHT); this->addView(browser); + moveFiles = new brls::ListItem("menus/tool_copyFiles"_i18n ); + moveFiles->getClickEvent()->subscribe([&](brls::View* view){ + chdir("/"); + std::string error = ""; + if(std::filesystem::exists(MOVE_FILES_JSON)){ + json toMove; + std::ifstream f(MOVE_FILES_JSON); + f >> toMove; + f.close(); + for (auto it = toMove.begin(); it != toMove.end(); ++it) { + if(std::filesystem::exists(it.key())) { + createTree(std::string(std::filesystem::path(it.value().get()).parent_path()) + "/"); + cp(it.key().c_str(), it.value().get().c_str()); + } + else { + error += it.key() + "\n"; + } + } + if(error == "") { + error = "menus/All_done"_i18n; + } + else { + error = "menus/files_not_found"_i18n + error; + } + } + else{ + error = "menus/move_files_not_found"_i18n; + } + brls::Dialog* dialog = new brls::Dialog(error); + brls::GenericEvent::Callback callback = [dialog](brls::View* view) { + dialog->close(); + }; + dialog->addButton("menus/Ok_button"_i18n , callback); + dialog->setCancelable(true); + dialog->open(); + }); + moveFiles->setHeight(LISTITEM_HEIGHT); + this->addView(moveFiles); + cleanUp = new brls::ListItem("menus/tool_cleanUp"_i18n ); cleanUp->getClickEvent()->subscribe([&](brls::View* view){ std::filesystem::remove(AMS_ZIP_PATH); @@ -152,31 +220,6 @@ ToolsTab::ToolsTab(std::string tag) : brls::List() }); hideTabs->setHeight(LISTITEM_HEIGHT); this->addView(hideTabs); - - //tag = "1.TEST" - if(!tag.empty() && tag != APP_VERSION){ - updateApp = new brls::ListItem("menus/tool_update"_i18n + tag +")"); - std::string text("menus/tool_DownLoad"_i18n + std::string(APP_URL)); - updateApp->getClickEvent()->subscribe([&, text, tag](brls::View* view) { - brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); - stagedFrame->setTitle("menus/tool_updating"_i18n ); - stagedFrame->addStage( - new ConfirmPage(stagedFrame, text) - ); - stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/tool_downloading"_i18n , [](){downloadArchive(APP_URL, app);}) - ); - stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/tool_extracting"_i18n , [tag](){extractArchive(app, tag);}) - ); - stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/tool_all_done"_i18n , true) - ); - brls::Application::pushView(stagedFrame); - }); - updateApp->setHeight(LISTITEM_HEIGHT); - this->addView(updateApp); - } changelog = new brls::ListItem("menus/tool_changelog"_i18n ); changelog->getClickEvent()->subscribe([&](brls::View* view){ diff --git a/source/utils.cpp b/source/utils.cpp index ad91e3c..b097a6f 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -63,8 +63,8 @@ void downloadArchive(std::string url, archiveType type){ downloadFile(url.c_str(), FIRMWARE_FILENAME, OFF); } else{ - showDialogBox("menus/utils_because"_i18n , "utils_ok"_i18n ); - brls::Application::pushView(new MainFrame()); + showDialogBox("menus/utils_because"_i18n , "menus/utils_ok"_i18n ); + brls::Application::popView(); } break; case app: