Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

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