mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2024-11-15 08:41:59 +00:00
fixed compilation with latest LZMA SDK on Windows.
LZMA SDK recently added an #include <windows.h> to its headers, meaning it's no longer safe to include its headers globally in platform independent files. The following changes were necessary: - rename DWORD type in zipdir.c - add USE_WINDOWS_DWORD and reorder includes in file_7z.cpp - wrap LZMA decoder stream into a local struct that's declared anonymously in files.h and adjust files.cpp for this change.
This commit is contained in:
parent
8aff59e704
commit
270541f942
4 changed files with 47 additions and 29 deletions
|
@ -33,11 +33,15 @@
|
|||
**
|
||||
*/
|
||||
|
||||
#define USE_WINDOWS_DWORD
|
||||
#include "LzmaDec.h"
|
||||
|
||||
#include "files.h"
|
||||
#include "i_system.h"
|
||||
#include "templates.h"
|
||||
#include "m_misc.h"
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FileReader
|
||||
|
@ -370,6 +374,15 @@ extern "C" void bz_internal_error (int errcode)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
// This is retarded but necessary to work around the inclusion of windows.h in recent
|
||||
// LZMA versions, meaning it's no longer possible to include the LZMA headers in files.h.
|
||||
// As a result we cannot declare the CLzmaDec member in the header so we work around
|
||||
// it my wrapping it into another struct that can be declared anonymously in the header.
|
||||
struct FileReaderLZMA::StreamPointer
|
||||
{
|
||||
CLzmaDec Stream;
|
||||
};
|
||||
|
||||
static void *SzAlloc(void *, size_t size) { return malloc(size); }
|
||||
static void SzFree(void *, void *address) { free(address); }
|
||||
ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||
|
@ -398,20 +411,22 @@ FileReaderLZMA::FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool
|
|||
|
||||
FillBuffer();
|
||||
|
||||
LzmaDec_Construct(&Stream);
|
||||
err = LzmaDec_Allocate(&Stream, header + 4, LZMA_PROPS_SIZE, &g_Alloc);
|
||||
Streamp = new StreamPointer;
|
||||
LzmaDec_Construct(&Streamp->Stream);
|
||||
err = LzmaDec_Allocate(&Streamp->Stream, header + 4, LZMA_PROPS_SIZE, &g_Alloc);
|
||||
|
||||
if (err != SZ_OK)
|
||||
{
|
||||
I_Error("FileReaderLZMA: LzmaDec_Allocate failed: %d\n", err);
|
||||
}
|
||||
|
||||
LzmaDec_Init(&Stream);
|
||||
LzmaDec_Init(&Streamp->Stream);
|
||||
}
|
||||
|
||||
FileReaderLZMA::~FileReaderLZMA ()
|
||||
{
|
||||
LzmaDec_Free(&Stream, &g_Alloc);
|
||||
LzmaDec_Free(&Streamp->Stream, &g_Alloc);
|
||||
delete Streamp;
|
||||
}
|
||||
|
||||
long FileReaderLZMA::Read (void *buffer, long len)
|
||||
|
@ -426,7 +441,7 @@ long FileReaderLZMA::Read (void *buffer, long len)
|
|||
size_t out_processed = len;
|
||||
size_t in_processed = InSize;
|
||||
|
||||
err = LzmaDec_DecodeToBuf(&Stream, next_out, &out_processed, InBuff + InPos, &in_processed, finish_mode, &status);
|
||||
err = LzmaDec_DecodeToBuf(&Streamp->Stream, next_out, &out_processed, InBuff + InPos, &in_processed, finish_mode, &status);
|
||||
InPos += in_processed;
|
||||
InSize -= in_processed;
|
||||
next_out += out_processed;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <stdio.h>
|
||||
#include <zlib.h>
|
||||
#include "bzlib.h"
|
||||
#include "LzmaDec.h"
|
||||
#include "doomtype.h"
|
||||
#include "m_swap.h"
|
||||
|
||||
|
@ -257,6 +256,8 @@ private:
|
|||
// Wraps around a FileReader to decompress a lzma stream
|
||||
class FileReaderLZMA : public FileReaderBase
|
||||
{
|
||||
struct StreamPointer;
|
||||
|
||||
public:
|
||||
FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool zip);
|
||||
~FileReaderLZMA ();
|
||||
|
@ -308,7 +309,7 @@ private:
|
|||
|
||||
FileReader &File;
|
||||
bool SawEOF;
|
||||
CLzmaDec Stream;
|
||||
StreamPointer *Streamp; // anonymous pointer to LKZA decoder struct - to avoid including the LZMA headers globally
|
||||
size_t Size;
|
||||
size_t InPos, InSize;
|
||||
size_t OutProcessed;
|
||||
|
|
|
@ -32,6 +32,10 @@
|
|||
**
|
||||
**
|
||||
*/
|
||||
#define USE_WINDOWS_DWORD
|
||||
|
||||
#include "7z.h"
|
||||
#include "7zCrc.h"
|
||||
|
||||
#include "resourcefile.h"
|
||||
#include "cmdlib.h"
|
||||
|
@ -41,8 +45,6 @@
|
|||
#include "i_system.h"
|
||||
#include "w_wad.h"
|
||||
|
||||
#include "7z.h"
|
||||
#include "7zCrc.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -129,7 +129,7 @@ typedef struct compressor_s
|
|||
int method;
|
||||
} compressor_t;
|
||||
|
||||
typedef unsigned int DWORD;
|
||||
typedef unsigned int UINT32;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
|
@ -139,49 +139,49 @@ typedef unsigned char BYTE;
|
|||
//#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
DWORD Magic; // 0
|
||||
UINT32 Magic; // 0
|
||||
BYTE VersionToExtract[2]; // 4
|
||||
WORD Flags; // 6
|
||||
WORD Method; // 8
|
||||
WORD ModTime; // 10
|
||||
WORD ModDate; // 12
|
||||
DWORD CRC32; // 14
|
||||
DWORD CompressedSize; // 18
|
||||
DWORD UncompressedSize; // 22
|
||||
UINT32 CRC32; // 14
|
||||
UINT32 CompressedSize; // 18
|
||||
UINT32 UncompressedSize; // 22
|
||||
WORD NameLength; // 26
|
||||
WORD ExtraLength; // 28
|
||||
} LocalFileHeader;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DWORD Magic;
|
||||
UINT32 Magic;
|
||||
BYTE VersionMadeBy[2];
|
||||
BYTE VersionToExtract[2];
|
||||
WORD Flags;
|
||||
WORD Method;
|
||||
WORD ModTime;
|
||||
WORD ModDate;
|
||||
DWORD CRC32;
|
||||
DWORD CompressedSize;
|
||||
DWORD UncompressedSize;
|
||||
UINT32 CRC32;
|
||||
UINT32 CompressedSize;
|
||||
UINT32 UncompressedSize;
|
||||
WORD NameLength;
|
||||
WORD ExtraLength;
|
||||
WORD CommentLength;
|
||||
WORD StartingDiskNumber;
|
||||
WORD InternalAttributes;
|
||||
DWORD ExternalAttributes;
|
||||
DWORD LocalHeaderOffset;
|
||||
UINT32 ExternalAttributes;
|
||||
UINT32 LocalHeaderOffset;
|
||||
} CentralDirectoryEntry;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DWORD Magic;
|
||||
UINT32 Magic;
|
||||
WORD DiskNumber;
|
||||
WORD FirstDisk;
|
||||
WORD NumEntries;
|
||||
WORD NumEntriesOnAllDisks;
|
||||
DWORD DirectorySize;
|
||||
DWORD DirectoryOffset;
|
||||
UINT32 DirectorySize;
|
||||
UINT32 DirectoryOffset;
|
||||
WORD ZipCommentLength;
|
||||
} EndOfCentralDirectory;
|
||||
//#pragma pack(pop)
|
||||
|
@ -1373,7 +1373,7 @@ BYTE *find_central_dir(FILE *fin)
|
|||
back_read = 4;
|
||||
while (back_read < max_back)
|
||||
{
|
||||
DWORD read_size, read_pos;
|
||||
UINT32 read_size, read_pos;
|
||||
int i;
|
||||
if (back_read + BUFREADCOMMENT > max_back)
|
||||
back_read = max_back;
|
||||
|
@ -1420,12 +1420,12 @@ BYTE *find_central_dir(FILE *fin)
|
|||
free(dir);
|
||||
return NULL;
|
||||
}
|
||||
if (*(DWORD *)dir != ZIP_CENTRALFILE)
|
||||
if (*(UINT32 *)dir != ZIP_CENTRALFILE)
|
||||
{
|
||||
free(dir);
|
||||
return NULL;
|
||||
}
|
||||
*(DWORD *)(dir + LittleLong(eod.DirectorySize)) = ZIP_ENDOFDIR;
|
||||
*(UINT32 *)(dir + LittleLong(eod.DirectorySize)) = ZIP_ENDOFDIR;
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
@ -1444,7 +1444,7 @@ CentralDirectoryEntry *find_file_in_zip(BYTE *dir, const char *path, unsigned in
|
|||
CentralDirectoryEntry *ent;
|
||||
int flags;
|
||||
|
||||
while (*(DWORD *)dir == ZIP_CENTRALFILE)
|
||||
while (*(UINT32 *)dir == ZIP_CENTRALFILE)
|
||||
{
|
||||
ent = (CentralDirectoryEntry *)dir;
|
||||
if (pathlen == LittleShort(ent->NameLength) &&
|
||||
|
@ -1455,7 +1455,7 @@ CentralDirectoryEntry *find_file_in_zip(BYTE *dir, const char *path, unsigned in
|
|||
}
|
||||
dir += sizeof(*ent) + LittleShort(ent->NameLength) + LittleShort(ent->ExtraLength) + LittleShort(ent->CommentLength);
|
||||
}
|
||||
if (*(DWORD *)dir != ZIP_CENTRALFILE)
|
||||
if (*(UINT32 *)dir != ZIP_CENTRALFILE)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1495,7 +1495,7 @@ int copy_zip_file(FILE *zip, file_entry_t *file, FILE *ozip, CentralDirectoryEnt
|
|||
{
|
||||
LocalFileHeader lfh;
|
||||
BYTE *buf;
|
||||
DWORD buf_size;
|
||||
UINT32 buf_size;
|
||||
|
||||
if (fseek(ozip, LittleLong(ent->LocalHeaderOffset), SEEK_SET) != 0)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue