The first line of each integrity file contains the combined hash for all files, if the hashes match then we assume that the unpacked data folder is up-to-date.
| 73 | // The first line of each integrity file contains the combined hash for all files, |
| 74 | // if the hashes match then we assume that the unpacked data folder is up-to-date. |
| 75 | static bool EqualIntegrityFiles(const char *pAssetFilename, const char *pStorageFilename) |
| 76 | { |
| 77 | IOHANDLE StorageFile = io_open(pStorageFilename, IOFLAG_READ); |
| 78 | if(!StorageFile) |
| 79 | { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | char aStorageMainSha256[SHA256_MAXSTRSIZE]; |
| 84 | const size_t StorageReadLength = io_read(StorageFile, aStorageMainSha256, sizeof(aStorageMainSha256) - 1); |
| 85 | io_close(StorageFile); |
| 86 | if(StorageReadLength != sizeof(aStorageMainSha256) - 1) |
| 87 | { |
| 88 | return false; |
| 89 | } |
| 90 | aStorageMainSha256[sizeof(aStorageMainSha256) - 1] = '\0'; |
| 91 | |
| 92 | char aAssetFilename[IO_MAX_PATH_LENGTH] = "asset_integrity_files/"; |
| 93 | str_append(aAssetFilename, pAssetFilename); |
| 94 | |
| 95 | SDL_RWops *pAssetFile = SDL_RWFromFile(aAssetFilename, "rb"); |
| 96 | if(!pAssetFile) |
| 97 | { |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | char aAssetMainSha256[SHA256_MAXSTRSIZE]; |
| 102 | const size_t AssetReadLength = SDL_RWread(pAssetFile, aAssetMainSha256, 1, sizeof(aAssetMainSha256) - 1); |
| 103 | SDL_RWclose(pAssetFile); |
| 104 | if(AssetReadLength != sizeof(aAssetMainSha256) - 1) |
| 105 | { |
| 106 | return false; |
| 107 | } |
| 108 | aAssetMainSha256[sizeof(aAssetMainSha256) - 1] = '\0'; |
| 109 | |
| 110 | return str_comp(aStorageMainSha256, aAssetMainSha256) == 0; |
| 111 | } |
| 112 | |
| 113 | class CIntegrityFileLine |
| 114 | { |
no test coverage detected