| 506 | } |
| 507 | |
| 508 | bool GameList::LoadEntriesFromCache(std::FILE* stream) |
| 509 | { |
| 510 | u32 file_signature, file_version; |
| 511 | s64 start_pos, file_size; |
| 512 | if (!ReadU32(stream, &file_signature) || !ReadU32(stream, &file_version) || file_signature != GAME_LIST_CACHE_SIGNATURE || |
| 513 | file_version != GAME_LIST_CACHE_VERSION || (start_pos = FileSystem::FTell64(stream)) < 0 || |
| 514 | FileSystem::FSeek64(stream, 0, SEEK_END) != 0 || (file_size = FileSystem::FTell64(stream)) < 0 || |
| 515 | FileSystem::FSeek64(stream, start_pos, SEEK_SET) != 0) |
| 516 | { |
| 517 | Console.Warning("Game list cache is corrupted"); |
| 518 | return false; |
| 519 | } |
| 520 | |
| 521 | while (FileSystem::FTell64(stream) != file_size) |
| 522 | { |
| 523 | std::string path; |
| 524 | GameList::Entry ge; |
| 525 | |
| 526 | u8 type; |
| 527 | u8 region; |
| 528 | u8 compatibility_rating; |
| 529 | u64 last_modified_time; |
| 530 | |
| 531 | if (!ReadString(stream, &path) || !ReadString(stream, &ge.serial) || !ReadString(stream, &ge.title) || !ReadString(stream, &ge.title_sort) || |
| 532 | !ReadString(stream, &ge.title_en) || !ReadU8(stream, &type) || !ReadU8(stream, ®ion) || !ReadU64(stream, &ge.total_size) || |
| 533 | !ReadU64(stream, &last_modified_time) || !ReadU32(stream, &ge.crc) || !ReadU8(stream, &compatibility_rating) || |
| 534 | region >= static_cast<u8>(Region::Count) || type >= static_cast<u8>(EntryType::Count) || |
| 535 | compatibility_rating > static_cast<u8>(CompatibilityRating::Perfect)) |
| 536 | { |
| 537 | Console.Warning("Game list cache entry is corrupted"); |
| 538 | return false; |
| 539 | } |
| 540 | |
| 541 | ge.path = path; |
| 542 | ge.region = static_cast<Region>(region); |
| 543 | ge.type = static_cast<EntryType>(type); |
| 544 | ge.compatibility_rating = static_cast<CompatibilityRating>(compatibility_rating); |
| 545 | ge.last_modified_time = static_cast<std::time_t>(last_modified_time); |
| 546 | |
| 547 | auto iter = s_cache_map.find(ge.path); |
| 548 | if (iter != s_cache_map.end()) |
| 549 | iter->second = std::move(ge); |
| 550 | else |
| 551 | s_cache_map.emplace(std::move(path), std::move(ge)); |
| 552 | } |
| 553 | |
| 554 | return true; |
| 555 | } |
| 556 | |
| 557 | static std::string GetCacheFilename() |
| 558 | { |