mirror of
https://github.com/HamletDuFromage/aio-switch-updater.git
synced 2024-12-29 10:56:01 +00:00
Added way to delete cheats for a specific game
This commit is contained in:
parent
8b7c5a01f4
commit
5259a461c4
7 changed files with 37 additions and 19 deletions
|
@ -33,5 +33,6 @@ namespace extract {
|
||||||
void extractCheats(const std::string& zipPath, std::vector<std::string> titles, CFW cfw, bool credits = false);
|
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 extractAllCheats(const std::string& zipPath, CFW cfw);
|
||||||
void removeCheats();
|
void removeCheats();
|
||||||
|
bool removeCheatsDirectory(const std::string& entry);
|
||||||
bool isBID(const std::string& bid);
|
bool isBID(const std::string& bid);
|
||||||
} // namespace extract
|
} // namespace extract
|
|
@ -6,7 +6,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
namespace fs {
|
namespace fs {
|
||||||
int removeDir(const char* path);
|
bool removeDir(const std::string& path);
|
||||||
nlohmann::ordered_json parseJsonFile(const std::string& path);
|
nlohmann::ordered_json parseJsonFile(const std::string& path);
|
||||||
void writeJsonToFile(nlohmann::json& data, const std::string& path);
|
void writeJsonToFile(nlohmann::json& data, const std::string& path);
|
||||||
bool copyFile(const std::string& from, const std::string& to);
|
bool copyFile(const std::string& from, const std::string& to);
|
||||||
|
|
|
@ -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.",
|
"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 {}",
|
"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"
|
"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": {
|
"common": {
|
||||||
"downloading": "Downloading…",
|
"downloading": "Downloading…",
|
||||||
|
|
|
@ -41,7 +41,7 @@ AmsTab::AmsTab(const nlohmann::json& nxlinks, const bool erista, const bool hide
|
||||||
});
|
});
|
||||||
this->addView(listItem);
|
this->addView(listItem);
|
||||||
|
|
||||||
CreateDownloadItems(util::getValueFromKey(cfws, "DeepSea"));
|
CreateDownloadItems(util::getValueFromKey(cfws, "DeepSea"), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto custom_pack = fs::parseJsonFile(CUSTOM_PACKS_PATH);
|
auto custom_pack = fs::parseJsonFile(CUSTOM_PACKS_PATH);
|
||||||
|
|
|
@ -275,8 +275,19 @@ void AppPage_DownloadedCheats::CreateLabel()
|
||||||
|
|
||||||
void AppPage_DownloadedCheats::DeclareGameListItem(const std::string& name, u64 tid, NsApplicationControlData** controlData)
|
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->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);
|
AppPage::DeclareGameListItem(name, tid, controlData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,21 +328,25 @@ namespace extract {
|
||||||
ProgressEvent::instance().reset();
|
ProgressEvent::instance().reset();
|
||||||
ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator()));
|
ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator()));
|
||||||
for (const auto& entry : std::filesystem::directory_iterator(path)) {
|
for (const auto& entry : std::filesystem::directory_iterator(path)) {
|
||||||
std::string cheatsPath = entry.path().string() + "/cheats";
|
removeCheatsDirectory(entry.path().string());
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ProgressEvent::instance().incrementStep(1);
|
ProgressEvent::instance().incrementStep(1);
|
||||||
}
|
}
|
||||||
//std::filesystem::remove(UPDATED_TITLES_PATH);
|
|
||||||
std::filesystem::remove(CHEATS_VERSION);
|
std::filesystem::remove(CHEATS_VERSION);
|
||||||
ProgressEvent::instance().setStep(ProgressEvent::instance().getMax());
|
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
|
} // namespace extract
|
|
@ -24,13 +24,13 @@ namespace {
|
||||||
|
|
||||||
namespace fs {
|
namespace fs {
|
||||||
|
|
||||||
int removeDir(const char* path)
|
bool removeDir(const std::string& path)
|
||||||
{
|
{
|
||||||
Result ret = 0;
|
Result ret = 0;
|
||||||
FsFileSystem* fs = fsdevGetDeviceFileSystem("sdmc");
|
FsFileSystem* fs = fsdevGetDeviceFileSystem("sdmc");
|
||||||
if (R_FAILED(ret = fsFsDeleteDirectoryRecursively(fs, path)))
|
if (R_FAILED(ret = fsFsDeleteDirectoryRecursively(fs, path.c_str())))
|
||||||
return ret;
|
return false;
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::ordered_json parseJsonFile(const std::string& path)
|
nlohmann::ordered_json parseJsonFile(const std::string& path)
|
||||||
|
|
Loading…
Reference in a new issue