| 671 | // SFileReadFile |
| 672 | |
| 673 | bool 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) |
no test coverage detected