xref: /reactos/base/setup/usetup/spapisup/cabinet.h (revision 8a978a17)
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 /* Cabinet structures */
10 
11 // Shadow types, implementation-specific
12 typedef struct _CFHEADER *PCFHEADER;
13 typedef struct _CFFOLDER *PCFFOLDER;
14 typedef struct _CFFILE *PCFFILE;
15 typedef struct _CFDATA *PCFDATA;
16 
17 struct _CABINET_CONTEXT;
18 
19 
20 /* Constants */
21 
22 /* Status codes */
23 #define CAB_STATUS_SUCCESS       0x00000000
24 #define CAB_STATUS_FAILURE       0x00000001
25 #define CAB_STATUS_NOMEMORY      0x00000002
26 #define CAB_STATUS_CANNOT_OPEN   0x00000003
27 #define CAB_STATUS_CANNOT_CREATE 0x00000004
28 #define CAB_STATUS_CANNOT_READ   0x00000005
29 #define CAB_STATUS_CANNOT_WRITE  0x00000006
30 #define CAB_STATUS_FILE_EXISTS   0x00000007
31 #define CAB_STATUS_INVALID_CAB   0x00000008
32 #define CAB_STATUS_NOFILE        0x00000009
33 #define CAB_STATUS_UNSUPPCOMP    0x0000000A
34 
35 
36 /* Codecs */
37 
38 typedef struct _CAB_CODEC *PCAB_CODEC;
39 
40 /* Codec status codes */
41 #define CS_SUCCESS      0x0000  /* All data consumed */
42 #define CS_NOMEMORY     0x0001  /* Not enough free memory */
43 #define CS_BADSTREAM    0x0002  /* Bad data stream */
44 
45 /* Codec identifiers */
46 #define CAB_CODEC_RAW   0x00
47 #define CAB_CODEC_LZX   0x01
48 #define CAB_CODEC_MSZIP 0x02
49 
50 
51 /* Event handler prototypes */
52 
53 typedef BOOL (*PCABINET_OVERWRITE)(
54     IN struct _CABINET_CONTEXT* CabinetContext,
55     IN PCFFILE File,
56     IN PCWSTR FileName);
57 
58 typedef VOID (*PCABINET_EXTRACT)(
59     IN struct _CABINET_CONTEXT* CabinetContext,
60     IN PCFFILE File,
61     IN PCWSTR FileName);
62 
63 typedef VOID (*PCABINET_DISK_CHANGE)(
64     IN struct _CABINET_CONTEXT* CabinetContext,
65     IN PCWSTR CabinetName,
66     IN PCWSTR DiskLabel);
67 
68 typedef PVOID (*PCABINET_CREATE_FILE)(
69     IN struct _CABINET_CONTEXT* CabinetContext,
70     IN ULONG FileSize);
71 
72 /* Classes */
73 
74 typedef struct _CAB_SEARCH
75 {
76     WCHAR        Search[MAX_PATH];  // Search criteria
77     WCHAR        Cabinet[MAX_PATH];
78     USHORT       Index;
79     PCFFILE      File;              // Pointer to current CFFILE
80     PCFDATA      CFData;
81     ULONG        Offset;
82 } CAB_SEARCH, *PCAB_SEARCH;
83 
84 typedef struct _CABINET_CONTEXT
85 {
86     WCHAR CabinetName[256];         // Filename of current cabinet
87     WCHAR CabinetPrev[256];         // Filename of previous cabinet
88     WCHAR DiskPrev[256];            // Label of cabinet in file CabinetPrev
89     WCHAR CabinetNext[256];         // Filename of next cabinet
90     WCHAR DiskNext[256];            // Label of cabinet in file CabinetNext
91     ULONG FolderUncompSize;         // Uncompressed size of folder
92     ULONG BytesLeftInBlock;         // Number of bytes left in current block
93     WCHAR DestPath[MAX_PATH];
94     HANDLE FileHandle;
95     HANDLE FileSectionHandle;
96     PUCHAR FileBuffer;
97     SIZE_T DestFileSize;
98     SIZE_T FileSize;
99     BOOL FileOpen;
100     PCFHEADER PCABHeader;
101     PCFFOLDER CabinetFolders;
102     ULONG CabinetReserved;
103     ULONG FolderReserved;
104     ULONG DataReserved;
105     PCAB_CODEC Codec;
106     ULONG CodecId;
107     BOOL CodecSelected;
108     ULONG LastFileOffset;           // Uncompressed offset of last extracted file
109     PCABINET_OVERWRITE OverwriteHandler;
110     PCABINET_EXTRACT ExtractHandler;
111     PCABINET_DISK_CHANGE DiskChangeHandler;
112     PCABINET_CREATE_FILE CreateFileHandler;
113     PVOID CabinetReservedArea;
114 } CABINET_CONTEXT, *PCABINET_CONTEXT;
115 
116 
117 /* Default constructor */
118 VOID
119 CabinetInitialize(
120     IN OUT PCABINET_CONTEXT CabinetContext);
121 
122 /* Default destructor */
123 VOID
124 CabinetCleanup(
125     IN OUT PCABINET_CONTEXT CabinetContext);
126 
127 #if 0
128 /* Returns a pointer to the filename part of a fully qualified filename */
129 PWCHAR CabinetGetFileName(PWCHAR Path);
130 /* Removes a filename from a fully qualified filename */
131 VOID CabinetRemoveFileName(PWCHAR Path);
132 /* Normalizes a path */
133 BOOL CabinetNormalizePath(PWCHAR Path, ULONG Length);
134 #endif
135 
136 /* Returns name of cabinet file */
137 PCWSTR
138 CabinetGetCabinetName(
139     IN PCABINET_CONTEXT CabinetContext);
140 
141 /* Sets the name of the cabinet file */
142 VOID
143 CabinetSetCabinetName(
144     IN PCABINET_CONTEXT CabinetContext,
145     IN PCWSTR FileName);
146 
147 /* Sets destination path for extracted files */
148 VOID
149 CabinetSetDestinationPath(
150     IN PCABINET_CONTEXT CabinetContext,
151     IN PCWSTR DestinationPath);
152 
153 /* Returns destination path */
154 PCWSTR
155 CabinetGetDestinationPath(
156     IN PCABINET_CONTEXT CabinetContext);
157 
158 #if 0
159 /* Returns zero-based current disk number */
160 ULONG CabinetGetCurrentDiskNumber(VOID);
161 #endif
162 
163 /* Opens the current cabinet file */
164 ULONG
165 CabinetOpen(
166     IN OUT PCABINET_CONTEXT CabinetContext);
167 
168 /* Closes the current open cabinet file */
169 VOID
170 CabinetClose(
171     IN OUT PCABINET_CONTEXT CabinetContext);
172 
173 /* Locates the first file in the current cabinet file that matches a search criteria */
174 ULONG
175 CabinetFindFirst(
176     IN PCABINET_CONTEXT CabinetContext,
177     IN PCWSTR FileName,
178     IN OUT PCAB_SEARCH Search);
179 
180 /* Locates the next file that matches the current search criteria */
181 ULONG
182 CabinetFindNext(
183     IN PCABINET_CONTEXT CabinetContext,
184     IN OUT PCAB_SEARCH Search);
185 
186 /* Locates the next file in the current cabinet file sequentially */
187 ULONG
188 CabinetFindNextFileSequential(
189     IN PCABINET_CONTEXT CabinetContext,
190     IN PCWSTR FileName,
191     IN OUT PCAB_SEARCH Search);
192 
193 /* Extracts a file from the current cabinet file */
194 ULONG
195 CabinetExtractFile(
196     IN PCABINET_CONTEXT CabinetContext,
197     IN PCAB_SEARCH Search);
198 
199 /* Select codec engine to use */
200 VOID
201 CabinetSelectCodec(
202     IN PCABINET_CONTEXT CabinetContext,
203     IN ULONG Id);
204 
205 /* Set event handlers */
206 VOID
207 CabinetSetEventHandlers(
208     IN PCABINET_CONTEXT CabinetContext,
209     IN PCABINET_OVERWRITE Overwrite,
210     IN PCABINET_EXTRACT Extract,
211     IN PCABINET_DISK_CHANGE DiskChange,
212     IN PCABINET_CREATE_FILE CreateFile);
213 
214 /* Get pointer to cabinet reserved area. NULL if none */
215 PVOID
216 CabinetGetCabinetReservedArea(
217     IN PCABINET_CONTEXT CabinetContext,
218     OUT PULONG Size);
219