| 437 | } |
| 438 | |
| 439 | std::optional<uint16_t> Section::getParagraphIndexForPage(const uint16_t page) const { |
| 440 | HalFile f; |
| 441 | if (!Storage.openFileForRead("SCT", filePath, f)) { |
| 442 | return std::nullopt; |
| 443 | } |
| 444 | |
| 445 | const uint32_t fileSize = f.size(); |
| 446 | f.seek(HEADER_SIZE - sizeof(uint32_t) * 2); |
| 447 | uint32_t paragraphLutOffset; |
| 448 | serialization::readPod(f, paragraphLutOffset); |
| 449 | if (paragraphLutOffset == 0 || paragraphLutOffset >= fileSize) { |
| 450 | return std::nullopt; |
| 451 | } |
| 452 | |
| 453 | f.seek(paragraphLutOffset); |
| 454 | uint16_t count; |
| 455 | serialization::readPod(f, count); |
| 456 | if (count == 0 || page >= count) { |
| 457 | return std::nullopt; |
| 458 | } |
| 459 | |
| 460 | const uint32_t entryEnd = paragraphLutOffset + sizeof(uint16_t) + (page + 1) * sizeof(uint16_t); |
| 461 | if (entryEnd > fileSize) { |
| 462 | return std::nullopt; |
| 463 | } |
| 464 | |
| 465 | f.seek(paragraphLutOffset + sizeof(uint16_t) + page * sizeof(uint16_t)); |
| 466 | uint16_t pIdx; |
| 467 | serialization::readPod(f, pIdx); |
| 468 | return pIdx; |
| 469 | } |
| 470 | |
| 471 | std::optional<uint16_t> Section::getPageForListItemIndex(const uint16_t liIndex) const { |
| 472 | HalFile f; |
no test coverage detected