Skip to content

Commit 87eb1df

Browse files
LadislavLadislav
Ladislav
authored and
Ladislav
committed
+ Support for compile-time messages for deprecated symbols
+ Replaced MPQ_FILE_COMPRESSED with more descriptive MPQ_FILE_COMPRESS_MASK
1 parent a9579a3 commit 87eb1df

7 files changed

+75
-16
lines changed

src/SBaseCommon.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ int AllocateSectorOffsets(TMPQFile * hf, bool bLoadFromFile)
11511151
dwSectorOffsLen += sizeof(DWORD);
11521152

11531153
// Only allocate and load the table if the file is compressed
1154-
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
1154+
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
11551155
{
11561156
__LoadSectorOffsets:
11571157

@@ -1364,7 +1364,7 @@ int WriteSectorOffsets(TMPQFile * hf)
13641364

13651365
// The caller must make sure that this function is only called
13661366
// when the following is true.
1367-
assert(hf->pFileEntry->dwFlags & MPQ_FILE_COMPRESSED);
1367+
assert(hf->pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK);
13681368
assert(hf->SectorOffsets != NULL);
13691369
dwSectorOffsLen = hf->SectorOffsets[0];
13701370

src/SFileAddFile.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int WriteDataToMpqFile(
140140
hf->dwCrc32 = crc32(hf->dwCrc32, hf->pbFileSector, dwBytesInSector);
141141

142142
// Compress the file sector, if needed
143-
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
143+
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
144144
{
145145
int nOutBuffer = (int)dwBytesInSector;
146146
int nInBuffer = (int)dwBytesInSector;
@@ -365,7 +365,7 @@ int SFileAddFile_Init(
365365
dwFlags &= ~MPQ_FILE_SECTOR_CRC;
366366

367367
// Sector CRC is not allowed if the file is not compressed
368-
if(!(dwFlags & MPQ_FILE_COMPRESSED))
368+
if(!(dwFlags & MPQ_FILE_COMPRESS_MASK))
369369
dwFlags &= ~MPQ_FILE_SECTOR_CRC;
370370

371371
// Fix Key is not allowed if the file is not enrypted

src/SFileCompactArchive.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static int CopyMpqFileSectors(
171171
DWORD dwSectorOffsLen = hf->SectorOffsets[0];
172172

173173
assert((pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT) == 0);
174-
assert(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED);
174+
assert(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK);
175175

176176
if(SectorOffsetsCopy == NULL)
177177
nError = ERROR_NOT_ENOUGH_MEMORY;

src/SFileReadFile.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW
143143
dwRawBytesToRead = dwBytesToRead;
144144

145145
// Perform all necessary work to do with compressed files
146-
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
146+
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
147147
{
148148
// If the sector positions are not loaded yet, do it
149149
if(hf->SectorOffsets == NULL)
@@ -209,7 +209,7 @@ static int ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, DW
209209
dwBytesInThisSector = dwBytesToRead;
210210

211211
// If the file is compressed, we have to adjust the raw sector size
212-
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
212+
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
213213
dwRawBytesInThisSector = hf->SectorOffsets[dwIndex + 1] - hf->SectorOffsets[dwIndex];
214214

215215
// If the file is encrypted, we have to decrypt the sector
@@ -332,7 +332,7 @@ static int ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos
332332
if(hf->dwSectorOffs != 0)
333333
{
334334
// Is the file compressed?
335-
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
335+
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
336336
{
337337
// Allocate space for compressed data
338338
pbCompressed = STORM_ALLOC(BYTE, pFileEntry->dwCmpSize);
@@ -357,7 +357,7 @@ static int ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos
357357
}
358358

359359
// If the file is compressed, we have to decompress it now
360-
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
360+
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
361361
{
362362
int cbOutBuffer = (int)hf->dwDataSize;
363363
int cbInBuffer = (int)pFileEntry->dwCmpSize;
@@ -455,7 +455,7 @@ static int ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos
455455
return nError;
456456

457457
// Is the file compressed?
458-
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
458+
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
459459
{
460460
// Allocate space for compressed data
461461
pbCompressed = STORM_ALLOC(BYTE, pFileEntry->dwCmpSize);
@@ -478,7 +478,7 @@ static int ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos
478478
}
479479

480480
// If the file is compressed, we have to decompress it now
481-
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESSED)
481+
if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK)
482482
{
483483
int cbOutBuffer = (int)hf->dwDataSize;
484484

src/StormLib.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,15 @@ extern "C" {
192192
// Flags for SFileAddFile
193193
#define MPQ_FILE_IMPLODE 0x00000100 // Implode method (By PKWARE Data Compression Library)
194194
#define MPQ_FILE_COMPRESS 0x00000200 // Compress methods (By multiple methods)
195-
#define MPQ_FILE_COMPRESSED 0x0000FF00 // File is compressed
196195
#define MPQ_FILE_ENCRYPTED 0x00010000 // Indicates whether file is encrypted
197196
#define MPQ_FILE_FIX_KEY 0x00020000 // File decryption key has to be fixed
198197
#define MPQ_FILE_PATCH_FILE 0x00100000 // The file is a patch file. Raw file data begin with TPatchInfo structure
199198
#define MPQ_FILE_SINGLE_UNIT 0x01000000 // File is stored as a single unit, rather than split into sectors (Thx, Quantam)
200199
#define MPQ_FILE_DELETE_MARKER 0x02000000 // File is a deletion marker. Used in MPQ patches, indicating that the file no longer exists.
201200
#define MPQ_FILE_SECTOR_CRC 0x04000000 // File has checksums for each sector.
202201
// Ignored if file is not compressed or imploded.
202+
203+
#define MPQ_FILE_COMPRESS_MASK 0x0000FF00 // Mask for a file being compressed
203204
#define MPQ_FILE_EXISTS 0x80000000 // Set if file exists, reset when the file was deleted
204205
#define MPQ_FILE_REPLACEEXISTING 0x80000000 // Replace when the file exist (SFileAddFile)
205206

@@ -213,6 +214,9 @@ extern "C" {
213214
MPQ_FILE_SECTOR_CRC | \
214215
MPQ_FILE_EXISTS)
215216

217+
// A notification that people should stop using this flag
218+
const STORMLIB_DEPRECATED("This symbol is deprecated. Use MPQ_FILE_COMPRESS_MASK") unsigned int MPQ_FILE_COMPRESSED = 0x0000FF00;
219+
216220
// Compression types for multiple compressions
217221
#define MPQ_COMPRESSION_HUFFMANN 0x01 // Huffmann compression (used on WAVE files only)
218222
#define MPQ_COMPRESSION_ZLIB 0x02 // ZLIB compression

src/StormPort.h

+26-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
#define false 0
3434
#endif
3535

36+
//-----------------------------------------------------------------------------
3637
// Defines for Windows
38+
3739
#if !defined(PLATFORM_DEFINED) && (defined(WIN32) || defined(WIN64))
3840

3941
// In MSVC 8.0, there are some functions declared as deprecated.
@@ -61,7 +63,9 @@
6163

6264
#endif
6365

64-
// Defines for Mac
66+
//-----------------------------------------------------------------------------
67+
// Defines for Mac
68+
6569
#if !defined(PLATFORM_DEFINED) && defined(__APPLE__) // Mac BSD API
6670

6771
// Macintosh
@@ -92,7 +96,9 @@
9296

9397
#endif
9498

99+
//-----------------------------------------------------------------------------
95100
// Assumption: we are not on Windows nor Macintosh, so this must be linux *grin*
101+
96102
#if !defined(PLATFORM_DEFINED)
97103

98104
#include <sys/types.h>
@@ -115,7 +121,9 @@
115121

116122
#endif
117123

118-
// Definition of Windows-specific structures for non-Windows platforms
124+
//-----------------------------------------------------------------------------
125+
// Definition of Windows-specific types for non-Windows platforms
126+
119127
#ifndef PLATFORM_WINDOWS
120128
#if __LP64__
121129
#define PLATFORM_64BIT
@@ -199,6 +207,9 @@
199207
#define ERROR_FILE_CORRUPT 1004 // No such error code under Linux
200208
#endif
201209

210+
//-----------------------------------------------------------------------------
211+
// Swapping functions
212+
202213
#ifdef PLATFORM_LITTLE_ENDIAN
203214
#define BSWAP_INT16_UNSIGNED(a) (a)
204215
#define BSWAP_INT16_SIGNED(a) (a)
@@ -249,4 +260,17 @@
249260
#define BSWAP_TMPKHEADER(a) ConvertTMPKHeader((a))
250261
#endif
251262

263+
//-----------------------------------------------------------------------------
264+
// Macro for deprecated symbols
265+
266+
#ifdef _MSC_VER
267+
#if _MSC_FULL_VER >= 140050320
268+
#define STORMLIB_DEPRECATED(_Text) __declspec(deprecated(_Text))
269+
#else
270+
#define STORMLIB_DEPRECATED(_Text) __declspec(deprecated)
271+
#endif
272+
#else
273+
#define STORMLIB_DEPRECATED(_Text) __attribute__((deprecated(_Text)))
274+
#endif
275+
252276
#endif // __STORMPORT_H__

test/Test.cpp

+33-2
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,33 @@ static int TestArchiveOpenAndClose(const TCHAR * szMpqName)
12221222
return nError;
12231223
}
12241224

1225+
static int TestAddFilesToArchive(const TCHAR * szMpqName)
1226+
{
1227+
HANDLE hFile;
1228+
HANDLE hMpq;
1229+
LPCSTR szFileData = "0123456789";
1230+
char szAddedFile[128];
1231+
DWORD dwFileSize = 10;
1232+
1233+
CopyFile(_T("e:\\Ladik\\Incoming\\Tya's Zerg Defense.SC2Map"), _T("e:\\Multimedia\\MPQs\\Tya's Zerg Defense.SC2Map"), FALSE);
1234+
1235+
for(int i = 0; i < 3; i++)
1236+
{
1237+
if(SFileOpenArchive(szMpqName, 0, 0, &hMpq))
1238+
{
1239+
sprintf(szAddedFile, "AddedFile%04u.txt", i);
1240+
1241+
if(SFileCreateFile(hMpq, szAddedFile, 0, dwFileSize, 0, MPQ_FILE_COMPRESS, &hFile))
1242+
{
1243+
SFileWriteFile(hMpq, szFileData, dwFileSize, MPQ_COMPRESSION_ZLIB);
1244+
SFileFinishFile(hFile);
1245+
}
1246+
}
1247+
}
1248+
1249+
return ERROR_SUCCESS;
1250+
}
1251+
12251252
static int TestFindFiles(const TCHAR * szMpqName)
12261253
{
12271254
TMPQFile * hf;
@@ -2213,11 +2240,15 @@ int main(void)
22132240
// nError = TestSectorCompress(MPQ_SECTOR_SIZE);
22142241

22152242
// Test the archive open and close
2216-
if(nError == ERROR_SUCCESS)
2217-
nError = TestArchiveOpenAndClose(MAKE_PATH("2012 - Longwu Online\\Data\\Scp.mpk"));
2243+
// if(nError == ERROR_SUCCESS)
2244+
// nError = TestArchiveOpenAndClose(MAKE_PATH("2012 - Longwu Online\\Data\\Scp.mpk"));
22182245
// nError = TestArchiveOpenAndClose(MAKE_PATH("1997 - Diablo I\\DIABDAT.MPQ"));
22192246
// nError = TestArchiveOpenAndClose(MAKE_PATH("2012 - War of the Immortals\\1\\Other.sqp"));
22202247

2248+
// Test for bug reported by BlueRaja
2249+
if(nError == ERROR_SUCCESS)
2250+
nError = TestAddFilesToArchive(MAKE_PATH("Tya's Zerg Defense.SC2Map"));
2251+
22212252
// if(nError == ERROR_SUCCESS)
22222253
// nError = TestFindFiles(MAKE_PATH("2002 - Warcraft III/HumanEd.mpq"));
22232254

0 commit comments

Comments
 (0)