MCPcopy Create free account
hub / github.com/diasurgical/devilution / SFileReadFile

Function SFileReadFile

3rdParty/StormLib/src/SFileReadFile.cpp:673–739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

671// SFileReadFile
672
673bool STORMAPI SFileReadFile(HANDLE hFile, void * pvBuffer, DWORD dwToRead, LPDWORD pdwRead, LPOVERLAPPED lpOverlapped)
674{
675 TMPQFile * hf = (TMPQFile *)hFile;
676 DWORD dwBytesRead = 0; // Number of bytes read
677 int nError = ERROR_SUCCESS;
678
679 // Always zero the result
680 if(pdwRead != NULL)
681 *pdwRead = 0;
682 lpOverlapped = lpOverlapped;
683
684 // Check valid parameters
685 if(!IsValidFileHandle(hFile))
686 {
687 SetLastError(ERROR_INVALID_HANDLE);
688 return false;
689 }
690
691 if(pvBuffer == NULL)
692 {
693 SetLastError(ERROR_INVALID_PARAMETER);
694 return false;
695 }
696
697 // If we didn't load the patch info yet, do it now
698 if(hf->pFileEntry != NULL && (hf->pFileEntry->dwFlags & MPQ_FILE_PATCH_FILE) && hf->pPatchInfo == NULL)
699 {
700 nError = AllocatePatchInfo(hf, true);
701 if(nError != ERROR_SUCCESS || hf->pPatchInfo == NULL)
702 {
703 SetLastError(nError);
704 return false;
705 }
706 }
707
708 // Clear the last used compression
709 hf->dwCompression0 = 0;
710
711 // If the file is local file, read the data directly from the stream
712 if(hf->pStream != NULL)
713 {
714 nError = ReadMpqFileLocalFile(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead);
715 }
716#ifdef FULL
717 // If the file is a patch file, we have to read it special way
718 else if(hf->hfPatch != NULL && (hf->pFileEntry->dwFlags & MPQ_FILE_PATCH_FILE) == 0)
719 {
720 nError = ReadMpqFilePatchFile(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead);
721 }
722#endif
723 // If the archive is a MPK archive, we need special way to read the file
724 else if(hf->ha->dwSubType == MPQ_SUBTYPE_MPK)
725 {
726 nError = ReadMpkFileSingleUnit(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead);
727 }
728
729 // If the file is single unit file, redirect it to read file
730 else if(hf->pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT)

Callers 10

sound_file_loadFunction · 0.85
music_startFunction · 0.85
SFileDdaBeginExFunction · 0.85
SBmpLoadImageFunction · 0.85
SVidPlayBeginFunction · 0.85
WReadFileFunction · 0.85
pfile_read_heroFunction · 0.85
pfile_readFunction · 0.85
SFileExtractFileFunction · 0.85
CreatePseudoFileNameFunction · 0.85

Calls 8

IsValidFileHandleFunction · 0.85
SetLastErrorFunction · 0.85
AllocatePatchInfoFunction · 0.85
ReadMpqFileLocalFileFunction · 0.85
ReadMpqFilePatchFileFunction · 0.85
ReadMpkFileSingleUnitFunction · 0.85
ReadMpqFileSingleUnitFunction · 0.85
ReadMpqFileSectorFileFunction · 0.85

Tested by

no test coverage detected