MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / LoadIndexFile_V2

Function LoadIndexFile_V2

src/External/CascLib/src/CascIndexFiles.cpp:395–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393}
394
395static DWORD LoadIndexFile_V2(TCascStorage * hs, CASC_INDEX_HEADER & InHeader, EKEY_ENTRY_CALLBACK PfnEKeyEntry, LPBYTE pbFileData, size_t cbFileData)
396{
397 LPBYTE pbEKeyEntry;
398 LPBYTE pbFileEnd = pbFileData + cbFileData;
399 LPBYTE pbFilePtr = pbFileData + InHeader.HeaderLength + InHeader.HeaderPadding;
400 size_t EKeyEntriesLength;
401 DWORD BlockSize = 0;
402 DWORD dwErrCode = ERROR_NOT_SUPPORTED;
403
404 // Remember the values from the index header
405 SaveFileOffsetBitsAndEKeyLength(hs, InHeader.FileOffsetBits, InHeader.EKeyLength);
406
407 // Get the pointer to the first block of EKey entries
408 if((pbEKeyEntry = CaptureGuardedBlock2(pbFilePtr, pbFileEnd, InHeader.EntryLength, &BlockSize)) != NULL)
409 {
410 // Supply the number of EKey entries
411 InHeader.HeaderPadding += sizeof(FILE_INDEX_GUARDED_BLOCK);
412
413 // Load the continuous array of EKeys
414 return LoadIndexItems(hs, InHeader, PfnEKeyEntry, pbEKeyEntry, pbEKeyEntry + BlockSize);
415 }
416
417 // Get the pointer to the second block of EKey entries.
418 // They are alway at the position aligned to 4096
419 EKeyEntriesLength = pbFileEnd - pbFilePtr;
420 if(EKeyEntriesLength >= 0x7800)
421 {
422 LPBYTE pbStartPage = pbFileData + 0x1000;
423 LPBYTE pbEndPage = pbStartPage + FILE_INDEX_PAGE_SIZE;
424 size_t AlignedLength = ALIGN_TO_SIZE(InHeader.EntryLength, 4);
425
426 // Parse the chunks with the EKey entries
427 while(pbStartPage < pbFileEnd)
428 {
429 pbEKeyEntry = pbStartPage;
430
431 while(pbEKeyEntry < pbEndPage)
432 {
433 // Check the EKey entry protected by 32-bit hash
434 if((pbEKeyEntry = CaptureGuardedBlock3(pbEKeyEntry, pbEndPage, InHeader.EntryLength)) == NULL)
435 break;
436
437 // CASC\\0001: Encoding
438 //BREAK_ON_XKEY3(pbEKeyEntry, 0xbc, 0xe8, 0x23);
439
440 // Call the EKey entry callback
441 if(!PfnEKeyEntry(hs, InHeader, pbEKeyEntry))
442 return ERROR_INDEX_PARSING_DONE;
443
444 pbEKeyEntry += AlignedLength;
445 }
446
447 // Move to the next chunk
448 pbStartPage += FILE_INDEX_PAGE_SIZE;
449 }
450 dwErrCode = ERROR_SUCCESS;
451 }
452

Callers 1

LoadIndexFileFunction · 0.85

Calls 4

CaptureGuardedBlock2Function · 0.85
LoadIndexItemsFunction · 0.85
CaptureGuardedBlock3Function · 0.85

Tested by

no test coverage detected