ReactOS 0.4.17-dev-806-gffa4164
cabinet_main.c File Reference
#include <assert.h>
#include <stdarg.h>
#include <string.h>
#include <fcntl.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 29 of file cabinet_main.c.

Function Documentation

◆ DllGetVersion()

HRESULT WINAPI DllGetVersion ( DLLVERSIONINFO pdvi)

Definition at line 55 of file cabinet_main.c.

56{
57 WARN("hmmm... not right version number \"5.1.1106.1\"?\n");
58
59 if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) return E_INVALIDARG;
60
61 pdvi->dwMajorVersion = 5;
62 pdvi->dwMinorVersion = 1;
63 pdvi->dwBuildNumber = 1106;
64 pdvi->dwPlatformID = 1;
65
66 return S_OK;
67}
#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:121
DWORD dwBuildNumber
Definition: shlwapi.h:123
DWORD dwMinorVersion
Definition: shlwapi.h:122
DWORD cbSize
Definition: shlwapi.h:120
DWORD dwPlatformID
Definition: shlwapi.h:124

◆ Extract()

HRESULT WINAPI Extract ( SESSION dest,
LPCSTR  szCabName 
)

Definition at line 327 of file cabinet_main.c.

328{
329 HRESULT res = S_OK;
330 HFDI hfdi;
331 char *str, *end, *path = NULL, *name = NULL;
332
333 TRACE("(%p, %s)\n", dest, debugstr_a(szCabName));
334
335 hfdi = FDICreate(mem_alloc,
336 mem_free,
337 fdi_open,
338 fdi_read,
339 fdi_write,
340 fdi_close,
341 fdi_seek,
343 &dest->Error);
344
345 if (!hfdi)
346 return E_FAIL;
347
349 {
350 res = S_OK;
351 goto end;
352 }
353
354 /* split the cabinet name into path + name */
355 str = HeapAlloc(GetProcessHeap(), 0, lstrlenA(szCabName)+1);
356 if (!str)
357 {
359 goto end;
360 }
361 lstrcpyA(str, szCabName);
362
363 if ((end = strrchr(str, '\\')))
364 {
365 path = str;
366 end++;
367 name = HeapAlloc( GetProcessHeap(), 0, strlen(end) + 1 );
368 if (!name)
369 {
371 goto end;
372 }
373 strcpy( name, end );
374 *end = 0;
375 }
376 else
377 {
378 name = str;
379 path = NULL;
380 }
381
382 dest->FileSize = 0;
383
384 if (!FDICopy(hfdi, name, path, 0,
387
388end:
391 FDIDestroy(hfdi);
392 return res;
393}
static INT_PTR CDECL fdi_notify_extract(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
Definition: cabinet_main.c:184
static UINT CDECL fdi_read(INT_PTR hf, void *pv, UINT cb)
Definition: cabinet_main.c:122
static LONG CDECL fdi_seek(INT_PTR hf, LONG dist, int seektype)
Definition: cabinet_main.c:150
static int CDECL fdi_close(INT_PTR hf)
Definition: cabinet_main.c:144
static UINT CDECL fdi_write(INT_PTR hf, void *pv, UINT cb)
Definition: cabinet_main.c:133
static INT_PTR CDECL fdi_open(char *pszFile, int oflag, int pmode)
Definition: cabinet_main.c:81
#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:2420
BOOL __cdecl FDIDestroy(HFDI hfdi)
Definition: fdi.c:2820
#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:620
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP char *__cdecl strrchr(const char *, int)
Definition: string.c:3303
#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:149
const WCHAR * str
strcpy
Definition: string.h:131
#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
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210

Referenced by CabinetSetEventHandlers().

◆ fdi_close()

static int CDECL fdi_close ( INT_PTR  hf)
static

Definition at line 144 of file cabinet_main.c.

145{
146 HANDLE handle = (HANDLE) hf;
147 return CloseHandle(handle) ? 0 : -1;
148}
#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 184 of file cabinet_main.c.

185{
186 switch (fdint)
187 {
188 case fdintCOPY_FILE:
189 {
190 struct FILELIST *fileList, *node = NULL;
191 SESSION *pDestination = pfdin->pv;
192 LPSTR szFullPath, szDirectory;
193 HANDLE hFile = 0;
195
196 dwSize = lstrlenA(pDestination->Destination) +
197 lstrlenA("\\") + lstrlenA(pfdin->psz1) + 1;
198 szFullPath = HeapAlloc(GetProcessHeap(), 0, dwSize);
199
200 lstrcpyA(szFullPath, pDestination->Destination);
201 lstrcatA(szFullPath, "\\");
202 lstrcatA(szFullPath, pfdin->psz1);
203
204 /* pull out the destination directory string from the full path */
205 dwSize = strrchr(szFullPath, '\\') - szFullPath + 1;
206 szDirectory = HeapAlloc(GetProcessHeap(), 0, dwSize);
207 lstrcpynA(szDirectory, szFullPath, dwSize);
208
209 pDestination->FileSize += pfdin->cb;
210
211 if (pDestination->Operation & EXTRACT_FILLFILELIST)
212 {
213 fileList = HeapAlloc(GetProcessHeap(), 0,
214 sizeof(struct FILELIST));
215
216 fill_file_node(fileList, pfdin->psz1);
217 fileList->DoExtract = TRUE;
218 fileList->next = pDestination->FileList;
219 pDestination->FileList = fileList;
220 lstrcpyA(pDestination->CurrentFile, szFullPath);
221 pDestination->FileCount++;
222 }
223
224 if ((pDestination->Operation & EXTRACT_EXTRACTFILES) ||
225 file_in_list(pDestination->FilterList, pfdin->psz1, NULL))
226 {
227 /* find the file node */
228 file_in_list(pDestination->FileList, pfdin->psz1, &node);
229
230 if (node && !node->DoExtract)
231 {
232 HeapFree(GetProcessHeap(), 0, szFullPath);
233 HeapFree(GetProcessHeap(), 0, szDirectory);
234 return 0;
235 }
236
237 /* create the destination directory if it doesn't exist */
239 {
240 char *ptr;
241
242 for(ptr = szDirectory + strlen(pDestination->Destination)+1; *ptr; ptr++) {
243 if(*ptr == '\\') {
244 *ptr = 0;
245 CreateDirectoryA(szDirectory, NULL);
246 *ptr = '\\';
247 }
248 }
249 CreateDirectoryA(szDirectory, NULL);
250 }
251
252 hFile = CreateFileA(szFullPath, GENERIC_READ | GENERIC_WRITE, 0, NULL,
254
256 node->DoExtract = FALSE;
257 }
258
259 HeapFree(GetProcessHeap(), 0, szFullPath);
260 HeapFree(GetProcessHeap(), 0, szDirectory);
261
262 return (INT_PTR) hFile;
263 }
264
266 {
267 FILETIME ft;
268 FILETIME ftLocal;
269 HANDLE handle = (HANDLE) pfdin->hf;
270
271 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
272 return FALSE;
273
274 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
275 return FALSE;
276
277 if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
278 return FALSE;
279
281 return TRUE;
282 }
283
284 default:
285 return 0;
286 }
287}
static BOOL file_in_list(struct FILELIST *pNode, LPCSTR szFilename, struct FILELIST **pOut)
Definition: cabinet_main.c:165
static void fill_file_node(struct FILELIST *pNode, LPCSTR szFilename)
Definition: cabinet_main.c:156
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define EXTRACT_EXTRACTFILES
Definition: files.c:518
#define EXTRACT_FILLFILELIST
Definition: files.c:517
#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:933
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:244
@ 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:522
BOOL DoExtract
Definition: files.c:523
Definition: files.c:526
struct FILELIST * FilterList
Definition: files.c:535
INT Operation
Definition: files.c:531
INT FileSize
Definition: files.c:527
CHAR CurrentFile[MAX_PATH]
Definition: files.c:533
struct FILELIST * FileList
Definition: files.c:529
INT FileCount
Definition: files.c:530
CHAR Destination[MAX_PATH]
Definition: files.c:532
int32_t INT_PTR
Definition: typedefs.h:64
char * LPSTR
Definition: typedefs.h:51
Definition: dlist.c:348

Referenced by Extract().

◆ fdi_open()

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

Definition at line 81 of file cabinet_main.c.

82{
84 DWORD dwAccess = 0;
85 DWORD dwShareMode = 0;
86 DWORD dwCreateDisposition;
87
88 switch (oflag & _O_ACCMODE)
89 {
90 case _O_RDONLY:
91 dwAccess = GENERIC_READ;
92 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
93 break;
94 case _O_WRONLY:
95 dwAccess = GENERIC_WRITE;
97 break;
98 case _O_RDWR:
99 dwAccess = GENERIC_READ | GENERIC_WRITE;
101 break;
102 }
103
104 if (oflag & _O_CREAT)
105 {
106 dwCreateDisposition = OPEN_ALWAYS;
107 if (oflag & _O_EXCL) dwCreateDisposition = CREATE_NEW;
108 else if (oflag & _O_TRUNC) dwCreateDisposition = CREATE_ALWAYS;
109 }
110 else
111 {
112 dwCreateDisposition = OPEN_EXISTING;
113 if (oflag & _O_TRUNC) dwCreateDisposition = TRUNCATE_EXISTING;
114 }
115
116 handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
117 dwCreateDisposition, 0, NULL);
118
119 return (INT_PTR) handle;
120}
#define OPEN_EXISTING
Definition: compat.h:775
#define FILE_SHARE_READ
Definition: compat.h:136
#define _O_RDWR
Definition: fcntl.h:15
#define _O_ACCMODE
Definition: fcntl.h:16
#define _O_RDONLY
Definition: fcntl.h:13
#define _O_TRUNC
Definition: fcntl.h:23
#define _O_CREAT
Definition: fcntl.h:22
#define _O_EXCL
Definition: fcntl.h:24
#define _O_WRONLY
Definition: fcntl.h:14
#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 122 of file cabinet_main.c.

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

Referenced by Extract().

◆ fdi_seek()

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

Definition at line 150 of file cabinet_main.c.

151{
152 HANDLE handle = (HANDLE) hf;
153 return SetFilePointer(handle, dist, NULL, seektype);
154}
#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 133 of file cabinet_main.c.

134{
135 HANDLE handle = (HANDLE) hf;
136 DWORD dwWritten;
137
138 if (WriteFile(handle, pv, cb, &dwWritten, NULL))
139 return dwWritten;
140
141 return 0;
142}
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25

Referenced by Extract().

◆ file_in_list()

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

Definition at line 165 of file cabinet_main.c.

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

Referenced by fdi_notify_extract().

◆ fill_file_node()

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

Definition at line 156 of file cabinet_main.c.

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

Referenced by fdi_notify_extract().

◆ mem_alloc()

static void *CDECL mem_alloc ( ULONG  cb)
static

Definition at line 71 of file cabinet_main.c.

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

◆ mem_free()

static void CDECL mem_free ( void memory)
static

Definition at line 76 of file cabinet_main.c.

77{
79}
static char memory[1024 *256]
Definition: process.c:122

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( cabinet  )