xref: /reactos/base/setup/usetup/spapisup/cabinet.h (revision ebaf247c)
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 
69 /* Classes */
70 
71 typedef struct _CAB_SEARCH
72 {
73     WCHAR        Search[MAX_PATH];  // Search criteria
74     WCHAR        Cabinet[MAX_PATH];
75     USHORT       Index;
76     PCFFILE      File;              // Pointer to current CFFILE
77     PCFDATA      CFData;
78     ULONG        Offset;
79 } CAB_SEARCH, *PCAB_SEARCH;
80 
81 typedef struct _CABINET_CONTEXT
82 {
83     WCHAR CabinetName[256];         // Filename of current cabinet
84     WCHAR CabinetPrev[256];         // Filename of previous cabinet
85     WCHAR DiskPrev[256];            // Label of cabinet in file CabinetPrev
86     WCHAR CabinetNext[256];         // Filename of next cabinet
87     WCHAR DiskNext[256];            // Label of cabinet in file CabinetNext
88     ULONG FolderUncompSize;         // Uncompressed size of folder
89     ULONG BytesLeftInBlock;         // Number of bytes left in current block
90     WCHAR DestPath[MAX_PATH];
91     HANDLE FileHandle;
92     HANDLE FileSectionHandle;
93     PUCHAR FileBuffer;
94     SIZE_T DestFileSize;
95     SIZE_T FileSize;
96     BOOL FileOpen;
97     PCFHEADER PCABHeader;
98     PCFFOLDER CabinetFolders;
99     ULONG CabinetReserved;
100     ULONG FolderReserved;
101     ULONG DataReserved;
102     PCAB_CODEC Codec;
103     ULONG CodecId;
104     BOOL CodecSelected;
105     ULONG LastFileOffset;           // Uncompressed offset of last extracted file
106     PCABINET_OVERWRITE OverwriteHandler;
107     PCABINET_EXTRACT ExtractHandler;
108     PCABINET_DISK_CHANGE DiskChangeHandler;
109     PVOID CabinetReservedArea;
110 } CABINET_CONTEXT, *PCABINET_CONTEXT;
111 
112 
113 /* Default constructor */
114 VOID
115 CabinetInitialize(
116     IN OUT PCABINET_CONTEXT CabinetContext);
117 
118 /* Default destructor */
119 VOID
120 CabinetCleanup(
121     IN OUT PCABINET_CONTEXT CabinetContext);
122 
123 #if 0
124 /* Returns a pointer to the filename part of a fully qualified filename */
125 PWCHAR CabinetGetFileName(PWCHAR Path);
126 /* Removes a filename from a fully qualified filename */
127 VOID CabinetRemoveFileName(PWCHAR Path);
128 /* Normalizes a path */
129 BOOL CabinetNormalizePath(PWCHAR Path, ULONG Length);
130 #endif
131 
132 /* Returns name of cabinet file */
133 PCWSTR
134 CabinetGetCabinetName(
135     IN PCABINET_CONTEXT CabinetContext);
136 
137 /* Sets the name of the cabinet file */
138 VOID
139 CabinetSetCabinetName(
140     IN PCABINET_CONTEXT CabinetContext,
141     IN PCWSTR FileName);
142 
143 /* Sets destination path for extracted files */
144 VOID
145 CabinetSetDestinationPath(
146     IN PCABINET_CONTEXT CabinetContext,
147     IN PCWSTR DestinationPath);
148 
149 /* Returns destination path */
150 PCWSTR
151 CabinetGetDestinationPath(
152     IN PCABINET_CONTEXT CabinetContext);
153 
154 #if 0
155 /* Returns zero-based current disk number */
156 ULONG CabinetGetCurrentDiskNumber(VOID);
157 #endif
158 
159 /* Opens the current cabinet file */
160 ULONG
161 CabinetOpen(
162     IN OUT PCABINET_CONTEXT CabinetContext);
163 
164 /* Closes the current open cabinet file */
165 VOID
166 CabinetClose(
167     IN OUT PCABINET_CONTEXT CabinetContext);
168 
169 /* Locates the first file in the current cabinet file that matches a search criteria */
170 ULONG
171 CabinetFindFirst(
172     IN PCABINET_CONTEXT CabinetContext,
173     IN PCWSTR FileName,
174     IN OUT PCAB_SEARCH Search);
175 
176 /* Locates the next file that matches the current search criteria */
177 ULONG
178 CabinetFindNext(
179     IN PCABINET_CONTEXT CabinetContext,
180     IN OUT PCAB_SEARCH Search);
181 
182 /* Locates the next file in the current cabinet file sequentially */
183 ULONG
184 CabinetFindNextFileSequential(
185     IN PCABINET_CONTEXT CabinetContext,
186     IN PCWSTR FileName,
187     IN OUT PCAB_SEARCH Search);
188 
189 /* Extracts a file from the current cabinet file */
190 ULONG
191 CabinetExtractFile(
192     IN PCABINET_CONTEXT CabinetContext,
193     IN PCAB_SEARCH Search);
194 
195 /* Select codec engine to use */
196 VOID
197 CabinetSelectCodec(
198     IN PCABINET_CONTEXT CabinetContext,
199     IN ULONG Id);
200 
201 /* Set event handlers */
202 VOID
203 CabinetSetEventHandlers(
204     IN PCABINET_CONTEXT CabinetContext,
205     IN PCABINET_OVERWRITE Overwrite,
206     IN PCABINET_EXTRACT Extract,
207     IN PCABINET_DISK_CHANGE DiskChange);
208 
209 /* Get pointer to cabinet reserved area. NULL if none */
210 PVOID
211 CabinetGetCabinetReservedArea(
212     IN PCABINET_CONTEXT CabinetContext,
213     OUT PULONG Size);
214