]> git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake3/common/unzip.h
Merge branch 'libpng16fix' into 'master'
[xonotic/netradiant.git] / tools / quake3 / common / unzip.h
1 /*
2    Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #include <zlib.h>
23
24 #if defined( STRICTUNZIP ) || defined( STRICTZIPUNZIP )
25 /* like the STRICT of WIN32, we define a pointer that cannot be converted
26     from (void*) without cast */
27 typedef struct TagunzFile__ { int unused; } unzFile__;
28 typedef unzFile__ *unzFile;
29 #else
30 typedef void* unzFile;
31 #endif
32
33
34 /* tm_unz contain date/time info */
35 typedef struct tm_unz_s
36 {
37         unsigned int tm_sec;            /* seconds after the minute - [0,59] */
38         unsigned int tm_min;            /* minutes after the hour - [0,59] */
39         unsigned int tm_hour;           /* hours since midnight - [0,23] */
40         unsigned int tm_mday;           /* day of the month - [1,31] */
41         unsigned int tm_mon;            /* months since January - [0,11] */
42         unsigned int tm_year;           /* years - [1980..2044] */
43 } tm_unz;
44
45 /* unz_global_info structure contain global data about the ZIPfile
46    These data comes from the end of central dir */
47 typedef struct unz_global_info_s
48 {
49         unsigned long number_entry;         /* total number of entries in the central dir on this disk */
50         unsigned long size_comment;         /* size of the global comment of the zipfile */
51 } unz_global_info;
52
53
54 /* unz_file_info contain information about a file in the zipfile */
55 typedef struct unz_file_info_s
56 {
57         unsigned long version;              /* version made by                 2 unsigned chars */
58         unsigned long version_needed;       /* version needed to extract       2 unsigned chars */
59         unsigned long flag;                 /* general purpose bit flag        2 unsigned chars */
60         unsigned long compression_method;   /* compression method              2 unsigned chars */
61         unsigned long dosDate;              /* last mod file date in Dos fmt   4 unsigned chars */
62         unsigned long crc;                  /* crc-32                          4 unsigned chars */
63         unsigned long compressed_size;      /* compressed size                 4 unsigned chars */
64         unsigned long uncompressed_size;    /* uncompressed size               4 unsigned chars */
65         unsigned long size_filename;        /* filename length                 2 unsigned chars */
66         unsigned long size_file_extra;      /* extra field length              2 unsigned chars */
67         unsigned long size_file_comment;    /* file comment length             2 unsigned chars */
68
69         unsigned long disk_num_start;       /* disk number start               2 unsigned chars */
70         unsigned long internal_fa;          /* internal file attributes        2 unsigned chars */
71         unsigned long external_fa;          /* external file attributes        4 unsigned chars */
72
73         tm_unz tmu_date;
74 } unz_file_info;
75
76 /* unz_file_info_interntal contain internal info about a file in zipfile*/
77 typedef struct unz_file_info_internal_s
78 {
79         unsigned long offset_curfile; /* relative offset of static header 4 unsigned chars */
80 } unz_file_info_internal;
81
82 typedef void* ( *alloc_func )( void* opaque, unsigned int items, unsigned int size );
83 typedef void ( *free_func )( void* opaque, void* address );
84
85 struct internal_state;
86
87 /* file_in_zip_read_info_s contain internal information about a file in zipfile,
88     when reading and decompress it */
89 typedef struct
90 {
91         char  *read_buffer;         /* internal buffer for compressed data */
92         z_stream stream;            /* zLib stream structure for inflate */
93
94         unsigned long pos_in_zipfile;       /* position in unsigned char on the zipfile, for fseek*/
95         unsigned long stream_initialised;   /* flag set if stream structure is initialised*/
96
97         unsigned long offset_local_extrafield; /* offset of the static extra field */
98         unsigned int size_local_extrafield; /* size of the static extra field */
99         unsigned long pos_local_extrafield;   /* position in the static extra field in read*/
100
101         unsigned long crc32;                /* crc32 of all data uncompressed */
102         unsigned long crc32_wait;           /* crc32 we must obtain after decompress all */
103         unsigned long rest_read_compressed; /* number of unsigned char to be decompressed */
104         unsigned long rest_read_uncompressed; /*number of unsigned char to be obtained after decomp*/
105         FILE* file;                 /* io structore of the zipfile */
106         unsigned long compression_method;   /* compression method (0==store) */
107         unsigned long byte_before_the_zipfile; /* unsigned char before the zipfile, (>0 for sfx)*/
108 } file_in_zip_read_info_s;
109
110
111 /* unz_s contain internal information about the zipfile
112  */
113 typedef struct
114 {
115         FILE* file;                 /* io structore of the zipfile */
116         unz_global_info gi;       /* public global information */
117         unsigned long byte_before_the_zipfile; /* unsigned char before the zipfile, (>0 for sfx)*/
118         unsigned long num_file;             /* number of the current file in the zipfile*/
119         unsigned long pos_in_central_dir;   /* pos of the current file in the central dir*/
120         unsigned long current_file_ok;      /* flag about the usability of the current file*/
121         unsigned long central_pos;          /* position of the beginning of the central dir*/
122
123         unsigned long size_central_dir;     /* size of the central directory  */
124         unsigned long offset_central_dir;   /* offset of start of central directory with
125                                                respect to the starting disk number */
126
127         unz_file_info cur_file_info; /* public info about the current file in zip*/
128         unz_file_info_internal cur_file_info_internal; /* private info about it*/
129         file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
130                                                        file if we are decompressing it */
131 } unz_s;
132
133 #define UNZ_OK                                  ( 0 )
134 #define UNZ_END_OF_LIST_OF_FILE ( -100 )
135 #define UNZ_ERRNO               ( Z_ERRNO )
136 #define UNZ_EOF                 ( 0 )
137 #define UNZ_PARAMERROR                  ( -102 )
138 #define UNZ_BADZIPFILE                  ( -103 )
139 #define UNZ_INTERNALERROR               ( -104 )
140 #define UNZ_CRCERROR                    ( -105 )
141
142 #define UNZ_CASESENSITIVE       1
143 #define UNZ_NOTCASESENSITIVE    2
144 #define UNZ_OSDEFAULTCASE       0
145
146 extern int unzStringFileNameCompare( const char* fileName1, const char* fileName2, int iCaseSensitivity );
147
148 /*
149    Compare two filename (fileName1,fileName2).
150    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
151    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
152                                 or strcasecmp)
153    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
154     (like 1 on Unix, 2 on Windows)
155  */
156
157 extern unzFile unzOpen( const char *path );
158 extern unzFile unzReOpen( const char* path, unzFile file );
159
160 /*
161    Open a Zip file. path contain the full pathname (by example,
162      on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
163      "zlib/zlib111.zip".
164      If the zipfile cannot be opened (file don't exist or in not valid), the
165        return value is NULL.
166      Else, the return value is a unzFile Handle, usable with other function
167        of this unzip package.
168  */
169
170 extern int unzClose( unzFile file );
171
172 /*
173    Close a ZipFile opened with unzipOpen.
174    If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
175     these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
176    return UNZ_OK if there is no problem. */
177
178 extern int unzGetGlobalInfo( unzFile file, unz_global_info *pglobal_info );
179
180 /*
181    Write info about the ZipFile in the *pglobal_info structure.
182    No preparation of the structure is needed
183    return UNZ_OK if there is no problem. */
184
185
186 extern int unzGetGlobalComment( unzFile file, char *szComment, unsigned long uSizeBuf );
187
188 /*
189    Get the global comment string of the ZipFile, in the szComment buffer.
190    uSizeBuf is the size of the szComment buffer.
191    return the number of unsigned char copied or an error code <0
192  */
193
194
195 /***************************************************************************/
196 /* Unzip package allow you browse the directory of the zipfile */
197
198 extern int unzGoToFirstFile( unzFile file );
199
200 /*
201    Set the current file of the zipfile to the first file.
202    return UNZ_OK if there is no problem
203  */
204
205 extern int unzGoToNextFile( unzFile file );
206
207 /*
208    Set the current file of the zipfile to the next file.
209    return UNZ_OK if there is no problem
210    return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
211  */
212
213 extern int unzLocateFile( unzFile file, const char *szFileName, int iCaseSensitivity );
214
215 /*
216    Try locate the file szFileName in the zipfile.
217    For the iCaseSensitivity signification, see unzStringFileNameCompare
218
219    return value :
220    UNZ_OK if the file is found. It becomes the current file.
221    UNZ_END_OF_LIST_OF_FILE if the file is not found
222  */
223
224
225 extern int unzGetCurrentFileInfo( unzFile file, unz_file_info *pfile_info, char *szFileName, unsigned long fileNameBufferSize, void *extraField, unsigned long extraFieldBufferSize, char *szComment, unsigned long commentBufferSize );
226
227 /*
228    Get Info about the current file
229    if pfile_info!=NULL, the *pfile_info structure will contain somes info about
230         the current file
231    if szFileName!=NULL, the filemane string will be copied in szFileName
232             (fileNameBufferSize is the size of the buffer)
233    if extraField!=NULL, the extra field information will be copied in extraField
234             (extraFieldBufferSize is the size of the buffer).
235             This is the Central-header version of the extra field
236    if szComment!=NULL, the comment string of the file will be copied in szComment
237             (commentBufferSize is the size of the buffer)
238  */
239
240 /***************************************************************************/
241 /* for reading the content of the current zipfile, you can open it, read data
242    from it, and close it (you can close it before reading all the file)
243  */
244
245 extern int unzOpenCurrentFile( unzFile file );
246
247 /*
248    Open for reading data the current file in the zipfile.
249    If there is no error, the return value is UNZ_OK.
250  */
251
252 extern int unzCloseCurrentFile( unzFile file );
253
254 /*
255    Close the file in zip opened with unzOpenCurrentFile
256    Return UNZ_CRCERROR if all the file was read but the CRC is not good
257  */
258
259
260 extern int unzReadCurrentFile( unzFile file, void* buf, unsigned len );
261
262 /*
263    Read unsigned chars from the current file (opened by unzOpenCurrentFile)
264    buf contain buffer where data must be copied
265    len the size of buf.
266
267    return the number of unsigned char copied if somes unsigned chars are copied
268    return 0 if the end of file was reached
269    return <0 with error code if there is an error
270     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
271  */
272
273 extern long unztell( unzFile file );
274
275 /*
276    Give the current position in uncompressed data
277  */
278
279 extern int unzeof( unzFile file );
280
281 /*
282    return 1 if the end of file was reached, 0 elsewhere
283  */
284
285 extern int unzGetLocalExtrafield( unzFile file, void* buf, unsigned len );
286
287 /*
288    Read extra field from the current file (opened by unzOpenCurrentFile)
289    This is the local-header version of the extra field (sometimes, there is
290     more info in the local-header version than in the central-header)
291
292    if buf==NULL, it return the size of the local extra field
293
294    if buf!=NULL, len is the size of the buffer, the extra header is copied in
295     buf.
296    the return value is the number of unsigned chars copied in buf, or (if <0)
297     the error code
298  */