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