1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-08 11:31:43 +00:00

Added way to delete cheats for a specific game

This commit is contained in:
flb 2021-09-21 15:07:47 +02:00
parent 8b7c5a01f4
commit 5259a461c4
7 changed files with 37 additions and 19 deletions

View file

@ -33,5 +33,6 @@ namespace extract {
void extractCheats(const std::string& zipPath, std::vector<std::string> 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

View file

@ -6,7 +6,7 @@
#include <set>
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);

View file

@ -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…",

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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

View file

@ -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)