refactor: unify book cache clearing for epub, txt, and xtc files (#1875)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#include "BookCacheUtils.h"
|
||||
|
||||
#include <Epub.h>
|
||||
#include <FsHelpers.h>
|
||||
#include <Logging.h>
|
||||
#include <Txt.h>
|
||||
#include <Xtc.h>
|
||||
|
||||
bool isBookCacheDirectoryName(const char* name) {
|
||||
if (!name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr char EPUB_PREFIX[] = "epub_";
|
||||
constexpr char TXT_PREFIX[] = "txt_";
|
||||
constexpr char XTC_PREFIX[] = "xtc_";
|
||||
|
||||
return strncmp(name, EPUB_PREFIX, std::size(EPUB_PREFIX) - 1) == 0 ||
|
||||
strncmp(name, TXT_PREFIX, std::size(TXT_PREFIX) - 1) == 0 ||
|
||||
strncmp(name, XTC_PREFIX, std::size(XTC_PREFIX) - 1) == 0;
|
||||
}
|
||||
|
||||
void clearBookCache(const std::string& path) {
|
||||
if (FsHelpers::hasEpubExtension(path)) {
|
||||
Epub(path, "/.crosspoint").clearCache();
|
||||
} else if (FsHelpers::hasXtcExtension(path)) {
|
||||
Xtc(path, "/.crosspoint").clearCache();
|
||||
} else if (FsHelpers::hasTxtExtension(path)) {
|
||||
Txt(path, "/.crosspoint").clearCache();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
LOG_DBG("BookCache", "Done checking metadata cache for: %s", path.c_str());
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// Clears the reading cache for a book file if its extension is recognised
|
||||
// (EPUB, XTC, or TXT). Does nothing for other file types.
|
||||
void clearBookCache(const std::string& path);
|
||||
|
||||
// Returns true if the directory name matches a book cache entry.
|
||||
bool isBookCacheDirectoryName(const char* name);
|
||||
Reference in New Issue
Block a user