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