Consolidate cache directories

This commit is contained in:
jpirnay
2026-05-13 22:10:13 +02:00
parent 4d5413fd5c
commit 776728d8e8
7 changed files with 47 additions and 20 deletions
@@ -65,9 +65,8 @@ std::string findUniquePathWithSuffix(const std::string& basePath) {
std::string findUniqueCompletedSidecarPath(const std::string& basePath) { return findUniquePathWithSuffix(basePath); }
std::string convertSidecarToBmp(const std::string& bookPath, const std::string& sidecarPath, int width, int height,
std::string convertSidecarToBmp(const std::string& cacheDir, const std::string& sidecarPath, int width, int height,
const std::string& fileName) {
const std::string cacheDir = "/.crosspoint/sidecar_" + std::to_string(std::hash<std::string>{}(bookPath));
if (!Storage.exists(cacheDir.c_str())) {
Storage.mkdir(cacheDir.c_str());
}
@@ -120,7 +119,7 @@ std::string getSidecarCoverBmpPath(const std::string& bookPath, int width, int h
}
const std::string fileName = "thumb_" + std::to_string(width) + "x" + std::to_string(height) + ".bmp";
return convertSidecarToBmp(bookPath, sidecarPath, width, height, fileName);
return convertSidecarToBmp(ReaderActivity::bookCacheDir(bookPath), sidecarPath, width, height, fileName);
}
bool moveSidecarFilesToCompleted(const std::string& currentBookPath, const std::string& targetBookPath) {
+6
View File
@@ -71,6 +71,12 @@ std::string ReaderActivity::sidecarCoverPath(const std::string& bookPath) {
return "";
}
std::string ReaderActivity::bookCacheDir(const std::string& bookPath) {
if (FsHelpers::hasEpubExtension(bookPath)) return Epub(bookPath, "/.crosspoint").getCachePath();
if (FsHelpers::hasXtcExtension(bookPath)) return Xtc(bookPath, "/.crosspoint").getCachePath();
return Txt(bookPath, "/.crosspoint").getCachePath();
}
std::unique_ptr<Epub> ReaderActivity::loadEpub(const std::string& path) {
if (!Storage.exists(path.c_str())) {
LOG_ERR("READER", "File does not exist: %s", path.c_str());
+1
View File
@@ -31,6 +31,7 @@ class ReaderActivity final : public Activity {
public:
static std::string sidecarCoverPath(const std::string& bookPath);
static std::string bookCacheDir(const std::string& bookPath);
explicit ReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string initialBookPath)
: Activity("Reader", renderer, mappedInput), initialBookPath(std::move(initialBookPath)) {}