MCPcopy Create free account
hub / github.com/Kenix3/libultraship / SFileAddFile_Write

Function SFileAddFile_Write

extern/StormLib/src/SFileAddFile.cpp:569–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

567}
568
569DWORD 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

Callers 4

SSignFileCreateFunction · 0.85
SFileWriteFileFunction · 0.85
SListFileSaveToMpqFunction · 0.85
SAttrFileSaveToMpqFunction · 0.85

Calls 13

AllocateSectorBufferFunction · 0.85
IsIncrementalPatchFileFunction · 0.85
AllocatePatchInfoFunction · 0.85
AllocateSectorOffsetsFunction · 0.85
AllocateSectorChecksumsFunction · 0.85
FileStream_WriteFunction · 0.85
GetLastErrorFunction · 0.85
WriteDataToMpqFileFunction · 0.85
md5_doneFunction · 0.85
WriteSectorChecksumsFunction · 0.85
WritePatchInfoFunction · 0.85
WriteSectorOffsetsFunction · 0.85

Tested by

no test coverage detected