diff --git a/lib/Epub/Epub.cpp b/lib/Epub/Epub.cpp index b04c771..d959cb7 100644 --- a/lib/Epub/Epub.cpp +++ b/lib/Epub/Epub.cpp @@ -219,9 +219,11 @@ const std::string& Epub::getPath() const { return filepath; } const std::string& Epub::getTitle() const { return title; } +std::string Epub::getCoverBmpPath() const { return cachePath + "/cover.bmp"; } + bool Epub::generateCoverBmp() const { // Already generated, return true - if (SD.exists((getCachePath() + "/cover.bmp").c_str())) { + if (SD.exists(getCoverBmpPath().c_str())) { return true; } @@ -238,11 +240,16 @@ bool Epub::generateCoverBmp() const { coverJpg.close(); coverJpg = SD.open((getCachePath() + "/.cover.jpg").c_str(), FILE_READ); - File coverBmp = SD.open((getCachePath() + "/cover.bmp").c_str(), FILE_WRITE, true); + File coverBmp = SD.open(getCoverBmpPath().c_str(), FILE_WRITE, true); const bool success = JpegToBmpConverter::jpegFileToBmpStream(coverJpg, coverBmp); coverJpg.close(); coverBmp.close(); SD.remove((getCachePath() + "/.cover.jpg").c_str()); + + if (!success) { + Serial.printf("[%lu] [EBP] Failed to generate BMP from JPG cover image\n", millis()); + SD.remove(getCoverBmpPath().c_str()); + } Serial.printf("[%lu] [EBP] Generated BMP from JPG cover image, success: %s\n", millis(), success ? "yes" : "no"); return success; } else { diff --git a/lib/Epub/Epub.h b/lib/Epub/Epub.h index f11e388..381379c 100644 --- a/lib/Epub/Epub.h +++ b/lib/Epub/Epub.h @@ -48,6 +48,7 @@ class Epub { 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;