mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-03-21 10:11:01 +00:00
minizip: re-add doom3-specific changes
This commit is contained in:
parent
954620e1b3
commit
f6f654ee53
6 changed files with 103 additions and 9 deletions
|
@ -26,6 +26,7 @@ Note: Numbers starting with a "#" like #330 refer to the bugreport with that num
|
|||
* Fix several compiler warnings
|
||||
* Added build instructions for Linux (and similar systems) to README.md
|
||||
* Updated stb_image and stb_vorbis
|
||||
* Updated minizip (from zlib/contrib) to latest upstream code
|
||||
|
||||
|
||||
1.5.2 (2022-06-13)
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
NOTE from Daniel Gibson:
|
||||
|
||||
These are parts of MiniZip (the unzip-parts), taken from zlib-1.2.7/contrib/minizip/
|
||||
and adjusted for doom3 by making small adjustments foor doom3 (doom3-specific allocator)
|
||||
These are parts of MiniZip (the unzip-parts), taken from zlib's contrib/minizip/,
|
||||
the now-current development branch (commit f56ad0aafa868303ce324ae8d45675570c66b050
|
||||
"Note termination of returned strings in contrib/minizip/unzip.h." from 2024-01-23)
|
||||
and adjusted for doom3 by making small adjustments for doom3 (doom3-specific allocator,
|
||||
which included reintroducing the TRYFREE macro that was removed upstream)
|
||||
and adding a function (unzReOpen()) from the original Doom3 GPL release by id Software
|
||||
that used MiniZip 0.15beta. It was adjusted by Daniel Gibson for MiniZip 1.1
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2012 Daniel Gibson
|
||||
Copyright (C) 2012,2024 Daniel Gibson
|
||||
|
||||
|
||||
########### Original Content of this File below #############
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
|
||||
#if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) || defined(__OpenBSD__)
|
||||
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
|
||||
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
|
||||
#define FTELLO_FUNC(stream) ftello(stream)
|
||||
|
|
|
@ -21,6 +21,12 @@
|
|||
#ifndef _ZLIBIOAPI64_H
|
||||
#define _ZLIBIOAPI64_H
|
||||
|
||||
// fixes Gentoo zlib problems, see
|
||||
// https://bugs.gentoo.org/show_bug.cgi?id=383179
|
||||
#ifndef OF
|
||||
#define OF(x) x
|
||||
#endif
|
||||
|
||||
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
|
||||
|
||||
// Linux needs this to support file operation on files larger then 4+GB
|
||||
|
@ -43,7 +49,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "zlib.h"
|
||||
#include <zlib.h>
|
||||
|
||||
#if defined(USE_FILE32API)
|
||||
#define fopen64 fopen
|
||||
|
|
|
@ -61,9 +61,18 @@
|
|||
|
||||
Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
|
||||
|
||||
####################################################################################
|
||||
|
||||
unzReOpen() was added by id Software (originally in framework/Unzip.cpp) for doom3
|
||||
and adjusted for MiniZip 1.1 by Daniel Gibson
|
||||
The file was renamed from unzip.c to unzip.cpp so we can use C++ functions from doom3
|
||||
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2012 Daniel Gibson
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#if 0 // we don't really want system includes here
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -80,6 +89,18 @@
|
|||
# include <errno.h>
|
||||
#endif
|
||||
|
||||
#else // 0
|
||||
// use doom3 headers
|
||||
#include "sys/platform.h"
|
||||
#include "idlib/Heap.h"
|
||||
#include "idlib/Lib.h"
|
||||
|
||||
// we don't need crypt support
|
||||
#define NOUNCRYPT 1
|
||||
|
||||
#include "unzip.h"
|
||||
#endif // 0
|
||||
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
|
@ -102,12 +123,17 @@
|
|||
#define UNZ_MAXFILENAMEINZIP (256)
|
||||
#endif
|
||||
|
||||
#if 0 // don't use system malloc but doom3's allocator
|
||||
#ifndef ALLOC
|
||||
# define ALLOC(size) (malloc(size))
|
||||
#endif
|
||||
#ifndef TRYFREE
|
||||
# define TRYFREE(p) { free(p);}
|
||||
#endif
|
||||
#else // 0
|
||||
#define ALLOC(size) (Mem_Alloc(size))
|
||||
#define TRYFREE(p) {Mem_Free(p);} // Mem_Free - as well as free() - check for NULL themselves, no need to do it here
|
||||
#endif // 0
|
||||
|
||||
#define SIZECENTRALDIRITEM (0x2e)
|
||||
#define SIZEZIPLOCALHEADER (0x1e)
|
||||
|
@ -1593,6 +1619,9 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len) {
|
|||
uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
|
||||
if (uReadThis == 0)
|
||||
return UNZ_EOF;
|
||||
// TODO: the following line was added by id Software to the original src - seems to work without it,
|
||||
// but if problems occur look here..
|
||||
// if(s->cur_file_info.compressed_size == pfile_in_zip_read_info->rest_read_compressed)
|
||||
if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
|
||||
pfile_in_zip_read_info->filestream,
|
||||
pfile_in_zip_read_info->pos_in_zipfile +
|
||||
|
@ -1982,3 +2011,42 @@ extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) {
|
|||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) {
|
||||
return unzSetOffset64(file,pos);
|
||||
}
|
||||
|
||||
|
||||
// ####################################################################
|
||||
// the following function was added for doom3 by id Software and
|
||||
// adjusted for MiniZip 1.1 by Daniel Gibson
|
||||
|
||||
|
||||
extern unzFile unzReOpen (const char* path, unzFile file)
|
||||
{
|
||||
unz64_s* s;
|
||||
unz64_s* zFile = (unz64_s*)file;
|
||||
|
||||
if(zFile == NULL)
|
||||
return NULL;
|
||||
|
||||
// create unz64_s* "s" as clone of "file"
|
||||
s=(unz64_s*)ALLOC(sizeof(unz64_s));
|
||||
if(s == NULL)
|
||||
return NULL;
|
||||
|
||||
memcpy(s, zFile, sizeof(unz64_s));
|
||||
|
||||
// create new filestream for path
|
||||
voidp fin = ZOPEN64(s->z_filefunc,
|
||||
path,
|
||||
ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_EXISTING);
|
||||
|
||||
if( fin == NULL ) {
|
||||
TRYFREE(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// set that filestream in s
|
||||
s->filestream = fin;
|
||||
|
||||
unzOpenCurrentFile( s );
|
||||
|
||||
return (unzFile)s;
|
||||
}
|
||||
|
|
|
@ -48,12 +48,12 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
// TODO #ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
// TODO #endif
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
#include "bzlib.h"
|
||||
|
@ -433,6 +433,22 @@ extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
|
|||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||
|
||||
|
||||
// ####################################################################
|
||||
|
||||
// the following function was added for doom3 by id Software
|
||||
|
||||
extern unzFile unzReOpen( const char* path, unzFile file );
|
||||
|
||||
/*
|
||||
Re-Open a Zip file, i.e. clone an existing one and give it a new file descriptor.
|
||||
path contain the full pathname (by example,
|
||||
on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
|
||||
"zlib/zlib111.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue