This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / subsys / system / usetup / cabinet.h
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS cabinet manager
4  * FILE:        apps/cabman/cabinet.h
5  * PURPOSE:     Cabinet definitions
6  */
7 #ifndef __CABINET_H
8 #define __CABINET_H
9
10 #include <string.h>
11
12 /* Cabinet constants */
13
14 #define CAB_SIGNATURE        0x4643534D // "MSCF"
15 #define CAB_VERSION          0x0103
16 #define CAB_BLOCKSIZE        32768
17
18 #define CAB_COMP_MASK        0x00FF
19 #define CAB_COMP_NONE        0x0000
20 #define CAB_COMP_MSZIP       0x0001
21 #define CAB_COMP_QUANTUM     0x0002
22 #define CAB_COMP_LZX         0x0003
23
24 #define CAB_FLAG_HASPREV     0x0001
25 #define CAB_FLAG_HASNEXT     0x0002
26 #define CAB_FLAG_RESERVE     0x0004
27
28 #define CAB_ATTRIB_READONLY  0x0001
29 #define CAB_ATTRIB_HIDDEN    0x0002
30 #define CAB_ATTRIB_SYSTEM    0x0004
31 #define CAB_ATTRIB_VOLUME    0x0008
32 #define CAB_ATTRIB_DIRECTORY 0x0010
33 #define CAB_ATTRIB_ARCHIVE   0x0020
34 #define CAB_ATTRIB_EXECUTE   0x0040
35 #define CAB_ATTRIB_UTF_NAME  0x0080
36
37 #define CAB_FILE_MAX_FOLDER  0xFFFC
38 #define CAB_FILE_CONTINUED   0xFFFD
39 #define CAB_FILE_SPLIT       0xFFFE
40 #define CAB_FILE_PREV_NEXT   0xFFFF
41
42
43 /* Cabinet structures */
44
45 typedef struct _CFHEADER
46 {
47     ULONG Signature;        // File signature 'MSCF' (CAB_SIGNATURE)
48     ULONG Reserved1;        // Reserved field
49     ULONG CabinetSize;      // Cabinet file size
50     ULONG Reserved2;        // Reserved field
51     ULONG FileTableOffset;  // Offset of first CFFILE
52     ULONG Reserved3;        // Reserved field
53     WORD  Version;          // Cabinet version (CAB_VERSION)
54     WORD  FolderCount;      // Number of folders
55     WORD  FileCount;        // Number of files
56     WORD  Flags;            // Cabinet flags (CAB_FLAG_*)
57     WORD  SetID;            // Cabinet set id
58     WORD  CabinetNumber;    // Zero-based cabinet number
59 /* Optional fields (depends on Flags)
60     WORD  CabinetResSize    // Per-cabinet reserved area size
61     CHAR  FolderResSize     // Per-folder reserved area size
62     CHAR  FileResSize       // Per-file reserved area size
63     CHAR  CabinetReserved[] // Per-cabinet reserved area
64     CHAR  CabinetPrev[]     // Name of previous cabinet file
65     CHAR  DiskPrev[]        // Name of previous disk
66     CHAR  CabinetNext[]     // Name of next cabinet file
67     CHAR  DiskNext[]        // Name of next disk
68  */
69 } CFHEADER, *PCFHEADER;
70
71
72 typedef struct _CFFOLDER
73 {
74     ULONG DataOffset;       // Absolute offset of first CFDATA block in this folder
75     WORD  DataBlockCount;   // Number of CFDATA blocks in this folder in this cabinet
76     WORD  CompressionType;  // Type of compression used for all CFDATA blocks in this folder
77 /* Optional fields (depends on Flags)
78     CHAR  FolderReserved[]  // Per-folder reserved area
79  */
80 } CFFOLDER, *PCFFOLDER;
81
82
83 typedef struct _CFFILE
84 {
85     ULONG FileSize;         // Uncompressed file size in bytes
86     ULONG FileOffset;       // Uncompressed offset of file in the folder
87     WORD  FileControlID;    // File control ID (CAB_FILE_*)
88     WORD  FileDate;         // File date stamp, as used by DOS
89     WORD  FileTime;         // File time stamp, as used by DOS
90     WORD  Attributes;       // File attributes (CAB_ATTRIB_*)
91     /* After this is the NULL terminated filename */
92 } CFFILE, *PCFFILE;
93
94
95 typedef struct _CFDATA
96 {
97     ULONG Checksum;         // Checksum of CFDATA entry
98     WORD  CompSize;         // Number of compressed bytes in this block
99     WORD  UncompSize;       // Number of uncompressed bytes in this block
100 /* Optional fields (depends on Flags)
101     CHAR  DataReserved[]    // Per-datablock reserved area
102  */
103 } CFDATA, *PCFDATA;
104
105 typedef struct _CFDATA_NODE
106 {
107     struct _CFDATA_NODE *Next;
108     struct _CFDATA_NODE *Prev;
109     ULONG               ScratchFilePosition;    // Absolute offset in scratch file
110     ULONG               AbsoluteOffset;         // Absolute offset in cabinet
111     ULONG               UncompOffset;           // Uncompressed offset in folder
112     CFDATA              Data;
113 } CFDATA_NODE, *PCFDATA_NODE;
114
115 typedef struct _CFFOLDER_NODE
116 {
117     struct _CFFOLDER_NODE *Next;
118     struct _CFFOLDER_NODE *Prev;
119     ULONG                 UncompOffset;     // File size accumulator
120     ULONG                 AbsoluteOffset;
121     ULONG                 TotalFolderSize;  // Total size of folder in current disk
122     PCFDATA_NODE          DataListHead;
123     PCFDATA_NODE          DataListTail;
124     ULONG                 Index;
125     BOOL                  Commit;           // TRUE if the folder should be committed
126     BOOL                  Delete;           // TRUE if marked for deletion
127     CFFOLDER              Folder;
128 } CFFOLDER_NODE, *PCFFOLDER_NODE;
129
130 typedef struct _CFFILE_NODE
131 {
132     struct _CFFILE_NODE *Next;
133     struct _CFFILE_NODE *Prev;
134     CFFILE              File;
135     PWCHAR              FileName;
136     PCFDATA_NODE        DataBlock;      // First data block of file. NULL if not known
137     BOOL                Commit;         // TRUE if the file data should be committed
138     BOOL                Delete;         // TRUE if marked for deletion
139         PCFFOLDER_NODE          FolderNode;             // Folder this file belong to
140 } CFFILE_NODE, *PCFFILE_NODE;
141
142
143 typedef struct _CAB_SEARCH
144 {
145     WCHAR        Search[MAX_PATH];   // Search criteria
146     PCFFILE_NODE Next;               // Pointer to next node
147     PCFFILE      File;               // Pointer to current CFFILE
148     PWCHAR       FileName;           // Current filename
149 } CAB_SEARCH, *PCAB_SEARCH;
150
151
152 /* Constants */
153
154 /* Status codes */
155 #define CAB_STATUS_SUCCESS       0x00000000
156 #define CAB_STATUS_FAILURE       0x00000001
157 #define CAB_STATUS_NOMEMORY      0x00000002
158 #define CAB_STATUS_CANNOT_OPEN   0x00000003
159 #define CAB_STATUS_CANNOT_CREATE 0x00000004
160 #define CAB_STATUS_CANNOT_READ   0x00000005
161 #define CAB_STATUS_CANNOT_WRITE  0x00000006
162 #define CAB_STATUS_FILE_EXISTS   0x00000007
163 #define CAB_STATUS_INVALID_CAB   0x00000008
164 #define CAB_STATUS_NOFILE        0x00000009
165 #define CAB_STATUS_UNSUPPCOMP    0x0000000A
166
167
168 /* Codecs */
169
170 /* Uncompresses a data block */
171 typedef ULONG (*PCABINET_CODEC_UNCOMPRESS)(PVOID OutputBuffer,
172   PVOID InputBuffer,
173   ULONG InputLength,
174   PULONG OutputLength);
175
176
177 /* Codec status codes */
178 #define CS_SUCCESS      0x0000  /* All data consumed */
179 #define CS_NOMEMORY     0x0001  /* Not enough free memory */
180 #define CS_BADSTREAM    0x0002  /* Bad data stream */
181
182 /* Codec indentifiers */
183 #define CAB_CODEC_RAW   0x00
184 #define CAB_CODEC_LZX   0x01
185 #define CAB_CODEC_MSZIP 0x02
186
187 #define MSZIP_MAGIC 0x4B43
188
189
190
191 /* Event handler prototypes */
192
193 typedef BOOL (*PCABINET_OVERWRITE)(PCFFILE File,
194   PWCHAR FileName);
195
196 typedef VOID (*PCABINET_EXTRACT)(PCFFILE File,
197   PWCHAR FileName);
198
199 typedef VOID (*PCABINET_DISK_CHANGE)(PWCHAR CabinetName,
200   PWCHAR DiskLabel);
201
202
203
204 /* Classes */
205
206 /* Default constructor */
207 VOID CabinetInitialize();
208 /* Default destructor */
209 VOID CabinetCleanup();
210 /* Returns a pointer to the filename part of a fully qualified filename */
211 PWCHAR CabinetGetFileName(PWCHAR Path);
212 /* Removes a filename from a fully qualified filename */
213 VOID CabinetRemoveFileName(PWCHAR Path);
214 /* Normalizes a path */
215 BOOL CabinetNormalizePath(PWCHAR Path, ULONG Length);
216 /* Returns name of cabinet file */
217 PWCHAR CabinetGetCabinetName();
218 /* Sets the name of the cabinet file */
219 VOID CabinetSetCabinetName(PWCHAR FileName);
220 /* Sets destination path for extracted files */
221 VOID CabinetSetDestinationPath(PWCHAR DestinationPath);
222 /* Returns destination path */
223 PWCHAR CabinetGetDestinationPath();
224 /* Returns zero-based current disk number */
225 ULONG CabinetGetCurrentDiskNumber();
226 /* Opens the current cabinet file */
227 ULONG CabinetOpen();
228 /* Closes the current open cabinet file */
229 VOID CabinetClose();
230 /* Locates the first file in the current cabinet file that matches a search criteria */
231 ULONG CabinetFindFirst(PWCHAR FileName, PCAB_SEARCH Search);
232 /* Locates the next file in the current cabinet file */
233 ULONG CabinetFindNext(PCAB_SEARCH Search);
234 /* Extracts a file from the current cabinet file */
235 ULONG CabinetExtractFile(PWCHAR FileName);
236 /* Select codec engine to use */
237 VOID CabinetSelectCodec(ULONG Id);
238 /* Set event handlers */
239 VOID CabinetSetEventHandlers(PCABINET_OVERWRITE Overwrite,
240   PCABINET_EXTRACT Extract,
241   PCABINET_DISK_CHANGE DiskChange);
242 /* Get pointer to cabinet reserved area. NULL if none */
243 PVOID CabinetGetCabinetReservedArea(PULONG Size);
244
245 #endif /* __CABINET_H */