mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 22:57:50 +03:00
## Summary * Use single unified cache file for book spine, table of contents, and core metadata (title, author, cover image) * Use new temp item store file in OPF parsing to store items to be rescaned when parsing spine * This avoids us holding these items in memory * Use new toc.bin.tmp and spine.bin.tmp to build out partial toc / spine data as part of parsing content.opf and the NCX file * These files are re-read multiple times to ultimately build book.bin ## Additional Context * Spec for file format included below as an image * This should help with: * #10 * #60 * #99
59 lines
2.1 KiB
C++
59 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
#include "Epub/BookMetadataCache.h"
|
|
|
|
class ZipFile;
|
|
|
|
class Epub {
|
|
// the ncx file
|
|
std::string tocNcxItem;
|
|
// where is the EPUBfile?
|
|
std::string filepath;
|
|
// the base path for items in the EPUB file
|
|
std::string contentBasePath;
|
|
// Uniq cache key based on filepath
|
|
std::string cachePath;
|
|
// Spine and TOC cache
|
|
std::unique_ptr<BookMetadataCache> bookMetadataCache;
|
|
|
|
bool findContentOpfFile(std::string* contentOpfFile) const;
|
|
bool parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata);
|
|
bool parseTocNcxFile() const;
|
|
static bool getItemSize(const ZipFile& zip, const std::string& itemHref, size_t* size);
|
|
|
|
public:
|
|
explicit Epub(std::string filepath, const std::string& cacheDir) : filepath(std::move(filepath)) {
|
|
// create a cache key based on the filepath
|
|
cachePath = cacheDir + "/epub_" + std::to_string(std::hash<std::string>{}(this->filepath));
|
|
}
|
|
~Epub() = default;
|
|
std::string& getBasePath() { return contentBasePath; }
|
|
bool load();
|
|
bool clearCache() const;
|
|
void setupCacheDir() const;
|
|
const std::string& getCachePath() const;
|
|
const std::string& getPath() const;
|
|
const std::string& getTitle() const;
|
|
std::string getCoverBmpPath() const;
|
|
bool generateCoverBmp() const;
|
|
uint8_t* readItemContentsToBytes(const std::string& itemHref, size_t* size = nullptr,
|
|
bool trailingNullByte = false) const;
|
|
bool readItemContentsToStream(const std::string& itemHref, Print& out, size_t chunkSize) const;
|
|
bool getItemSize(const std::string& itemHref, size_t* size) const;
|
|
BookMetadataCache::SpineEntry getSpineItem(int spineIndex) const;
|
|
BookMetadataCache::TocEntry getTocItem(int tocIndex) const;
|
|
int getSpineItemsCount() const;
|
|
int getTocItemsCount() const;
|
|
int getSpineIndexForTocIndex(int tocIndex) const;
|
|
int getTocIndexForSpineIndex(int spineIndex) const;
|
|
size_t getCumulativeSpineItemSize(int spineIndex) const;
|
|
|
|
size_t getBookSize() const;
|
|
uint8_t calculateProgress(const int currentSpineIndex, const float currentSpineRead) const;
|
|
};
|