Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
5.2 KiB

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