diff --git a/Makefile b/Makefile index 20b7dfc..2bb2ed9 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ DATA := data INCLUDES := include lib/zipper/include /lib/borealis/library/include/borealis/extern/nlohmann APP_TITLE := All-in-One Switch Updater APP_AUTHOR := HamletDuFromage -APP_VERSION := 2.11.0 +APP_VERSION := 2.11.1 TARGET := $(notdir $(CURDIR)) ROMFS := resources diff --git a/include/app_page.hpp b/include/app_page.hpp index 49b647b..02f57d1 100644 --- a/include/app_page.hpp +++ b/include/app_page.hpp @@ -73,8 +73,6 @@ class AppPage_DownloadedCheats : public AppPage void CreateLabel() override; void DeclareGameListItem(const std::string& name, uint64_t tid, NsApplicationControlData **controlData) override; void GetExistingCheatsTids(); - void ShowCheatFiles(uint64_t tid, const std::string& name); - bool CreateCheatList(const std::filesystem::path& path, brls::TabFrame** appView); public: AppPage_DownloadedCheats(); diff --git a/include/download_cheats_page.hpp b/include/download_cheats_page.hpp index 33397cf..ae7d1ae 100644 --- a/include/download_cheats_page.hpp +++ b/include/download_cheats_page.hpp @@ -3,6 +3,14 @@ #include #include #include +#include + +namespace show_cheats { + + void ShowCheatFiles(uint64_t tid, const std::string& name); + bool CreateCheatList(const std::filesystem::path& path, brls::TabFrame** appView); + +} class DownloadCheatsPage : public brls::AppletFrame { diff --git a/resources/i18n/en-US/menus.json b/resources/i18n/en-US/menus.json index 57bc5b7..37f27f1 100644 --- a/resources/i18n/en-US/menus.json +++ b/resources/i18n/en-US/menus.json @@ -42,7 +42,8 @@ "gbatemp_dl_successful_dl": "Successfully downloaded the following cheat code:\n{}", "applet_mode_not_supported": "Due to memory constraints, in applet mode you may only fetch cheat codes for the game you're currently playing. Please launch aio-switch-updater through title redirection to download cheat codes for any game you own.", "cheatfile_label": "Here are the cheat codes listed in file {}", - "not_found": "No proper cheat codes could be found for this game" + "not_found": "No proper cheat codes could be found for this game", + "show_existing": "Show existing" }, "common": { "downloading": "Downloading...", diff --git a/source/app_page.cpp b/source/app_page.cpp index 0789111..229f4b4 100644 --- a/source/app_page.cpp +++ b/source/app_page.cpp @@ -277,7 +277,7 @@ void AppPage_DownloadedCheats::CreateLabel() void AppPage_DownloadedCheats::DeclareGameListItem(const std::string& name, u64 tid, NsApplicationControlData **controlData) { if (titles.find(util::formatApplicationId(tid)) != titles.end()) { - listItem->getClickEvent()->subscribe([this, tid, name](brls::View* view) { ShowCheatFiles(tid, name); }); + listItem->getClickEvent()->subscribe([this, tid, name](brls::View* view) { show_cheats::ShowCheatFiles(tid, name); }); AppPage::DeclareGameListItem(name, tid, controlData); } } @@ -297,53 +297,3 @@ void AppPage_DownloadedCheats::GetExistingCheatsTids() { } } -void AppPage_DownloadedCheats::ShowCheatFiles(u64 tid, const std::string& name) { - std::string path = util::getContentsPath(); - path += util::formatApplicationId(tid) + "/cheats/"; - - brls::TabFrame* appView = new brls::TabFrame(); - bool is_populated = false; - if(std::filesystem::exists(path)) { - for(const auto& cheatFile : std::filesystem::directory_iterator(path)){ - is_populated |= CreateCheatList(cheatFile.path(), &appView); - } - } - if(is_populated) { - brls::PopupFrame::open(name, appView, ""); - } - else { - brls::Dialog* dialog = new brls::Dialog("menus/cheats/not_found"_i18n); - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); - } -} - -bool AppPage_DownloadedCheats::CreateCheatList(const std::filesystem::path& path, brls::TabFrame** appView) { - bool res = false; - brls::List* cheatsList = new brls::List(); - if(extract::isBID(path.filename().stem())) { - cheatsList->addView(new brls::Label(brls::LabelStyle::DESCRIPTION, fmt::format("menus/cheats/cheatfile_label"_i18n, path.filename().string()), true)); - - std::string str; - std::regex cheats_expr(R"(\[.+\])"); - std::ifstream in(path); - if(in) { - while (std::getline(in, str)) { - if(str.size() > 0) { - if(std::regex_search(str, cheats_expr)) { - cheatsList->addView(new brls::ListItem(str)); - res = true; - } - } - } - } - } - if(res) { - (*appView)->addTab(util::upperCase(path.filename().stem()), cheatsList); - } - return res; -} \ No newline at end of file diff --git a/source/changelog_page.cpp b/source/changelog_page.cpp index 9bca656..366d2a3 100644 --- a/source/changelog_page.cpp +++ b/source/changelog_page.cpp @@ -181,6 +181,9 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true) verTitles.push_back("v2.11.0"); changes.push_back("\uE016 Borealis changes for visual tweaks (tickering labels, scroll bar etc).\n\uE016 When needed, issue a warning about custom themes after downloading a new firmware.\n\uE016 Abort AMS update process for Mariko Switches when payload.bin cannot be found."); + verTitles.push_back("v2.11.1"); + changes.push_back("\uE016 Added ability to view existing cheats when downloading cheat codes/sheets.\n\uE016 Fixed wrong tid for theme detection."); + for(int i = verTitles.size() -1 ; i >= 0; i--){ listItem = new brls::ListItem(verTitles[i]); change = changes[i]; diff --git a/source/download_cheats_page.cpp b/source/download_cheats_page.cpp index 1a2e585..793b1f6 100644 --- a/source/download_cheats_page.cpp +++ b/source/download_cheats_page.cpp @@ -12,13 +12,71 @@ namespace i18n = brls::i18n; using namespace i18n::literals; using json = nlohmann::json; +namespace show_cheats { + +void ShowCheatFiles(u64 tid, const std::string& name) { + std::string path = util::getContentsPath(); + path += util::formatApplicationId(tid) + "/cheats/"; + + brls::TabFrame* appView = new brls::TabFrame(); + bool is_populated = false; + if(std::filesystem::exists(path)) { + for(const auto& cheatFile : std::filesystem::directory_iterator(path)){ + is_populated |= CreateCheatList(cheatFile.path(), &appView); + } + } + if(is_populated) { + brls::PopupFrame::open(name, appView, ""); + } + else { + brls::Dialog* dialog = new brls::Dialog("menus/cheats/not_found"_i18n); + brls::GenericEvent::Callback callback = [dialog](brls::View* view) { + dialog->close(); + }; + dialog->addButton("menus/common/ok"_i18n, callback); + dialog->setCancelable(true); + dialog->open(); + } +} + +bool CreateCheatList(const std::filesystem::path& path, brls::TabFrame** appView) { + bool res = false; + brls::List* cheatsList = new brls::List(); + if(extract::isBID(path.filename().stem())) { + cheatsList->addView(new brls::Label(brls::LabelStyle::DESCRIPTION, fmt::format("menus/cheats/cheatfile_label"_i18n, path.filename().string()), true)); + + std::string str; + std::regex cheats_expr(R"(\[.+\])"); + std::ifstream in(path); + if(in) { + while (std::getline(in, str)) { + if(str.size() > 0) { + if(std::regex_search(str, cheats_expr)) { + cheatsList->addView(new brls::ListItem(str)); + res = true; + } + } + } + } + } + if(res) { + (*appView)->addTab(util::upperCase(path.filename().stem()), cheatsList); + } + return res; +} +} + DownloadCheatsPage::DownloadCheatsPage(uint64_t tid, const std::string& name) : AppletFrame(true, true), tid(tid) { list = new brls::List(); GetVersion(); GetBuildID(); this->setTitle(name); - this->setFooterText("Game version: v" + std::to_string(this->version / 0x10000)); + this->setFooterText("v" + std::to_string(this->version / 0x10000)); + this->registerAction("menus/cheats/show_existing"_i18n , brls::Key::X, [this, tid, name] { + show_cheats::ShowCheatFiles(tid, name); + return true; + }); } void DownloadCheatsPage::GetBuildID() { diff --git a/source/list_download_tab.cpp b/source/list_download_tab.cpp index 1b6d6a2..5dbce22 100644 --- a/source/list_download_tab.cpp +++ b/source/list_download_tab.cpp @@ -99,16 +99,19 @@ ListDownloadTab::ListDownloadTab(const archiveType type) : new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [type](){util::extractArchive(type);}) ); std::string doneMsg = "menus/common/all_done"_i18n; - std::string themePath; + std::string contentsPath; switch(type){ case archiveType::ams_cfw: case archiveType::app: case archiveType::cfw: case archiveType::cheats: case archiveType::fw: - themePath = util::getContentsPath() + "0100000000010000"; - if(std::filesystem::exists(themePath) && !std::filesystem::is_empty(themePath)) { - doneMsg += "\n" + "menus/main/theme_warning"_i18n; + contentsPath = util::getContentsPath(); + for (const auto& tid : {"0100000000001000", "0100000000001007", "0100000000001013"}) { + if(std::filesystem::exists(contentsPath + tid) && !std::filesystem::is_empty(contentsPath + tid)) { + doneMsg += "\n" + "menus/main/theme_warning"_i18n; + break; + } } break; case archiveType::sigpatches: