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
);
40 /* the following defintions are copied from msvcrt/fcntl.h */
45 #define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR)
48 /***********************************************************************
49 * DllGetVersion (CABINET.2)
51 * Retrieves version information of the 'CABINET.DLL'
54 * pdvi [O] pointer to version information structure.
58 * Failure: E_INVALIDARG
61 * Supposedly returns version from IE6SP1RP1
63 HRESULT WINAPI
DllGetVersion (DLLVERSIONINFO
*pdvi
)
65 WARN("hmmm... not right version number \"5.1.1106.1\"?\n");
67 if (pdvi
->cbSize
!= sizeof(DLLVERSIONINFO
)) return E_INVALIDARG
;
69 pdvi
->dwMajorVersion
= 5;
70 pdvi
->dwMinorVersion
= 1;
71 pdvi
->dwBuildNumber
= 1106;
72 pdvi
->dwPlatformID
= 1;
77 /* FDI callback functions */
79 static void *mem_alloc(ULONG cb
)
81 return HeapAlloc(GetProcessHeap(), 0, cb
);
84 static void mem_free(void *memory
)
86 HeapFree(GetProcessHeap(), 0, memory
);
89 static INT_PTR
fdi_open(char *pszFile
, int oflag
, int pmode
)
93 DWORD dwShareMode
= 0;
94 DWORD dwCreateDisposition
= OPEN_EXISTING
;
96 switch (oflag
& _O_ACCMODE
)
99 dwAccess
= GENERIC_READ
;
100 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
103 dwAccess
= GENERIC_WRITE
;
104 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
107 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
108 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
112 if (GetFileAttributesA(pszFile
) != INVALID_FILE_ATTRIBUTES
)
113 dwCreateDisposition
= OPEN_EXISTING
;
115 dwCreateDisposition
= CREATE_NEW
;
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 ExtractFileList
*pNode
, LPSTR szFilename
)
160 pNode
->unknown
= TRUE
;
162 pNode
->filename
= HeapAlloc(GetProcessHeap(), 0, strlen(szFilename
) + 1);
163 lstrcpyA(pNode
->filename
, szFilename
);
166 static BOOL
file_in_list(struct ExtractFileList
*pNode
, LPSTR szFilename
)
170 if (!lstrcmpiA(pNode
->filename
, szFilename
))
179 static INT_PTR
fdi_notify_extract(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
185 struct ExtractFileList
**fileList
;
186 EXTRACTdest
*pDestination
= pfdin
->pv
;
187 LPSTR szFullPath
, szDirectory
;
191 dwSize
= lstrlenA(pDestination
->directory
) +
192 lstrlenA("\\") + lstrlenA(pfdin
->psz1
) + 1;
193 szFullPath
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
195 lstrcpyA(szFullPath
, pDestination
->directory
);
196 lstrcatA(szFullPath
, "\\");
197 lstrcatA(szFullPath
, pfdin
->psz1
);
199 /* pull out the destination directory string from the full path */
200 dwSize
= strrchr(szFullPath
, '\\') - szFullPath
+ 1;
201 szDirectory
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
202 lstrcpynA(szDirectory
, szFullPath
, dwSize
);
204 if (pDestination
->flags
& EXTRACT_FILLFILELIST
)
206 fileList
= &pDestination
->filelist
;
209 fileList
= &((*fileList
)->next
);
211 *fileList
= HeapAlloc(GetProcessHeap(), 0,
212 sizeof(struct ExtractFileList
));
214 fill_file_node(*fileList
, pfdin
->psz1
);
215 lstrcpyA(pDestination
->lastfile
, szFullPath
);
216 pDestination
->filecount
++;
219 if (pDestination
->flags
& EXTRACT_EXTRACTFILES
)
221 /* skip this file it it's not in the file list */
222 if (!file_in_list(pDestination
->filelist
, pfdin
->psz1
))
225 /* create the destination directory if it doesn't exist */
226 if (GetFileAttributesA(szDirectory
) == INVALID_FILE_ATTRIBUTES
)
227 CreateDirectoryA(szDirectory
, NULL
);
229 hFile
= CreateFileA(szFullPath
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
230 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, NULL
);
232 if (hFile
== INVALID_HANDLE_VALUE
)
236 HeapFree(GetProcessHeap(), 0, szFullPath
);
237 HeapFree(GetProcessHeap(), 0, szDirectory
);
239 return (INT_PTR
) hFile
;
242 case fdintCLOSE_FILE_INFO
:
246 HANDLE handle
= (HANDLE
) pfdin
->hf
;
248 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
251 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
254 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
266 /***********************************************************************
267 * Extract (CABINET.3)
269 * Extracts the contents of the cabinet file to the specified
273 * dest [I/O] Controls the operation of Extract. See NOTES.
274 * szCabName [I] Filename of the cabinet to extract.
281 * The following members of the dest struct control the operation
283 * filelist [I] A linked list of filenames. Extract only extracts
284 * files from the cabinet that are in this list.
285 * filecount [O] Contains the number of files in filelist on
287 * flags [I] See Operation.
288 * directory [I] The destination directory.
289 * lastfile [O] The last file extracted.
292 * If flags contains EXTRACT_FILLFILELIST, then filelist will be
293 * filled with all the files in the cabinet. If flags contains
294 * EXTRACT_EXTRACTFILES, then only the files in the filelist will
295 * be extracted from the cabinet. EXTRACT_FILLFILELIST can be called
296 * by itself, but EXTRACT_EXTRACTFILES must have a valid filelist
297 * in order to succeed. If flags contains both EXTRACT_FILLFILELIST
298 * and EXTRACT_EXTRACTFILES, then all the files in the cabinet
301 HRESULT WINAPI
Extract(EXTRACTdest
*dest
, LPCSTR szCabName
)
307 TRACE("(%p, %s)\n", dest
, szCabName
);
309 hfdi
= FDICreate(mem_alloc
,
322 if (GetFileAttributesA(dest
->directory
) == INVALID_FILE_ATTRIBUTES
)
325 if (!FDICopy(hfdi
, (LPSTR
)szCabName
, "", 0,
326 fdi_notify_extract
, NULL
, dest
))