MCPcopy Create free account
hub / github.com/Kenix3/libultraship / SFileReadFile

Function SFileReadFile

extern/StormLib/src/SFileReadFile.cpp:678–764  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 14

LoadMpqFileFunction · 0.85
TestOnLocalListFile_ReadFunction · 0.85
TestArchive_PatchedFunction · 0.85
VerifyFileFunction · 0.85
LoadFilePatch_COPYFunction · 0.85
LoadFilePatch_BSD0Function · 0.85
IsMatchingPatchFileFunction · 0.85
Patch_ProcessFunction · 0.85
SFileExtractFileFunction · 0.85
CreatePseudoFileNameFunction · 0.85
LoadListFile_MPQFunction · 0.85
SAttrLoadAttributesFunction · 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 3

LoadMpqFileFunction · 0.68
TestOnLocalListFile_ReadFunction · 0.68
TestArchive_PatchedFunction · 0.68