mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2024-11-15 16:51:31 +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 "files.h"
|
||||||
#include "i_system.h"
|
#include "i_system.h"
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "m_misc.h"
|
#include "m_misc.h"
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// FileReader
|
// 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 *SzAlloc(void *, size_t size) { return malloc(size); }
|
||||||
static void SzFree(void *, void *address) { free(address); }
|
static void SzFree(void *, void *address) { free(address); }
|
||||||
ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||||
|
@ -398,20 +411,22 @@ FileReaderLZMA::FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool
|
||||||
|
|
||||||
FillBuffer();
|
FillBuffer();
|
||||||
|
|
||||||
LzmaDec_Construct(&Stream);
|
Streamp = new StreamPointer;
|
||||||
err = LzmaDec_Allocate(&Stream, header + 4, LZMA_PROPS_SIZE, &g_Alloc);
|
LzmaDec_Construct(&Streamp->Stream);
|
||||||
|
err = LzmaDec_Allocate(&Streamp->Stream, header + 4, LZMA_PROPS_SIZE, &g_Alloc);
|
||||||
|
|
||||||
if (err != SZ_OK)
|
if (err != SZ_OK)
|
||||||
{
|
{
|
||||||
I_Error("FileReaderLZMA: LzmaDec_Allocate failed: %d\n", err);
|
I_Error("FileReaderLZMA: LzmaDec_Allocate failed: %d\n", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
LzmaDec_Init(&Stream);
|
LzmaDec_Init(&Streamp->Stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReaderLZMA::~FileReaderLZMA ()
|
FileReaderLZMA::~FileReaderLZMA ()
|
||||||
{
|
{
|
||||||
LzmaDec_Free(&Stream, &g_Alloc);
|
LzmaDec_Free(&Streamp->Stream, &g_Alloc);
|
||||||
|
delete Streamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
long FileReaderLZMA::Read (void *buffer, long len)
|
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 out_processed = len;
|
||||||
size_t in_processed = InSize;
|
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;
|
InPos += in_processed;
|
||||||
InSize -= in_processed;
|
InSize -= in_processed;
|
||||||
next_out += out_processed;
|
next_out += out_processed;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include "bzlib.h"
|
#include "bzlib.h"
|
||||||
#include "LzmaDec.h"
|
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
#include "m_swap.h"
|
#include "m_swap.h"
|
||||||
|
|
||||||
|
@ -257,6 +256,8 @@ private:
|
||||||
// Wraps around a FileReader to decompress a lzma stream
|
// Wraps around a FileReader to decompress a lzma stream
|
||||||
class FileReaderLZMA : public FileReaderBase
|
class FileReaderLZMA : public FileReaderBase
|
||||||
{
|
{
|
||||||
|
struct StreamPointer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool zip);
|
FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool zip);
|
||||||
~FileReaderLZMA ();
|
~FileReaderLZMA ();
|
||||||
|
@ -308,7 +309,7 @@ private:
|
||||||
|
|
||||||
FileReader &File;
|
FileReader &File;
|
||||||
bool SawEOF;
|
bool SawEOF;
|
||||||
CLzmaDec Stream;
|
StreamPointer *Streamp; // anonymous pointer to LKZA decoder struct - to avoid including the LZMA headers globally
|
||||||
size_t Size;
|
size_t Size;
|
||||||
size_t InPos, InSize;
|
size_t InPos, InSize;
|
||||||
size_t OutProcessed;
|
size_t OutProcessed;
|
||||||
|
|
|
@ -32,6 +32,10 @@
|
||||||
**
|
**
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
#define USE_WINDOWS_DWORD
|
||||||
|
|
||||||
|
#include "7z.h"
|
||||||
|
#include "7zCrc.h"
|
||||||
|
|
||||||
#include "resourcefile.h"
|
#include "resourcefile.h"
|
||||||
#include "cmdlib.h"
|
#include "cmdlib.h"
|
||||||
|
@ -41,8 +45,6 @@
|
||||||
#include "i_system.h"
|
#include "i_system.h"
|
||||||
#include "w_wad.h"
|
#include "w_wad.h"
|
||||||
|
|
||||||
#include "7z.h"
|
|
||||||
#include "7zCrc.h"
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
|
@ -129,7 +129,7 @@ typedef struct compressor_s
|
||||||
int method;
|
int method;
|
||||||
} compressor_t;
|
} compressor_t;
|
||||||
|
|
||||||
typedef unsigned int DWORD;
|
typedef unsigned int UINT32;
|
||||||
typedef unsigned short WORD;
|
typedef unsigned short WORD;
|
||||||
typedef unsigned char BYTE;
|
typedef unsigned char BYTE;
|
||||||
|
|
||||||
|
@ -139,49 +139,49 @@ typedef unsigned char BYTE;
|
||||||
//#pragma pack(push,1)
|
//#pragma pack(push,1)
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
DWORD Magic; // 0
|
UINT32 Magic; // 0
|
||||||
BYTE VersionToExtract[2]; // 4
|
BYTE VersionToExtract[2]; // 4
|
||||||
WORD Flags; // 6
|
WORD Flags; // 6
|
||||||
WORD Method; // 8
|
WORD Method; // 8
|
||||||
WORD ModTime; // 10
|
WORD ModTime; // 10
|
||||||
WORD ModDate; // 12
|
WORD ModDate; // 12
|
||||||
DWORD CRC32; // 14
|
UINT32 CRC32; // 14
|
||||||
DWORD CompressedSize; // 18
|
UINT32 CompressedSize; // 18
|
||||||
DWORD UncompressedSize; // 22
|
UINT32 UncompressedSize; // 22
|
||||||
WORD NameLength; // 26
|
WORD NameLength; // 26
|
||||||
WORD ExtraLength; // 28
|
WORD ExtraLength; // 28
|
||||||
} LocalFileHeader;
|
} LocalFileHeader;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
DWORD Magic;
|
UINT32 Magic;
|
||||||
BYTE VersionMadeBy[2];
|
BYTE VersionMadeBy[2];
|
||||||
BYTE VersionToExtract[2];
|
BYTE VersionToExtract[2];
|
||||||
WORD Flags;
|
WORD Flags;
|
||||||
WORD Method;
|
WORD Method;
|
||||||
WORD ModTime;
|
WORD ModTime;
|
||||||
WORD ModDate;
|
WORD ModDate;
|
||||||
DWORD CRC32;
|
UINT32 CRC32;
|
||||||
DWORD CompressedSize;
|
UINT32 CompressedSize;
|
||||||
DWORD UncompressedSize;
|
UINT32 UncompressedSize;
|
||||||
WORD NameLength;
|
WORD NameLength;
|
||||||
WORD ExtraLength;
|
WORD ExtraLength;
|
||||||
WORD CommentLength;
|
WORD CommentLength;
|
||||||
WORD StartingDiskNumber;
|
WORD StartingDiskNumber;
|
||||||
WORD InternalAttributes;
|
WORD InternalAttributes;
|
||||||
DWORD ExternalAttributes;
|
UINT32 ExternalAttributes;
|
||||||
DWORD LocalHeaderOffset;
|
UINT32 LocalHeaderOffset;
|
||||||
} CentralDirectoryEntry;
|
} CentralDirectoryEntry;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
DWORD Magic;
|
UINT32 Magic;
|
||||||
WORD DiskNumber;
|
WORD DiskNumber;
|
||||||
WORD FirstDisk;
|
WORD FirstDisk;
|
||||||
WORD NumEntries;
|
WORD NumEntries;
|
||||||
WORD NumEntriesOnAllDisks;
|
WORD NumEntriesOnAllDisks;
|
||||||
DWORD DirectorySize;
|
UINT32 DirectorySize;
|
||||||
DWORD DirectoryOffset;
|
UINT32 DirectoryOffset;
|
||||||
WORD ZipCommentLength;
|
WORD ZipCommentLength;
|
||||||
} EndOfCentralDirectory;
|
} EndOfCentralDirectory;
|
||||||
//#pragma pack(pop)
|
//#pragma pack(pop)
|
||||||
|
@ -1373,7 +1373,7 @@ BYTE *find_central_dir(FILE *fin)
|
||||||
back_read = 4;
|
back_read = 4;
|
||||||
while (back_read < max_back)
|
while (back_read < max_back)
|
||||||
{
|
{
|
||||||
DWORD read_size, read_pos;
|
UINT32 read_size, read_pos;
|
||||||
int i;
|
int i;
|
||||||
if (back_read + BUFREADCOMMENT > max_back)
|
if (back_read + BUFREADCOMMENT > max_back)
|
||||||
back_read = max_back;
|
back_read = max_back;
|
||||||
|
@ -1420,12 +1420,12 @@ BYTE *find_central_dir(FILE *fin)
|
||||||
free(dir);
|
free(dir);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (*(DWORD *)dir != ZIP_CENTRALFILE)
|
if (*(UINT32 *)dir != ZIP_CENTRALFILE)
|
||||||
{
|
{
|
||||||
free(dir);
|
free(dir);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*(DWORD *)(dir + LittleLong(eod.DirectorySize)) = ZIP_ENDOFDIR;
|
*(UINT32 *)(dir + LittleLong(eod.DirectorySize)) = ZIP_ENDOFDIR;
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1444,7 +1444,7 @@ CentralDirectoryEntry *find_file_in_zip(BYTE *dir, const char *path, unsigned in
|
||||||
CentralDirectoryEntry *ent;
|
CentralDirectoryEntry *ent;
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
while (*(DWORD *)dir == ZIP_CENTRALFILE)
|
while (*(UINT32 *)dir == ZIP_CENTRALFILE)
|
||||||
{
|
{
|
||||||
ent = (CentralDirectoryEntry *)dir;
|
ent = (CentralDirectoryEntry *)dir;
|
||||||
if (pathlen == LittleShort(ent->NameLength) &&
|
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);
|
dir += sizeof(*ent) + LittleShort(ent->NameLength) + LittleShort(ent->ExtraLength) + LittleShort(ent->CommentLength);
|
||||||
}
|
}
|
||||||
if (*(DWORD *)dir != ZIP_CENTRALFILE)
|
if (*(UINT32 *)dir != ZIP_CENTRALFILE)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1495,7 +1495,7 @@ int copy_zip_file(FILE *zip, file_entry_t *file, FILE *ozip, CentralDirectoryEnt
|
||||||
{
|
{
|
||||||
LocalFileHeader lfh;
|
LocalFileHeader lfh;
|
||||||
BYTE *buf;
|
BYTE *buf;
|
||||||
DWORD buf_size;
|
UINT32 buf_size;
|
||||||
|
|
||||||
if (fseek(ozip, LittleLong(ent->LocalHeaderOffset), SEEK_SET) != 0)
|
if (fseek(ozip, LittleLong(ent->LocalHeaderOffset), SEEK_SET) != 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue