mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 23:27:38 +03:00
Update recent books store paths on rename/move
This commit is contained in:
parent
da4d3b5ea5
commit
7753c71dc0
@ -104,3 +104,21 @@ bool RecentBooksStore::loadFromFile() {
|
|||||||
Serial.printf("[%lu] [RBS] Recent books loaded from file (%d entries)\n", millis(), recentBooks.size());
|
Serial.printf("[%lu] [RBS] Recent books loaded from file (%d entries)\n", millis(), recentBooks.size());
|
||||||
return true;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -32,8 +32,17 @@ class RecentBooksStore {
|
|||||||
int getCount() const { return static_cast<int>(recentBooks.size()); }
|
int getCount() const { return static_cast<int>(recentBooks.size()); }
|
||||||
|
|
||||||
bool saveToFile() const;
|
bool saveToFile() const;
|
||||||
|
|
||||||
bool loadFromFile();
|
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
|
// Helper macro to access recent books store
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user