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
This commit is contained in:
cottongin
2026-03-09 00:39:32 -04:00
parent 255b98bda0
commit 4cf395aee9
129 changed files with 244823 additions and 248138 deletions

View File

@@ -15,6 +15,7 @@ Tracking document for upstream PRs ported into this mod.
- [PR #1320](#pr-1320-jpeg-resource-cleanup) — RAII JPEG resource cleanup (upstream)
- [PR #1322](#pr-1322-early-exit-on-filluncompressedsizes) — Early exit on fillUncompressedSizes (jpirnay)
- [PR #1325](#pr-1325-settings-tab-label) — Dynamic settings tab label (upstream)
- [PR #1342](#pr-1342-book-info-metadata-serialization-safety) — Book Info screen, richer EPUB metadata, serialization safety (upstream, adapted)
---
@@ -413,3 +414,52 @@ Inter-word gap widths were computed as two separately-snapped integers: `fp4::to
### Notable PR discussion
- CodeRabbit flagged a theoretical duplicate-match overcount issue, but znelson and ngxson approved as-is since duplicate central-directory filenames are not expected in valid EPUB/ZIP files.
---
## PR #1342: Book Info, metadata, serialization safety
- **URL:** [https://github.com/crosspoint-reader/crosspoint-reader/pull/1342](https://github.com/crosspoint-reader/crosspoint-reader/pull/1342)
- **Author:** upstream
- **Status in upstream:** Open (not yet merged)
- **Method:** Manual port with mod-specific adaptations
### Context
Upstream PR #1342 adds a Book Info screen, richer EPUB metadata (series, seriesIndex, description), bounded serialization reads, and file browser controls for accessing the new info screen. This port adapts the feature with two significant mod-specific changes: a different file browser button mapping and mandatory confirmation guards on all destructive book actions.
### Changes applied
1. **EPUB metadata expansion** (`lib/Epub/Epub/parsers/ContentOpfParser.h/.cpp`, `lib/Epub/Epub/BookMetadataCache.h/.cpp`, `lib/Epub/Epub.h/.cpp`): Added `series`, `seriesIndex`, `description` fields. Parses `dc:description`, `calibre:series`/`calibre:series_index` (OPF2), and EPUB3 `belongs-to-collection`/`group-position`. Bumped `BOOK_CACHE_VERSION` from 5 to 6. Added `stripHtml()` and `trim()` helpers for description text. Capped description at 2048 chars.
2. **Serialization safety** (`lib/Serialization/Serialization.h`): Changed both `readString` overloads from `void` to `bool`. Added `MAX_STRING_LENGTH = 4096` guard. Updated all 37 call sites across 10 files to check the return value.
3. **RecentBooksStore series field** (`src/RecentBooksStore.h/.cpp`, `src/JsonSettingsIO.cpp`): Added `series` field to `RecentBook` struct. Updated `addBook()`/`updateBook()` signatures. Updated JSON serialization and binary migration. Updated all reader call sites to pass series data.
4. **BookInfoActivity** (`src/activities/home/BookInfoActivity.h/.cpp`): New ActivityManager-compliant activity displaying title, author, series, language, file size, and description with scrollable content. Loads metadata synchronously in `onEnter()`, no background tasks.
5. **File browser controls** (`src/activities/home/FileBrowserActivity.h/.cpp`): **See mod adaptation below.**
6. **ConfirmationActivity input gating** (`src/activities/util/ConfirmationActivity.h/.cpp`): Added `inputArmed` mechanism — input is ignored until all buttons are released after dialog opens, preventing accidental confirm from the press that opened the dialog.
7. **Confirmation guards** (`HomeActivity`, `RecentBooksActivity`, `EpubReaderActivity`, `FileBrowserActivity`): All `BookManager::deleteBook()` and `BookManager::archiveBook()` calls now chain through `ConfirmationActivity` before executing. **See mod adaptation below.**
8. **i18n keys** (`lib/I18n/translations/english.yaml`): Added `STR_BOOK_INFO`, `STR_AUTHOR`, `STR_SERIES`, `STR_FILE_SIZE`, `STR_DESCRIPTION`, `STR_MANAGE`, `STR_INFO`.
9. **Recent books subtitle** (`src/activities/home/RecentBooksActivity.cpp`): List subtitle now shows "Author • Series" when series is available.
### Differences from upstream PR
- **File browser button mapping (mod-adapted):**
| Button | Upstream | Mod |
|--------|----------|-----|
| Back short | parent dir / home | parent dir / home |
| Back long | home | home |
| Confirm short | open | open |
| Confirm long | no-op | no-op |
| Left short | (unused) | **open ManageBook menu** |
| Left long | delete (hidden) | (no action) |
| Right short | Book Info | Book Info |
The upstream PR hid the delete action behind a long-press of the Left button. The mod instead exposes the full ManageBook menu (archive, delete, reindex, etc.) via a short-press of Left, consistent with the ManageBook menu available from the Home screen and reader.
- **Confirmation guards (mod-specific addition):** The upstream PR does not add confirmation dialogs for destructive actions. The mod wraps all 10 delete/archive call sites across `HomeActivity`, `RecentBooksActivity`, `EpubReaderActivity`, and `FileBrowserActivity` in `ConfirmationActivity` chains using ActivityManager's safe `startActivityForResult` chaining pattern.
- **No upstream file deletion in browser:** Upstream's file browser had a direct `Storage.remove()` delete path. The mod replaces this entirely with the ManageBook menu which routes through `BookManager` (proper cache cleanup, recents removal, etc.).
### Notable upstream PR discussion
- The upstream PR went through multiple review rounds with CodeRabbit, addressing bounded string appending in description parsing, first-description guards, proper HTML tag heuristics, and inputArmed timing.