A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Version section bin files

+31 -20
+24 -14
lib/Epub/Epub/Section.cpp
··· 7 7 8 8 #include "EpubHtmlParserSlim.h" 9 9 #include "Page.h" 10 + #include "Serialization.h" 11 + 12 + constexpr uint8_t SECTION_FILE_VERSION = 2; 10 13 11 14 void Section::onPageComplete(const Page* page) { 12 15 Serial.printf("Page %d complete - free mem: %lu\n", pageCount, ESP.getFreeHeap()); ··· 21 24 delete page; 22 25 } 23 26 24 - bool Section::hasCache() { 27 + void Section::writeCacheMetadata() const { 28 + std::ofstream outputFile(("/sd" + cachePath + "/section.bin").c_str()); 29 + serialization::writePod(outputFile, SECTION_FILE_VERSION); 30 + serialization::writePod(outputFile, pageCount); 31 + outputFile.close(); 32 + } 33 + 34 + bool Section::loadCacheMetadata() { 25 35 if (!SD.exists(cachePath.c_str())) { 26 36 return false; 27 37 } ··· 31 41 return false; 32 42 } 33 43 34 - File sectionFile = SD.open(sectionFilePath.c_str(), FILE_READ); 35 - uint8_t pageCountBytes[2] = {0, 0}; 36 - sectionFile.read(pageCountBytes, 2); 37 - sectionFile.close(); 38 - 39 - pageCount = pageCountBytes[0] + (pageCountBytes[1] << 8); 44 + std::ifstream inputFile(("/sd" + sectionFilePath).c_str()); 45 + uint8_t version; 46 + serialization::readPod(inputFile, version); 47 + if (version != SECTION_FILE_VERSION) { 48 + inputFile.close(); 49 + SD.remove(sectionFilePath.c_str()); 50 + Serial.printf("Section state file: Unknown version %u\n", version); 51 + return false; 52 + } 53 + serialization::readPod(inputFile, pageCount); 54 + inputFile.close(); 40 55 Serial.printf("Loaded cache: %d pages\n", pageCount); 41 - 42 56 return true; 43 57 } 44 58 ··· 86 100 return false; 87 101 } 88 102 89 - File sectionFile = SD.open((cachePath + "/section.bin").c_str(), FILE_WRITE, true); 90 - const uint8_t pageCountBytes[2] = {static_cast<uint8_t>(pageCount & 0xFF), 91 - static_cast<uint8_t>((pageCount >> 8) & 0xFF)}; 92 - sectionFile.write(pageCountBytes, 2); 93 - sectionFile.close(); 103 + writeCacheMetadata(); 94 104 95 105 return true; 96 106 } 97 107 98 - void Section::renderPage() { 108 + void Section::renderPage() const { 99 109 if (0 <= currentPage && currentPage < pageCount) { 100 110 const auto filePath = "/sd" + cachePath + "/page_" + std::to_string(currentPage) + ".bin"; 101 111 std::ifstream inputFile(filePath);
+3 -2
lib/Epub/Epub/Section.h
··· 21 21 cachePath = epub->getCachePath() + "/" + std::to_string(spineIndex); 22 22 } 23 23 ~Section() = default; 24 - bool hasCache(); 24 + void writeCacheMetadata() const; 25 + bool loadCacheMetadata(); 25 26 void setupCacheDir() const; 26 27 void clearCache() const; 27 28 bool persistPageDataToSD(); 28 - void renderPage(); 29 + void renderPage() const; 29 30 };
+3 -3
src/CrossPointState.cpp
··· 6 6 7 7 #include <fstream> 8 8 9 - constexpr uint8_t STATE_VERSION = 1; 9 + constexpr uint8_t STATE_FILE_VERSION = 1; 10 10 constexpr char STATE_FILE[] = "/sd/.crosspoint/state.bin"; 11 11 12 12 bool CrossPointState::saveToFile() const { 13 13 std::ofstream outputFile(STATE_FILE); 14 - serialization::writePod(outputFile, STATE_VERSION); 14 + serialization::writePod(outputFile, STATE_FILE_VERSION); 15 15 serialization::writeString(outputFile, openEpubPath); 16 16 outputFile.close(); 17 17 return true; ··· 22 22 23 23 uint8_t version; 24 24 serialization::readPod(inputFile, version); 25 - if (version != STATE_VERSION) { 25 + if (version != STATE_FILE_VERSION) { 26 26 Serial.printf("CrossPointState: Unknown version %u\n", version); 27 27 inputFile.close(); 28 28 return false;
+1 -1
src/screens/EpubReaderScreen.cpp
··· 148 148 const auto filepath = epub->getSpineItem(currentSpineIndex); 149 149 Serial.printf("Loading file: %s, index: %d\n", filepath.c_str(), currentSpineIndex); 150 150 section = new Section(epub, currentSpineIndex, renderer); 151 - if (!section->hasCache()) { 151 + if (!section->loadCacheMetadata()) { 152 152 Serial.println("Cache not found, building..."); 153 153 154 154 {