]> Shamusworld >> Repos - virtualjaguar/blob - src/unzip.h
d8ddb312c96c0c0482cce5721b70b9bb3d65743f
[virtualjaguar] / src / unzip.h
1 #ifndef __UNZIP_H__
2 #define __UNZIP_H__
3
4 #include <stdio.h>
5 #include <stdint.h>
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 /***************************************************************************
12  * Support for retrieving files from zipfiles
13  ***************************************************************************/
14
15 struct zipent
16 {
17         uint32_t        cent_file_header_sig;
18         uint8_t version_made_by;
19         uint8_t host_os;
20         uint8_t version_needed_to_extract;
21         uint8_t os_needed_to_extract;
22         uint16_t        general_purpose_bit_flag;
23         uint16_t        compression_method;
24         uint16_t        last_mod_file_time;
25         uint16_t        last_mod_file_date;
26         uint32_t        crc32;
27         uint32_t        compressed_size;
28         uint32_t        uncompressed_size;
29         uint16_t        filename_length;
30         uint16_t        extra_field_length;
31         uint16_t        file_comment_length;
32         uint16_t        disk_number_start;
33         uint16_t        internal_file_attrib;
34         uint32_t        external_file_attrib;
35         uint32_t        offset_lcl_hdr_frm_frst_disk;
36         char *  name; /* 0 terminated */
37 };
38
39 typedef struct _ZIP
40 {
41         char * zip;                                     /* zip name */
42         FILE * fp;                                      /* zip handler */
43         int pathtype, pathindex;        /* additional path info */
44         long length;                            /* length of zip file */
45         char * ecd;                                     /* end_of_cent_dir data */
46         unsigned ecd_length;            /* end_of_cent_dir length */
47         char * cd;                                      /* cent_dir data */
48         unsigned cd_pos;                        /* position in cent_dir */
49         struct zipent ent;                      /* buffer for readzip */
50         /* end_of_cent_dir */
51         uint32_t        end_of_cent_dir_sig;
52         uint16_t        number_of_this_disk;
53         uint16_t        number_of_disk_start_cent_dir;
54         uint16_t        total_entries_cent_dir_this_disk;
55         uint16_t        total_entries_cent_dir;
56         uint32_t        size_of_cent_dir;
57         uint32_t        offset_to_start_of_cent_dir;
58         uint16_t        zipfile_comment_length;
59         char *  zipfile_comment;        /* pointer in ecd */
60 } ZIP;
61
62 /* Opens a zip stream for reading
63    return:
64      !=0 success, zip stream
65      ==0 error
66 */
67 ZIP * openzip(int pathtype, int pathindex, const char * path);
68
69 /* Closes a zip stream */
70 void closezip(ZIP * zip);
71
72 /* Reads the current entry from a zip stream
73    in:
74      zip opened zip
75    return:
76      !=0 success
77      ==0 error
78 */
79 struct zipent * readzip(ZIP * zip);
80
81 /* Suspend access to a zip file (release file handler)
82    in:
83       zip opened zip
84    note:
85      A suspended zip is automatically reopened at first call of
86      readuncompressd() or readcompressed() functions
87 */
88 void suspendzip(ZIP * zip);
89
90 /* Resets a zip stream to the first entry
91    in:
92      zip opened zip
93    note:
94      ZIP file must be opened and not suspended
95 */
96 void rewindzip(ZIP * zip);
97
98 /* Read compressed data from a zip entry
99    in:
100      zip opened zip
101      ent entry to read
102    out:
103      data buffer for data, ent.compressed_size uint8_ts allocated by the caller
104    return:
105      ==0 success
106      <0 error
107 */
108 int readcompresszip(ZIP * zip, struct zipent * ent, char * data);
109
110 /* Read decompressed data from a zip entry
111    in:
112      zip zip stream open
113      ent entry to read
114    out:
115      data buffer for data, ent.uncompressed_size uint8_ts allocated by the caller
116    return:
117      ==0 success
118      <0 error
119 */
120 int readuncompresszip(ZIP * zip, struct zipent * ent, char * data);
121
122 /* public functions */
123 int /* error */ load_zipped_file(int pathtype, int pathindex, const char * zipfile, const char * filename,
124         unsigned char ** buf, uint32_t * length);
125
126 void unzip_cache_clear(void);
127
128 /* public globals */
129 extern int      gUnzipQuiet;    /* flag controls error messages */
130
131 #ifdef __cplusplus
132 }
133 #endif
134
135 #endif  // __UNZIP_H__