Remove missing books from recent list
This commit is contained in:
@@ -30,6 +30,8 @@ void RecentBooksStore::addBook(const std::string& path, const std::string& title
|
|||||||
int8_t bionicReadingOverride = -1;
|
int8_t bionicReadingOverride = -1;
|
||||||
int8_t paragraphAlignmentOverride = -1;
|
int8_t paragraphAlignmentOverride = -1;
|
||||||
|
|
||||||
|
pruneMissing();
|
||||||
|
|
||||||
// Remove existing entry if present
|
// Remove existing entry if present
|
||||||
auto it =
|
auto it =
|
||||||
std::find_if(recentBooks.begin(), recentBooks.end(), [&](const RecentBook& book) { return book.path == path; });
|
std::find_if(recentBooks.begin(), recentBooks.end(), [&](const RecentBook& book) { return book.path == path; });
|
||||||
@@ -66,6 +68,14 @@ void RecentBooksStore::removeBook(const std::string& path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RecentBooksStore::isMissing(const RecentBook& book) { return !Storage.exists(book.path.c_str()); }
|
||||||
|
|
||||||
|
bool RecentBooksStore::pruneMissing() {
|
||||||
|
const size_t before = recentBooks.size();
|
||||||
|
recentBooks.erase(std::remove_if(recentBooks.begin(), recentBooks.end(), &isMissing), recentBooks.end());
|
||||||
|
return recentBooks.size() != before;
|
||||||
|
}
|
||||||
|
|
||||||
void RecentBooksStore::updateBook(const std::string& path, const std::string& title, const std::string& author,
|
void RecentBooksStore::updateBook(const std::string& path, const std::string& title, const std::string& author,
|
||||||
const std::string& series, const std::string& coverBmpPath) {
|
const std::string& series, const std::string& coverBmpPath) {
|
||||||
auto it =
|
auto it =
|
||||||
|
|||||||
@@ -62,6 +62,13 @@ class RecentBooksStore {
|
|||||||
// Get the count of recent books
|
// Get the count of recent books
|
||||||
int getCount() const { return static_cast<int>(recentBooks.size()); }
|
int getCount() const { return static_cast<int>(recentBooks.size()); }
|
||||||
|
|
||||||
|
// Returns true if the book's file is missing from storage
|
||||||
|
static bool isMissing(const RecentBook& book);
|
||||||
|
|
||||||
|
// Remove entries whose backing file is no longer on the SD card.
|
||||||
|
// Returns true if any entry was removed. Does not persist — caller decides.
|
||||||
|
bool pruneMissing();
|
||||||
|
|
||||||
bool saveToFile() const;
|
bool saveToFile() const;
|
||||||
|
|
||||||
bool loadFromFile();
|
bool loadFromFile();
|
||||||
|
|||||||
@@ -168,8 +168,7 @@ void HomeActivity::loadRecentBooks(int maxBooks) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if file no longer exists
|
if (RecentBooksStore::isMissing(book)) {
|
||||||
if (!Storage.exists(book.path.c_str())) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,15 +68,7 @@ std::string gridThumbPath(const std::string& coverBmpPath, int tw, int th) {
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void RecentBooksActivity::loadRecentBooks() {
|
void RecentBooksActivity::loadRecentBooks() { recentBooks = RECENT_BOOKS.getBooks(); }
|
||||||
recentBooks.clear();
|
|
||||||
const auto& books = RECENT_BOOKS.getBooks();
|
|
||||||
recentBooks.reserve(books.size());
|
|
||||||
for (const auto& book : books) {
|
|
||||||
if (!Storage.exists(book.path.c_str())) continue;
|
|
||||||
recentBooks.push_back(book);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RecentBooksActivity::loadNextCover() {
|
bool RecentBooksActivity::loadNextCover() {
|
||||||
const Rect contentRect = UITheme::getContentRect(renderer, true, true);
|
const Rect contentRect = UITheme::getContentRect(renderer, true, true);
|
||||||
@@ -134,6 +126,10 @@ bool RecentBooksActivity::loadNextCover() {
|
|||||||
void RecentBooksActivity::onEnter() {
|
void RecentBooksActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
|
|
||||||
|
if (RECENT_BOOKS.pruneMissing()) {
|
||||||
|
RECENT_BOOKS.saveToFile();
|
||||||
|
}
|
||||||
|
|
||||||
loadRecentBooks();
|
loadRecentBooks();
|
||||||
|
|
||||||
selectorIndex = 0;
|
selectorIndex = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user