* Process (parse) a PAK file. * * @param pakpath real path to open PAK file. * @param paksize size (bytes) of the PAK file. * @param pakInfo pointer to the FileInfo for PAK file. * @return True if PAK processing was ok. */
| 388 | * @return True if PAK processing was ok. |
| 389 | */ |
| 390 | static bool _File_Init_ProcessPak(const char *pakpath, uint32 paksize, FileInfo *pakInfo) |
| 391 | { |
| 392 | FILE *f; |
| 393 | uint32 position; |
| 394 | uint32 nextposition; |
| 395 | uint32 size; |
| 396 | char filename[256]; |
| 397 | unsigned int i; |
| 398 | |
| 399 | f = fopen(pakpath, "rb"); |
| 400 | if (f == NULL) { |
| 401 | Error("failed to open %s", pakpath); |
| 402 | return false; |
| 403 | } |
| 404 | if (!fread_le_uint32(&nextposition, f)) { |
| 405 | fclose(f); |
| 406 | return false; |
| 407 | } |
| 408 | while (nextposition != 0) { |
| 409 | position = nextposition; |
| 410 | for (i = 0; i < sizeof(filename); i++) { |
| 411 | if (fread(filename + i, 1, 1, f) != 1) { |
| 412 | fclose(f); |
| 413 | return false; |
| 414 | } |
| 415 | if (filename[i] == '\0') break; |
| 416 | } |
| 417 | if (i == sizeof(filename)) { |
| 418 | fclose(f); |
| 419 | return false; |
| 420 | } |
| 421 | if (!fread_le_uint32(&nextposition, f)) { |
| 422 | fclose(f); |
| 423 | return false; |
| 424 | } |
| 425 | size = (nextposition != 0) ? nextposition - position : paksize - position; |
| 426 | if (_File_Init_AddFileInPak(filename, size, position, pakInfo) == NULL) { |
| 427 | fclose(f); |
| 428 | return false; |
| 429 | } |
| 430 | } |
| 431 | fclose(f); |
| 432 | return true; |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * Callback for processing files found in data/ directory. |
no test coverage detected