ReactOS 0.4.15-dev-7906-g1b85a5f
setupcab.c File Reference
#include "setupapi_private.h"
#include <fcntl.h>
#include <share.h>
#include <fdi.h>
Include dependency graph for setupcab.c:

Go to the source code of this file.

Classes

struct  SC_HSC_A
 
struct  SC_HSC_W
 

Macros

#define SC_HSC_A_MAGIC   0xACABFEED
 
#define SC_HSC_W_MAGIC   0x0CABFEED
 
#define SIZEOF_MYSTERIO   (MAX_PATH*3)
 

Typedefs

typedef struct SC_HSC_APSC_HSC_A
 
typedef struct SC_HSC_WPSC_HSC_W
 

Functions

static HFDI (__cdecl *sc_FDICreate)(PFNALLOC
 
static BOOL (__cdecl *sc_FDICopy)(HFDI
 
static BOOL LoadCABINETDll (void)
 
static void *CDECL sc_cb_alloc (ULONG cb)
 
static void CDECL sc_cb_free (void *pv)
 
static INT_PTR CDECL sc_cb_open (char *pszFile, int oflag, int pmode)
 
static UINT CDECL sc_cb_read (INT_PTR hf, void *pv, UINT cb)
 
static UINT CDECL sc_cb_write (INT_PTR hf, void *pv, UINT cb)
 
static int CDECL sc_cb_close (INT_PTR hf)
 
static LONG CDECL sc_cb_lseek (INT_PTR hf, LONG dist, int seektype)
 
static INT_PTR CDECL sc_FNNOTIFY_A (FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
 
static INT_PTR CDECL sc_FNNOTIFY_W (FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
 
BOOL WINAPI SetupIterateCabinetA (PCSTR CabinetFile, DWORD Reserved, PSP_FILE_CALLBACK_A MsgHandler, PVOID Context)
 
BOOL WINAPI SetupIterateCabinetW (PCWSTR CabinetFile, DWORD Reserved, PSP_FILE_CALLBACK_W MsgHandler, PVOID Context)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 

Variables

HINSTANCE hInstance = NULL
 
OSVERSIONINFOEXW OsVersionInfo
 
static HINSTANCE CABINET_hInstance = NULL
 
static PFNFREE
 
static PFNOPEN
 
static PFNREAD
 
static PFNWRITE
 
static PFNCLOSE
 
static PFNSEEK
 
static int
 
static PERF
 
static char char PFNFDINOTIFY
 
static char char PFNFDIDECRYPT
 

Macro Definition Documentation

◆ SC_HSC_A_MAGIC

#define SC_HSC_A_MAGIC   0xACABFEED

Definition at line 45 of file setupcab.c.

◆ SC_HSC_W_MAGIC

#define SC_HSC_W_MAGIC   0x0CABFEED

Definition at line 55 of file setupcab.c.

◆ SIZEOF_MYSTERIO

#define SIZEOF_MYSTERIO   (MAX_PATH*3)

Definition at line 231 of file setupcab.c.

Typedef Documentation

◆ PSC_HSC_A

◆ PSC_HSC_W

Function Documentation

◆ BOOL()

static BOOL ( __cdecl sc_FDICopy)
static

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 650 of file setupcab.c.

651{
652 switch (fdwReason) {
657 return FALSE;
658 hInstance = (HINSTANCE)hinstDLL;
659 break;
661 if (lpvReserved) break;
664 break;
665 }
666
667 return TRUE;
668}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define FreeLibrary(x)
Definition: compat.h:748
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
void WINAPI SetupCloseLog(void)
Definition: misc.c:2017
static HINSTANCE CABINET_hInstance
Definition: setupcab.c:35
HINSTANCE hInstance
Definition: setupcab.c:32
OSVERSIONINFOEXW OsVersionInfo
Definition: setupcab.c:33
static IN DWORD IN LPVOID lpvReserved
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
HANDLE HINSTANCE
Definition: typedefs.h:77

◆ HFDI()

static HFDI ( __cdecl sc_FDICreate)
static

◆ LoadCABINETDll()

static BOOL LoadCABINETDll ( void  )
static

Definition at line 65 of file setupcab.c.

66{
67 if (!CABINET_hInstance) {
68 CABINET_hInstance = LoadLibraryA("cabinet.dll");
70 sc_FDICreate = (void *)GetProcAddress(CABINET_hInstance, "FDICreate");
71 sc_FDICopy = (void *)GetProcAddress(CABINET_hInstance, "FDICopy");
72 sc_FDIDestroy = (void *)GetProcAddress(CABINET_hInstance, "FDIDestroy");
73 return TRUE;
74 } else {
75 ERR("load cabinet dll failed.\n");
76 return FALSE;
77 }
78 } else
79 return TRUE;
80}
#define ERR(fmt,...)
Definition: debug.h:110
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111

Referenced by SetupIterateCabinetA(), and SetupIterateCabinetW().

◆ sc_cb_alloc()

static void *CDECL sc_cb_alloc ( ULONG  cb)
static

Definition at line 84 of file setupcab.c.

85{
86 return HeapAlloc(GetProcessHeap(), 0, cb);
87}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33

Referenced by SetupIterateCabinetA(), and SetupIterateCabinetW().

◆ sc_cb_close()

static int CDECL sc_cb_close ( INT_PTR  hf)
static

Definition at line 203 of file setupcab.c.

204{
205 /* TRACE("(hf == %d)\n", hf); */
206
207 if (CloseHandle((HANDLE) hf))
208 return 0;
209 else
210 return -1;
211}
#define CloseHandle
Definition: compat.h:739

Referenced by sc_FNNOTIFY_A(), sc_FNNOTIFY_W(), SetupIterateCabinetA(), and SetupIterateCabinetW().

◆ sc_cb_free()

static void CDECL sc_cb_free ( void pv)
static

Definition at line 89 of file setupcab.c.

90{
91 HeapFree(GetProcessHeap(), 0, pv);
92}
#define HeapFree(x, y, z)
Definition: compat.h:735

Referenced by SetupIterateCabinetA(), and SetupIterateCabinetW().

◆ sc_cb_lseek()

static LONG CDECL sc_cb_lseek ( INT_PTR  hf,
LONG  dist,
int  seektype 
)
static

Definition at line 213 of file setupcab.c.

214{
215 DWORD ret;
216
217 /* TRACE("(hf == %d, dist == %ld, seektype == %d)\n", hf, dist, seektype); */
218
219 if (seektype < 0 || seektype > 2)
220 return -1;
221
222 if (((ret = SetFilePointer((HANDLE) hf, dist, NULL, seektype)) != INVALID_SET_FILE_POINTER) || !GetLastError()) {
223 /* TRACE("<-- %lu\n", ret); */
224 return ret;
225 } else {
226 /* TRACE("<-- -1\n"); */
227 return -1;
228 }
229}
#define NULL
Definition: types.h:112
#define INVALID_SET_FILE_POINTER
Definition: compat.h:732
#define SetFilePointer
Definition: compat.h:743
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by SetupIterateCabinetA(), and SetupIterateCabinetW().

◆ sc_cb_open()

static INT_PTR CDECL sc_cb_open ( char pszFile,
int  oflag,
int  pmode 
)
static

Definition at line 94 of file setupcab.c.

95{
96 DWORD creation = 0, sharing = 0;
97 int ioflag = 0;
98 INT_PTR ret = 0;
100
101 /* TRACE("(pszFile == %s, oflag == %d, pmode == %d)\n", debugstr_a(pszFile), oflag, pmode); */
102
103 switch(oflag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {
104 case _O_RDONLY:
105 ioflag |= GENERIC_READ;
106 break;
107 case _O_WRONLY:
108 ioflag |= GENERIC_WRITE;
109 break;
110 case _O_RDWR:
111 ioflag |= GENERIC_READ | GENERIC_WRITE;
112 break;
113 case _O_WRONLY | _O_RDWR: /* hmmm.. */
114 ERR("_O_WRONLY & _O_RDWR in oflag?\n");
115 return -1;
116 }
117
118 if (oflag & _O_CREAT) {
119 if (oflag & _O_EXCL)
120 creation = CREATE_NEW;
121 else if (oflag & _O_TRUNC)
122 creation = CREATE_ALWAYS;
123 else
124 creation = OPEN_ALWAYS;
125 } else /* no _O_CREAT */ {
126 if (oflag & _O_TRUNC)
127 creation = TRUNCATE_EXISTING;
128 else
129 creation = OPEN_EXISTING;
130 }
131
132 switch( pmode & 0x70 ) {
133 case _SH_DENYRW:
134 sharing = 0L;
135 break;
136 case _SH_DENYWR:
138 break;
139 case _SH_DENYRD:
141 break;
142 case _SH_COMPAT:
143 case _SH_DENYNO:
145 break;
146 default:
147 ERR("<-- -1 (Unhandled pmode 0x%x)\n", pmode);
148 return -1;
149 }
150
152 WARN("unsupported oflag 0x%04x\n",oflag);
153
154 sa.nLength = sizeof( SECURITY_ATTRIBUTES );
155 sa.lpSecurityDescriptor = NULL;
156 sa.bInheritHandle = !(ioflag & _O_NOINHERIT);
157
158 ret = (INT_PTR) CreateFileA(pszFile, ioflag, sharing, &sa, creation, FILE_ATTRIBUTE_NORMAL, NULL);
159
160 /* TRACE("<-- %d\n", ret); */
161
162 return ret;
163}
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define WARN(fmt,...)
Definition: debug.h:112
#define _O_RDWR
Definition: cabinet.h:39
#define _O_BINARY
Definition: cabinet.h:51
#define _O_NOINHERIT
Definition: cabinet.h:45
#define _O_RDONLY
Definition: cabinet.h:37
#define _O_TRUNC
Definition: cabinet.h:47
#define _O_CREAT
Definition: cabinet.h:46
#define _O_EXCL
Definition: cabinet.h:48
#define _O_WRONLY
Definition: cabinet.h:38
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
#define OPEN_EXISTING
Definition: compat.h:775
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
#define CREATE_ALWAYS
Definition: disk.h:72
#define TRUNCATE_EXISTING
Definition: disk.h:71
#define CREATE_NEW
Definition: disk.h:69
#define OPEN_ALWAYS
Definition: disk.h:70
static ULONG POBJECT_ATTRIBUTES PIO_STATUS_BLOCK ULONG sharing
Definition: pipe.c:70
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
#define L(x)
Definition: ntvdm.h:50
#define _SH_DENYRW
Definition: share.h:14
#define _SH_DENYRD
Definition: share.h:16
#define _SH_COMPAT
Definition: share.h:13
#define _SH_DENYNO
Definition: share.h:17
#define _SH_DENYWR
Definition: share.h:15
int32_t INT_PTR
Definition: typedefs.h:64

Referenced by sc_FNNOTIFY_A(), sc_FNNOTIFY_W(), SetupIterateCabinetA(), and SetupIterateCabinetW().

◆ sc_cb_read()

static UINT CDECL sc_cb_read ( INT_PTR  hf,
void pv,
UINT  cb 
)
static

Definition at line 165 of file setupcab.c.

166{
167 DWORD num_read;
168 BOOL rslt;
169
170 /* TRACE("(hf == %d, pv == ^%p, cb == %u)\n", hf, pv, cb); */
171
172 rslt = ReadFile((HANDLE) hf, pv, cb, &num_read, NULL);
173
174
175 /* eof and failure both give "-1" return */
176 if ((! rslt) || ((cb > 0) && (num_read == 0))) {
177 /* TRACE("<-- -1\n"); */
178 return -1;
179 }
180
181 /* TRACE("<-- %lu\n", num_read); */
182 return num_read;
183}
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by SetupIterateCabinetA(), and SetupIterateCabinetW().

◆ sc_cb_write()

static UINT CDECL sc_cb_write ( INT_PTR  hf,
void pv,
UINT  cb 
)
static

Definition at line 185 of file setupcab.c.

186{
187 DWORD num_written;
188 /* BOOL rv; */
189
190 /* TRACE("(hf == %d, pv == ^%p, cb == %u)\n", hf, pv, cb); */
191
192 if ( /* (rv = */ WriteFile((HANDLE) hf, pv, cb, &num_written, NULL) /* ) */
193 && (num_written == cb)) {
194 /* TRACE("<-- %lu\n", num_written); */
195 return num_written;
196 } else {
197 /* TRACE("rv == %d, num_written == %lu, cb == %u\n", rv, num_written,cb); */
198 /* TRACE("<-- -1\n"); */
199 return -1;
200 }
201}
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24

Referenced by SetupIterateCabinetA(), and SetupIterateCabinetW().

◆ sc_FNNOTIFY_A()

static INT_PTR CDECL sc_FNNOTIFY_A ( FDINOTIFICATIONTYPE  fdint,
PFDINOTIFICATION  pfdin 
)
static

Definition at line 235 of file setupcab.c.

236{
238 PSC_HSC_A phsc;
240 FILEPATHS_A fp;
241 UINT err;
242
243 CHAR mysterio[SIZEOF_MYSTERIO]; /* how big? undocumented! probably 256... */
244
245 memset(mysterio, 0, SIZEOF_MYSTERIO);
246
247 TRACE("(fdint == %d, pfdin == ^%p)\n", fdint, pfdin);
248
249 if (pfdin && pfdin->pv && (((PSC_HSC_A) pfdin->pv)->magic == SC_HSC_A_MAGIC))
250 phsc = pfdin->pv;
251 else {
252 ERR("pv %p is not an SC_HSC_A.\n", (pfdin) ? pfdin->pv : NULL);
253 return -1;
254 }
255
256 switch (fdint) {
258 TRACE("Cabinet info notification\n");
259 /* TRACE(" Cabinet name: %s\n", debugstr_a(pfdin->psz1));
260 TRACE(" Cabinet disk: %s\n", debugstr_a(pfdin->psz2));
261 TRACE(" Cabinet path: %s\n", debugstr_a(pfdin->psz3));
262 TRACE(" Cabinet Set#: %d\n", pfdin->setID);
263 TRACE(" Cabinet Cab#: %d\n", pfdin->iCabinet); */
264 WARN("SPFILENOTIFY_CABINETINFO undocumented: guess implementation.\n");
266 ci.CabinetPath = pfdin->psz3;
267 ci.DiskName = pfdin->psz2;
268 ci.SetId = pfdin->setID;
269 ci.CabinetNumber = pfdin->iCabinet;
270 phsc->msghandler(phsc->context, SPFILENOTIFY_CABINETINFO, (UINT_PTR) &ci, 0);
271 return 0;
273 TRACE("Partial file notification\n");
274 /* TRACE(" Partial file name: %s\n", debugstr_a(pfdin->psz1)); */
275 return 0;
276 case fdintCOPY_FILE:
277 TRACE("Copy file notification\n");
278 TRACE(" File name: %s\n", debugstr_a(pfdin->psz1));
279 /* TRACE(" File size: %ld\n", pfdin->cb);
280 TRACE(" File date: %u\n", pfdin->date);
281 TRACE(" File time: %u\n", pfdin->time);
282 TRACE(" File attr: %u\n", pfdin->attribs); */
283 fici.NameInCabinet = pfdin->psz1;
284 fici.FileSize = pfdin->cb;
285 fici.Win32Error = 0;
286 fici.DosDate = pfdin->date;
287 fici.DosTime = pfdin->time;
288 fici.DosAttribs = pfdin->attribs;
291 (UINT_PTR)&fici, (UINT_PTR)pfdin->psz1);
292 if (err == FILEOP_DOIT) {
293 TRACE(" Callback specified filename: %s\n", debugstr_a(fici.FullTargetName));
294 if (!fici.FullTargetName[0]) {
295 WARN(" Empty return string causing abort.\n");
297 return -1;
298 }
299 strcpy( phsc->most_recent_target, fici.FullTargetName );
300 return sc_cb_open(fici.FullTargetName, _O_BINARY | _O_CREAT | _O_WRONLY, _S_IREAD | _S_IWRITE);
301 } else {
302 TRACE(" Callback skipped file.\n");
303 return 0;
304 }
306 TRACE("Close file notification\n");
307 /* TRACE(" File name: %s\n", debugstr_a(pfdin->psz1));
308 TRACE(" Exec file? %s\n", (pfdin->cb) ? "Yes" : "No");
309 TRACE(" File hndl: %d\n", pfdin->hf); */
311 fp.Target = phsc->most_recent_target;
312 fp.Win32Error = 0;
313 fp.Flags = 0;
314 /* the following should be a fixme -- but it occurs too many times */
315 WARN("Should set file date/time/attribs (and execute files?)\n");
316 if (sc_cb_close(pfdin->hf))
317 WARN("_close failed.\n");
319 if (err) {
321 return FALSE;
322 } else
323 return TRUE;
325 TRACE("Next cabinet notification\n");
326 /* TRACE(" Cabinet name: %s\n", debugstr_a(pfdin->psz1));
327 TRACE(" Cabinet disk: %s\n", debugstr_a(pfdin->psz2));
328 TRACE(" Cabinet path: %s\n", debugstr_a(pfdin->psz3));
329 TRACE(" Cabinet Set#: %d\n", pfdin->setID);
330 TRACE(" Cabinet Cab#: %d\n", pfdin->iCabinet); */
331 ci.CabinetFile = pfdin->psz1;
332 ci.CabinetPath = pfdin->psz3;
333 ci.DiskName = pfdin->psz2;
334 ci.SetId = pfdin->setID;
335 ci.CabinetNumber = pfdin->iCabinet;
336 /* remember the new cabinet name */
337 strcpy(phsc->most_recent_cabinet_name, pfdin->psz1);
338 err = phsc->msghandler(phsc->context, SPFILENOTIFY_NEEDNEWCABINET, (UINT_PTR)&ci, (UINT_PTR)mysterio);
339 if (err) {
341 return -1;
342 } else {
343 if (mysterio[0]) {
344 /* some easy paranoia. no such carefulness exists on the wide API IIRC */
345 lstrcpynA(pfdin->psz3, mysterio, SIZEOF_MYSTERIO);
346 }
347 return 0;
348 }
349 default:
350 FIXME("Unknown notification type %d.\n", fdint);
351 return 0;
352 }
353}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define FIXME(fmt,...)
Definition: debug.h:111
#define _S_IWRITE
Definition: cabinet.h:33
#define _S_IREAD
Definition: cabinet.h:34
#define lstrcpynA
Definition: compat.h:751
#define SetLastError(x)
Definition: compat.h:752
#define MAX_PATH
Definition: compat.h:34
static INT_PTR CDECL sc_cb_open(char *pszFile, int oflag, int pmode)
Definition: setupcab.c:94
#define SC_HSC_A_MAGIC
Definition: setupcab.c:45
static int CDECL sc_cb_close(INT_PTR hf)
Definition: setupcab.c:203
#define SIZEOF_MYSTERIO
Definition: setupcab.c:231
@ fdintCABINET_INFO
Definition: fdi.h:247
@ fdintCOPY_FILE
Definition: fdi.h:249
@ fdintPARTIAL_FILE
Definition: fdi.h:248
@ fdintCLOSE_FILE_INFO
Definition: fdi.h:250
@ fdintNEXT_CABINET
Definition: fdi.h:251
#define FILEOP_DOIT
Definition: fileqsup.h:48
#define debugstr_a
Definition: kernel32.h:31
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
#define err(...)
#define memset(x, y, z)
Definition: compat.h:39
#define SPFILENOTIFY_CABINETINFO
Definition: setupapi.h:561
#define SPFILENOTIFY_NEEDNEWCABINET
Definition: setupapi.h:563
#define SPFILENOTIFY_FILEEXTRACTED
Definition: setupapi.h:564
#define SPFILENOTIFY_FILEINCABINET
Definition: setupapi.h:562
#define TRACE(s)
Definition: solgame.cpp:4
USHORT setID
Definition: fdi.h:239
USHORT iCabinet
Definition: fdi.h:240
char * psz3
Definition: fdi.h:230
char * psz2
Definition: fdi.h:229
USHORT time
Definition: fdi.h:236
void * pv
Definition: fdi.h:231
INT_PTR hf
Definition: fdi.h:233
char * psz1
Definition: fdi.h:228
USHORT date
Definition: fdi.h:235
USHORT attribs
Definition: fdi.h:237
LONG cb
Definition: fdi.h:227
CHAR most_recent_cabinet_name[MAX_PATH]
Definition: setupcab.c:51
PVOID context
Definition: setupcab.c:50
PSP_FILE_CALLBACK_A msghandler
Definition: setupcab.c:49
CHAR most_recent_target[MAX_PATH]
Definition: setupcab.c:52
PCSTR CabinetFile
Definition: setupapi.h:776
USHORT CabinetNumber
Definition: setupapi.h:779
PCSTR CabinetPath
Definition: setupapi.h:775
USHORT SetId
Definition: setupapi.h:778
PCSTR DiskName
Definition: setupapi.h:777
PCSTR Source
Definition: setupapi.h:748
DWORD Flags
Definition: setupapi.h:750
PCSTR Target
Definition: setupapi.h:747
UINT Win32Error
Definition: setupapi.h:749
CHAR FullTargetName[MAX_PATH]
Definition: setupapi.h:795
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
char CHAR
Definition: xmlstorage.h:175

Referenced by SetupIterateCabinetA().

◆ sc_FNNOTIFY_W()

static INT_PTR CDECL sc_FNNOTIFY_W ( FDINOTIFICATIONTYPE  fdint,
PFDINOTIFICATION  pfdin 
)
static

Definition at line 355 of file setupcab.c.

356{
358 PSC_HSC_W phsc;
360 FILEPATHS_W fp;
361 UINT err;
362 int len;
363
364 WCHAR mysterio[SIZEOF_MYSTERIO]; /* how big? undocumented! */
365 WCHAR buf[MAX_PATH], buf2[MAX_PATH];
366 CHAR charbuf[MAX_PATH];
367
368 memset(mysterio, 0, SIZEOF_MYSTERIO * sizeof(WCHAR));
369 memset(buf, 0, MAX_PATH * sizeof(WCHAR));
370 memset(buf2, 0, MAX_PATH * sizeof(WCHAR));
371 memset(charbuf, 0, MAX_PATH);
372
373 TRACE("(fdint == %d, pfdin == ^%p)\n", fdint, pfdin);
374
375 if (pfdin && pfdin->pv && (((PSC_HSC_W) pfdin->pv)->magic == SC_HSC_W_MAGIC))
376 phsc = pfdin->pv;
377 else {
378 ERR("pv %p is not an SC_HSC_W.\n", (pfdin) ? pfdin->pv : NULL);
379 return -1;
380 }
381
382 switch (fdint) {
384 TRACE("Cabinet info notification\n");
385 /* TRACE(" Cabinet name: %s\n", debugstr_a(pfdin->psz1));
386 TRACE(" Cabinet disk: %s\n", debugstr_a(pfdin->psz2));
387 TRACE(" Cabinet path: %s\n", debugstr_a(pfdin->psz3));
388 TRACE(" Cabinet Set#: %d\n", pfdin->setID);
389 TRACE(" Cabinet Cab#: %d\n", pfdin->iCabinet); */
390 WARN("SPFILENOTIFY_CABINETINFO undocumented: guess implementation.\n");
392 len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz3, -1, buf, MAX_PATH);
393 if ((len > MAX_PATH) || (len <= 1))
394 buf[0] = '\0';
395 ci.CabinetPath = buf;
396 len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz2, -1, buf2, MAX_PATH);
397 if ((len > MAX_PATH) || (len <= 1))
398 buf2[0] = '\0';
399 ci.DiskName = buf2;
400 ci.SetId = pfdin->setID;
401 ci.CabinetNumber = pfdin->iCabinet;
403 return 0;
405 TRACE("Partial file notification\n");
406 /* TRACE(" Partial file name: %s\n", debugstr_a(pfdin->psz1)); */
407 return 0;
408 case fdintCOPY_FILE:
409 TRACE("Copy file notification\n");
410 TRACE(" File name: %s\n", debugstr_a(pfdin->psz1));
411 /* TRACE(" File size: %ld\n", pfdin->cb);
412 TRACE(" File date: %u\n", pfdin->date);
413 TRACE(" File time: %u\n", pfdin->time);
414 TRACE(" File attr: %u\n", pfdin->attribs); */
415 len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz1, -1, buf2, MAX_PATH);
416 if ((len > MAX_PATH) || (len <= 1))
417 buf2[0] = '\0';
418 fici.NameInCabinet = buf2;
419 fici.FileSize = pfdin->cb;
420 fici.Win32Error = 0;
421 fici.DosDate = pfdin->date;
422 fici.DosTime = pfdin->time;
423 fici.DosAttribs = pfdin->attribs;
424 memset(fici.FullTargetName, 0, MAX_PATH * sizeof(WCHAR));
426 (UINT_PTR)&fici, (UINT_PTR)pfdin->psz1);
427 if (err == FILEOP_DOIT) {
428 TRACE(" Callback specified filename: %s\n", debugstr_w(fici.FullTargetName));
429 if (fici.FullTargetName[0]) {
430 len = strlenW(fici.FullTargetName) + 1;
431 if ((len > MAX_PATH ) || (len <= 1))
432 return 0;
433 if (!WideCharToMultiByte(CP_ACP, 0, fici.FullTargetName, len, charbuf, MAX_PATH, 0, 0))
434 return 0;
435 } else {
436 WARN("Empty buffer string caused abort.\n");
438 return -1;
439 }
440 strcpyW( phsc->most_recent_target, fici.FullTargetName );
442 } else {
443 TRACE(" Callback skipped file.\n");
444 return 0;
445 }
447 TRACE("Close file notification\n");
448 /* TRACE(" File name: %s\n", debugstr_a(pfdin->psz1));
449 TRACE(" Exec file? %s\n", (pfdin->cb) ? "Yes" : "No");
450 TRACE(" File hndl: %d\n", pfdin->hf); */
452 fp.Target = phsc->most_recent_target;
453 fp.Win32Error = 0;
454 fp.Flags = 0;
455 /* a valid fixme -- but occurs too many times */
456 /* FIXME("Should set file date/time/attribs (and execute files?)\n"); */
457 if (sc_cb_close(pfdin->hf))
458 WARN("_close failed.\n");
460 if (err) {
462 return FALSE;
463 } else
464 return TRUE;
466 TRACE("Next cabinet notification\n");
467 /* TRACE(" Cabinet name: %s\n", debugstr_a(pfdin->psz1));
468 TRACE(" Cabinet disk: %s\n", debugstr_a(pfdin->psz2));
469 TRACE(" Cabinet path: %s\n", debugstr_a(pfdin->psz3));
470 TRACE(" Cabinet Set#: %d\n", pfdin->setID);
471 TRACE(" Cabinet Cab#: %d\n", pfdin->iCabinet); */
472 /* remember the new cabinet name */
474 if ((len > MAX_PATH) || (len <= 1))
475 phsc->most_recent_cabinet_name[0] = '\0';
476 ci.CabinetFile = phsc->most_recent_cabinet_name;
477 len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz3, -1, buf, MAX_PATH);
478 if ((len > MAX_PATH) || (len <= 1))
479 buf[0] = '\0';
480 ci.CabinetPath = buf;
481 len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz2, -1, buf2, MAX_PATH);
482 if ((len > MAX_PATH) || (len <= 1))
483 buf2[0] = '\0';
484 ci.DiskName = buf2;
485 ci.SetId = pfdin->setID;
486 ci.CabinetNumber = pfdin->iCabinet;
487 err = phsc->msghandler(phsc->context, SPFILENOTIFY_NEEDNEWCABINET, (UINT_PTR)&ci, (UINT_PTR)mysterio);
488 if (err) {
490 return -1;
491 } else {
492 if (mysterio[0]) {
493 len = strlenW(mysterio) + 1;
494 if ((len > 255) || (len <= 1))
495 return 0;
496 if (!WideCharToMultiByte(CP_ACP, 0, mysterio, len, pfdin->psz3, 255, 0, 0))
497 return 0;
498 }
499 return 0;
500 }
501 default:
502 FIXME("Unknown notification type %d.\n", fdint);
503 return 0;
504 }
505}
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
#define SC_HSC_W_MAGIC
Definition: setupcab.c:55
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
#define debugstr_w
Definition: kernel32.h:32
#define strlenW(s)
Definition: unicode.h:28
#define strcpyW(d, s)
Definition: unicode.h:29
PSP_FILE_CALLBACK_W msghandler
Definition: setupcab.c:59
WCHAR most_recent_cabinet_name[MAX_PATH]
Definition: setupcab.c:61
PVOID context
Definition: setupcab.c:60
WCHAR most_recent_target[MAX_PATH]
Definition: setupcab.c:62
USHORT CabinetNumber
Definition: setupapi.h:786
PCWSTR CabinetPath
Definition: setupapi.h:782
USHORT SetId
Definition: setupapi.h:785
PCWSTR CabinetFile
Definition: setupapi.h:783
PCWSTR DiskName
Definition: setupapi.h:784
ULONG Flags
Definition: fileqsup.h:63
UINT Win32Error
Definition: fileqsup.h:62
PCWSTR Source
Definition: fileqsup.h:61
PCWSTR Target
Definition: fileqsup.h:60
WCHAR FullTargetName[MAX_PATH]
Definition: setupapi.h:804
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by SetupIterateCabinetW().

