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