From 7753c71dc02c505c353911282881dcd522a6ce54 Mon Sep 17 00:00:00 2001 From: zandoli Date: Thu, 29 Jan 2026 22:50:28 +0100 Subject: [PATCH] Update recent books store paths on rename/move --- src/RecentBooksStore.cpp | 18 ++++++++++++++++++ src/RecentBooksStore.h | 11 ++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/RecentBooksStore.cpp b/src/RecentBooksStore.cpp index 5932de36..cdec3b00 100644 --- a/src/RecentBooksStore.cpp +++ b/src/RecentBooksStore.cpp @@ -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(); + } +} diff --git a/src/RecentBooksStore.h b/src/RecentBooksStore.h index 7b87f1e0..3574063f 100644 --- a/src/RecentBooksStore.h +++ b/src/RecentBooksStore.h @@ -32,8 +32,17 @@ class RecentBooksStore { int getCount() const { return static_cast(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