UI: Allow sorting saves by date too.

This commit is contained in:
Unknown W. Brackets 2018-11-25 08:21:31 -08:00
parent b8b4763ef2
commit 38461ed821
2 changed files with 28 additions and 0 deletions

View file

@ -323,6 +323,8 @@ void SavedataBrowser::SetSortOption(SavedataSortOption opt) {
gl->SetCompare(&ByFilename, &SortDone);
} else if (sortOption_ == SavedataSortOption::SIZE) {
gl->SetCompare(&BySize, &SortDone);
} else if (sortOption_ == SavedataSortOption::DATE) {
gl->SetCompare(&ByDate, &SortDone);
}
}
}
@ -345,6 +347,29 @@ bool SavedataBrowser::BySize(const UI::View *v1, const UI::View *v2) {
return g1info->gameSize > g2info->gameSize;
}
bool SavedataBrowser::ByDate(const UI::View *v1, const UI::View *v2) {
const SavedataButton *b1 = static_cast<const SavedataButton *>(v1);
const SavedataButton *b2 = static_cast<const SavedataButton *>(v2);
auto getDateSeconds = [&](const SavedataButton *b) {
std::shared_ptr<GameInfo> ginfo = g_gameInfoCache->GetInfo(nullptr, b->GamePath(), 0);
tm datetm;
bool success;
if (ginfo && ginfo->fileType == IdentifiedFileType::PSP_SAVEDATA_DIRECTORY) {
success = File::GetModifTime(b->GamePath() + "/PARAM.SFO", datetm);
} else {
success = File::GetModifTime(b->GamePath(), datetm);
}
if (success) {
return mktime(&datetm);
}
return (time_t)0;
};
return getDateSeconds(b1) > getDateSeconds(b2);
}
bool SavedataBrowser::SortDone() {
PrioritizedWorkQueue *wq = g_gameInfoCache->WorkQueue();
return wq->Done();
@ -454,6 +479,7 @@ void SavedataScreen::CreateViews() {
ChoiceStrip *sortStrip = new ChoiceStrip(ORIENT_HORIZONTAL, new AnchorLayoutParams(NONE, 0, 0, NONE));
sortStrip->AddChoice(sa->T("Filename"));
sortStrip->AddChoice(sa->T("Size"));
sortStrip->AddChoice(sa->T("Date"));
sortStrip->SetSelection((int)sortOption_);
sortStrip->OnChoice.Handle<SavedataScreen>(this, &SavedataScreen::OnSortClick);

View file

@ -29,6 +29,7 @@
enum class SavedataSortOption {
FILENAME,
SIZE,
DATE,
};
class SavedataBrowser : public UI::LinearLayout {
@ -42,6 +43,7 @@ public:
private:
static bool ByFilename(const UI::View *, const UI::View *);
static bool BySize(const UI::View *, const UI::View *);
static bool ByDate(const UI::View *, const UI::View *);
static bool SortDone();
void Refresh();