ReactOS 0.4.16-dev-240-gdb5fa3b
cabinet_main.c File Reference
#include "config.h"
#include <assert.h>
#include <stdarg.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "shlwapi.h"
#include "cabinet.h"
#include "wine/debug.h"
Include dependency graph for cabinet_main.c:

Go to the source code of this file.

Macros

#define NO_SHLWAPI_REG
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (cabinet)
 
HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
 
static void *CDECL mem_alloc (ULONG cb)
 
static void CDECL mem_free (void *memory)
 
static INT_PTR CDECL fdi_open (char *pszFile, int oflag, int pmode)
 
static UINT CDECL fdi_read (INT_PTR hf, void *pv, UINT cb)
 
static UINT CDECL fdi_write (INT_PTR hf, void *pv, UINT cb)
 
static int CDECL fdi_close (INT_PTR hf)
 
static LONG CDECL fdi_seek (INT_PTR hf, LONG dist, int seektype)
 
static void fill_file_node (struct FILELIST *pNode, LPCSTR szFilename)
 
static BOOL file_in_list (struct FILELIST *pNode, LPCSTR szFilename, struct FILELIST **pOut)
 
static INT_PTR CDECL fdi_notify_extract (FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
 
HRESULT WINAPI Extract (SESSION *dest, LPCSTR szCabName)
 

Macro Definition Documentation

◆ NO_SHLWAPI_REG

#define NO_SHLWAPI_REG

Definition at line 30 of file cabinet_main.c.

Function Documentation

◆ DllGetVersion()

HRESULT WINAPI DllGetVersion ( DLLVERSIONINFO pdvi)

Definition at line 56 of file cabinet_main.c.

57{
58 WARN("hmmm... not right version number \"5.1.1106.1\"?\n");
59
60 if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) return E_INVALIDARG;
61
62 pdvi->dwMajorVersion = 5;
63 pdvi->dwMinorVersion = 1;
64 pdvi->dwBuildNumber = 1106;
65 pdvi->dwPlatformID = 1;
66
67 return S_OK;
68}
#define WARN(fmt,...)
Definition: precomp.h:61
#define E_INVALIDARG
Definition: ddrawi.h:101
#define S_OK
Definition: intsafe.h:52
DWORD dwMajorVersion
Definition: shlwapi.h:1983
DWORD dwBuildNumber
Definition: shlwapi.h:1985
DWORD dwMinorVersion
Definition: shlwapi.h:1984
DWORD dwPlatformID
Definition: shlwapi.h:1986

◆ Extract()

HRESULT WINAPI Extract ( SESSION dest,
LPCSTR  szCabName 
)

Definition at line 328 of file cabinet_main.c.

