Merge pull request #461 from negativeExponent/libchdr
[pcsx_rearmed.git] / deps / lzma-16.04 / C / 7z.h
1 /* 7z.h -- 7z interface\r
2 2015-11-18 : Igor Pavlov : Public domain */\r
3 \r
4 #ifndef __7Z_H\r
5 #define __7Z_H\r
6 \r
7 #include "7zTypes.h"\r
8 \r
9 EXTERN_C_BEGIN\r
10 \r
11 #define k7zStartHeaderSize 0x20\r
12 #define k7zSignatureSize 6\r
13 \r
14 extern const Byte k7zSignature[k7zSignatureSize];\r
15 \r
16 typedef struct\r
17 {\r
18   const Byte *Data;\r
19   size_t Size;\r
20 } CSzData;\r
21 \r
22 /* CSzCoderInfo & CSzFolder support only default methods */\r
23 \r
24 typedef struct\r
25 {\r
26   size_t PropsOffset;\r
27   UInt32 MethodID;\r
28   Byte NumStreams;\r
29   Byte PropsSize;\r
30 } CSzCoderInfo;\r
31 \r
32 typedef struct\r
33 {\r
34   UInt32 InIndex;\r
35   UInt32 OutIndex;\r
36 } CSzBond;\r
37 \r
38 #define SZ_NUM_CODERS_IN_FOLDER_MAX 4\r
39 #define SZ_NUM_BONDS_IN_FOLDER_MAX 3\r
40 #define SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX 4\r
41 \r
42 typedef struct\r
43 {\r
44   UInt32 NumCoders;\r
45   UInt32 NumBonds;\r
46   UInt32 NumPackStreams;\r
47   UInt32 UnpackStream;\r
48   UInt32 PackStreams[SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX];\r
49   CSzBond Bonds[SZ_NUM_BONDS_IN_FOLDER_MAX];\r
50   CSzCoderInfo Coders[SZ_NUM_CODERS_IN_FOLDER_MAX];\r
51 } CSzFolder;\r
52 \r
53 \r
54 SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd);\r
55 \r
56 typedef struct\r
57 {\r
58   UInt32 Low;\r
59   UInt32 High;\r
60 } CNtfsFileTime;\r
61 \r
62 typedef struct\r
63 {\r
64   Byte *Defs; /* MSB 0 bit numbering */\r
65   UInt32 *Vals;\r
66 } CSzBitUi32s;\r
67 \r
68 typedef struct\r
69 {\r
70   Byte *Defs; /* MSB 0 bit numbering */\r
71   // UInt64 *Vals;\r
72   CNtfsFileTime *Vals;\r
73 } CSzBitUi64s;\r
74 \r
75 #define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)\r
76 \r
77 #define SzBitWithVals_Check(p, i) ((p)->Defs && ((p)->Defs[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)\r
78 \r
79 typedef struct\r
80 {\r
81   UInt32 NumPackStreams;\r
82   UInt32 NumFolders;\r
83 \r
84   UInt64 *PackPositions;          // NumPackStreams + 1\r
85   CSzBitUi32s FolderCRCs;         // NumFolders\r
86 \r
87   size_t *FoCodersOffsets;        // NumFolders + 1\r
88   UInt32 *FoStartPackStreamIndex; // NumFolders + 1\r
89   UInt32 *FoToCoderUnpackSizes;   // NumFolders + 1\r
90   Byte *FoToMainUnpackSizeIndex;  // NumFolders\r
91   UInt64 *CoderUnpackSizes;       // for all coders in all folders\r
92 \r
93   Byte *CodersData;\r
94 } CSzAr;\r
95 \r
96 UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex);\r
97 \r
98 SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,\r
99     ILookInStream *stream, UInt64 startPos,\r
100     Byte *outBuffer, size_t outSize,\r
101     ISzAlloc *allocMain);\r
102 \r
103 typedef struct\r
104 {\r
105   CSzAr db;\r
106 \r
107   UInt64 startPosAfterHeader;\r
108   UInt64 dataPos;\r
109   \r
110   UInt32 NumFiles;\r
111 \r
112   UInt64 *UnpackPositions;  // NumFiles + 1\r
113   // Byte *IsEmptyFiles;\r
114   Byte *IsDirs;\r
115   CSzBitUi32s CRCs;\r
116 \r
117   CSzBitUi32s Attribs;\r
118   // CSzBitUi32s Parents;\r
119   CSzBitUi64s MTime;\r
120   CSzBitUi64s CTime;\r
121 \r
122   UInt32 *FolderToFile;   // NumFolders + 1\r
123   UInt32 *FileToFolder;   // NumFiles\r
124 \r
125   size_t *FileNameOffsets; /* in 2-byte steps */\r
126   Byte *FileNames;  /* UTF-16-LE */\r
127 } CSzArEx;\r
128 \r
129 #define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i))\r
130 \r
131 #define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i])\r
132 \r
133 void SzArEx_Init(CSzArEx *p);\r
134 void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);\r
135 UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);\r
136 int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);\r
137 \r
138 /*\r
139 if dest == NULL, the return value specifies the required size of the buffer,\r
140   in 16-bit characters, including the null-terminating character.\r
141 if dest != NULL, the return value specifies the number of 16-bit characters that\r
142   are written to the dest, including the null-terminating character. */\r
143 \r
144 size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest);\r
145 \r
146 /*\r
147 size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex);\r
148 UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest);\r
149 */\r
150 \r
151 \r
152 \r
153 /*\r
154   SzArEx_Extract extracts file from archive\r
155 \r
156   *outBuffer must be 0 before first call for each new archive.\r
157 \r
158   Extracting cache:\r
159     If you need to decompress more than one file, you can send\r
160     these values from previous call:\r
161       *blockIndex,\r
162       *outBuffer,\r
163       *outBufferSize\r
164     You can consider "*outBuffer" as cache of solid block. If your archive is solid,\r
165     it will increase decompression speed.\r
166   \r
167     If you use external function, you can declare these 3 cache variables\r
168     (blockIndex, outBuffer, outBufferSize) as static in that external function.\r
169     \r
170     Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r
171 */\r
172 \r
173 SRes SzArEx_Extract(\r
174     const CSzArEx *db,\r
175     ILookInStream *inStream,\r
176     UInt32 fileIndex,         /* index of file */\r
177     UInt32 *blockIndex,       /* index of solid block */\r
178     Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r
179     size_t *outBufferSize,    /* buffer size for output buffer */\r
180     size_t *offset,           /* offset of stream for required file in *outBuffer */\r
181     size_t *outSizeProcessed, /* size of file in *outBuffer */\r
182     ISzAlloc *allocMain,\r
183     ISzAlloc *allocTemp);\r
184 \r
185 \r
186 /*\r
187 SzArEx_Open Errors:\r
188 SZ_ERROR_NO_ARCHIVE\r
189 SZ_ERROR_ARCHIVE\r
190 SZ_ERROR_UNSUPPORTED\r
191 SZ_ERROR_MEM\r
192 SZ_ERROR_CRC\r
193 SZ_ERROR_INPUT_EOF\r
194 SZ_ERROR_FAIL\r
195 */\r
196 \r
197 SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,\r
198     ISzAlloc *allocMain, ISzAlloc *allocTemp);\r
199 \r
200 EXTERN_C_END\r
201 \r
202 #endif\r