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

Function ReadFile_WholeFile

src/External/CascLib/src/CascReadFile.cpp:775–820  ·  view source on GitHub ↗

No cache at all. The entire file will be read directly to the user buffer

Source from the content-addressed store, hash-verified

773
774// No cache at all. The entire file will be read directly to the user buffer
775static DWORD ReadFile_WholeFile(TCascFile * hf, LPBYTE pbBuffer)
776{
777 PCASC_CKEY_ENTRY pCKeyEntry = hf->pCKeyEntry;
778 PCASC_FILE_SPAN pFileSpan = hf->pFileSpan;
779 LPBYTE pbSaveBuffer = pbBuffer;
780 LPBYTE pbEncoded;
781 LPBYTE pbEncodedPtr;
782 DWORD dwErrCode;
783
784 for(DWORD SpanIndex = 0; SpanIndex < hf->SpanCount; SpanIndex++, pCKeyEntry++, pFileSpan++)
785 {
786 ULONGLONG ByteOffset = pFileSpan->ArchiveOffs + pFileSpan->HeaderSize;
787 DWORD EncodedSize = pCKeyEntry->EncodedSize - pFileSpan->HeaderSize;
788
789 // Allocate the buffer for the entire encoded span
790 pbEncodedPtr = pbEncoded = CASC_ALLOC<BYTE>(EncodedSize);
791 if(pbEncoded == NULL)
792 {
793 SetCascError(ERROR_NOT_ENOUGH_MEMORY);
794 return 0;
795 }
796
797 // Load the encoded buffer
798 if(FileStream_Read(pFileSpan->pStream, &ByteOffset, pbEncoded, EncodedSize))
799 {
800 PCASC_FILE_FRAME pFileFrame = pFileSpan->pFrames;
801
802 for(DWORD FrameIndex = 0; FrameIndex < pFileSpan->FrameCount; FrameIndex++, pFileFrame++)
803 {
804 // Decode the file frame
805 dwErrCode = DecodeFileFrame(hf, pCKeyEntry, pFileFrame, pbEncodedPtr, pbBuffer, FrameIndex);
806 if(dwErrCode != ERROR_SUCCESS)
807 break;
808
809 // Move pointers
810 pbEncodedPtr += pFileFrame->EncodedSize;
811 pbBuffer += pFileFrame->ContentSize;
812 }
813 }
814
815 CASC_FREE(pbEncoded);
816 }
817
818 // Give the amount of bytes read
819 return (DWORD)(pbBuffer - pbSaveBuffer);
820}
821
822static DWORD ReadFile_FrameCached(TCascFile * hf, LPBYTE pbBuffer, ULONGLONG StartOffset, ULONGLONG EndOffset)
823{

Callers 1

ReadFile_NonCachedFunction · 0.85

Calls 4

SetCascErrorFunction · 0.85
FileStream_ReadFunction · 0.85
DecodeFileFrameFunction · 0.85
CASC_FREEFunction · 0.85

Tested by

no test coverage detected