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