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
23 #define NO_SHLWAPI_REG
27 /***********************************************************************
28 * DllGetVersion (CABINET.2)
30 * Retrieves version information of the 'CABINET.DLL'
33 * pdvi [O] pointer to version information structure.
37 * Failure: E_INVALIDARG
40 * Supposedly returns version from IE6SP1RP1
42 HRESULT WINAPI
DllGetVersion (DLLVERSIONINFO
*pdvi
)
44 WARN("hmmm... not right version number \"5.1.1106.1\"?\n");
46 if (pdvi
->cbSize
!= sizeof(DLLVERSIONINFO
)) return E_INVALIDARG
;
48 pdvi
->dwMajorVersion
= 5;
49 pdvi
->dwMinorVersion
= 1;
50 pdvi
->dwBuildNumber
= 1106;
51 pdvi
->dwPlatformID
= 1;
56 /* FDI callback functions */
58 static void * CDECL
mem_alloc(ULONG cb
)
60 return HeapAlloc(GetProcessHeap(), 0, cb
);
63 static void CDECL
mem_free(void *memory
)
65 HeapFree(GetProcessHeap(), 0, memory
);
68 static INT_PTR CDECL
fdi_open(char *pszFile
, int oflag
, int pmode
)
72 DWORD dwShareMode
= 0;
73 DWORD dwCreateDisposition
;
75 switch (oflag
& _O_ACCMODE
)
78 dwAccess
= GENERIC_READ
;
79 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
82 dwAccess
= GENERIC_WRITE
;
83 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
86 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
87 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
93 dwCreateDisposition
= OPEN_ALWAYS
;
94 if (oflag
& _O_EXCL
) dwCreateDisposition
= CREATE_NEW
;
95 else if (oflag
& _O_TRUNC
) dwCreateDisposition
= CREATE_ALWAYS
;
99 dwCreateDisposition
= OPEN_EXISTING
;
100 if (oflag
& _O_TRUNC
) dwCreateDisposition
= TRUNCATE_EXISTING
;
103 handle
= CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
104 dwCreateDisposition
, 0, NULL
);
106 return (INT_PTR
) handle
;
109 static UINT CDECL
fdi_read(INT_PTR hf
, void *pv
, UINT cb
)
111 HANDLE handle
= (HANDLE
) hf
;
114 if (ReadFile(handle
, pv
, cb
, &dwRead
, NULL
))
120 static UINT CDECL
fdi_write(INT_PTR hf
, void *pv
, UINT cb
)
122 HANDLE handle
= (HANDLE
) hf
;
125 if (WriteFile(handle
, pv
, cb
, &dwWritten
, NULL
))
131 static int CDECL
fdi_close(INT_PTR hf
)
133 HANDLE handle
= (HANDLE
) hf
;
134 return CloseHandle(handle
) ? 0 : -1;
137 static LONG CDECL
fdi_seek(INT_PTR hf
, LONG dist
, int seektype
)
139 HANDLE handle
= (HANDLE
) hf
;
140 return SetFilePointer(handle
, dist
, NULL
, seektype
);
143 static void fill_file_node(struct FILELIST
*pNode
, LPCSTR szFilename
)
146 pNode
->DoExtract
= FALSE
;
148 pNode
->FileName
= HeapAlloc(GetProcessHeap(), 0, strlen(szFilename
) + 1);
149 lstrcpyA(pNode
->FileName
, szFilename
);
152 static BOOL
file_in_list(struct FILELIST
*pNode
, LPCSTR szFilename
,
153 struct FILELIST
**pOut
)
157 if (!lstrcmpiA(pNode
->FileName
, szFilename
))
171 static INT_PTR CDECL
fdi_notify_extract(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
177 struct FILELIST
*fileList
, *node
= NULL
;
178 SESSION
*pDestination
= pfdin
->pv
;
179 LPSTR szFullPath
, szDirectory
;
183 dwSize
= lstrlenA(pDestination
->Destination
) +
184 lstrlenA("\\") + lstrlenA(pfdin
->psz1
) + 1;
185 szFullPath
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
187 lstrcpyA(szFullPath
, pDestination
->Destination
);
188 lstrcatA(szFullPath
, "\\");
189 lstrcatA(szFullPath
, pfdin
->psz1
);
191 /* pull out the destination directory string from the full path */
192 dwSize
= strrchr(szFullPath
, '\\') - szFullPath
+ 1;
193 szDirectory
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
194 lstrcpynA(szDirectory
, szFullPath
, dwSize
);
196 pDestination
->FileSize
+= pfdin
->cb
;
198 if (pDestination
->Operation
& EXTRACT_FILLFILELIST
)
200 fileList
= HeapAlloc(GetProcessHeap(), 0,
201 sizeof(struct FILELIST
));
203 fill_file_node(fileList
, pfdin
->psz1
);
204 fileList
->DoExtract
= TRUE
;
205 fileList
->next
= pDestination
->FileList
;
206 pDestination
->FileList
= fileList
;
207 lstrcpyA(pDestination
->CurrentFile
, szFullPath
);
208 pDestination
->FileCount
++;
211 if ((pDestination
->Operation
& EXTRACT_EXTRACTFILES
) ||
212 file_in_list(pDestination
->FilterList
, pfdin
->psz1
, NULL
))
214 /* find the file node */
215 file_in_list(pDestination
->FileList
, pfdin
->psz1
, &node
);
217 if (node
&& !node
->DoExtract
)
219 HeapFree(GetProcessHeap(), 0, szFullPath
);
220 HeapFree(GetProcessHeap(), 0, szDirectory
);
224 /* create the destination directory if it doesn't exist */
225 if (GetFileAttributesA(szDirectory
) == INVALID_FILE_ATTRIBUTES
)
229 for(ptr
= szDirectory
+ strlen(pDestination
->Destination
)+1; *ptr
; ptr
++) {
232 CreateDirectoryA(szDirectory
, NULL
);
236 CreateDirectoryA(szDirectory
, NULL
);
239 hFile
= CreateFileA(szFullPath
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
240 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, NULL
);
242 if (hFile
== INVALID_HANDLE_VALUE
)
245 node
->DoExtract
= FALSE
;
248 HeapFree(GetProcessHeap(), 0, szFullPath
);
249 HeapFree(GetProcessHeap(), 0, szDirectory
);
251 return (INT_PTR
) hFile
;
254 case fdintCLOSE_FILE_INFO
:
258 HANDLE handle
= (HANDLE
) pfdin
->hf
;
260 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
263 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
266 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
278 /***********************************************************************
279 * Extract (CABINET.3)
281 * Extracts the contents of the cabinet file to the specified
285 * dest [I/O] Controls the operation of Extract. See NOTES.
286 * szCabName [I] Filename of the cabinet to extract.
293 * The following members of the dest struct control the operation
295 * FileSize [O] The size of all files extracted up to CurrentFile.
296 * Error [O] The error in case the extract operation fails.
297 * FileList [I] A linked list of filenames. Extract only extracts
298 * files from the cabinet that are in this list.
299 * FileCount [O] Contains the number of files in FileList on
301 * Operation [I] See Operation.
302 * Destination [I] The destination directory.
303 * CurrentFile [O] The last file extracted.
304 * FilterList [I] A linked list of files that should not be extracted.
307 * If Operation contains EXTRACT_FILLFILELIST, then FileList will be
308 * filled with all the files in the cabinet. If Operation contains
309 * EXTRACT_EXTRACTFILES, then only the files in the FileList will
310 * be extracted from the cabinet. EXTRACT_FILLFILELIST can be called
311 * by itself, but EXTRACT_EXTRACTFILES must have a valid FileList
312 * in order to succeed. If Operation contains both EXTRACT_FILLFILELIST
313 * and EXTRACT_EXTRACTFILES, then all the files in the cabinet
316 HRESULT WINAPI
Extract(SESSION
*dest
, LPCSTR szCabName
)
320 char *str
, *end
, *path
= NULL
, *name
= NULL
;
322 TRACE("(%p, %s)\n", dest
, szCabName
);
324 hfdi
= FDICreate(mem_alloc
,
337 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
);
352 if ((end
= strrchr(str
, '\\')))
356 name
= HeapAlloc( GetProcessHeap(), 0, strlen(end
) + 1 );
373 if (!FDICopy(hfdi
, name
, path
, 0,
374 fdi_notify_extract
, NULL
, dest
))
375 res
= HRESULT_FROM_WIN32(GetLastError());
378 HeapFree(GetProcessHeap(), 0, path
);
379 HeapFree(GetProcessHeap(), 0, name
);