mirror of
https://github.com/HamletDuFromage/aio-switch-updater.git
synced 2024-11-24 18:42:05 +00:00
added option to delete orphaned cheats
This commit is contained in:
parent
7295942829
commit
4656b860e8
5 changed files with 48 additions and 18 deletions
|
@ -6,10 +6,7 @@ class CheatsPage : public brls::AppletFrame
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
brls::List* list;
|
brls::List* list;
|
||||||
brls::ListItem* view;
|
brls::ListItem* item;
|
||||||
brls::ListItem* deleteCheats;
|
|
||||||
brls::ListItem* exclude;
|
|
||||||
brls::ListItem* dlAll;
|
|
||||||
brls::StagedAppletFrame* stagedFrame;
|
brls::StagedAppletFrame* stagedFrame;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -33,6 +33,7 @@ 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();
|
||||||
|
void removeOrphanedCheats();
|
||||||
bool removeCheatsDirectory(const std::string& entry);
|
bool removeCheatsDirectory(const std::string& entry);
|
||||||
bool isBID(const std::string& bid);
|
bool isBID(const std::string& bid);
|
||||||
} // namespace extract
|
} // namespace extract
|
|
@ -15,7 +15,7 @@
|
||||||
"view": "View installed cheats",
|
"view": "View installed cheats",
|
||||||
"exclude": "Exclude games from receiving cheat updates",
|
"exclude": "Exclude games from receiving cheat updates",
|
||||||
"delete_existing": "Delete all existing cheat codes",
|
"delete_existing": "Delete all existing cheat codes",
|
||||||
"delete_all": "Delete all cheats",
|
"delete_orphaned": "Delete orphaned cheat chodes",
|
||||||
"deleting": "Deleting…",
|
"deleting": "Deleting…",
|
||||||
"cheastlips_title": "Cheatslips cheats",
|
"cheastlips_title": "Cheatslips cheats",
|
||||||
"gbatemp_title": "GBAtemp cheats",
|
"gbatemp_title": "GBAtemp cheats",
|
||||||
|
|
|
@ -17,34 +17,46 @@ CheatsPage::CheatsPage() : AppletFrame(true, true)
|
||||||
this->setTitle("menus/cheats/menu"_i18n);
|
this->setTitle("menus/cheats/menu"_i18n);
|
||||||
list = new brls::List();
|
list = new brls::List();
|
||||||
|
|
||||||
view = new brls::ListItem("menus/cheats/view"_i18n);
|
item = new brls::ListItem("menus/cheats/view"_i18n);
|
||||||
view->getClickEvent()->subscribe([](brls::View* view) {
|
item->getClickEvent()->subscribe([](brls::View* view) {
|
||||||
brls::Application::pushView(new AppPage_DownloadedCheats());
|
brls::Application::pushView(new AppPage_DownloadedCheats());
|
||||||
});
|
});
|
||||||
list->addView(view);
|
list->addView(item);
|
||||||
|
|
||||||
exclude = new brls::ListItem("menus/cheats/exclude"_i18n);
|
item = new brls::ListItem("menus/cheats/exclude"_i18n);
|
||||||
exclude->getClickEvent()->subscribe([](brls::View* view) {
|
item->getClickEvent()->subscribe([](brls::View* view) {
|
||||||
brls::Application::pushView(new AppPage_Exclude());
|
brls::Application::pushView(new AppPage_Exclude());
|
||||||
});
|
});
|
||||||
list->addView(exclude);
|
list->addView(item);
|
||||||
|
|
||||||
deleteCheats = new brls::ListItem("menus/cheats/delete_existing"_i18n);
|
item = new brls::ListItem("menus/cheats/delete_existing"_i18n);
|
||||||
deleteCheats->getClickEvent()->subscribe([](brls::View* view) {
|
item->getClickEvent()->subscribe([](brls::View* view) {
|
||||||
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
|
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
|
||||||
stagedFrame->setTitle("menus/cheats/delete_all"_i18n);
|
stagedFrame->setTitle("menus/cheats/delete_existing"_i18n);
|
||||||
stagedFrame->addStage(
|
stagedFrame->addStage(
|
||||||
new WorkerPage(stagedFrame, "menus/cheats/deleting"_i18n, []() { extract::removeCheats(); }));
|
new WorkerPage(stagedFrame, "menus/cheats/deleting"_i18n, []() { extract::removeCheats(); }));
|
||||||
stagedFrame->addStage(
|
stagedFrame->addStage(
|
||||||
new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true));
|
new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true));
|
||||||
brls::Application::pushView(stagedFrame);
|
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);
|
std::string cheatsVer = util::downloadFileToString(CHEATS_URL_VERSION);
|
||||||
if (cheatsVer != "") {
|
if (cheatsVer != "") {
|
||||||
dlAll = new brls::ListItem("menus/cheats/dl_all"_i18n);
|
item = new brls::ListItem("menus/cheats/dl_all"_i18n);
|
||||||
dlAll->getClickEvent()->subscribe([cheatsVer](brls::View* view) {
|
item->getClickEvent()->subscribe([cheatsVer](brls::View* view) {
|
||||||
std::string url;
|
std::string url;
|
||||||
switch (CurrentCfw::running_cfw) {
|
switch (CurrentCfw::running_cfw) {
|
||||||
case CFW::sxos:
|
case CFW::sxos:
|
||||||
|
@ -70,7 +82,7 @@ CheatsPage::CheatsPage() : AppletFrame(true, true)
|
||||||
new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true));
|
new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true));
|
||||||
brls::Application::pushView(stagedFrame);
|
brls::Application::pushView(stagedFrame);
|
||||||
});
|
});
|
||||||
list->addView(dlAll);
|
list->addView(item);
|
||||||
}
|
}
|
||||||
this->setContentView(list);
|
this->setContentView(list);
|
||||||
}
|
}
|
|
@ -288,6 +288,26 @@ namespace extract {
|
||||||
ProgressEvent::instance().setStep(ProgressEvent::instance().getMax());
|
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 removeCheatsDirectory(const std::string& entry)
|
||||||
{
|
{
|
||||||
bool res = true;
|
bool res = true;
|
||||||
|
|
Loading…
Reference in a new issue