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

added option to delete orphaned cheats

This commit is contained in:
flb 2021-10-14 21:50:18 +02:00
parent 7295942829
commit 4656b860e8
5 changed files with 48 additions and 18 deletions

View file

@ -6,10 +6,7 @@ class CheatsPage : public brls::AppletFrame
{
private:
brls::List* list;
brls::ListItem* view;
brls::ListItem* deleteCheats;
brls::ListItem* exclude;
brls::ListItem* dlAll;
brls::ListItem* item;
brls::StagedAppletFrame* stagedFrame;
public:

View file

@ -33,6 +33,7 @@ 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();
void removeOrphanedCheats();
bool removeCheatsDirectory(const std::string& entry);
bool isBID(const std::string& bid);
} // namespace extract

View file

@ -15,7 +15,7 @@
"view": "View installed cheats",
"exclude": "Exclude games from receiving cheat updates",
"delete_existing": "Delete all existing cheat codes",
"delete_all": "Delete all cheats",
"delete_orphaned": "Delete orphaned cheat chodes",
"deleting": "Deleting…",
"cheastlips_title": "Cheatslips cheats",
"gbatemp_title": "GBAtemp cheats",

View file

@ -17,34 +17,46 @@ CheatsPage::CheatsPage() : AppletFrame(true, true)
this->setTitle("menus/cheats/menu"_i18n);
list = new brls::List();
view = new brls::ListItem("menus/cheats/view"_i18n);
view->getClickEvent()->subscribe([](brls::View* view) {
item = new brls::ListItem("menus/cheats/view"_i18n);
item->getClickEvent()->subscribe([](brls::View* view) {
brls::Application::pushView(new AppPage_DownloadedCheats());
});
list->addView(view);
list->addView(item);
exclude = new brls::ListItem("menus/cheats/exclude"_i18n);
exclude->getClickEvent()->subscribe([](brls::View* view) {
item = new brls::ListItem("menus/cheats/exclude"_i18n);
item->getClickEvent()->subscribe([](brls::View* view) {
brls::Application::pushView(new AppPage_Exclude());
});
list->addView(exclude);
list->addView(item);
deleteCheats = new brls::ListItem("menus/cheats/delete_existing"_i18n);
deleteCheats->getClickEvent()->subscribe([](brls::View* view) {
item = new brls::ListItem("menus/cheats/delete_existing"_i18n);
item->getClickEvent()->subscribe([](brls::View* view) {
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
stagedFrame->setTitle("menus/cheats/delete_all"_i18n);
stagedFrame->setTitle("menus/cheats/delete_existing"_i18n);
stagedFrame->addStage(
new WorkerPage(stagedFrame, "menus/cheats/deleting"_i18n, []() { extract::removeCheats(); }));
stagedFrame->addStage(
new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true));
brls::Application::pushView(stagedFrame);
});
list->addView(deleteCheats);
list->addView(item);
item = new brls::ListItem("menus/cheats/delete_orphaned"_i18n);
item->getClickEvent()->subscribe([](brls::View* view) {
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
stagedFrame->setTitle("menus/cheats/delete_orphaned"_i18n);
stagedFrame->addStage(
new WorkerPage(stagedFrame, "menus/cheats/deleting"_i18n, []() { extract::removeOrphanedCheats(); }));
stagedFrame->addStage(
new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true));
brls::Application::pushView(stagedFrame);
});
list->addView(item);
std::string cheatsVer = util::downloadFileToString(CHEATS_URL_VERSION);
if (cheatsVer != "") {
dlAll = new brls::ListItem("menus/cheats/dl_all"_i18n);
dlAll->getClickEvent()->subscribe([cheatsVer](brls::View* view) {
item = new brls::ListItem("menus/cheats/dl_all"_i18n);
item->getClickEvent()->subscribe([cheatsVer](brls::View* view) {
std::string url;
switch (CurrentCfw::running_cfw) {
case CFW::sxos:
@ -70,7 +82,7 @@ CheatsPage::CheatsPage() : AppletFrame(true, true)
new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true));
brls::Application::pushView(stagedFrame);
});
list->addView(dlAll);
list->addView(item);
}
this->setContentView(list);
}

View file

@ -288,6 +288,26 @@ namespace extract {
ProgressEvent::instance().setStep(ProgressEvent::instance().getMax());
}
void removeOrphanedCheats()
{
auto path = util::getContentsPath();
std::vector<std::string> titles = getInstalledTitlesNs();
ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator()) + 1);
for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (ProgressEvent::instance().getInterupt()) {
break;
}
if (std::find_if(titles.begin(), titles.end(), [&entry](std::string title) {
return caselessCompare(entry.path().filename(), title);
}) == titles.end()) {
removeCheatsDirectory(entry.path().string());
}
ProgressEvent::instance().incrementStep(1);
}
std::filesystem::remove(CHEATS_VERSION);
ProgressEvent::instance().setStep(ProgressEvent::instance().getMax());
}
bool removeCheatsDirectory(const std::string& entry)
{
bool res = true;