329{
330 HRESULT res = S_OK;
331 HFDI hfdi;
332 char *str, *end, *path = NULL, *name = NULL;
333
334 TRACE("(%p, %s)\n", dest, debugstr_a(szCabName));
335
336 hfdi = FDICreate(mem_alloc,
337 mem_free,
338 fdi_open,
339 fdi_read,
340 fdi_write,
341 fdi_close,
342 fdi_seek,
344 &dest->Error);
345
346 if (!hfdi)
347 return E_FAIL;
348
350 {
351 res = S_OK;
352 goto end;
353 }
354
355 /* split the cabinet name into path + name */
356 str = HeapAlloc(GetProcessHeap(), 0, lstrlenA(szCabName)+1);
357 if (!str)
358 {
360 goto end;
361 }
362 lstrcpyA(str, szCabName);
363
364 if ((end = strrchr(str, '\\')))
365 {
366 path = str;
367 end++;
368 name = HeapAlloc( GetProcessHeap(), 0, strlen(end) + 1 );
369 if (!name)
370 {
372 goto end;
373 }
374 strcpy( name, end );
375 *end = 0;
376 }
377 else
378 {
379 name = str;
380 path = NULL;
381 }
382
383 dest->FileSize = 0;
384
385 if (!FDICopy(hfdi, name, path, 0,
388
389end:
392 FDIDestroy(hfdi);
393 return res;
394}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
static INT_PTR CDECL fdi_notify_extract(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
Definition: cabinet_main.c:185
static UINT CDECL fdi_read(INT_PTR hf, void *pv, UINT cb)
Definition: cabinet_main.c:123
static LONG CDECL fdi_seek(INT_PTR hf, LONG dist, int seektype)
Definition: cabinet_main.c:151
static int CDECL fdi_close(INT_PTR hf)
Definition: cabinet_main.c:145
static UINT CDECL fdi_write(INT_PTR hf, void *pv, UINT cb)
Definition: cabinet_main.c:134
static INT_PTR CDECL fdi_open(char *pszFile, int oflag, int pmode)
Definition: cabinet_main.c:82
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define mem_free(ptr, bsize)
Definition: types.h:124
#define NULL
Definition: types.h:112
#define mem_alloc(bsize)
Definition: types.h:123
HFDI __cdecl FDICreate(PFNALLOC pfnalloc, PFNFREE pfnfree, PFNOPEN pfnopen, PFNREAD pfnread, PFNWRITE pfnwrite, PFNCLOSE pfnclose, PFNSEEK pfnseek, int cpuType, PERF perf)
Definition: fdi.c:412
BOOL __cdecl FDICopy(HFDI hfdi, char *pszCabinet, char *pszCabPath, int flags, PFNFDINOTIFY pfnfdin, PFNFDIDECRYPT pfnfdid, void *pvUser)
Definition: fdi.c:2431
BOOL __cdecl FDIDestroy(HFDI hfdi)
Definition: fdi.c:2831
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:636
#define cpuUNKNOWN
Definition: fdi.h:269
GLuint GLuint end
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
#define debugstr_a
Definition: kernel32.h:31
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
static char * dest
Definition: rtl.c:135
const WCHAR * str
_CRT_RESTORE_GCC_WARNINGS _CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define TRACE(s)
Definition: solgame.cpp:4
Definition: name.c:39
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92

Referenced by CabinetSetEventHandlers().

◆ fdi_close()

static int CDECL fdi_close ( INT_PTR  hf)
static

Definition at line 145 of file cabinet_main.c.

146{
147 HANDLE handle = (HANDLE) hf;
148 return CloseHandle(handle) ? 0 : -1;
149}
#define CloseHandle
Definition: compat.h:739
PVOID HANDLE
Definition: typedefs.h:73

Referenced by Extract().

◆ fdi_notify_extract()

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

Definition at line 185 of file cabinet_main.c.

186{
187 switch (fdint)
188 {
189 case fdintCOPY_FILE:
190 {
191 struct FILELIST *fileList, *node = NULL;
192 SESSION *pDestination = pfdin->pv;
193 LPSTR szFullPath, szDirectory;
194 HANDLE hFile = 0;
196
197 dwSize = lstrlenA(pDestination->Destination) +
198 lstrlenA("\\") + lstrlenA(pfdin->psz1) + 1;
199 szFullPath = HeapAlloc(GetProcessHeap(), 0, dwSize);
200
201 lstrcpyA(szFullPath, pDestination->Destination);
202 lstrcatA(szFullPath, "\\");
203 lstrcatA(szFullPath, pfdin->psz1);
204
205 /* pull out the destination directory string from the full path */
206 dwSize = strrchr(szFullPath, '\\') - szFullPath + 1;
207 szDirectory = HeapAlloc(GetProcessHeap(), 0, dwSize);
208 lstrcpynA(szDirectory, szFullPath, dwSize);
209
210 pDestination->FileSize += pfdin->cb;
211
212 if (pDestination->Operation & EXTRACT_FILLFILELIST)
213 {
214 fileList = HeapAlloc(GetProcessHeap(), 0,
215 sizeof(struct FILELIST));
216
217 fill_file_node(fileList, pfdin->psz1);
218 fileList->DoExtract = TRUE;
219 fileList->next = pDestination->FileList;
220 pDestination->FileList = fileList;
221 lstrcpyA(pDestination->CurrentFile, szFullPath);
222 pDestination->FileCount++;
223 }
224
225 if ((pDestination->Operation & EXTRACT_EXTRACTFILES) ||
226 file_in_list(pDestination->FilterList, pfdin->psz1, NULL))
227 {
228 /* find the file node */
229 file_in_list(pDestination->FileList, pfdin->psz1, &node);
230
231 if (node && !node->DoExtract)
232 {
233 HeapFree(GetProcessHeap(), 0, szFullPath);
234 HeapFree(GetProcessHeap(), 0, szDirectory);
235 return 0;
236 }
237
238 /* create the destination directory if it doesn't exist */
240 {
241 char *ptr;
242
243 for(ptr = szDirectory + strlen(pDestination->Destination)+1; *ptr; ptr++) {
244 if(*ptr == '\\') {
245 *ptr = 0;
246 CreateDirectoryA(szDirectory, NULL);
247 *ptr = '\\';
248 }
249 }
250 CreateDirectoryA(szDirectory, NULL);
251 }
252
253 hFile = CreateFileA(szFullPath, GENERIC_READ | GENERIC_WRITE, 0, NULL,
255
257 node->DoExtract = FALSE;
258 }
259
260 HeapFree(GetProcessHeap(), 0, szFullPath);
261 HeapFree(GetProcessHeap(), 0, szDirectory);
262
263 return (INT_PTR) hFile;
264 }
265
267 {
268 FILETIME ft;
269 FILETIME ftLocal;
270 HANDLE handle = (HANDLE) pfdin->hf;
271
272 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
273 return FALSE;
274
275 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
276 return FALSE;
277
278 if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
279 return FALSE;
280
282 return TRUE;
283 }
284
285 default:
286 return 0;
287 }
288}
static BOOL file_in_list(struct FILELIST *pNode, LPCSTR szFilename, struct FILELIST **pOut)
Definition: cabinet_main.c:166
static void fill_file_node(struct FILELIST *pNode, LPCSTR szFilename)
Definition: cabinet_main.c:157
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define EXTRACT_EXTRACTFILES
Definition: files.c:543
#define EXTRACT_FILLFILELIST
Definition: files.c:542
#define lstrcpynA
Definition: compat.h:751
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#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
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:948
BOOL WINAPI DosDateTimeToFileTime(IN WORD wFatDate, IN WORD wFatTime, OUT LPFILETIME lpFileTime)
Definition: time.c:75
BOOL WINAPI LocalFileTimeToFileTime(IN CONST FILETIME *lpLocalFileTime, OUT LPFILETIME lpFileTime)
Definition: time.c:253
@ fdintCOPY_FILE
Definition: fdi.h:249
@ fdintCLOSE_FILE_INFO
Definition: fdi.h:250
unsigned long DWORD
Definition: ntddk_ex.h:95
if(dx< 0)
Definition: linetemp.h:194
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
#define CREATE_ALWAYS
Definition: disk.h:72
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static PVOID ptr
Definition: dispmode.c:27
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90
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
LONG cb
Definition: fdi.h:227
struct FILELIST * next
Definition: files.c:547
BOOL DoExtract
Definition: files.c:548
Definition: files.c:551
struct FILELIST * FilterList
Definition: files.c:560
INT Operation
Definition: files.c:556
INT FileSize
Definition: files.c:552
CHAR CurrentFile[MAX_PATH]
Definition: files.c:558
struct FILELIST * FileList
Definition: files.c:554
INT FileCount
Definition: files.c:555
CHAR Destination[MAX_PATH]
Definition: files.c:557
int32_t INT_PTR
Definition: typedefs.h:64
Definition: dlist.c:348
char * LPSTR
Definition: xmlstorage.h:182

Referenced by Extract().

◆ fdi_open()

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

Definition at line 82 of file cabinet_main.c.

83{
85 DWORD dwAccess = 0;
86 DWORD dwShareMode = 0;
87 DWORD dwCreateDisposition;
88
89 switch (oflag & _O_ACCMODE)
90 {
91 case _O_RDONLY:
92 dwAccess = GENERIC_READ;
93 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
94 break;
95 case _O_WRONLY:
96 dwAccess = GENERIC_WRITE;
98 break;
99 case _O_RDWR:
100 dwAccess = GENERIC_READ | GENERIC_WRITE;
102 break;
103 }
104
105 if (oflag & _O_CREAT)
106 {
107 dwCreateDisposition = OPEN_ALWAYS;
108 if (oflag & _O_EXCL) dwCreateDisposition = CREATE_NEW;
109 else if (oflag & _O_TRUNC) dwCreateDisposition = CREATE_ALWAYS;
110 }
111 else
112 {
113 dwCreateDisposition = OPEN_EXISTING;
114 if (oflag & _O_TRUNC) dwCreateDisposition = TRUNCATE_EXISTING;
115 }
116
117 handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
118 dwCreateDisposition, 0, NULL);
119
120 return (INT_PTR) handle;
121}
#define _O_RDWR
Definition: cabinet.h:39
#define _O_ACCMODE
Definition: cabinet.h:40
#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
#define OPEN_EXISTING
Definition: compat.h:775
#define FILE_SHARE_READ
Definition: compat.h:136
#define TRUNCATE_EXISTING
Definition: disk.h:71
#define CREATE_NEW
Definition: disk.h:69
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_DELETE
Definition: nt_native.h:682

Referenced by Extract().

◆ fdi_read()

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

Definition at line 123 of file cabinet_main.c.

124{
125 HANDLE handle = (HANDLE) hf;
126 DWORD dwRead;
127
128 if (ReadFile(handle, pv, cb, &dwRead, NULL))
129 return dwRead;
130
131 return 0;
132}
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33

Referenced by Extract().

◆ fdi_seek()

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

Definition at line 151 of file cabinet_main.c.

152{
153 HANDLE handle = (HANDLE) hf;
154 return SetFilePointer(handle, dist, NULL, seektype);
155}
#define SetFilePointer
Definition: compat.h:743

Referenced by Extract().

◆ fdi_write()

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

Definition at line 134 of file cabinet_main.c.

135{
136 HANDLE handle = (HANDLE) hf;
137 DWORD dwWritten;
138
139 if (WriteFile(handle, pv, cb, &dwWritten, NULL))
140 return dwWritten;
141
142 return 0;
143}
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 Extract().

◆ file_in_list()

static BOOL file_in_list ( struct FILELIST pNode,
LPCSTR  szFilename,
struct FILELIST **  pOut 
)
static

Definition at line 166 of file cabinet_main.c.

168{
169 while (pNode)
170 {
171 if (!lstrcmpiA(pNode->FileName, szFilename))
172 {
173 if (pOut)
174 *pOut = pNode;
175
176 return TRUE;
177 }
178
179 pNode = pNode->next;
180 }
181
182 return FALSE;
183}
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4224
LPSTR FileName
Definition: files.c:546

Referenced by fdi_notify_extract().

◆ fill_file_node()

static void fill_file_node ( struct FILELIST pNode,
LPCSTR  szFilename 
)
static

Definition at line 157 of file cabinet_main.c.

158{
159 pNode->next = NULL;
160 pNode->DoExtract = FALSE;
161
162 pNode->FileName = HeapAlloc(GetProcessHeap(), 0, strlen(szFilename) + 1);
163 lstrcpyA(pNode->FileName, szFilename);
164}

Referenced by fdi_notify_extract().

◆ mem_alloc()

static void *CDECL mem_alloc ( ULONG  cb)
static

Definition at line 72 of file cabinet_main.c.

73{
74 return HeapAlloc(GetProcessHeap(), 0, cb);
75}

◆ mem_free()

static void CDECL mem_free ( void memory)
static

Definition at line 77 of file cabinet_main.c.

78{
80}
static char memory[1024 *256]
Definition: process.c:116

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( cabinet  )