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