From 870acd582701bc67c29b48319972303e5ceb706d Mon Sep 17 00:00:00 2001 From: Ladislav Date: Mon, 18 Nov 2013 12:35:21 +0100 Subject: + Adding files to MPQ no longer removes (listfile) and (attributes) when not enough space in the hash table + Fixes in deletion of files from MPQs v 4.0 --- src/SFileAddFile.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/SFileAddFile.cpp') diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp index 59a245a..775a969 100644 --- a/src/SFileAddFile.cpp +++ b/src/SFileAddFile.cpp @@ -386,7 +386,7 @@ int SFileAddFile_Init( if(nError == ERROR_SUCCESS) { // Find the position where the file will be stored - FindFreeMpqSpace(ha, &hf->MpqFilePos); + hf->MpqFilePos = FindFreeMpqSpace(ha); hf->RawFilePos = ha->MpqPos + hf->MpqFilePos; hf->bIsWriteHandle = true; @@ -418,15 +418,19 @@ int SFileAddFile_Init( } else { - // If the file exists and "replace existing" is not set, fail it - if((dwFlags & MPQ_FILE_REPLACEEXISTING) == 0) - nError = ERROR_ALREADY_EXISTS; - - // If the file entry already contains a file - // and it is a pseudo-name, replace it - if(nError == ERROR_SUCCESS) + // Only if the file really exists + if(pFileEntry->dwFlags & MPQ_FILE_EXISTS) { - AllocateFileName(pFileEntry, szFileName); + // If the file exists and "replace existing" is not set, fail it + if((dwFlags & MPQ_FILE_REPLACEEXISTING) == 0) + nError = ERROR_ALREADY_EXISTS; + + // If the file entry already contains a file + // and it is a pseudo-name, replace it + if(nError == ERROR_SUCCESS) + { + AllocateFileName(pFileEntry, szFileName); + } } } } -- cgit v1.2.3