summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLadislav <Zezula>2013-11-15 10:17:43 +0100
committerLadislav <Zezula>2013-11-15 10:17:43 +0100
commit87eb1df287ebe76725d376a28facccbe0ccd7f92 (patch)
treed911227a2c9976a075426f9817812f9119404759
parenta9579a3f4ab1a27a822bcc53f3e6a9b1a00e6418 (diff)
+ Support for compile-time messages for deprecated symbols
+ Replaced MPQ_FILE_COMPRESSED with more descriptive MPQ_FILE_COMPRESS_MASK
-rw-r--r--src/SBaseCommon.cpp4
-rw-r--r--src/SFileAddFile.cpp4
-rw-r--r--src/SFileCompactArchive.cpp2
-rw-r--r--src/SFileReadFile.cpp12
-rw-r--r--src/StormLib.h6
-rw-r--r--src/StormPort.h28
-rw-r--r--test/Test.cpp35
7 files changed, 75 insertions, 16 deletions
diff --git a/src/SBaseCommon.cpp b/src/SBaseCommon.cpp
index 78537cf..c0bfffb 100644
--- a/src/SBaseCommon.cpp
+++ b/src/SBaseCommon.cpp
@@ -1151,7 +1151,7 @@ int AllocateSectorOffsets(TMPQFile * hf, bool bLoadFromFile)
dwSectorOffsLen += sizeof(DWORD);
// Only allocate and load the table if the file is compressed
- if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
+ if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
{
__LoadSectorOffsets:
@@ -1364,7 +1364,7 @@ int WriteSectorOffsets(TMPQFile * hf)
// The caller must make sure that this function is only called
// when the following is true.
- assert(hf->pFileEntry->dwFlags & MPQ_FILE_COMPRESSED);
+ assert(hf->pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK);
assert(hf->SectorOffsets != NULL);
dwSectorOffsLen = hf->SectorOffsets[0];
diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp
index aba421e..59a245a 100644
--- a/src/SFileAddFile.cpp
+++ b/src/SFileAddFile.cpp
@@ -140,7 +140,7 @@ static int WriteDataToMpqFile(
hf->dwCrc32 = crc32(hf->dwCrc32, hf->pbFileSector, dwBytesInSector);
// Compress the file sector, if needed
- if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
+ if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
{
int nOutBuffer = (int)dwBytesInSector;
int nInBuffer = (int)dwBytesInSector;
@@ -365,7 +365,7 @@ int SFileAddFile_Init(
dwFlags &= ~MPQ_FILE_SECTOR_CRC;
// Sector CRC is not allowed if the file is not compressed
- if(!(dwFlags & MPQ_FILE_COMPRESSED))
+ if(!(dwFlags & MPQ_FILE_COMPRESS_MASK))
dwFlags &= ~MPQ_FILE_SECTOR_CRC;
// Fix Key is not allowed if the file is not enrypted
diff --git a/src/SFileCompactArchive.cpp b/src/SFileCompactArchive.cpp
index a7706d0..cc2df09 100644
--- a/src/SFileCompactArchive.cpp
+++ b/src/SFileCompactArchive.cpp
@@ -171,7 +171,7 @@ static int CopyMpqFileSectors(
DWORD dwSectorOffsLen = hf->SectorOffsets[0];
assert((pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT) == 0);
- assert(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED);
+ assert(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK);
if(SectorOffsetsCopy == NULL)
nError = ERROR_NOT_ENOUGH_MEMORY;
diff --git a/src/SFileReadFile.cpp b/src/SFileReadFile.cpp
index 5a034b3..6eb0d10 100644
--- a/src/SFileReadFile.cpp
+++ b/src/SFileReadFile.cpp
@@ -143,7 +143,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW
dwRawBytesToRead = dwBytesToRead;
// Perform all necessary work to do with compressed files
- if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
+ if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
{
// If the sector positions are not loaded yet, do it
if(hf->SectorOffsets == NULL)
@@ -209,7 +209,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW
dwBytesInThisSector = dwBytesToRead;
// If the file is compressed, we have to adjust the raw sector size
- if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
+ if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
dwRawBytesInThisSector = hf->SectorOffsets[dwIndex + 1] - hf->SectorOffsets[dwIndex];
// If the file is encrypted, we have to decrypt the sector
@@ -332,7 +332,7 @@ static int ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos
if(hf->dwSectorOffs != 0)
{
// Is the file compressed?
- if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
+ if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
{
// Allocate space for compressed data
pbCompressed = STORM_ALLOC(BYTE, pFileEntry->dwCmpSize);
@@ -357,7 +357,7 @@ static int ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos
}
// If the file is compressed, we have to decompress it now
- if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
+ if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
{
int cbOutBuffer = (int)hf->dwDataSize;
int cbInBuffer = (int)pFileEntry->dwCmpSize;
@@ -455,7 +455,7 @@ static int ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos
return nError;
// Is the file compressed?
- if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
+ if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
{
// Allocate space for compressed data
pbCompressed = STORM_ALLOC(BYTE, pFileEntry->dwCmpSize);
@@ -478,7 +478,7 @@ static int ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos
}
// If the file is compressed, we have to decompress it now
- if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
+ if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
{
int cbOutBuffer = (int)hf->dwDataSize;
diff --git a/src/StormLib.h b/src/StormLib.h
index 972e22b..8488e3e 100644
--- a/src/StormLib.h
+++ b/src/StormLib.h
@@ -192,7 +192,6 @@ extern "C" {
// Flags for SFileAddFile
#define MPQ_FILE_IMPLODE 0x00000100 // Implode method (By PKWARE Data Compression Library)
#define MPQ_FILE_COMPRESS 0x00000200 // Compress methods (By multiple methods)
-#define MPQ_FILE_COMPRESSED 0x0000FF00 // File is compressed
#define MPQ_FILE_ENCRYPTED 0x00010000 // Indicates whether file is encrypted
#define MPQ_FILE_FIX_KEY 0x00020000 // File decryption key has to be fixed
#define MPQ_FILE_PATCH_FILE 0x00100000 // The file is a patch file. Raw file data begin with TPatchInfo structure
@@ -200,6 +199,8 @@ extern "C" {
#define MPQ_FILE_DELETE_MARKER 0x02000000 // File is a deletion marker. Used in MPQ patches, indicating that the file no longer exists.
#define MPQ_FILE_SECTOR_CRC 0x04000000 // File has checksums for each sector.
// Ignored if file is not compressed or imploded.
+
+#define MPQ_FILE_COMPRESS_MASK 0x0000FF00 // Mask for a file being compressed
#define MPQ_FILE_EXISTS 0x80000000 // Set if file exists, reset when the file was deleted
#define MPQ_FILE_REPLACEEXISTING 0x80000000 // Replace when the file exist (SFileAddFile)
@@ -213,6 +214,9 @@ extern "C" {
MPQ_FILE_SECTOR_CRC | \
MPQ_FILE_EXISTS)
+// A notification that people should stop using this flag
+const STORMLIB_DEPRECATED("This symbol is deprecated. Use MPQ_FILE_COMPRESS_MASK") unsigned int MPQ_FILE_COMPRESSED = 0x0000FF00;
+
// Compression types for multiple compressions
#define MPQ_COMPRESSION_HUFFMANN 0x01 // Huffmann compression (used on WAVE files only)
#define MPQ_COMPRESSION_ZLIB 0x02 // ZLIB compression
diff --git a/src/StormPort.h b/src/StormPort.h
index b2d3158..4e34280 100644
--- a/src/StormPort.h
+++ b/src/StormPort.h
@@ -33,7 +33,9 @@
#define false 0
#endif
+//-----------------------------------------------------------------------------
// Defines for Windows
+
#if !defined(PLATFORM_DEFINED) && (defined(WIN32) || defined(WIN64))
// In MSVC 8.0, there are some functions declared as deprecated.
@@ -61,7 +63,9 @@
#endif
-// Defines for Mac
+//-----------------------------------------------------------------------------
+// Defines for Mac
+
#if !defined(PLATFORM_DEFINED) && defined(__APPLE__) // Mac BSD API
// Macintosh
@@ -92,7 +96,9 @@
#endif
+//-----------------------------------------------------------------------------
// Assumption: we are not on Windows nor Macintosh, so this must be linux *grin*
+
#if !defined(PLATFORM_DEFINED)
#include <sys/types.h>
@@ -115,7 +121,9 @@
#endif
-// Definition of Windows-specific structures for non-Windows platforms
+//-----------------------------------------------------------------------------
+// Definition of Windows-specific types for non-Windows platforms
+
#ifndef PLATFORM_WINDOWS
#if __LP64__
#define PLATFORM_64BIT
@@ -199,6 +207,9 @@
#define ERROR_FILE_CORRUPT 1004 // No such error code under Linux
#endif
+//-----------------------------------------------------------------------------
+// Swapping functions
+
#ifdef PLATFORM_LITTLE_ENDIAN
#define BSWAP_INT16_UNSIGNED(a) (a)
#define BSWAP_INT16_SIGNED(a) (a)
@@ -249,4 +260,17 @@
#define BSWAP_TMPKHEADER(a) ConvertTMPKHeader((a))
#endif
+//-----------------------------------------------------------------------------
+// Macro for deprecated symbols
+
+#ifdef _MSC_VER
+ #if _MSC_FULL_VER >= 140050320
+ #define STORMLIB_DEPRECATED(_Text) __declspec(deprecated(_Text))
+ #else
+ #define STORMLIB_DEPRECATED(_Text) __declspec(deprecated)
+ #endif
+#else
+ #define STORMLIB_DEPRECATED(_Text) __attribute__((deprecated(_Text)))
+#endif
+
#endif // __STORMPORT_H__
diff --git a/test/Test.cpp b/test/Test.cpp
index 3e4b1fb..3d8b785 100644
--- a/test/Test.cpp
+++ b/test/Test.cpp
@@ -1222,6 +1222,33 @@ static int TestArchiveOpenAndClose(const TCHAR * szMpqName)
return nError;
}
+static int TestAddFilesToArchive(const TCHAR * szMpqName)
+{
+ HANDLE hFile;
+ HANDLE hMpq;
+ LPCSTR szFileData = "0123456789";
+ char szAddedFile[128];
+ DWORD dwFileSize = 10;
+
+ CopyFile(_T("e:\\Ladik\\Incoming\\Tya's Zerg Defense.SC2Map"), _T("e:\\Multimedia\\MPQs\\Tya's Zerg Defense.SC2Map"), FALSE);
+
+ for(int i = 0; i < 3; i++)
+ {
+ if(SFileOpenArchive(szMpqName, 0, 0, &hMpq))
+ {
+ sprintf(szAddedFile, "AddedFile%04u.txt", i);
+
+ if(SFileCreateFile(hMpq, szAddedFile, 0, dwFileSize, 0, MPQ_FILE_COMPRESS, &hFile))
+ {
+ SFileWriteFile(hMpq, szFileData, dwFileSize, MPQ_COMPRESSION_ZLIB);
+ SFileFinishFile(hFile);
+ }
+ }
+ }
+
+ return ERROR_SUCCESS;
+}
+
static int TestFindFiles(const TCHAR * szMpqName)
{
TMPQFile * hf;
@@ -2213,11 +2240,15 @@ int main(void)
// nError = TestSectorCompress(MPQ_SECTOR_SIZE);
// Test the archive open and close
- if(nError == ERROR_SUCCESS)
- nError = TestArchiveOpenAndClose(MAKE_PATH("2012 - Longwu Online\\Data\\Scp.mpk"));
+// if(nError == ERROR_SUCCESS)
+// nError = TestArchiveOpenAndClose(MAKE_PATH("2012 - Longwu Online\\Data\\Scp.mpk"));
// nError = TestArchiveOpenAndClose(MAKE_PATH("1997 - Diablo I\\DIABDAT.MPQ"));
// nError = TestArchiveOpenAndClose(MAKE_PATH("2012 - War of the Immortals\\1\\Other.sqp"));
+ // Test for bug reported by BlueRaja
+ if(nError == ERROR_SUCCESS)
+ nError = TestAddFilesToArchive(MAKE_PATH("Tya's Zerg Defense.SC2Map"));
+
// if(nError == ERROR_SUCCESS)
// nError = TestFindFiles(MAKE_PATH("2002 - Warcraft III/HumanEd.mpq"));