| 508 | } |
| 509 | |
| 510 | static DWORD LoadLocalIndexFiles(TCascStorage * hs) |
| 511 | { |
| 512 | ULONGLONG TotalSize = 0; |
| 513 | DWORD dwIndexCount = 0; |
| 514 | DWORD dwErrCode; |
| 515 | |
| 516 | // Inform the user about what we are doing |
| 517 | if(InvokeProgressCallback(hs, "Loading index files", NULL, 0, 0)) |
| 518 | return ERROR_CANCELLED; |
| 519 | |
| 520 | // Perform the directory scan |
| 521 | if((dwErrCode = ScanDirectory(hs->szIndexPath, NULL, IndexDirectory_OnFileFound, hs)) == ERROR_SUCCESS) |
| 522 | { |
| 523 | // If no index file was found, we cannot load anything |
| 524 | if(hs->szIndexFormat == NULL) |
| 525 | return ERROR_FILE_NOT_FOUND; |
| 526 | |
| 527 | // Load each index file |
| 528 | for(DWORD i = 0; i < CASC_INDEX_COUNT; i++) |
| 529 | { |
| 530 | CASC_INDEX & IndexFile = hs->IndexFiles[i]; |
| 531 | |
| 532 | // Create the file name |
| 533 | if((IndexFile.szFileName = CreateIndexFileName(hs, i, IndexFile.NewSubIndex)) == NULL) |
| 534 | return ERROR_NOT_ENOUGH_MEMORY; |
| 535 | |
| 536 | // WoW6 actually reads THE ENTIRE file to memory. Verified on Mac build (x64). |
| 537 | dwErrCode = LoadFileToMemory(IndexFile.szFileName, IndexFile.FileData); |
| 538 | if(dwErrCode != ERROR_SUCCESS) |
| 539 | { |
| 540 | // Storages downloaded by Blizzget tool don't have all index files present |
| 541 | if((dwErrCode = GetCascError()) == ERROR_FILE_NOT_FOUND) |
| 542 | { |
| 543 | dwErrCode = ERROR_SUCCESS; |
| 544 | break; |
| 545 | } |
| 546 | return dwErrCode; |
| 547 | } |
| 548 | |
| 549 | // Add to the total size of the index files |
| 550 | TotalSize += IndexFile.FileData.cbData; |
| 551 | dwIndexCount++; |
| 552 | } |
| 553 | |
| 554 | // Build the map of EKey -> IndexEKeyEntry |
| 555 | dwErrCode = hs->IndexEKeyMap.Create((size_t)(TotalSize / sizeof(FILE_EKEY_ENTRY)), CASC_EKEY_SIZE, 0); |
| 556 | if(dwErrCode == ERROR_SUCCESS) |
| 557 | { |
| 558 | dwErrCode = ProcessLocalIndexFiles(hs, InsertEncodingEKeyToMap, dwIndexCount); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | return dwErrCode; |
| 563 | } |
| 564 | |
| 565 | //----------------------------------------------------------------------------- |
| 566 | // Online index files |
no test coverage detected