| 396 | // Internal support for MPQ modifications |
| 397 | |
| 398 | DWORD SFileAddFile_Init( |
| 399 | TMPQArchive * ha, |
| 400 | const char * szFileName, |
| 401 | ULONGLONG FileTime, |
| 402 | DWORD dwFileSize, |
| 403 | LCID lcFileLocale, |
| 404 | DWORD dwFlags, |
| 405 | TMPQFile ** phf) |
| 406 | { |
| 407 | TFileEntry * pFileEntry = NULL; |
| 408 | TMPQFile * hf = NULL; // File structure for newly added file |
| 409 | DWORD dwHashIndex = HASH_ENTRY_FREE; |
| 410 | DWORD dwErrCode = ERROR_SUCCESS; |
| 411 | |
| 412 | // |
| 413 | // Note: This is an internal function so no validity checks are done. |
| 414 | // It is the caller's responsibility to make sure that no invalid |
| 415 | // flags get to this point |
| 416 | // |
| 417 | |
| 418 | // Sestor CRC is not allowed with single unit files |
| 419 | if(dwFlags & MPQ_FILE_SINGLE_UNIT) |
| 420 | dwFlags &= ~MPQ_FILE_SECTOR_CRC; |
| 421 | |
| 422 | // Sector CRC is not allowed if the file is not compressed |
| 423 | if(!(dwFlags & MPQ_FILE_COMPRESS_MASK)) |
| 424 | dwFlags &= ~MPQ_FILE_SECTOR_CRC; |
| 425 | |
| 426 | // Fix Key is not allowed if the file is not encrypted |
| 427 | if(!(dwFlags & MPQ_FILE_ENCRYPTED)) |
| 428 | dwFlags &= ~MPQ_FILE_FIX_KEY; |
| 429 | |
| 430 | // If the MPQ is of version 3.0 or higher, we ignore file locale. |
| 431 | // This is because HET and BET tables have no known support for it |
| 432 | if(ha->pHeader->wFormatVersion >= MPQ_FORMAT_VERSION_3) |
| 433 | lcFileLocale = 0; |
| 434 | |
| 435 | // Allocate the TMPQFile entry for newly added file |
| 436 | hf = CreateWritableHandle(ha, dwFileSize); |
| 437 | if(hf == NULL) |
| 438 | return false; |
| 439 | |
| 440 | // Allocate file entry in the MPQ |
| 441 | if(dwErrCode == ERROR_SUCCESS) |
| 442 | { |
| 443 | // Check if the file already exists in the archive |
| 444 | pFileEntry = GetFileEntryExact(ha, szFileName, lcFileLocale, &dwHashIndex); |
| 445 | if(pFileEntry != NULL) |
| 446 | { |
| 447 | if(dwFlags & MPQ_FILE_REPLACEEXISTING) |
| 448 | InvalidateInternalFiles(ha); |
| 449 | else |
| 450 | dwErrCode = ERROR_ALREADY_EXISTS; |
| 451 | } |
| 452 | else |
| 453 | { |
| 454 | // Attempt to allocate new file entry |
| 455 | pFileEntry = AllocateFileEntry(ha, szFileName, lcFileLocale, &dwHashIndex); |
no test coverage detected