Ports upstream PR #1342 (feat: Add Book Info screen, richer metadata, and safer file-browser controls) with mod-specific adaptations: - Parse and cache series, seriesIndex, description from EPUB OPF - Bump book.bin cache version to 6 for new metadata fields - Add BookInfoActivity (new screen) accessible via Right button in FileBrowser - Add ManageBook menu via Left button in FileBrowser (replaces upstream hidden delete) - Guard all delete/archive actions with ConfirmationActivity (10 call sites) - Add inputArmed gating to ConfirmationActivity to prevent accidental confirmation - Safe deserialization: readString now returns bool with MAX_STRING_LENGTH guard - Add series field to RecentBooksStore with JSON and binary serialization - Add i18n keys: STR_BOOK_INFO, STR_AUTHOR, STR_SERIES, STR_FILE_SIZE, etc. Made-with: Cursor
60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#pragma once
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
struct RecentBook {
|
|
std::string path;
|
|
std::string title;
|
|
std::string author;
|
|
std::string series;
|
|
std::string coverBmpPath;
|
|
|
|
bool operator==(const RecentBook& other) const { return path == other.path; }
|
|
};
|
|
|
|
class RecentBooksStore;
|
|
namespace JsonSettingsIO {
|
|
bool loadRecentBooks(RecentBooksStore& store, const char* json);
|
|
} // namespace JsonSettingsIO
|
|
|
|
class RecentBooksStore {
|
|
// Static instance
|
|
static RecentBooksStore instance;
|
|
|
|
std::vector<RecentBook> recentBooks;
|
|
|
|
friend bool JsonSettingsIO::loadRecentBooks(RecentBooksStore&, const char*);
|
|
|
|
public:
|
|
~RecentBooksStore() = default;
|
|
|
|
// Get singleton instance
|
|
static RecentBooksStore& getInstance() { return instance; }
|
|
|
|
// Add a book to the recent list (moves to front if already exists)
|
|
void addBook(const std::string& path, const std::string& title, const std::string& author, const std::string& series,
|
|
const std::string& coverBmpPath);
|
|
|
|
void updateBook(const std::string& path, const std::string& title, const std::string& author,
|
|
const std::string& series, const std::string& coverBmpPath);
|
|
|
|
void removeBook(const std::string& path);
|
|
|
|
// Get the list of recent books (most recent first)
|
|
const std::vector<RecentBook>& getBooks() const { return recentBooks; }
|
|
|
|
// Get the count of recent books
|
|
int getCount() const { return static_cast<int>(recentBooks.size()); }
|
|
|
|
bool saveToFile() const;
|
|
|
|
bool loadFromFile();
|
|
RecentBook getDataFromBook(std::string path) const;
|
|
|
|
private:
|
|
bool loadFromBinaryFile();
|
|
};
|
|
|
|
// Helper macro to access recent books store
|
|
#define RECENT_BOOKS RecentBooksStore::getInstance()
|