◆ SetupIterateCabinetA()

BOOL WINAPI SetupIterateCabinetA ( PCSTR  CabinetFile,
DWORD  Reserved,
PSP_FILE_CALLBACK_A  MsgHandler,
PVOID  Context 
)

Definition at line 510 of file setupcab.c.

512{
513
514 SC_HSC_A my_hsc;
515 ERF erf;
516 CHAR pszCabinet[MAX_PATH], pszCabPath[MAX_PATH], *p = NULL;
517 DWORD fpnsize;
518 BOOL ret;
519
520 TRACE("(CabinetFile == %s, Reserved == %u, MsgHandler == ^%p, Context == ^%p)\n",
521 debugstr_a(CabinetFile), Reserved, MsgHandler, Context);
522
523 if (!LoadCABINETDll())
524 return FALSE;
525
526 if (!CabinetFile)
527 {
529 return FALSE;
530 }
531
532 fpnsize = strlen(CabinetFile);
533 if (fpnsize >= MAX_PATH) {
535 return FALSE;
536 }
537
538 fpnsize = GetFullPathNameA(CabinetFile, MAX_PATH, pszCabPath, &p);
539 if (fpnsize > MAX_PATH) {
541 return FALSE;
542 }
543
544 if (p) {
545 strcpy(pszCabinet, p);
546 *p = '\0';
547 } else {
548 strcpy(pszCabinet, CabinetFile);
549 pszCabPath[0] = '\0';
550 }
551
552 TRACE("path: %s, cabfile: %s\n", debugstr_a(pszCabPath), debugstr_a(pszCabinet));
553
554 /* remember the cabinet name */
555 strcpy(my_hsc.most_recent_cabinet_name, pszCabinet);
556
557 my_hsc.magic = SC_HSC_A_MAGIC;
558 my_hsc.msghandler = MsgHandler;
559 my_hsc.context = Context;
560 my_hsc.hfdi = sc_FDICreate( sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read,
562
563 if (!my_hsc.hfdi) return FALSE;
564
565 ret = sc_FDICopy(my_hsc.hfdi, pszCabinet, pszCabPath, 0, sc_FNNOTIFY_A, NULL, &my_hsc);
566
567 sc_FDIDestroy(my_hsc.hfdi);
568 return ret;
569}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
DWORD WINAPI GetFullPathNameA(IN LPCSTR lpFileName, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart)
Definition: path.c:993
static void *CDECL sc_cb_alloc(ULONG cb)
Definition: setupcab.c:84
static void CDECL sc_cb_free(void *pv)
Definition: setupcab.c:89
static BOOL LoadCABINETDll(void)
Definition: setupcab.c:65
static UINT CDECL sc_cb_write(INT_PTR hf, void *pv, UINT cb)
Definition: setupcab.c:185
static UINT CDECL sc_cb_read(INT_PTR hf, void *pv, UINT cb)
Definition: setupcab.c:165
static LONG CDECL sc_cb_lseek(INT_PTR hf, LONG dist, int seektype)
Definition: setupcab.c:213
static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
Definition: setupcab.c:235
#define cpuUNKNOWN
Definition: fdi.h:269
GLfloat GLfloat p
Definition: glext.h:8902
double __cdecl erf(double)
Definition: fci.h:44
HFDI hfdi
Definition: setupcab.c:48
UINT magic
Definition: setupcab.c:47
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
#define ERROR_BAD_PATHNAME
Definition: winerror.h:233

Referenced by main(), test_invalid_callbackA(), test_invalid_parametersA(), and test_simple_enumerationA().

◆ SetupIterateCabinetW()

BOOL WINAPI SetupIterateCabinetW ( PCWSTR  CabinetFile,
DWORD  Reserved,
PSP_FILE_CALLBACK_W  MsgHandler,
PVOID  Context 
)

Definition at line 575 of file setupcab.c.

577{
578 CHAR pszCabinet[MAX_PATH], pszCabPath[MAX_PATH];
579 UINT len;
580 SC_HSC_W my_hsc;
581 ERF erf;
582 WCHAR pszCabPathW[MAX_PATH], *p = NULL;
583 DWORD fpnsize;
584 BOOL ret;
585
586 TRACE("(CabinetFile == %s, Reserved == %u, MsgHandler == ^%p, Context == ^%p)\n",
587 debugstr_w(CabinetFile), Reserved, MsgHandler, Context);
588
589 if (!LoadCABINETDll())
590 return FALSE;
591
592 if (!CabinetFile)
593 {
595 return FALSE;
596 }
597
598 fpnsize = GetFullPathNameW(CabinetFile, MAX_PATH, pszCabPathW, &p);
599 if (fpnsize > MAX_PATH) {
601 return FALSE;
602 }
603
604 if (p) {
606 *p = 0;
607 len = WideCharToMultiByte(CP_ACP, 0, pszCabPathW, -1, pszCabPath,
608 MAX_PATH, 0, 0);
609 if (!len) return FALSE;
610 } else {
611 strcpyW(my_hsc.most_recent_cabinet_name, CabinetFile);
612 pszCabPath[0] = '\0';
613 }
614
616 pszCabinet, MAX_PATH, 0, 0);
617 if (!len) return FALSE;
618
619 TRACE("path: %s, cabfile: %s\n",
620 debugstr_a(pszCabPath), debugstr_a(pszCabinet));
621
622 my_hsc.magic = SC_HSC_W_MAGIC;
623 my_hsc.msghandler = MsgHandler;
624 my_hsc.context = Context;
625 my_hsc.hfdi = sc_FDICreate( sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read,
627
628 if (!my_hsc.hfdi) return FALSE;
629
630 ret = sc_FDICopy(my_hsc.hfdi, pszCabinet, pszCabPath, 0, sc_FNNOTIFY_W, NULL, &my_hsc);
631
632 sc_FDIDestroy(my_hsc.hfdi);
633 return ret;
634}
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
static INT_PTR CDECL sc_FNNOTIFY_W(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
Definition: setupcab.c:355
HFDI hfdi
Definition: setupcab.c:58
UINT magic
Definition: setupcab.c:57

Referenced by decompress_file_cab(), extract(), extract_cabinet_file(), get_file_sizes_cab(), test_invalid_callbackW(), test_invalid_parametersW(), test_simple_enumerationW(), and wWinMain().

Variable Documentation

◆ CABINET_hInstance

HINSTANCE CABINET_hInstance = NULL
static

Definition at line 35 of file setupcab.c.

Referenced by DllMain(), and LoadCABINETDll().

◆ hInstance

HINSTANCE hInstance = NULL

Definition at line 32 of file setupcab.c.

Referenced by DllMain().

◆ int

char char int

Definition at line 38 of file setupcab.c.

◆ OsVersionInfo

OSVERSIONINFOEXW OsVersionInfo

Definition at line 33 of file setupcab.c.

Referenced by DllMain(), and SetupDiGetActualSectionToInstallExW().

◆ PERF

Definition at line 38 of file setupcab.c.

◆ PFNCLOSE

PFNCLOSE

Definition at line 38 of file setupcab.c.

◆ PFNFDIDECRYPT

char char PFNFDIDECRYPT

Definition at line 41 of file setupcab.c.

◆ PFNFDINOTIFY

char char PFNFDINOTIFY

Definition at line 41 of file setupcab.c.

◆ PFNFREE

PFNFREE

Definition at line 37 of file setupcab.c.

◆ PFNOPEN

PFNOPEN

Definition at line 37 of file setupcab.c.

◆ PFNREAD

PFNREAD

Definition at line 38 of file setupcab.c.

◆ PFNSEEK

PFNSEEK

Definition at line 38 of file setupcab.c.

◆ PFNWRITE

PFNWRITE

Definition at line 38 of file setupcab.c.