| 1524 | |
| 1525 | #if !defined(DEATH_TARGET_EMSCRIPTEN) |
| 1526 | void GameEventHandler::RefreshCache() |
| 1527 | { |
| 1528 | ZoneScopedC(0x888888); |
| 1529 | |
| 1530 | if (PreferencesCache::BypassCache) { |
| 1531 | LOGI("Cache is bypassed by command-line parameter"); |
| 1532 | _flags |= Flags::IsVerified | Flags::IsPlayable; |
| 1533 | return; |
| 1534 | } |
| 1535 | |
| 1536 | constexpr std::uint64_t currentVersion = parseVersion(NCINE_VERSION_s); |
| 1537 | |
| 1538 | auto& resolver = ContentResolver::Get(); |
| 1539 | auto cachePath = fs::CombinePath(resolver.GetCachePath(), "Source.idx"_s); |
| 1540 | |
| 1541 | // Check cache state |
| 1542 | { |
| 1543 | auto s = fs::Open(cachePath, FileAccess::Read); |
| 1544 | if (s->GetSize() < 16) { |
| 1545 | goto RecreateCache; |
| 1546 | } |
| 1547 | |
| 1548 | std::uint64_t signature = s->ReadValueAsLE<std::uint64_t>(); |
| 1549 | std::uint8_t fileType = s->ReadValue<std::uint8_t>(); |
| 1550 | std::uint16_t version = s->ReadValueAsLE<std::uint16_t>(); |
| 1551 | if (signature != 0x2095A59FF0BFBBEF || fileType != ContentResolver::CacheIndexFile || version != Compatibility::JJ2Anims::CacheVersion) { |
| 1552 | goto RecreateCache; |
| 1553 | } |
| 1554 | |
| 1555 | std::uint8_t flags = s->ReadValue<std::uint8_t>(); |
| 1556 | if ((flags & 0x01) == 0x01) { |
| 1557 | // Don't overwrite cache |
| 1558 | LOGI("Cache is protected"); |
| 1559 | _flags |= Flags::IsVerified | Flags::IsPlayable; |
| 1560 | return; |
| 1561 | } |
| 1562 | |
| 1563 | String animsPath = fs::FindPathCaseInsensitive(fs::CombinePath(resolver.GetSourcePath(), "Anims.j2a"_s)); |
| 1564 | if (!fs::IsReadableFile(animsPath)) { |
| 1565 | animsPath = fs::FindPathCaseInsensitive(fs::CombinePath(resolver.GetSourcePath(), "AnimsSw.j2a"_s)); |
| 1566 | } |
| 1567 | std::int64_t animsCached = s->ReadValueAsLE<std::int64_t>(); |
| 1568 | std::int64_t animsModified = fs::GetLastModificationTime(animsPath).ToUnixMilliseconds(); |
| 1569 | if (animsModified != 0 && animsCached != animsModified) { |
| 1570 | goto RecreateCache; |
| 1571 | } |
| 1572 | |
| 1573 | // If some events were added, recreate cache |
| 1574 | std::uint16_t eventTypeCount = s->ReadValueAsLE<std::uint16_t>(); |
| 1575 | if (eventTypeCount != (std::uint16_t)EventType::Count) { |
| 1576 | goto RecreateCache; |
| 1577 | } |
| 1578 | |
| 1579 | // Cache is up-to-date |
| 1580 | std::uint64_t lastVersion = s->ReadValueAsLE<std::uint64_t>(); |
| 1581 | |
| 1582 | // Close the file, so it can be writable for possible update |
| 1583 | s = nullptr; |
nothing calls this directly
no test coverage detected