| 58 | } |
| 59 | |
| 60 | std::string Txt::findCoverImage() const { |
| 61 | // Get the folder containing the txt file |
| 62 | size_t lastSlash = filepath.find_last_of('/'); |
| 63 | std::string folder = (lastSlash != std::string::npos) ? filepath.substr(0, lastSlash) : ""; |
| 64 | if (folder.empty()) { |
| 65 | folder = "/"; |
| 66 | } |
| 67 | |
| 68 | // Get the base filename without extension (e.g., "mybook" from "/books/mybook.txt") |
| 69 | std::string baseName = getTitle(); |
| 70 | |
| 71 | // Image extensions to try |
| 72 | const char* extensions[] = {".bmp", ".jpg", ".jpeg", ".png", ".BMP", ".JPG", ".JPEG", ".PNG"}; |
| 73 | |
| 74 | // First priority: look for image with same name as txt file (e.g., mybook.jpg) |
| 75 | for (const auto& ext : extensions) { |
| 76 | std::string coverPath = folder + "/" + baseName + ext; |
| 77 | if (Storage.exists(coverPath.c_str())) { |
| 78 | LOG_DBG("TXT", "Found matching cover image: %s", coverPath.c_str()); |
| 79 | return coverPath; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // Fallback: look for cover image files |
| 84 | const char* coverNames[] = {"cover", "Cover", "COVER"}; |
| 85 | for (const auto& name : coverNames) { |
| 86 | for (const auto& ext : extensions) { |
| 87 | std::string coverPath = folder + "/" + std::string(name) + ext; |
| 88 | if (Storage.exists(coverPath.c_str())) { |
| 89 | LOG_DBG("TXT", "Found fallback cover image: %s", coverPath.c_str()); |
| 90 | return coverPath; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return ""; |
| 96 | } |
| 97 | |
| 98 | std::string Txt::getCoverBmpPath() const { return cachePath + "/cover.bmp"; } |
| 99 | |