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

Function ReadMpqFilePatchFile

extern/StormLib/src/SFileReadFile.cpp:586–641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

584}
585
586static DWORD ReadMpqFilePatchFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead)
587{
588 TMPQPatcher Patcher;
589 DWORD dwBytesToRead = dwToRead;
590 DWORD dwBytesRead = 0;
591 DWORD dwErrCode = ERROR_SUCCESS;
592
593 // Make sure that the patch file is loaded completely
594 if(dwErrCode == ERROR_SUCCESS && hf->pbFileData == NULL)
595 {
596 // Initialize patching process and allocate data
597 dwErrCode = Patch_InitPatcher(&Patcher, hf);
598 if(dwErrCode != ERROR_SUCCESS)
599 return dwErrCode;
600
601 // Set the current data size
602 Patcher.cbFileData = hf->pFileEntry->dwFileSize;
603
604 // Initialize the patcher object with initial file data
605 if(hf->pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT)
606 dwErrCode = ReadMpqFileSingleUnit(hf, Patcher.pbFileData1, 0, Patcher.cbFileData, &dwBytesRead);
607 else
608 dwErrCode = ReadMpqFileSectorFile(hf, Patcher.pbFileData1, 0, Patcher.cbFileData, &dwBytesRead);
609
610 // Perform the patching process
611 if(dwErrCode == ERROR_SUCCESS)
612 dwErrCode = Patch_Process(&Patcher, hf);
613
614 // Finalize the patcher structure
615 Patch_Finalize(&Patcher);
616 dwBytesRead = 0;
617 }
618
619 // If there is something to read, do it
620 if(dwErrCode == ERROR_SUCCESS)
621 {
622 if(dwFilePos < hf->cbFileData)
623 {
624 // Make sure we don't copy more than file size
625 if((dwFilePos + dwToRead) > hf->cbFileData)
626 dwToRead = hf->cbFileData - dwFilePos;
627
628 // Copy the appropriate amount of the file data to the caller's buffer
629 memcpy(pvBuffer, hf->pbFileData + dwFilePos, dwToRead);
630 dwBytesRead = dwToRead;
631 }
632
633 // Set the proper error code
634 dwErrCode = (dwBytesRead == dwBytesToRead) ? ERROR_SUCCESS : ERROR_HANDLE_EOF;
635 }
636
637 // Give the result to the caller
638 if(pdwBytesRead != NULL)
639 *pdwBytesRead = dwBytesRead;
640 return dwErrCode;
641}
642
643static DWORD ReadMpqFileLocalFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead)

Callers 1

SFileReadFileFunction · 0.85

Calls 5

Patch_InitPatcherFunction · 0.85
ReadMpqFileSingleUnitFunction · 0.85
ReadMpqFileSectorFileFunction · 0.85
Patch_ProcessFunction · 0.85
Patch_FinalizeFunction · 0.85

Tested by

no test coverage detected