| 383 | } |
| 384 | |
| 385 | bool TitleCatalog::isCacheFresh(void) |
| 386 | { |
| 387 | u8 hash[SHA256_BLOCK_SIZE]; |
| 388 | calculateTitleDBHash(hash); |
| 389 | |
| 390 | auto writeHash = [&] { |
| 391 | FSUSER_DeleteFile(Archive::sdmc(), fsMakePath(PATH_UTF16, titlesHashPath.data())); |
| 392 | FSStream output(Archive::sdmc(), titlesHashPath, FS_OPEN_WRITE, SHA256_BLOCK_SIZE); |
| 393 | output.write(hash, SHA256_BLOCK_SIZE); |
| 394 | output.close(); |
| 395 | }; |
| 396 | |
| 397 | if (!io::fileExists(Archive::sdmc(), titlesHashPath) || !io::fileExists(Archive::sdmc(), saveCachePath) || |
| 398 | !io::fileExists(Archive::sdmc(), extdataCachePath)) { |
| 399 | writeHash(); |
| 400 | return false; |
| 401 | } |
| 402 | |
| 403 | FSStream input(Archive::sdmc(), titlesHashPath, FS_OPEN_READ); |
| 404 | if (input.good() && input.size() == SHA256_BLOCK_SIZE) { |
| 405 | u8 buf[SHA256_BLOCK_SIZE]; |
| 406 | input.read(buf, SHA256_BLOCK_SIZE); |
| 407 | input.close(); |
| 408 | if (memcmp(hash, buf, SHA256_BLOCK_SIZE) == 0) { |
| 409 | return true; |
| 410 | } |
| 411 | writeHash(); |
| 412 | } |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | void TitleCatalog::loadFromCache(std::vector<Title>& saves, std::vector<Title>& extdatas, IconStore& icons) |
| 417 | { |