| 567 | } |
| 568 | |
| 569 | DWORD SFileAddFile_Write(TMPQFile * hf, const void * pvData, DWORD dwSize, DWORD dwCompression) |
| 570 | { |
| 571 | TMPQArchive * ha; |
| 572 | TFileEntry * pFileEntry; |
| 573 | DWORD dwErrCode = ERROR_SUCCESS; |
| 574 | |
| 575 | // Don't bother if the caller gave us zero size |
| 576 | if(pvData == NULL || dwSize == 0) |
| 577 | return ERROR_SUCCESS; |
| 578 | |
| 579 | // Get pointer to the MPQ archive |
| 580 | pFileEntry = hf->pFileEntry; |
| 581 | ha = hf->ha; |
| 582 | |
| 583 | // Allocate file buffers |
| 584 | if(hf->pbFileSector == NULL) |
| 585 | { |
| 586 | ULONGLONG RawFilePos = hf->RawFilePos; |
| 587 | |
| 588 | // Allocate buffer for file sector |
| 589 | hf->dwAddFileError = dwErrCode = AllocateSectorBuffer(hf); |
| 590 | if(dwErrCode != ERROR_SUCCESS) |
| 591 | return dwErrCode; |
| 592 | |
| 593 | // Allocate patch info, if the data is patch |
| 594 | if(hf->pPatchInfo == NULL && IsIncrementalPatchFile(pvData, dwSize, &hf->dwPatchedFileSize)) |
| 595 | { |
| 596 | // Set the MPQ_FILE_PATCH_FILE flag |
| 597 | pFileEntry->dwFlags |= MPQ_FILE_PATCH_FILE; |
| 598 | |
| 599 | // Allocate the patch info |
| 600 | hf->dwAddFileError = dwErrCode = AllocatePatchInfo(hf, false); |
| 601 | if(dwErrCode != ERROR_SUCCESS) |
| 602 | return dwErrCode; |
| 603 | } |
| 604 | |
| 605 | // Allocate sector offsets |
| 606 | if(hf->SectorOffsets == NULL) |
| 607 | { |
| 608 | hf->dwAddFileError = dwErrCode = AllocateSectorOffsets(hf, false); |
| 609 | if(dwErrCode != ERROR_SUCCESS) |
| 610 | return dwErrCode; |
| 611 | } |
| 612 | |
| 613 | // Create array of sector checksums |
| 614 | if(hf->SectorChksums == NULL && (pFileEntry->dwFlags & MPQ_FILE_SECTOR_CRC)) |
| 615 | { |
| 616 | hf->dwAddFileError = dwErrCode = AllocateSectorChecksums(hf, false); |
| 617 | if(dwErrCode != ERROR_SUCCESS) |
| 618 | return dwErrCode; |
| 619 | } |
| 620 | |
| 621 | // Pre-save the patch info, if any |
| 622 | if(hf->pPatchInfo != NULL) |
| 623 | { |
| 624 | if(!FileStream_Write(ha->pStream, &RawFilePos, hf->pPatchInfo, hf->pPatchInfo->dwLength)) |
| 625 | dwErrCode = GetLastError(); |
| 626 |
no test coverage detected