4 * Copyright 2002 Patrik Stridvall
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #define NO_SHLWAPI_REG
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(cabinet
);
41 /***********************************************************************
42 * DllGetVersion (CABINET.2)
44 * Retrieves version information of the 'CABINET.DLL'
47 * pdvi [O] pointer to version information structure.
51 * Failure: E_INVALIDARG
54 * Supposedly returns version from IE6SP1RP1
56 HRESULT WINAPI
DllGetVersion (DLLVERSIONINFO
*pdvi
)
58 WARN("hmmm... not right version number \"5.1.1106.1\"?\n");
60 if (pdvi
->cbSize
!= sizeof(DLLVERSIONINFO
)) return E_INVALIDARG
;
62 pdvi
->dwMajorVersion
= 5;
63 pdvi
->dwMinorVersion
= 1;
64 pdvi
->dwBuildNumber
= 1106;
65 pdvi
->dwPlatformID
= 1;
70 /* FDI callback functions */
72 static void *mem_alloc(ULONG cb
)
74 return HeapAlloc(GetProcessHeap(), 0, cb
);
77 static void mem_free(void *memory
)
79 HeapFree(GetProcessHeap(), 0, memory
);
82 static INT_PTR
fdi_open(char *pszFile
, int oflag
, int pmode
)
86 DWORD dwShareMode
= 0;
87 DWORD dwCreateDisposition
;
89 switch (oflag
& _O_ACCMODE
)
92 dwAccess
= GENERIC_READ
;
93 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
96 dwAccess
= GENERIC_WRITE
;
97 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
100 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
101 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
105 if (oflag
& _O_CREAT
)
107 dwCreateDisposition
= OPEN_ALWAYS
;
108 if (oflag
& _O_EXCL
) dwCreateDisposition
= CREATE_NEW
;
109 else if (oflag
& _O_TRUNC
) dwCreateDisposition
= CREATE_ALWAYS
;
113 dwCreateDisposition
= OPEN_EXISTING
;
114 if (oflag
& _O_TRUNC
) dwCreateDisposition
= TRUNCATE_EXISTING
;
117 handle
= CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
118 dwCreateDisposition
, 0, NULL
);
120 return (INT_PTR
) handle
;
123 static UINT
fdi_read(INT_PTR hf
, void *pv
, UINT cb
)
125 HANDLE handle
= (HANDLE
) hf
;
128 if (ReadFile(handle
, pv
, cb
, &dwRead
, NULL
))
134 static UINT
fdi_write(INT_PTR hf
, void *pv
, UINT cb
)
136 HANDLE handle
= (HANDLE
) hf
;
139 if (WriteFile(handle
, pv
, cb
, &dwWritten
, NULL
))
145 static int fdi_close(INT_PTR hf
)
147 HANDLE handle
= (HANDLE
) hf
;
148 return CloseHandle(handle
) ? 0 : -1;
151 static long fdi_seek(INT_PTR hf
, long dist
, int seektype
)
153 HANDLE handle
= (HANDLE
) hf
;
154 return SetFilePointer(handle
, dist
, NULL
, seektype
);
157 static void fill_file_node(struct FILELIST
*pNode
, LPCSTR szFilename
)
160 pNode
->DoExtract
= FALSE
;
162 pNode
->FileName
= HeapAlloc(GetProcessHeap(), 0, strlen(szFilename
) + 1);
163 lstrcpyA(pNode
->FileName
, szFilename
);
166 static BOOL
file_in_list(struct FILELIST
*pNode
, LPCSTR szFilename
,
167 struct FILELIST
**pOut
)
171 if (!lstrcmpiA(pNode
->FileName
, szFilename
))
185 static INT_PTR
fdi_notify_extract(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
191 struct FILELIST
*fileList
, *node
= NULL
;
192 SESSION
*pDestination
= pfdin
->pv
;
193 LPSTR szFullPath
, szDirectory
;
197 dwSize
= lstrlenA(pDestination
->Destination
) +
198 lstrlenA("\\") + lstrlenA(pfdin
->psz1
) + 1;
199 szFullPath
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
201 lstrcpyA(szFullPath
, pDestination
->Destination
);
202 lstrcatA(szFullPath
, "\\");
203 lstrcatA(szFullPath
, pfdin
->psz1
);
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
);
210 pDestination
->FileSize
+= pfdin
->cb
;
212 if (pDestination
->Operation
& EXTRACT_FILLFILELIST
)
214 fileList
= HeapAlloc(GetProcessHeap(), 0,
215 sizeof(struct FILELIST
));
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
++;
225 if ((pDestination
->Operation
& EXTRACT_EXTRACTFILES
) ||
226 file_in_list(pDestination
->FilterList
, pfdin
->psz1
, NULL
))
228 /* find the file node */
229 file_in_list(pDestination
->FileList
, pfdin
->psz1
, &node
);
231 if (node
&& !node
->DoExtract
)
233 HeapFree(GetProcessHeap(), 0, szFullPath
);
234 HeapFree(GetProcessHeap(), 0, szDirectory
);
238 /* create the destination directory if it doesn't exist */
239 if (GetFileAttributesA(szDirectory
) == INVALID_FILE_ATTRIBUTES
)
240 CreateDirectoryA(szDirectory
, NULL
);
242 hFile
= CreateFileA(szFullPath
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
243 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, NULL
);
245 if (hFile
== INVALID_HANDLE_VALUE
)
248 node
->DoExtract
= FALSE
;
251 HeapFree(GetProcessHeap(), 0, szFullPath
);
252 HeapFree(GetProcessHeap(), 0, szDirectory
);
254 return (INT_PTR
) hFile
;
257 case fdintCLOSE_FILE_INFO
:
261 HANDLE handle
= (HANDLE
) pfdin
->hf
;
263 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
266 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
269 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
281 /***********************************************************************
282 * Extract (CABINET.3)
284 * Extracts the contents of the cabinet file to the specified
288 * dest [I/O] Controls the operation of Extract. See NOTES.
289 * szCabName [I] Filename of the cabinet to extract.
296 * The following members of the dest struct control the operation
298 * FileSize [O] The size of all files extracted up to CurrentFile.
299 * Error [O] The error in case the extract operation fails.
300 * FileList [I] A linked list of filenames. Extract only extracts
301 * files from the cabinet that are in this list.
302 * FileCount [O] Contains the number of files in FileList on
304 * Operation [I] See Operation.
305 * Destination [I] The destination directory.
306 * CurrentFile [O] The last file extracted.
307 * FilterList [I] A linked list of files that should not be extracted.
310 * If Operation contains EXTRACT_FILLFILELIST, then FileList will be
311 * filled with all the files in the cabinet. If Operation contains
312 * EXTRACT_EXTRACTFILES, then only the files in the FileList will
313 * be extracted from the cabinet. EXTRACT_FILLFILELIST can be called
314 * by itself, but EXTRACT_EXTRACTFILES must have a valid FileList
315 * in order to succeed. If Operation contains both EXTRACT_FILLFILELIST
316 * and EXTRACT_EXTRACTFILES, then all the files in the cabinet
319 HRESULT WINAPI
Extract(SESSION
*dest
, LPCSTR szCabName
)
323 char *str
, *path
, *name
;
325 TRACE("(%p, %s)\n", dest
, szCabName
);
327 hfdi
= FDICreate(mem_alloc
,
340 if (GetFileAttributesA(dest
->Destination
) == INVALID_FILE_ATTRIBUTES
)
343 /* split the cabinet name into path + name */
344 str
= HeapAlloc(GetProcessHeap(), 0, lstrlenA(szCabName
)+1);
350 lstrcpyA(str
, szCabName
);
353 name
= strrchr(path
, '\\');
364 if (!FDICopy(hfdi
, name
, path
, 0,
365 fdi_notify_extract
, NULL
, dest
))
366 res
= HRESULT_FROM_WIN32(GetLastError());
368 HeapFree(GetProcessHeap(), 0, str
);