* Sync with recent trunk (r52637).
[reactos.git] / base / setup / 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 #pragma once
8
9 #include <string.h>
10
11 /* Cabinet constants */
12
13 #define CAB_SIGNATURE 0x4643534D // "MSCF"
14 #define CAB_VERSION 0x0103
15 #define CAB_BLOCKSIZE 32768
16
17 #define CAB_COMP_MASK 0x00FF
18 #define CAB_COMP_NONE 0x0000
19 #define CAB_COMP_MSZIP 0x0001
20 #define CAB_COMP_QUANTUM 0x0002
21 #define CAB_COMP_LZX 0x0003
22
23 #define CAB_FLAG_HASPREV 0x0001
24 #define CAB_FLAG_HASNEXT 0x0002
25 #define CAB_FLAG_RESERVE 0x0004
26
27 #define CAB_ATTRIB_READONLY 0x0001
28 #define CAB_ATTRIB_HIDDEN 0x0002
29 #define CAB_ATTRIB_SYSTEM 0x0004
30 #define CAB_ATTRIB_VOLUME 0x0008
31 #define CAB_ATTRIB_DIRECTORY 0x0010
32 #define CAB_ATTRIB_ARCHIVE 0x0020
33 #define CAB_ATTRIB_EXECUTE 0x0040
34 #define CAB_ATTRIB_UTF_NAME 0x0080
35
36 #define CAB_FILE_MAX_FOLDER 0xFFFC
37 #define CAB_FILE_CONTINUED 0xFFFD
38 #define CAB_FILE_SPLIT 0xFFFE
39 #define CAB_FILE_PREV_NEXT 0xFFFF
40
41
42 /* Cabinet structures */
43
44 typedef struct _CFHEADER
45 {
46 ULONG Signature; // File signature 'MSCF' (CAB_SIGNATURE)
47 ULONG Reserved1; // Reserved field
48 ULONG CabinetSize; // Cabinet file size
49 ULONG Reserved2; // Reserved field
50 ULONG FileTableOffset; // Offset of first CFFILE
51 ULONG Reserved3; // Reserved field
52 WORD Version; // Cabinet version (CAB_VERSION)
53 WORD FolderCount; // Number of folders
54 WORD FileCount; // Number of files
55 WORD Flags; // Cabinet flags (CAB_FLAG_*)
56 WORD SetID; // Cabinet set id
57 WORD CabinetNumber; // Zero-based cabinet number
58 /* Optional fields (depends on Flags)
59 WORD CabinetResSize // Per-cabinet reserved area size
60 CHAR FolderResSize // Per-folder reserved area size
61 CHAR FileResSize // Per-file reserved area size
62 CHAR CabinetReserved[] // Per-cabinet reserved area
63 CHAR CabinetPrev[] // Name of previous cabinet file
64 CHAR DiskPrev[] // Name of previous disk
65 CHAR CabinetNext[] // Name of next cabinet file
66 CHAR DiskNext[] // Name of next disk
67 */
68 } CFHEADER, *PCFHEADER;
69
70
71 typedef struct _CFFOLDER
72 {
73 ULONG DataOffset; // Absolute offset of first CFDATA block in this folder
74 WORD DataBlockCount; // Number of CFDATA blocks in this folder in this cabinet
75 WORD CompressionType; // Type of compression used for all CFDATA blocks in this folder
76 /* Optional fields (depends on Flags)
77 CHAR FolderReserved[] // Per-folder reserved area
78 */
79 } CFFOLDER, *PCFFOLDER;
80
81
82 typedef struct _CFFILE
83 {
84 ULONG FileSize; // Uncompressed file size in bytes
85 ULONG FileOffset; // Uncompressed offset of file in the folder
86 WORD FolderIndex; // Index number of the folder that contains this file
87 WORD FileDate; // File date stamp, as used by DOS
88 WORD FileTime; // File time stamp, as used by DOS
89 WORD Attributes; // File attributes (CAB_ATTRIB_*)
90 CHAR FileName[ANYSIZE_ARRAY];
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 _CAB_SEARCH
106 {
107 WCHAR Search[MAX_PATH]; // Search criteria
108 WCHAR Cabinet[MAX_PATH];
109 USHORT Index;
110 PCFFILE File; // Pointer to current CFFILE
111 } CAB_SEARCH, *PCAB_SEARCH;
112
113
114 /* Constants */
115
116 /* Status codes */
117 #define CAB_STATUS_SUCCESS 0x00000000
118 #define CAB_STATUS_FAILURE 0x00000001
119 #define CAB_STATUS_NOMEMORY 0x00000002
120 #define CAB_STATUS_CANNOT_OPEN 0x00000003
121 #define CAB_STATUS_CANNOT_CREATE 0x00000004
122 #define CAB_STATUS_CANNOT_READ 0x00000005
123 #define CAB_STATUS_CANNOT_WRITE 0x00000006
124 #define CAB_STATUS_FILE_EXISTS 0x00000007
125 #define CAB_STATUS_INVALID_CAB 0x00000008
126 #define CAB_STATUS_NOFILE 0x00000009
127 #define CAB_STATUS_UNSUPPCOMP 0x0000000A
128
129
130 /* Codecs */
131
132 /* Uncompresses a data block */
133 typedef ULONG (*PCABINET_CODEC_UNCOMPRESS)(PVOID OutputBuffer,
134 PVOID InputBuffer,
135 PLONG InputLength,
136 PLONG OutputLength);
137
138
139 /* Codec status codes */
140 #define CS_SUCCESS 0x0000 /* All data consumed */
141 #define CS_NOMEMORY 0x0001 /* Not enough free memory */
142 #define CS_BADSTREAM 0x0002 /* Bad data stream */
143
144 /* Codec indentifiers */
145 #define CAB_CODEC_RAW 0x00
146 #define CAB_CODEC_LZX 0x01
147 #define CAB_CODEC_MSZIP 0x02
148
149 #define MSZIP_MAGIC 0x4B43
150
151
152
153 /* Event handler prototypes */
154
155 typedef BOOL (*PCABINET_OVERWRITE)(PCFFILE File,
156 PWCHAR FileName);
157
158 typedef VOID (*PCABINET_EXTRACT)(PCFFILE File,
159 PWCHAR FileName);
160
161 typedef VOID (*PCABINET_DISK_CHANGE)(PWCHAR CabinetName,
162 PWCHAR DiskLabel);
163
164
165
166 /* Classes */
167
168 /* Default constructor */
169 VOID CabinetInitialize(VOID);
170 /* Default destructor */
171 VOID CabinetCleanup(VOID);
172 /* Returns a pointer to the filename part of a fully qualified filename */
173 PWCHAR CabinetGetFileName(PWCHAR Path);
174 /* Removes a filename from a fully qualified filename */
175 VOID CabinetRemoveFileName(PWCHAR Path);
176 /* Normalizes a path */
177 BOOL CabinetNormalizePath(PWCHAR Path, ULONG Length);
178 /* Returns name of cabinet file */
179 PWCHAR CabinetGetCabinetName(VOID);
180 /* Sets the name of the cabinet file */
181 VOID CabinetSetCabinetName(PWCHAR FileName);
182 /* Sets destination path for extracted files */
183 VOID CabinetSetDestinationPath(PWCHAR DestinationPath);
184 /* Returns destination path */
185 PWCHAR CabinetGetDestinationPath(VOID);
186 /* Returns zero-based current disk number */
187 ULONG CabinetGetCurrentDiskNumber(VOID);
188 /* Opens the current cabinet file */
189 ULONG CabinetOpen(VOID);
190 /* Closes the current open cabinet file */
191 VOID CabinetClose(VOID);
192 /* Locates the first file in the current cabinet file that matches a search criteria */
193 ULONG CabinetFindFirst(PWCHAR FileName, PCAB_SEARCH Search);
194 /* Locates the next file in the current cabinet file */
195 ULONG CabinetFindNext(PCAB_SEARCH Search);
196 /* Extracts a file from the current cabinet file */
197 ULONG CabinetExtractFile(PCAB_SEARCH Search);
198 /* Select codec engine to use */
199 VOID CabinetSelectCodec(ULONG Id);
200 /* Set event handlers */
201 VOID CabinetSetEventHandlers(PCABINET_OVERWRITE Overwrite,
202 PCABINET_EXTRACT Extract,
203 PCABINET_DISK_CHANGE DiskChange);
204 /* Get pointer to cabinet reserved area. NULL if none */
205 PVOID CabinetGetCabinetReservedArea(PULONG Size);