fix: localize sleep overlay strings, validate TXT cache header, migrate overlay enum
This commit is contained in:
@@ -143,6 +143,19 @@ bool JsonSettingsIO::loadSettings(CrossPointSettings& s, const char* json, bool*
|
||||
applyLegacyStatusBarSettings(s);
|
||||
}
|
||||
|
||||
// Legacy migration: sleepCoverOverlay was a Toggle (0=off, 1=on). Now it's a 4-way Enum:
|
||||
// {WHITE(0), GRAY(1), BLACK(2), OFF(3)}. Translate old values before the generic loop clamps.
|
||||
if (!doc["sleepCoverOverlay"].isNull()) {
|
||||
uint8_t legacyOverlay = doc["sleepCoverOverlay"] | (uint8_t)0;
|
||||
if (legacyOverlay == 0) {
|
||||
s.sleepCoverOverlay = 3; // OFF
|
||||
doc["sleepCoverOverlay"] = 3;
|
||||
if (needsResave) *needsResave = true;
|
||||
} else if (legacyOverlay == 1) {
|
||||
s.sleepCoverOverlay = 1; // GRAY (old "on" = gray dither)
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& info : getSettingsList()) {
|
||||
if (!info.key) continue;
|
||||
// Dynamic entries (KOReader etc.) are stored in their own files — skip.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <GfxRenderer.h>
|
||||
#include <HalStorage.h>
|
||||
#include <I18n.h>
|
||||
#include <Serialization.h>
|
||||
#include <Txt.h>
|
||||
#include <Xtc.h>
|
||||
|
||||
@@ -155,8 +156,8 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c
|
||||
uint32_t totalPages = xtc.getPageCount();
|
||||
float progress = xtc.calculateProgress(currentPage) * 100.0f;
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "Reading progress: Page %lu/%u - %.0f%%", (unsigned long)currentPage + 1,
|
||||
totalPages, progress);
|
||||
snprintf(buf, sizeof(buf), tr(STR_OVERLAY_READING_PROGRESS), (unsigned long)currentPage + 1, totalPages,
|
||||
progress);
|
||||
info.progressText = buf;
|
||||
}
|
||||
f.close();
|
||||
@@ -176,8 +177,15 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c
|
||||
uint32_t totalPages = 0;
|
||||
FsFile indexFile;
|
||||
if (Storage.openFileForRead("SLP", txt.getCachePath() + "/index.bin", indexFile)) {
|
||||
indexFile.seek(32);
|
||||
if (indexFile.read(reinterpret_cast<uint8_t*>(&totalPages), sizeof(totalPages)) == sizeof(totalPages)) {
|
||||
uint32_t magic;
|
||||
serialization::readPod(indexFile, magic);
|
||||
uint8_t version;
|
||||
serialization::readPod(indexFile, version);
|
||||
static constexpr uint32_t INDEX_CACHE_MAGIC = 0x54585449; // "TXTI"
|
||||
static constexpr uint8_t INDEX_CACHE_VERSION = 2;
|
||||
if (magic == INDEX_CACHE_MAGIC && version == INDEX_CACHE_VERSION) {
|
||||
indexFile.seek(32);
|
||||
serialization::readPod(indexFile, totalPages);
|
||||
}
|
||||
indexFile.close();
|
||||
}
|
||||
@@ -185,12 +193,12 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c
|
||||
if (totalPages > 0) {
|
||||
float progress = (currentPage + 1) * 100.0f / totalPages;
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "Reading progress: Page %lu/%u - %.0f%%", (unsigned long)currentPage + 1,
|
||||
totalPages, progress);
|
||||
snprintf(buf, sizeof(buf), tr(STR_OVERLAY_READING_PROGRESS), (unsigned long)currentPage + 1, totalPages,
|
||||
progress);
|
||||
info.progressText = buf;
|
||||
} else {
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "Reading progress: Page %lu", (unsigned long)currentPage + 1);
|
||||
snprintf(buf, sizeof(buf), tr(STR_OVERLAY_READING_PROGRESS_NO_TOTAL), (unsigned long)currentPage + 1);
|
||||
info.progressText = buf;
|
||||
}
|
||||
}
|
||||
@@ -219,13 +227,14 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c
|
||||
const auto tocItem = epub.getTocItem(tocIndex);
|
||||
info.chapterName = tocItem.title;
|
||||
char suffix[64];
|
||||
snprintf(suffix, sizeof(suffix), " - Page %d/%d - %.0f%%", currentPage + 1, pageCount, bookProgress);
|
||||
snprintf(suffix, sizeof(suffix), tr(STR_OVERLAY_CHAPTER_PAGE_SUFFIX), currentPage + 1, pageCount,
|
||||
bookProgress);
|
||||
info.progressSuffix = suffix;
|
||||
info.progressText = "Chapter: " + info.chapterName + info.progressSuffix;
|
||||
info.progressText = std::string(tr(STR_CHAPTER_PREFIX)) + info.chapterName + info.progressSuffix;
|
||||
} else {
|
||||
char buf[80];
|
||||
snprintf(buf, sizeof(buf), "Reading progress: Page %d/%d - %.0f%%", currentPage + 1, pageCount,
|
||||
bookProgress);
|
||||
snprintf(buf, sizeof(buf), tr(STR_OVERLAY_READING_PROGRESS), (unsigned long)currentPage + 1,
|
||||
(unsigned)pageCount, bookProgress);
|
||||
info.progressText = buf;
|
||||
}
|
||||
}
|
||||
@@ -341,7 +350,7 @@ void SleepActivity::renderBitmapSleepScreen(const Bitmap& bitmap) const {
|
||||
if (hasProgress) {
|
||||
std::string progressStr;
|
||||
if (!overlayInfo.chapterName.empty()) {
|
||||
const std::string prefix = "Chapter: ";
|
||||
const std::string prefix = tr(STR_CHAPTER_PREFIX);
|
||||
const int prefixWidth = renderer.getTextWidth(UI_10_FONT_ID, prefix.c_str());
|
||||
const int suffixWidth = renderer.getTextWidth(UI_10_FONT_ID, overlayInfo.progressSuffix.c_str());
|
||||
const int maxChapterWidth = availableWidth - prefixWidth - suffixWidth;
|
||||
|
||||
Reference in New Issue
Block a user