Update recent books store paths on rename/move

This commit is contained in:
zandoli 2026-01-29 22:50:28 +01:00
parent da4d3b5ea5
commit 7753c71dc0
2 changed files with 28 additions and 1 deletions

View File

@ -104,3 +104,21 @@ bool RecentBooksStore::loadFromFile() {
Serial.printf("[%lu] [RBS] Recent books loaded from file (%d entries)\n", millis(), recentBooks.size());
return true;
}
void RecentBooksStore::updatePath(const std::string& oldPath, const std::string& newPath) {
bool changed = false;
for (auto& book : recentBooks) {
if (book.path == oldPath) {
book.path = newPath;
changed = true;
} else if (book.path.find(oldPath + "/") == 0) {
// It's a directory move/rename
book.path = newPath + book.path.substr(oldPath.length());
changed = true;
}
}
if (changed) {
saveToFile();
}
}

View File

@ -32,8 +32,17 @@ class RecentBooksStore {
int getCount() const { return static_cast<int>(recentBooks.size()); }
bool saveToFile() const;
bool loadFromFile();
/**
* Update the path of a book in the recent list.
* Useful when moving/renaming files or entire directories.
* If oldPath is a directory, all books within will have their paths updated.
*
* @param oldPath Original absolute path
* @param newPath New absolute path
*/
void updatePath(const std::string& oldPath, const std::string& newPath);
};
// Helper macro to access recent books store