mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-07 21:58:03 +00:00
filesystem: zip: remove XASH_ZLIB macro
This commit is contained in:
parent
3c0a34926a
commit
b04a48f126
engine/common
@ -16,6 +16,7 @@ GNU General Public License for more details.
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <zlib.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
@ -33,10 +34,6 @@ GNU General Public License for more details.
|
|||||||
#define FILE_COPY_SIZE (1024 * 1024)
|
#define FILE_COPY_SIZE (1024 * 1024)
|
||||||
#define FILE_BUFF_SIZE (2048)
|
#define FILE_BUFF_SIZE (2048)
|
||||||
|
|
||||||
#ifdef XASH_ZLIB
|
|
||||||
#include <zlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// PAK errors
|
// PAK errors
|
||||||
#define PAK_LOAD_OK 0
|
#define PAK_LOAD_OK 0
|
||||||
#define PAK_LOAD_COULDNT_OPEN 1
|
#define PAK_LOAD_COULDNT_OPEN 1
|
||||||
@ -63,8 +60,6 @@ GNU General Public License for more details.
|
|||||||
#define ZIP_LOAD_NO_FILES 5
|
#define ZIP_LOAD_NO_FILES 5
|
||||||
#define ZIP_LOAD_CORRUPTED 6
|
#define ZIP_LOAD_CORRUPTED 6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct stringlist_s
|
typedef struct stringlist_s
|
||||||
{
|
{
|
||||||
// maxstrings changes as needed, causing reallocation of strings[] array
|
// maxstrings changes as needed, causing reallocation of strings[] array
|
||||||
@ -693,7 +688,9 @@ static zip_t *FS_LoadZip( const char *zipfile, int *error )
|
|||||||
Zip_Close( zip );
|
Zip_Close( zip );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if( signature != ZIP_HEADER_LF ) {
|
|
||||||
|
if( signature != ZIP_HEADER_LF )
|
||||||
|
{
|
||||||
Con_Reportf( "%s is not a zip file. Ignored.\n", zipfile );
|
Con_Reportf( "%s is not a zip file. Ignored.\n", zipfile );
|
||||||
if( error )
|
if( error )
|
||||||
*error = ZIP_LOAD_BAD_HEADER;
|
*error = ZIP_LOAD_BAD_HEADER;
|
||||||
@ -804,7 +801,7 @@ static byte *Zip_LoadFile( const char *path, fs_offset_t *sizeptr, qboolean game
|
|||||||
zip_header_t header;
|
zip_header_t header;
|
||||||
zipfile_t *file = NULL;
|
zipfile_t *file = NULL;
|
||||||
|
|
||||||
if(sizeptr) sizeptr == 0;
|
if( sizeptr ) sizeptr == 0;
|
||||||
|
|
||||||
search = FS_FindFile( path, &index, gamedironly );
|
search = FS_FindFile( path, &index, gamedironly );
|
||||||
|
|
||||||
@ -823,7 +820,7 @@ static byte *Zip_LoadFile( const char *path, fs_offset_t *sizeptr, qboolean game
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(header.compression_flags == ZIP_COMPRESSION_NO_COMPRESSION)
|
if( header.compression_flags == ZIP_COMPRESSION_NO_COMPRESSION )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( header.filename_len )
|
if( header.filename_len )
|
||||||
@ -858,8 +855,9 @@ static byte *Zip_LoadFile( const char *path, fs_offset_t *sizeptr, qboolean game
|
|||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
#ifdef XASH_ZLIB
|
|
||||||
if( header.compression_flags == ZIP_COMPRESSION_DEFLATED ) {
|
if( header.compression_flags == ZIP_COMPRESSION_DEFLATED )
|
||||||
|
{
|
||||||
|
|
||||||
if( header.filename_len )
|
if( header.filename_len )
|
||||||
FS_Seek( search->zip->handle, header.filename_len, SEEK_CUR );
|
FS_Seek( search->zip->handle, header.filename_len, SEEK_CUR );
|
||||||
@ -892,35 +890,34 @@ static byte *Zip_LoadFile( const char *path, fs_offset_t *sizeptr, qboolean game
|
|||||||
CRC32_Init( &test_crc );
|
CRC32_Init( &test_crc );
|
||||||
CRC32_ProcessBuffer( &test_crc, decompresed_buffer, file->size );
|
CRC32_ProcessBuffer( &test_crc, decompresed_buffer, file->size );
|
||||||
|
|
||||||
dword final_crc = CRC32_Final(test_crc);
|
dword final_crc = CRC32_Final( test_crc );
|
||||||
|
|
||||||
if(final_crc != header.crc32)
|
if( final_crc != header.crc32 )
|
||||||
{
|
{
|
||||||
Con_Reportf( S_ERROR "Zip_LoadFile: %s file crc32 mismatch\n", file->name );
|
Con_Reportf( S_ERROR "Zip_LoadFile: %s file crc32 mismatch\n", file->name );
|
||||||
Mem_Free( decompresed_buffer );
|
Mem_Free( decompresed_buffer );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( sizeptr ) *sizeptr = file->size;
|
||||||
|
|
||||||
} else if( zlib_result == Z_DATA_ERROR ){
|
return decompresed_buffer;
|
||||||
Con_Reportf( S_ERROR "Zip_LoadFile: %s : compressed files data corrupted.\n", file->name );
|
|
||||||
|
} else if( zlib_result == Z_DATA_ERROR )
|
||||||
|
{
|
||||||
|
Con_Reportf( S_ERROR "Zip_LoadFile: %s : compressed file data corrupted.\n", file->name );
|
||||||
Mem_Free( compresed_buffer );
|
Mem_Free( compresed_buffer );
|
||||||
Mem_Free( decompresed_buffer );
|
Mem_Free( decompresed_buffer );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
Con_Reportf( S_ERROR "Zip_LoadFile: %s : file compressed with unknown algorithm.\n", file->name );
|
Con_Reportf( S_ERROR "Zip_LoadFile: %s : file compressed with unknown algorithm.\n", file->name );
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
else {
|
|
||||||
Con_Reportf( S_ERROR "Zip_LoadFile: %s : compressed files not supported.\n", file->name );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user