1 #ifndef UAE_ZARCHIVE_H 2 #define UAE_ZARCHIVE_H 3 4 #include "uae/types.h" 5 #ifdef FSUAE 6 #include "zfile.h" 7 #include <stdio.h> 8 #include <stddef.h> 9 #endif 10 11 typedef uae_s64 (*ZFILEREAD)(void*, uae_u64, uae_u64, struct zfile*); 12 typedef uae_s64 (*ZFILEWRITE)(const void*, uae_u64, uae_u64, struct zfile*); 13 typedef uae_s64 (*ZFILESEEK)(struct zfile*, uae_s64, int); 14 15 struct zfile { 16 TCHAR *name; 17 TCHAR *zipname; 18 TCHAR *mode; 19 TCHAR *originalname; 20 FILE *f; // real file handle if physical file 21 uae_u8 *data; // unpacked data 22 int dataseek; // use seek position even if real file 23 struct zfile *archiveparent; // set if parent is archive and this has not yet been unpacked (datasize < size) 24 int archiveid; 25 uae_s64 size; // real size 26 uae_s64 datasize; // available size (not yet unpacked completely?) 27 uae_s64 allocsize; // memory allocated before realloc() needed again 28 uae_s64 seek; // seek position 29 int deleteafterclose; 30 int textmode; 31 struct zfile *next; 32 int zfdmask; 33 struct zfile *parent; 34 uae_u64 offset; // byte offset from parent file 35 int opencnt; 36 ZFILEREAD zfileread; 37 ZFILEWRITE zfilewrite; 38 ZFILESEEK zfileseek; 39 void *userdata; 40 int useparent; 41 }; 42 43 #define ZNODE_FILE 0 44 #define ZNODE_DIR 1 45 #define ZNODE_VDIR -1 46 struct znode { 47 int type; 48 struct znode *sibling; 49 struct znode *child; 50 struct zvolume *vchild; 51 struct znode *parent; 52 struct zvolume *volume; 53 struct znode *next; 54 struct znode *prev; 55 struct znode *vfile; // points to real file when this node is virtual directory 56 TCHAR *name; 57 TCHAR *fullname; 58 uae_s64 size; 59 struct zfile *f; 60 TCHAR *comment; 61 int flags; 62 struct mytimeval mtime; 63 /* decompressor specific */ 64 unsigned int offset; 65 unsigned int offset2; 66 unsigned int method; 67 unsigned int packedsize; 68 }; 69 70 struct zvolume 71 { 72 struct zfile *archive; 73 void *handle; 74 struct znode root; 75 struct zvolume *next; 76 struct znode *last; 77 struct znode *parentz; 78 struct zvolume *parent; 79 uae_s64 size; 80 unsigned int blocks; 81 unsigned int id; 82 uae_s64 archivesize; 83 unsigned int method; 84 TCHAR *volumename; 85 int zfdmask; 86 }; 87 88 struct zarchive_info 89 { 90 TCHAR *name; 91 uae_s64 size; 92 int flags; 93 TCHAR *comment; 94 struct mytimeval tv; 95 }; 96 97 #define MCC(a,b,c,d) (((a)<<24) | ((b)<<16) | ((c)<<8) | (d)) 98 99 #define ArchiveFormat7Zip MCC('7', 'z', ' ', ' ') 100 #define ArchiveFormatRAR MCC('r', 'a', 'r', ' ') 101 #define ArchiveFormatZIP MCC('z', 'i', 'p', ' ') 102 #define ArchiveFormatLHA MCC('l', 'h', 'a', ' ') 103 #define ArchiveFormatLZX MCC('l', 'z', 'x', ' ') 104 #define ArchiveFormatPLAIN MCC('-', '-', '-', '-') 105 #define ArchiveFormatDIR MCC('D', 'I', 'R', ' ') 106 #define ArchiveFormatAA MCC('a', 'a', ' ', ' ') // method only 107 #define ArchiveFormatADF MCC('D', 'O', 'S', ' ') 108 #define ArchiveFormatRDB MCC('R', 'D', 'S', 'K') 109 #define ArchiveFormatMBR MCC('M', 'B', 'R', ' ') 110 #define ArchiveFormatFAT MCC('F', 'A', 'T', ' ') 111 #define ArchiveFormatTAR MCC('t', 'a', 'r', ' ') 112 113 #define PEEK_BYTES 1024 114 #define FILE_PEEK 1 115 #define FILE_DELAYEDOPEN 2 116 117 extern int zfile_is_ignore_ext (const TCHAR *name); 118 119 extern struct zvolume *zvolume_alloc (struct zfile *z, unsigned int id, void *handle, const TCHAR*); 120 extern struct zvolume *zvolume_alloc_empty (struct zvolume *zv, const TCHAR *name); 121 122 extern struct znode *zvolume_addfile_abs (struct zvolume *zv, struct zarchive_info*); 123 extern struct znode *zvolume_adddir_abs (struct zvolume *zv, struct zarchive_info *zai); 124 extern struct znode *znode_adddir (struct znode *parent, const TCHAR *name, struct zarchive_info*); 125 126 extern struct zvolume *archive_directory_plain (struct zfile *zf); 127 extern struct zvolume *archive_directory_lha(struct zfile *zf); 128 extern struct zfile *archive_access_lha (struct znode *zn); 129 extern struct zvolume *archive_directory_zip(struct zfile *zf); 130 extern struct zvolume *archive_directory_7z (struct zfile *z); 131 extern struct zfile *archive_access_7z (struct znode *zn); 132 extern struct zvolume *archive_directory_rar (struct zfile *z); 133 extern struct zfile *archive_access_rar (struct znode *zn); 134 extern struct zvolume *archive_directory_lzx (struct zfile *in_file); 135 extern struct zfile *archive_access_lzx (struct znode *zn); 136 extern struct zvolume *archive_directory_arcacc (struct zfile *z, unsigned int id); 137 extern struct zfile *archive_access_arcacc (struct znode *zn); 138 extern struct zvolume *archive_directory_adf (struct znode *zn, struct zfile *z); 139 extern struct zvolume *archive_directory_rdb (struct zfile *z); 140 extern struct zvolume *archive_directory_fat (struct zfile *z); 141 extern struct zvolume *archive_directory_tar (struct zfile *zf); 142 extern struct zfile *archive_access_tar (struct znode *zn); 143 144 extern struct zfile *archive_access_select (struct znode *parent, struct zfile *zf, unsigned int id, int doselect, int *retcode, int index); 145 extern struct zfile *archive_access_arcacc_select (struct zfile *zf, unsigned int id, int *retcode); 146 extern int isfat (uae_u8*); 147 148 extern void archive_access_scan (struct zfile *zf, zfile_callback zc, void *user, unsigned int id); 149 150 extern void archive_access_close (void *handle, unsigned int id); 151 152 extern struct zfile *archive_getzfile (struct znode *zn, unsigned int id, int flags); 153 extern struct zfile *archive_unpackzfile (struct zfile *zf); 154 155 extern struct zfile *decompress_zfd (struct zfile*); 156 157 #endif /* UAE_ZARCHIVE_H */ 158