static int WriteListFileLine( TMPQFile * hf, const char * szLine) { char szNewLine[2] = {0x0D, 0x0A}; size_t nLength = strlen(szLine); int nError; nError = SFileAddFile_Write(hf, szLine, (DWORD)nLength, MPQ_COMPRESSION_ZLIB); if(nError != ERROR_SUCCESS) return nError; return SFileAddFile_Write(hf, szNewLine, sizeof(szNewLine), MPQ_COMPRESSION_ZLIB); }
bool WINAPI SFileWriteFile( HANDLE hFile, const void * pvData, DWORD dwSize, DWORD dwCompression) { TMPQFile * hf = (TMPQFile *)hFile; int nError = ERROR_SUCCESS; // Check the proper parameters if(!IsValidFileHandle(hf)) nError = ERROR_INVALID_HANDLE; if(hf->bIsWriteHandle == false) nError = ERROR_INVALID_HANDLE; // Special checks for single unit files if(nError == ERROR_SUCCESS && (hf->pBlock->dwFlags & MPQ_FILE_SINGLE_UNIT)) { // // Note: Blizzard doesn't support single unit files // that are stored as encrypted or imploded. We will allow them here, // the calling application must ensure that such flag combination doesn't get here // // if(dwFlags & MPQ_FILE_IMPLODE) // nError = ERROR_INVALID_PARAMETER; // // if(dwFlags & MPQ_FILE_ENCRYPTED) // nError = ERROR_INVALID_PARAMETER; // Lossy compression is not allowed on single unit files if(dwCompression & LOSSY_COMPRESSION_MASK) nError = ERROR_INVALID_PARAMETER; } // Write the data to the file if(nError == ERROR_SUCCESS) nError = SFileAddFile_Write(hf, pvData, dwSize, dwCompression); // Deal with errors if(nError != ERROR_SUCCESS) SetLastError(nError); return (nError == ERROR_SUCCESS); }
int SSignFileCreate(TMPQArchive * ha) { TMPQFile * hf = NULL; BYTE EmptySignature[MPQ_SIGNATURE_FILE_SIZE]; int nError = ERROR_SUCCESS; // Only save the signature if we should do so if(ha->dwFileFlags3 != 0) { // The (signature) file must be non-encrypted and non-compressed assert(ha->dwFlags & MPQ_FLAG_SIGNATURE_NEW); assert(ha->dwFileFlags3 == MPQ_FILE_EXISTS); assert(ha->dwReservedFiles > 0); // Create the (signature) file file in the MPQ // Note that the file must not be compressed or encrypted nError = SFileAddFile_Init(ha, SIGNATURE_NAME, 0, sizeof(EmptySignature), LANG_NEUTRAL, ha->dwFileFlags3 | MPQ_FILE_REPLACEEXISTING, &hf); // Write the empty signature file to the archive if(nError == ERROR_SUCCESS) { // Write the empty zeroed file to the MPQ memset(EmptySignature, 0, sizeof(EmptySignature)); nError = SFileAddFile_Write(hf, EmptySignature, (DWORD)sizeof(EmptySignature), 0); SFileAddFile_Finish(hf); // Clear the invalid mark ha->dwFlags &= ~(MPQ_FLAG_SIGNATURE_NEW | MPQ_FLAG_SIGNATURE_NONE); ha->dwReservedFiles--; } } return nError; }