2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS cabinet manager
4 * FILE: apps/cabman/cabinet.h
5 * PURPOSE: Cabinet definitions
12 /* Cabinet constants */
14 #define CAB_SIGNATURE 0x4643534D // "MSCF"
15 #define CAB_VERSION 0x0103
16 #define CAB_BLOCKSIZE 32768
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
24 #define CAB_FLAG_HASPREV 0x0001
25 #define CAB_FLAG_HASNEXT 0x0002
26 #define CAB_FLAG_RESERVE 0x0004
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
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
43 /* Cabinet structures */
45 typedef struct _CFHEADER
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
69 } CFHEADER
, *PCFHEADER
;
72 typedef struct _CFFOLDER
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
80 } CFFOLDER
, *PCFFOLDER
;
83 typedef struct _CFFILE
85 ULONG FileSize
; // Uncompressed file size in bytes
86 ULONG FileOffset
; // Uncompressed offset of file in the folder
87 WORD FolderIndex
; // Index number of the folder that contains this 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 CHAR FileName
[ANYSIZE_ARRAY
];
92 /* After this is the NULL terminated filename */
96 typedef struct _CFDATA
98 ULONG Checksum
; // Checksum of CFDATA entry
99 WORD CompSize
; // Number of compressed bytes in this block
100 WORD UncompSize
; // Number of uncompressed bytes in this block
101 /* Optional fields (depends on Flags)
102 CHAR DataReserved[] // Per-datablock reserved area
106 typedef struct _CAB_SEARCH
108 WCHAR Search
[MAX_PATH
]; // Search criteria
109 WCHAR Cabinet
[MAX_PATH
];
111 PCFFILE File
; // Pointer to current CFFILE
112 } CAB_SEARCH
, *PCAB_SEARCH
;
118 #define CAB_STATUS_SUCCESS 0x00000000
119 #define CAB_STATUS_FAILURE 0x00000001
120 #define CAB_STATUS_NOMEMORY 0x00000002
121 #define CAB_STATUS_CANNOT_OPEN 0x00000003
122 #define CAB_STATUS_CANNOT_CREATE 0x00000004
123 #define CAB_STATUS_CANNOT_READ 0x00000005
124 #define CAB_STATUS_CANNOT_WRITE 0x00000006
125 #define CAB_STATUS_FILE_EXISTS 0x00000007
126 #define CAB_STATUS_INVALID_CAB 0x00000008
127 #define CAB_STATUS_NOFILE 0x00000009
128 #define CAB_STATUS_UNSUPPCOMP 0x0000000A
133 /* Uncompresses a data block */
134 typedef ULONG (*PCABINET_CODEC_UNCOMPRESS
)(PVOID OutputBuffer
,
140 /* Codec status codes */
141 #define CS_SUCCESS 0x0000 /* All data consumed */
142 #define CS_NOMEMORY 0x0001 /* Not enough free memory */
143 #define CS_BADSTREAM 0x0002 /* Bad data stream */
145 /* Codec indentifiers */
146 #define CAB_CODEC_RAW 0x00
147 #define CAB_CODEC_LZX 0x01
148 #define CAB_CODEC_MSZIP 0x02
150 #define MSZIP_MAGIC 0x4B43
154 /* Event handler prototypes */
156 typedef BOOL (*PCABINET_OVERWRITE
)(PCFFILE File
,
159 typedef VOID (*PCABINET_EXTRACT
)(PCFFILE File
,
162 typedef VOID (*PCABINET_DISK_CHANGE
)(PWCHAR CabinetName
,
169 /* Default constructor */
170 VOID
CabinetInitialize();
171 /* Default destructor */
172 VOID
CabinetCleanup();
173 /* Returns a pointer to the filename part of a fully qualified filename */
174 PWCHAR
CabinetGetFileName(PWCHAR Path
);
175 /* Removes a filename from a fully qualified filename */
176 VOID
CabinetRemoveFileName(PWCHAR Path
);
177 /* Normalizes a path */
178 BOOL
CabinetNormalizePath(PWCHAR Path
, ULONG Length
);
179 /* Returns name of cabinet file */
180 PWCHAR
CabinetGetCabinetName();
181 /* Sets the name of the cabinet file */
182 VOID
CabinetSetCabinetName(PWCHAR FileName
);
183 /* Sets destination path for extracted files */
184 VOID
CabinetSetDestinationPath(PWCHAR DestinationPath
);
185 /* Returns destination path */
186 PWCHAR
CabinetGetDestinationPath();
187 /* Returns zero-based current disk number */
188 ULONG
CabinetGetCurrentDiskNumber();
189 /* Opens the current cabinet file */
191 /* Closes the current open cabinet file */
193 /* Locates the first file in the current cabinet file that matches a search criteria */
194 ULONG
CabinetFindFirst(PWCHAR FileName
, PCAB_SEARCH Search
);
195 /* Locates the next file in the current cabinet file */
196 ULONG
CabinetFindNext(PCAB_SEARCH Search
);
197 /* Extracts a file from the current cabinet file */
198 ULONG
CabinetExtractFile(PCAB_SEARCH Search
);
199 /* Select codec engine to use */
200 VOID
CabinetSelectCodec(ULONG Id
);
201 /* Set event handlers */
202 VOID
CabinetSetEventHandlers(PCABINET_OVERWRITE Overwrite
,
203 PCABINET_EXTRACT Extract
,
204 PCABINET_DISK_CHANGE DiskChange
);
205 /* Get pointer to cabinet reserved area. NULL if none */
206 PVOID
CabinetGetCabinetReservedArea(PULONG Size
);
208 #endif /* __CABINET_H */