2025-12-03 22:00:29 +11:00
|
|
|
#pragma once
|
2026-02-08 21:29:14 +01:00
|
|
|
#include <HalStorage.h>
|
2025-12-23 14:14:10 +11:00
|
|
|
|
2025-12-03 22:00:29 +11:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
namespace serialization {
|
|
|
|
|
template <typename T>
|
|
|
|
|
static void writePod(std::ostream& os, const T& value) {
|
|
|
|
|
os.write(reinterpret_cast<const char*>(&value), sizeof(T));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 14:14:10 +11:00
|
|
|
template <typename T>
|
2025-12-30 15:09:30 +10:00
|
|
|
static void writePod(FsFile& file, const T& value) {
|
2025-12-23 14:14:10 +11:00
|
|
|
file.write(reinterpret_cast<const uint8_t*>(&value), sizeof(T));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 22:00:29 +11:00
|
|
|
template <typename T>
|
|
|
|
|
static void readPod(std::istream& is, T& value) {
|
|
|
|
|
is.read(reinterpret_cast<char*>(&value), sizeof(T));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 14:14:10 +11:00
|
|
|
template <typename T>
|
2025-12-30 15:09:30 +10:00
|
|
|
static void readPod(FsFile& file, T& value) {
|
2025-12-23 14:14:10 +11:00
|
|
|
file.read(reinterpret_cast<uint8_t*>(&value), sizeof(T));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 22:00:29 +11:00
|
|
|
static void writeString(std::ostream& os, const std::string& s) {
|
|
|
|
|
const uint32_t len = s.size();
|
|
|
|
|
writePod(os, len);
|
|
|
|
|
os.write(s.data(), len);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-30 15:09:30 +10:00
|
|
|
static void writeString(FsFile& file, const std::string& s) {
|
2025-12-23 14:14:10 +11:00
|
|
|
const uint32_t len = s.size();
|
|
|
|
|
writePod(file, len);
|
|
|
|
|
file.write(reinterpret_cast<const uint8_t*>(s.data()), len);
|
|
|
|
|
}
|
|
|
|
|
|
port: upstream PR #1342 - Book Info screen, richer metadata, safer controls
Ports upstream PR #1342 (feat: Add Book Info screen, richer metadata,
and safer file-browser controls) with mod-specific adaptations:
- Parse and cache series, seriesIndex, description from EPUB OPF
- Bump book.bin cache version to 6 for new metadata fields
- Add BookInfoActivity (new screen) accessible via Right button in FileBrowser
- Add ManageBook menu via Left button in FileBrowser (replaces upstream hidden delete)
- Guard all delete/archive actions with ConfirmationActivity (10 call sites)
- Add inputArmed gating to ConfirmationActivity to prevent accidental confirmation
- Safe deserialization: readString now returns bool with MAX_STRING_LENGTH guard
- Add series field to RecentBooksStore with JSON and binary serialization
- Add i18n keys: STR_BOOK_INFO, STR_AUTHOR, STR_SERIES, STR_FILE_SIZE, etc.
Made-with: Cursor
2026-03-09 00:39:32 -04:00
|
|
|
static constexpr uint32_t MAX_STRING_LENGTH = 4096;
|
|
|
|
|
|
|
|
|
|
static bool readString(std::istream& is, std::string& s) {
|
2025-12-03 22:00:29 +11:00
|
|
|
uint32_t len;
|
|
|
|
|
readPod(is, len);
|
port: upstream PR #1342 - Book Info screen, richer metadata, safer controls
Ports upstream PR #1342 (feat: Add Book Info screen, richer metadata,
and safer file-browser controls) with mod-specific adaptations:
- Parse and cache series, seriesIndex, description from EPUB OPF
- Bump book.bin cache version to 6 for new metadata fields
- Add BookInfoActivity (new screen) accessible via Right button in FileBrowser
- Add ManageBook menu via Left button in FileBrowser (replaces upstream hidden delete)
- Guard all delete/archive actions with ConfirmationActivity (10 call sites)
- Add inputArmed gating to ConfirmationActivity to prevent accidental confirmation
- Safe deserialization: readString now returns bool with MAX_STRING_LENGTH guard
- Add series field to RecentBooksStore with JSON and binary serialization
- Add i18n keys: STR_BOOK_INFO, STR_AUTHOR, STR_SERIES, STR_FILE_SIZE, etc.
Made-with: Cursor
2026-03-09 00:39:32 -04:00
|
|
|
if (len > MAX_STRING_LENGTH) return false;
|
2025-12-03 22:00:29 +11:00
|
|
|
s.resize(len);
|
|
|
|
|
is.read(&s[0], len);
|
port: upstream PR #1342 - Book Info screen, richer metadata, safer controls
Ports upstream PR #1342 (feat: Add Book Info screen, richer metadata,
and safer file-browser controls) with mod-specific adaptations:
- Parse and cache series, seriesIndex, description from EPUB OPF
- Bump book.bin cache version to 6 for new metadata fields
- Add BookInfoActivity (new screen) accessible via Right button in FileBrowser
- Add ManageBook menu via Left button in FileBrowser (replaces upstream hidden delete)
- Guard all delete/archive actions with ConfirmationActivity (10 call sites)
- Add inputArmed gating to ConfirmationActivity to prevent accidental confirmation
- Safe deserialization: readString now returns bool with MAX_STRING_LENGTH guard
- Add series field to RecentBooksStore with JSON and binary serialization
- Add i18n keys: STR_BOOK_INFO, STR_AUTHOR, STR_SERIES, STR_FILE_SIZE, etc.
Made-with: Cursor
2026-03-09 00:39:32 -04:00
|
|
|
return true;
|
2025-12-03 22:00:29 +11:00
|
|
|
}
|
2025-12-23 14:14:10 +11:00
|
|
|
|
port: upstream PR #1342 - Book Info screen, richer metadata, safer controls
Ports upstream PR #1342 (feat: Add Book Info screen, richer metadata,
and safer file-browser controls) with mod-specific adaptations:
- Parse and cache series, seriesIndex, description from EPUB OPF
- Bump book.bin cache version to 6 for new metadata fields
- Add BookInfoActivity (new screen) accessible via Right button in FileBrowser
- Add ManageBook menu via Left button in FileBrowser (replaces upstream hidden delete)
- Guard all delete/archive actions with ConfirmationActivity (10 call sites)
- Add inputArmed gating to ConfirmationActivity to prevent accidental confirmation
- Safe deserialization: readString now returns bool with MAX_STRING_LENGTH guard
- Add series field to RecentBooksStore with JSON and binary serialization
- Add i18n keys: STR_BOOK_INFO, STR_AUTHOR, STR_SERIES, STR_FILE_SIZE, etc.
Made-with: Cursor
2026-03-09 00:39:32 -04:00
|
|
|
static bool readString(FsFile& file, std::string& s) {
|
2025-12-23 14:14:10 +11:00
|
|
|
uint32_t len;
|
|
|
|
|
readPod(file, len);
|
port: upstream PR #1342 - Book Info screen, richer metadata, safer controls
Ports upstream PR #1342 (feat: Add Book Info screen, richer metadata,
and safer file-browser controls) with mod-specific adaptations:
- Parse and cache series, seriesIndex, description from EPUB OPF
- Bump book.bin cache version to 6 for new metadata fields
- Add BookInfoActivity (new screen) accessible via Right button in FileBrowser
- Add ManageBook menu via Left button in FileBrowser (replaces upstream hidden delete)
- Guard all delete/archive actions with ConfirmationActivity (10 call sites)
- Add inputArmed gating to ConfirmationActivity to prevent accidental confirmation
- Safe deserialization: readString now returns bool with MAX_STRING_LENGTH guard
- Add series field to RecentBooksStore with JSON and binary serialization
- Add i18n keys: STR_BOOK_INFO, STR_AUTHOR, STR_SERIES, STR_FILE_SIZE, etc.
Made-with: Cursor
2026-03-09 00:39:32 -04:00
|
|
|
if (len > MAX_STRING_LENGTH) return false;
|
2025-12-23 14:14:10 +11:00
|
|
|
s.resize(len);
|
2025-12-30 15:09:30 +10:00
|
|
|
file.read(&s[0], len);
|
port: upstream PR #1342 - Book Info screen, richer metadata, safer controls
Ports upstream PR #1342 (feat: Add Book Info screen, richer metadata,
and safer file-browser controls) with mod-specific adaptations:
- Parse and cache series, seriesIndex, description from EPUB OPF
- Bump book.bin cache version to 6 for new metadata fields
- Add BookInfoActivity (new screen) accessible via Right button in FileBrowser
- Add ManageBook menu via Left button in FileBrowser (replaces upstream hidden delete)
- Guard all delete/archive actions with ConfirmationActivity (10 call sites)
- Add inputArmed gating to ConfirmationActivity to prevent accidental confirmation
- Safe deserialization: readString now returns bool with MAX_STRING_LENGTH guard
- Add series field to RecentBooksStore with JSON and binary serialization
- Add i18n keys: STR_BOOK_INFO, STR_AUTHOR, STR_SERIES, STR_FILE_SIZE, etc.
Made-with: Cursor
2026-03-09 00:39:32 -04:00
|
|
|
return true;
|
2025-12-23 14:14:10 +11:00
|
|
|
}
|
2025-12-03 22:00:29 +11:00
|
|
|
} // namespace serialization
|