mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 23:27:38 +03:00
Cleanup and TODO
This commit is contained in:
parent
7d600b5ff6
commit
4c3b4f42ad
@ -131,6 +131,9 @@ bool BookMetadataCache::buildBookBin(const std::string& epubPath, const BookMeta
|
|||||||
tocFile.close();
|
tocFile.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// TODO: For large ZIPs loading the all localHeaderOffsets will crash.
|
||||||
|
// However not having them loaded is extremely slow. Need a better solution here.
|
||||||
|
// Perhaps only a cache of spine items or a better way to speedup lookups?
|
||||||
if (!zip.loadAllLocalHeaderOffsets()) {
|
if (!zip.loadAllLocalHeaderOffsets()) {
|
||||||
Serial.printf("[%lu] [BMC] Could not load zip local header offsets for size calculations\n", millis());
|
Serial.printf("[%lu] [BMC] Could not load zip local header offsets for size calculations\n", millis());
|
||||||
bookFile.close();
|
bookFile.close();
|
||||||
@ -241,6 +244,8 @@ void BookMetadataCache::createTocEntry(const std::string& title, const std::stri
|
|||||||
|
|
||||||
int spineIndex = -1;
|
int spineIndex = -1;
|
||||||
// find spine index
|
// find spine index
|
||||||
|
// TODO: This lookup is slow as need to scan through all items each time. We can't hold it all in memory due to size.
|
||||||
|
// But perhaps we can load just the hrefs in a vector/list to do an index lookup?
|
||||||
spineFile.seek(0);
|
spineFile.seek(0);
|
||||||
for (int i = 0; i < spineCount; i++) {
|
for (int i = 0; i < spineCount; i++) {
|
||||||
auto spineEntry = readSpineEntry(spineFile);
|
auto spineEntry = readSpineEntry(spineFile);
|
||||||
|
|||||||
@ -182,6 +182,8 @@ void XMLCALL ContentOpfParser::startElement(void* userData, const XML_Char* name
|
|||||||
if (strcmp(atts[i], "idref") == 0) {
|
if (strcmp(atts[i], "idref") == 0) {
|
||||||
const std::string idref = atts[i + 1];
|
const std::string idref = atts[i + 1];
|
||||||
// Resolve the idref to href using items map
|
// Resolve the idref to href using items map
|
||||||
|
// TODO: This lookup is slow as need to scan through all items each time.
|
||||||
|
// It can take up to 200ms per item when getting to 1500 items.
|
||||||
self->tempItemStore.seek(0);
|
self->tempItemStore.seek(0);
|
||||||
std::string itemId;
|
std::string itemId;
|
||||||
std::string href;
|
std::string href;
|
||||||
|
|||||||
@ -47,6 +47,9 @@ bool ZipFile::loadAllLocalHeaderOffsets() {
|
|||||||
uint32_t sig;
|
uint32_t sig;
|
||||||
char itemName[256];
|
char itemName[256];
|
||||||
|
|
||||||
|
localHeaderOffsets.clear();
|
||||||
|
localHeaderOffsets.reserve(zipDetails.totalEntries);
|
||||||
|
|
||||||
while (file.available()) {
|
while (file.available()) {
|
||||||
file.read(reinterpret_cast<uint8_t*>(&sig), 4);
|
file.read(reinterpret_cast<uint8_t*>(&sig), 4);
|
||||||
if (sig != 0x02014b50) break; // End of list
|
if (sig != 0x02014b50) break; // End of list
|
||||||
@ -77,11 +80,14 @@ bool ZipFile::loadAllLocalHeaderOffsets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ZipFile::loadLocalHeaderOffset(const char* filename, uint32_t* localHeaderOffset) {
|
bool ZipFile::loadLocalHeaderOffset(const char* filename, uint32_t* localHeaderOffset) {
|
||||||
if (localHeaderOffsets.count(filename) > 0) {
|
// If we have saved any offset, assume they're all loaded
|
||||||
*localHeaderOffset = localHeaderOffsets.at(filename);
|
if (!localHeaderOffsets.empty()) {
|
||||||
Serial.printf("[%lu] [ZIP] Found cached local header offset for file: %s (LHO: %lu)\n", millis(), filename,
|
if (localHeaderOffsets.count(filename) > 0) {
|
||||||
static_cast<unsigned long>(*localHeaderOffset));
|
*localHeaderOffset = localHeaderOffsets.at(filename);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool wasOpen = isOpen();
|
const bool wasOpen = isOpen();
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
class ZipFile {
|
class ZipFile {
|
||||||
public:
|
public:
|
||||||
@ -23,7 +23,7 @@ class ZipFile {
|
|||||||
const std::string& filePath;
|
const std::string& filePath;
|
||||||
File file;
|
File file;
|
||||||
ZipDetails zipDetails = {0, 0, false};
|
ZipDetails zipDetails = {0, 0, false};
|
||||||
std::map<std::string, uint32_t> localHeaderOffsets;
|
std::unordered_map<std::string, uint32_t> localHeaderOffsets;
|
||||||
bool loadLocalHeaderOffset(const char* filename, uint32_t* localHeaderOffset);
|
bool loadLocalHeaderOffset(const char* filename, uint32_t* localHeaderOffset);
|
||||||
|
|
||||||
bool loadFileStatSlim(const char* filename, FileStatSlim* fileStat);
|
bool loadFileStatSlim(const char* filename, FileStatSlim* fileStat);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user