[SETUPLIB][USETUP] Move some code to the SetupLib.
[reactos.git] / base / setup / usetup / cabinet.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS cabinet manager
4 * FILE: base/setup/usetup/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 PCFDATA CFData;
112 ULONG Offset;
113 } CAB_SEARCH, *PCAB_SEARCH;
114
115
116 /* Constants */
117
118 /* Status codes */
119 #define CAB_STATUS_SUCCESS 0x00000000
120 #define CAB_STATUS_FAILURE 0x00000001
121 #define CAB_STATUS_NOMEMORY 0x00000002
122 #define CAB_STATUS_CANNOT_OPEN 0x00000003
123 #define CAB_STATUS_CANNOT_CREATE 0x00000004
124 #define CAB_STATUS_CANNOT_READ 0x00000005
125 #define CAB_STATUS_CANNOT_WRITE 0x00000006
126 #define CAB_STATUS_FILE_EXISTS 0x00000007
127 #define CAB_STATUS_INVALID_CAB 0x00000008
128 #define CAB_STATUS_NOFILE 0x00000009
129 #define CAB_STATUS_UNSUPPCOMP 0x0000000A
130
131
132 /* Codecs */
133
134 /* Uncompresses a data block */
135 typedef ULONG (*PCABINET_CODEC_UNCOMPRESS)(PVOID OutputBuffer,
136 PVOID InputBuffer,
137 PLONG InputLength,
138 PLONG OutputLength);
139
140
141 /* Codec status codes */
142 #define CS_SUCCESS 0x0000 /* All data consumed */
143 #define CS_NOMEMORY 0x0001 /* Not enough free memory */
144 #define CS_BADSTREAM 0x0002 /* Bad data stream */
145
146 /* Codec identifiers */
147 #define CAB_CODEC_RAW 0x00
148 #define CAB_CODEC_LZX 0x01
149 #define CAB_CODEC_MSZIP 0x02
150
151 #define MSZIP_MAGIC 0x4B43
152
153
154
155 /* Event handler prototypes */
156
157 typedef BOOL (*PCABINET_OVERWRITE)(PCFFILE File,
158 PWCHAR FileName);
159
160 typedef VOID (*PCABINET_EXTRACT)(PCFFILE File,
161 PWCHAR FileName);
162
163 typedef VOID (*PCABINET_DISK_CHANGE)(PWCHAR CabinetName,
164 PWCHAR DiskLabel);
165
166
167
168 /* Classes */
169
170 /* Default constructor */
171 VOID CabinetInitialize(VOID);
172 /* Default destructor */
173 VOID CabinetCleanup(VOID);
174 /* Returns a pointer to the filename part of a fully qualified filename */
175 PWCHAR CabinetGetFileName(PWCHAR Path);
176 /* Removes a filename from a fully qualified filename */
177 VOID CabinetRemoveFileName(PWCHAR Path);
178 /* Normalizes a path */
179 BOOL CabinetNormalizePath(PWCHAR Path, ULONG Length);
180 /* Returns name of cabinet file */
181 PWCHAR CabinetGetCabinetName(VOID);
182 /* Sets the name of the cabinet file */
183 VOID CabinetSetCabinetName(PWCHAR FileName);
184 /* Sets destination path for extracted files */
185 VOID CabinetSetDestinationPath(PWCHAR DestinationPath);
186 /* Returns destination path */
187 PWCHAR CabinetGetDestinationPath(VOID);
188 /* Returns zero-based current disk number */
189 ULONG CabinetGetCurrentDiskNumber(VOID);
190 /* Opens the current cabinet file */
191 ULONG CabinetOpen(VOID);
192 /* Closes the current open cabinet file */
193 VOID CabinetClose(VOID);
194 /* Locates the first file in the current cabinet file that matches a search criteria */
195 ULONG CabinetFindFirst(PWCHAR FileName, PCAB_SEARCH Search);
196 /* Locates the next file that matches the current search criteria */
197 ULONG CabinetFindNext(PCAB_SEARCH Search);
198 /* Locates the next file in the current cabinet file sequentially */
199 ULONG CabinetFindNextFileSequential(PWCHAR FileName, PCAB_SEARCH Search);
200 /* Extracts a file from the current cabinet file */
201 ULONG CabinetExtractFile(PCAB_SEARCH Search);
202 /* Select codec engine to use */
203 VOID CabinetSelectCodec(ULONG Id);
204 /* Set event handlers */
205 VOID CabinetSetEventHandlers(PCABINET_OVERWRITE Overwrite,
206 PCABINET_EXTRACT Extract,
207 PCABINET_DISK_CHANGE DiskChange);
208 /* Get pointer to cabinet reserved area. NULL if none */
209 PVOID CabinetGetCabinetReservedArea(PULONG Size);