| 709 | } |
| 710 | |
| 711 | DWORD SFileAddFile_Finish(TMPQFile * hf) |
| 712 | { |
| 713 | TMPQArchive * ha = hf->ha; |
| 714 | TFileEntry * pFileEntry = hf->pFileEntry; |
| 715 | DWORD dwErrCode = hf->dwAddFileError; |
| 716 | |
| 717 | // If all previous operations succeeded, we can update the MPQ |
| 718 | if(dwErrCode == ERROR_SUCCESS) |
| 719 | { |
| 720 | // Verify if the caller wrote the file properly |
| 721 | if(hf->pPatchInfo == NULL) |
| 722 | { |
| 723 | assert(pFileEntry != NULL); |
| 724 | if(hf->dwFilePos != pFileEntry->dwFileSize) |
| 725 | dwErrCode = ERROR_CAN_NOT_COMPLETE; |
| 726 | } |
| 727 | else |
| 728 | { |
| 729 | if(hf->dwFilePos != hf->pPatchInfo->dwDataSize) |
| 730 | dwErrCode = ERROR_CAN_NOT_COMPLETE; |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | // Now we need to recreate the HET table, if exists |
| 735 | if(dwErrCode == ERROR_SUCCESS && ha->pHetTable != NULL) |
| 736 | { |
| 737 | dwErrCode = RebuildHetTable(ha); |
| 738 | } |
| 739 | |
| 740 | // Update the block table size |
| 741 | if(dwErrCode == ERROR_SUCCESS) |
| 742 | { |
| 743 | // Call the user callback, if any |
| 744 | if(ha->pfnAddFileCB != NULL) |
| 745 | ha->pfnAddFileCB(ha->pvAddFileUserData, hf->dwDataSize, hf->dwDataSize, true); |
| 746 | } |
| 747 | else |
| 748 | { |
| 749 | // Free the file entry in MPQ tables |
| 750 | if(pFileEntry != NULL) |
| 751 | DeleteFileEntry(ha, hf); |
| 752 | } |
| 753 | |
| 754 | // Clear the add file callback |
| 755 | FreeFileHandle(hf); |
| 756 | return dwErrCode; |
| 757 | } |
| 758 | |
| 759 | //----------------------------------------------------------------------------- |
| 760 | // Adds data as file to the archive |
no test coverage detected