diff --git a/include/extract.hpp b/include/extract.hpp index f8dc754..5a827eb 100644 --- a/include/extract.hpp +++ b/include/extract.hpp @@ -33,5 +33,6 @@ namespace extract { void extractCheats(const std::string& zipPath, std::vector titles, CFW cfw, bool credits = false); void extractAllCheats(const std::string& zipPath, CFW cfw); void removeCheats(); + bool removeCheatsDirectory(const std::string& entry); bool isBID(const std::string& bid); } // namespace extract \ No newline at end of file diff --git a/include/fs.hpp b/include/fs.hpp index f95173f..b282481 100644 --- a/include/fs.hpp +++ b/include/fs.hpp @@ -6,7 +6,7 @@ #include namespace fs { - int removeDir(const char* path); + bool removeDir(const std::string& path); nlohmann::ordered_json parseJsonFile(const std::string& path); void writeJsonToFile(nlohmann::json& data, const std::string& path); bool copyFile(const std::string& from, const std::string& to); diff --git a/resources/i18n/en-US/menus.json b/resources/i18n/en-US/menus.json index d159f84..0250a21 100644 --- a/resources/i18n/en-US/menus.json +++ b/resources/i18n/en-US/menus.json @@ -43,7 +43,9 @@ "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", - "show_existing": "Show existing" + "show_existing": "Show existing", + "delete_cheats": "Delete cheats for this game", + "deletion_error": "Couldn't delete the cheat files for game with id:\n{}" }, "common": { "downloading": "Downloading…", diff --git a/source/ams_tab.cpp b/source/ams_tab.cpp index 0f5b944..18d461a 100644 --- a/source/ams_tab.cpp +++ b/source/ams_tab.cpp @@ -41,7 +41,7 @@ AmsTab::AmsTab(const nlohmann::json& nxlinks, const bool erista, const bool hide }); this->addView(listItem); - CreateDownloadItems(util::getValueFromKey(cfws, "DeepSea")); + CreateDownloadItems(util::getValueFromKey(cfws, "DeepSea"), false); } auto custom_pack = fs::parseJsonFile(CUSTOM_PACKS_PATH); diff --git a/source/app_page.cpp b/source/app_page.cpp index 80be6f5..55519d8 100644 --- a/source/app_page.cpp +++ b/source/app_page.cpp @@ -275,8 +275,19 @@ void AppPage_DownloadedCheats::CreateLabel() void AppPage_DownloadedCheats::DeclareGameListItem(const std::string& name, u64 tid, NsApplicationControlData** controlData) { - if (titles.find(util::formatApplicationId(tid)) != titles.end()) { + auto tid_str = util::formatApplicationId(tid); + if (titles.find(tid_str) != titles.end()) { listItem->getClickEvent()->subscribe([this, tid, name](brls::View* view) { show_cheats::ShowCheatFiles(tid, name); }); + listItem->registerAction("menus/cheats/delete_cheats"_i18n, brls::Key::Y, [this, tid_str] { + brls::Dialog* dialog = new brls::Dialog(extract::removeCheatsDirectory(fmt::format("{}{}", util::getContentsPath(), tid_str)) ? "menus/common/all_done"_i18n : fmt::format("menus/cheats/deletion_error"_i18n, tid_str)); + brls::GenericEvent::Callback callback = [dialog](brls::View* view) { + dialog->close(); + }; + dialog->addButton("menus/common/ok"_i18n, callback); + dialog->setCancelable(true); + dialog->open(); + return true; + }); AppPage::DeclareGameListItem(name, tid, controlData); } } diff --git a/source/extract.cpp b/source/extract.cpp index 97641cc..fa5f6a9 100644 --- a/source/extract.cpp +++ b/source/extract.cpp @@ -328,21 +328,25 @@ namespace extract { ProgressEvent::instance().reset(); ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator())); for (const auto& entry : std::filesystem::directory_iterator(path)) { - std::string cheatsPath = entry.path().string() + "/cheats"; - if (std::filesystem::exists(cheatsPath)) { - for (const auto& cheat : std::filesystem::directory_iterator(cheatsPath)) { - std::filesystem::remove(cheat); - } - rmdir(cheatsPath.c_str()); - if (std::filesystem::is_empty(entry)) { - rmdir(entry.path().string().c_str()); - } - } + removeCheatsDirectory(entry.path().string()); ProgressEvent::instance().incrementStep(1); } - //std::filesystem::remove(UPDATED_TITLES_PATH); std::filesystem::remove(CHEATS_VERSION); ProgressEvent::instance().setStep(ProgressEvent::instance().getMax()); } + bool removeCheatsDirectory(const std::string& entry) + { + bool res = true; + std::string cheatsPath = fmt::format("{}/cheats", entry); + if (std::filesystem::exists(cheatsPath)) { + res &= fs::removeDir(cheatsPath); + if (std::filesystem::is_empty(entry)) { + res &= fs::removeDir(entry); + } + return res; + } + return false; + } + } // namespace extract \ No newline at end of file diff --git a/source/fs.cpp b/source/fs.cpp index 74fa847..87849d9 100644 --- a/source/fs.cpp +++ b/source/fs.cpp @@ -24,13 +24,13 @@ namespace { namespace fs { - int removeDir(const char* path) + bool removeDir(const std::string& path) { Result ret = 0; FsFileSystem* fs = fsdevGetDeviceFileSystem("sdmc"); - if (R_FAILED(ret = fsFsDeleteDirectoryRecursively(fs, path))) - return ret; - return 0; + if (R_FAILED(ret = fsFsDeleteDirectoryRecursively(fs, path.c_str()))) + return false; + return true; } nlohmann::ordered_json parseJsonFile(const std::string& path)