| 676 | // SFileReadFile |
| 677 | |
| 678 | bool 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 | |