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
21 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
33 //#include "winerror.h"
34 #define NO_SHLWAPI_REG
40 #include <wine/debug.h>
42 WINE_DEFAULT_DEBUG_CHANNEL(cabinet
);
45 /***********************************************************************
46 * DllGetVersion (CABINET.2)
48 * Retrieves version information of the 'CABINET.DLL'
51 * pdvi [O] pointer to version information structure.
55 * Failure: E_INVALIDARG
58 * Supposedly returns version from IE6SP1RP1
60 HRESULT WINAPI
DllGetVersion (DLLVERSIONINFO
*pdvi
)
62 WARN("hmmm... not right version number \"5.1.1106.1\"?\n");
64 if (pdvi
->cbSize
!= sizeof(DLLVERSIONINFO
)) return E_INVALIDARG
;
66 pdvi
->dwMajorVersion
= 5;
67 pdvi
->dwMinorVersion
= 1;
68 pdvi
->dwBuildNumber
= 1106;
69 pdvi
->dwPlatformID
= 1;
74 /* FDI callback functions */
76 static void * CDECL
mem_alloc(ULONG cb
)
78 return HeapAlloc(GetProcessHeap(), 0, cb
);
81 static void CDECL
mem_free(void *memory
)
83 HeapFree(GetProcessHeap(), 0, memory
);
86 static INT_PTR CDECL
fdi_open(char *pszFile
, int oflag
, int pmode
)
90 DWORD dwShareMode
= 0;
91 DWORD dwCreateDisposition
;
93 switch (oflag
& _O_ACCMODE
)
96 dwAccess
= GENERIC_READ
;
97 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
100 dwAccess
= GENERIC_WRITE
;
101 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
104 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
105 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
109 if (oflag
& _O_CREAT
)
111 dwCreateDisposition
= OPEN_ALWAYS
;
112 if (oflag
& _O_EXCL
) dwCreateDisposition
= CREATE_NEW
;
113 else if (oflag
& _O_TRUNC
) dwCreateDisposition
= CREATE_ALWAYS
;
117 dwCreateDisposition
= OPEN_EXISTING
;
118 if (oflag
& _O_TRUNC
) dwCreateDisposition
= TRUNCATE_EXISTING
;
121 handle
= CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
122 dwCreateDisposition
, 0, NULL
);
124 return (INT_PTR
) handle
;
127 static UINT CDECL
fdi_read(INT_PTR hf
, void *pv
, UINT cb
)
129 HANDLE handle
= (HANDLE
) hf
;
132 if (ReadFile(handle
, pv
, cb
, &dwRead
, NULL
))
138 static UINT CDECL
fdi_write(INT_PTR hf
, void *pv
, UINT cb
)
140 HANDLE handle
= (HANDLE
) hf
;
143 if (WriteFile(handle
, pv
, cb
, &dwWritten
, NULL
))
149 static int CDECL
fdi_close(INT_PTR hf
)
151 HANDLE handle
= (HANDLE
) hf
;
152 return CloseHandle(handle
) ? 0 : -1;
155 static LONG CDECL
fdi_seek(INT_PTR hf
, LONG dist
, int seektype
)
157 HANDLE handle
= (HANDLE
) hf
;
158 return SetFilePointer(handle
, dist
, NULL
, seektype
);
161 static void fill_file_node(struct FILELIST
*pNode
, LPCSTR szFilename
)
164 pNode
->DoExtract
= FALSE
;
166 pNode
->FileName
= HeapAlloc(GetProcessHeap(), 0, strlen(szFilename
) + 1);
167 lstrcpyA(pNode
->FileName
, szFilename
);
170 static BOOL
file_in_list(struct FILELIST
*pNode
, LPCSTR szFilename
,
171 struct FILELIST
**pOut
)
175 if (!lstrcmpiA(pNode
->FileName
, szFilename
))
189 static INT_PTR CDECL
fdi_notify_extract(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
195 struct FILELIST
*fileList
, *node
= NULL
;
196 SESSION
*pDestination
= pfdin
->pv
;
197 LPSTR szFullPath
, szDirectory
;
201 dwSize
= lstrlenA(pDestination
->Destination
) +
202 lstrlenA("\\") + lstrlenA(pfdin
->psz1
) + 1;
203 szFullPath
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
205 lstrcpyA(szFullPath
, pDestination
->Destination
);
206 lstrcatA(szFullPath
, "\\");
207 lstrcatA(szFullPath
, pfdin
->psz1
);
209 /* pull out the destination directory string from the full path */
210 dwSize
= strrchr(szFullPath
, '\\') - szFullPath
+ 1;
211 szDirectory
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
212 lstrcpynA(szDirectory
, szFullPath
, dwSize
);
214 pDestination
->FileSize
+= pfdin
->cb
;
216 if (pDestination
->Operation
& EXTRACT_FILLFILELIST
)
218 fileList
= HeapAlloc(GetProcessHeap(), 0,
219 sizeof(struct FILELIST
));
221 fill_file_node(fileList
, pfdin
->psz1
);
222 fileList
->DoExtract
= TRUE
;
223 fileList
->next
= pDestination
->FileList
;
224 pDestination
->FileList
= fileList
;
225 lstrcpyA(pDestination
->CurrentFile
, szFullPath
);
226 pDestination
->FileCount
++;
229 if ((pDestination
->Operation
& EXTRACT_EXTRACTFILES
) ||
230 file_in_list(pDestination
->FilterList
, pfdin
->psz1
, NULL
))
232 /* find the file node */
233 file_in_list(pDestination
->FileList
, pfdin
->psz1
, &node
);
235 if (node
&& !node
->DoExtract
)
237 HeapFree(GetProcessHeap(), 0, szFullPath
);
238 HeapFree(GetProcessHeap(), 0, szDirectory
);
242 /* create the destination directory if it doesn't exist */
243 if (GetFileAttributesA(szDirectory
) == INVALID_FILE_ATTRIBUTES
)
247 for(ptr
= szDirectory
+ strlen(pDestination
->Destination
)+1; *ptr
; ptr
++) {
250 CreateDirectoryA(szDirectory
, NULL
);
254 CreateDirectoryA(szDirectory
, NULL
);
257 hFile
= CreateFileA(szFullPath
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
258 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, NULL
);
260 if (hFile
== INVALID_HANDLE_VALUE
)
263 node
->DoExtract
= FALSE
;
266 HeapFree(GetProcessHeap(), 0, szFullPath
);
267 HeapFree(GetProcessHeap(), 0, szDirectory
);
269 return (INT_PTR
) hFile
;
272 case fdintCLOSE_FILE_INFO
:
276 HANDLE handle
= (HANDLE
) pfdin
->hf
;
278 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
281 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
284 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
296 /***********************************************************************
297 * Extract (CABINET.3)
299 * Extracts the contents of the cabinet file to the specified
303 * dest [I/O] Controls the operation of Extract. See NOTES.
304 * szCabName [I] Filename of the cabinet to extract.
311 * The following members of the dest struct control the operation
313 * FileSize [O] The size of all files extracted up to CurrentFile.
314 * Error [O] The error in case the extract operation fails.
315 * FileList [I] A linked list of filenames. Extract only extracts
316 * files from the cabinet that are in this list.
317 * FileCount [O] Contains the number of files in FileList on
319 * Operation [I] See Operation.
320 * Destination [I] The destination directory.
321 * CurrentFile [O] The last file extracted.
322 * FilterList [I] A linked list of files that should not be extracted.
325 * If Operation contains EXTRACT_FILLFILELIST, then FileList will be
326 * filled with all the files in the cabinet. If Operation contains
327 * EXTRACT_EXTRACTFILES, then only the files in the FileList will
328 * be extracted from the cabinet. EXTRACT_FILLFILELIST can be called
329 * by itself, but EXTRACT_EXTRACTFILES must have a valid FileList
330 * in order to succeed. If Operation contains both EXTRACT_FILLFILELIST
331 * and EXTRACT_EXTRACTFILES, then all the files in the cabinet
334 HRESULT WINAPI
Extract(SESSION
*dest
, LPCSTR szCabName
)
338 char *str
, *end
, *path
= NULL
, *name
= NULL
;
340 TRACE("(%p, %s)\n", dest
, szCabName
);
342 hfdi
= FDICreate(mem_alloc
,
355 if (GetFileAttributesA(dest
->Destination
) == INVALID_FILE_ATTRIBUTES
)
361 /* split the cabinet name into path + name */
362 str
= HeapAlloc(GetProcessHeap(), 0, lstrlenA(szCabName
)+1);
368 lstrcpyA(str
, szCabName
);
370 if ((end
= strrchr(str
, '\\')))
374 name
= HeapAlloc( GetProcessHeap(), 0, strlen(end
) + 1 );
391 if (!FDICopy(hfdi
, name
, path
, 0,
392 fdi_notify_extract
, NULL
, dest
))
393 res
= HRESULT_FROM_WIN32(GetLastError());
396 HeapFree(GetProcessHeap(), 0, path
);
397 HeapFree(GetProcessHeap(), 0, name
);