2002-12-19 22:16:56 +01:00
|
|
|
/*
|
|
|
|
* cabinet.dll main
|
|
|
|
*
|
|
|
|
* Copyright 2002 Patrik Stridvall
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-12-19 22:16:56 +01:00
|
|
|
*/
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2002-12-19 22:16:56 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2002-12-19 22:16:56 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#define NO_SHLWAPI_REG
|
|
|
|
#include "shlwapi.h"
|
|
|
|
#undef NO_SHLWAPI_REG
|
|
|
|
|
|
|
|
#include "cabinet.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(cabinet);
|
|
|
|
|
2006-01-10 12:13:07 +01:00
|
|
|
|
2002-12-19 22:16:56 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DllGetVersion (CABINET.2)
|
|
|
|
*
|
|
|
|
* Retrieves version information of the 'CABINET.DLL'
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pdvi [O] pointer to version information structure.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: E_INVALIDARG
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Supposedly returns version from IE6SP1RP1
|
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
|
2002-12-19 22:16:56 +01:00
|
|
|
{
|
|
|
|
WARN("hmmm... not right version number \"5.1.1106.1\"?\n");
|
|
|
|
|
|
|
|
if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) return E_INVALIDARG;
|
|
|
|
|
|
|
|
pdvi->dwMajorVersion = 5;
|
|
|
|
pdvi->dwMinorVersion = 1;
|
|
|
|
pdvi->dwBuildNumber = 1106;
|
|
|
|
pdvi->dwPlatformID = 1;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-01-10 12:13:07 +01:00
|
|
|
/* FDI callback functions */
|
|
|
|
|
2009-01-05 12:39:02 +01:00
|
|
|
static void * CDECL mem_alloc(ULONG cb)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, cb);
|
|
|
|
}
|
|
|
|
|
2009-01-05 12:39:02 +01:00
|
|
|
static void CDECL mem_free(void *memory)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, memory);
|
|
|
|
}
|
|
|
|
|
2009-01-05 12:39:02 +01:00
|
|
|
static INT_PTR CDECL fdi_open(char *pszFile, int oflag, int pmode)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
DWORD dwAccess = 0;
|
|
|
|
DWORD dwShareMode = 0;
|
2007-08-22 11:55:01 +02:00
|
|
|
DWORD dwCreateDisposition;
|
2006-01-10 12:13:07 +01:00
|
|
|
|
|
|
|
switch (oflag & _O_ACCMODE)
|
|
|
|
{
|
|
|
|
case _O_RDONLY:
|
|
|
|
dwAccess = GENERIC_READ;
|
|
|
|
dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
|
|
|
|
break;
|
|
|
|
case _O_WRONLY:
|
|
|
|
dwAccess = GENERIC_WRITE;
|
|
|
|
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
|
|
|
break;
|
|
|
|
case _O_RDWR:
|
|
|
|
dwAccess = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-08-22 11:55:01 +02:00
|
|
|
if (oflag & _O_CREAT)
|
|
|
|
{
|
|
|
|
dwCreateDisposition = OPEN_ALWAYS;
|
|
|
|
if (oflag & _O_EXCL) dwCreateDisposition = CREATE_NEW;
|
|
|
|
else if (oflag & _O_TRUNC) dwCreateDisposition = CREATE_ALWAYS;
|
|
|
|
}
|
2006-01-10 12:13:07 +01:00
|
|
|
else
|
2007-08-22 11:55:01 +02:00
|
|
|
{
|
|
|
|
dwCreateDisposition = OPEN_EXISTING;
|
|
|
|
if (oflag & _O_TRUNC) dwCreateDisposition = TRUNCATE_EXISTING;
|
|
|
|
}
|
2006-01-10 12:13:07 +01:00
|
|
|
|
|
|
|
handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
|
|
|
|
dwCreateDisposition, 0, NULL);
|
|
|
|
|
|
|
|
return (INT_PTR) handle;
|
|
|
|
}
|
|
|
|
|
2009-01-05 12:39:02 +01:00
|
|
|
static UINT CDECL fdi_read(INT_PTR hf, void *pv, UINT cb)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE) hf;
|
|
|
|
DWORD dwRead;
|
|
|
|
|
|
|
|
if (ReadFile(handle, pv, cb, &dwRead, NULL))
|
|
|
|
return dwRead;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-05 12:39:02 +01:00
|
|
|
static UINT CDECL fdi_write(INT_PTR hf, void *pv, UINT cb)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE) hf;
|
|
|
|
DWORD dwWritten;
|
|
|
|
|
|
|
|
if (WriteFile(handle, pv, cb, &dwWritten, NULL))
|
|
|
|
return dwWritten;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-05 12:39:02 +01:00
|
|
|
static int CDECL fdi_close(INT_PTR hf)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE) hf;
|
|
|
|
return CloseHandle(handle) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2009-01-13 23:31:50 +01:00
|
|
|
static LONG CDECL fdi_seek(INT_PTR hf, LONG dist, int seektype)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE) hf;
|
|
|
|
return SetFilePointer(handle, dist, NULL, seektype);
|
|
|
|
}
|
|
|
|
|
2007-08-23 02:35:53 +02:00
|
|
|
static void fill_file_node(struct FILELIST *pNode, LPCSTR szFilename)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
pNode->next = NULL;
|
2007-08-27 03:15:41 +02:00
|
|
|
pNode->DoExtract = FALSE;
|
2006-01-10 12:13:07 +01:00
|
|
|
|
2007-08-23 02:35:53 +02:00
|
|
|
pNode->FileName = HeapAlloc(GetProcessHeap(), 0, strlen(szFilename) + 1);
|
|
|
|
lstrcpyA(pNode->FileName, szFilename);
|
2006-01-10 12:13:07 +01:00
|
|
|
}
|
|
|
|
|
2007-08-23 23:42:27 +02:00
|
|
|
static BOOL file_in_list(struct FILELIST *pNode, LPCSTR szFilename,
|
|
|
|
struct FILELIST **pOut)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
while (pNode)
|
|
|
|
{
|
2007-08-23 02:35:53 +02:00
|
|
|
if (!lstrcmpiA(pNode->FileName, szFilename))
|
2007-08-23 23:42:27 +02:00
|
|
|
{
|
|
|
|
if (pOut)
|
|
|
|
*pOut = pNode;
|
|
|
|
|
2006-01-10 12:13:07 +01:00
|
|
|
return TRUE;
|
2007-08-23 23:42:27 +02:00
|
|
|
}
|
2006-01-10 12:13:07 +01:00
|
|
|
|
|
|
|
pNode = pNode->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-05 12:39:02 +01:00
|
|
|
static INT_PTR CDECL fdi_notify_extract(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
|
|
|
switch (fdint)
|
|
|
|
{
|
|
|
|
case fdintCOPY_FILE:
|
|
|
|
{
|
2007-08-27 03:15:41 +02:00
|
|
|
struct FILELIST *fileList, *node = NULL;
|
2007-08-23 02:35:53 +02:00
|
|
|
SESSION *pDestination = pfdin->pv;
|
2006-01-10 12:13:07 +01:00
|
|
|
LPSTR szFullPath, szDirectory;
|
|
|
|
HANDLE hFile = 0;
|
|
|
|
DWORD dwSize;
|
|
|
|
|
2007-08-23 02:35:53 +02:00
|
|
|
dwSize = lstrlenA(pDestination->Destination) +
|
2006-01-10 12:13:07 +01:00
|
|
|
lstrlenA("\\") + lstrlenA(pfdin->psz1) + 1;
|
|
|
|
szFullPath = HeapAlloc(GetProcessHeap(), 0, dwSize);
|
|
|
|
|
2007-08-23 02:35:53 +02:00
|
|
|
lstrcpyA(szFullPath, pDestination->Destination);
|
2006-01-10 12:13:07 +01:00
|
|
|
lstrcatA(szFullPath, "\\");
|
|
|
|
lstrcatA(szFullPath, pfdin->psz1);
|
|
|
|
|
|
|
|
/* pull out the destination directory string from the full path */
|
|
|
|
dwSize = strrchr(szFullPath, '\\') - szFullPath + 1;
|
|
|
|
szDirectory = HeapAlloc(GetProcessHeap(), 0, dwSize);
|
|
|
|
lstrcpynA(szDirectory, szFullPath, dwSize);
|
|
|
|
|
2007-08-23 23:42:27 +02:00
|
|
|
pDestination->FileSize += pfdin->cb;
|
|
|
|
|
2007-08-23 02:35:53 +02:00
|
|
|
if (pDestination->Operation & EXTRACT_FILLFILELIST)
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
2007-08-23 23:42:27 +02:00
|
|
|
fileList = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
sizeof(struct FILELIST));
|
2006-01-10 12:13:07 +01:00
|
|
|
|
2007-08-23 23:42:27 +02:00
|
|
|
fill_file_node(fileList, pfdin->psz1);
|
2007-08-27 03:15:41 +02:00
|
|
|
fileList->DoExtract = TRUE;
|
2007-08-23 23:42:27 +02:00
|
|
|
fileList->next = pDestination->FileList;
|
|
|
|
pDestination->FileList = fileList;
|
2007-08-23 02:35:53 +02:00
|
|
|
lstrcpyA(pDestination->CurrentFile, szFullPath);
|
|
|
|
pDestination->FileCount++;
|
2006-01-10 12:13:07 +01:00
|
|
|
}
|
|
|
|
|
2007-08-23 02:35:53 +02:00
|
|
|
if ((pDestination->Operation & EXTRACT_EXTRACTFILES) ||
|
2007-08-23 23:42:27 +02:00
|
|
|
file_in_list(pDestination->FilterList, pfdin->psz1, NULL))
|
2006-01-10 12:13:07 +01:00
|
|
|
{
|
2007-08-27 03:15:41 +02:00
|
|
|
/* find the file node */
|
|
|
|
file_in_list(pDestination->FileList, pfdin->psz1, &node);
|
|
|
|
|
|
|
|
if (node && !node->DoExtract)
|
2007-12-31 00:24:26 +01:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, szFullPath);
|
|
|
|
HeapFree(GetProcessHeap(), 0, szDirectory);
|
2006-01-10 12:13:07 +01:00
|
|
|
return 0;
|
2007-12-31 00:24:26 +01:00
|
|
|
}
|
2006-01-10 12:13:07 +01:00
|
|
|
|
|
|
|
/* create the destination directory if it doesn't exist */
|
|
|
|
if (GetFileAttributesA(szDirectory) == INVALID_FILE_ATTRIBUTES)
|
2008-12-29 14:50:26 +01:00
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
for(ptr = szDirectory + strlen(pDestination->Destination)+1; *ptr; ptr++) {
|
|
|
|
if(*ptr == '\\') {
|
|
|
|
*ptr = 0;
|
|
|
|
CreateDirectoryA(szDirectory, NULL);
|
|
|
|
*ptr = '\\';
|
|
|
|
}
|
|
|
|
}
|
2006-01-10 12:13:07 +01:00
|
|
|
CreateDirectoryA(szDirectory, NULL);
|
2008-12-29 14:50:26 +01:00
|
|
|
}
|
2006-01-10 12:13:07 +01:00
|
|
|
|
|
|
|
hFile = CreateFileA(szFullPath, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
2017-02-04 13:24:49 +01:00
|
|
|
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
2006-01-10 12:13:07 +01:00
|
|
|
|
2017-02-04 13:24:50 +01:00
|
|
|
if (hFile != INVALID_HANDLE_VALUE && node)
|
2007-08-27 03:15:41 +02:00
|
|
|
node->DoExtract = FALSE;
|
2006-01-10 12:13:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, szFullPath);
|
|
|
|
HeapFree(GetProcessHeap(), 0, szDirectory);
|
|
|
|
|
|
|
|
return (INT_PTR) hFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
case fdintCLOSE_FILE_INFO:
|
|
|
|
{
|
|
|
|
FILETIME ft;
|
|
|
|
FILETIME ftLocal;
|
|
|
|
HANDLE handle = (HANDLE) pfdin->hf;
|
|
|
|
|
|
|
|
if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!LocalFileTimeToFileTime(&ft, &ftLocal))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
CloseHandle(handle);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-19 22:16:56 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* Extract (CABINET.3)
|
|
|
|
*
|
2006-01-09 20:24:21 +01:00
|
|
|
* Extracts the contents of the cabinet file to the specified
|
|
|
|
* destination.
|
2002-12-19 22:16:56 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2006-01-09 20:24:21 +01:00
|
|
|
* dest [I/O] Controls the operation of Extract. See NOTES.
|
2006-01-09 20:23:26 +01:00
|
|
|
* szCabName [I] Filename of the cabinet to extract.
|
2002-12-19 22:16:56 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2006-01-09 20:24:21 +01:00
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: E_FAIL.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The following members of the dest struct control the operation
|
|
|
|
* of Extract:
|
2007-08-23 02:35:53 +02:00
|
|
|
* FileSize [O] The size of all files extracted up to CurrentFile.
|
|
|
|
* Error [O] The error in case the extract operation fails.
|
|
|
|
* FileList [I] A linked list of filenames. Extract only extracts
|
|
|
|
* files from the cabinet that are in this list.
|
|
|
|
* FileCount [O] Contains the number of files in FileList on
|
|
|
|
* completion.
|
|
|
|
* Operation [I] See Operation.
|
|
|
|
* Destination [I] The destination directory.
|
|
|
|
* CurrentFile [O] The last file extracted.
|
|
|
|
* FilterList [I] A linked list of files that should not be extracted.
|
2006-01-09 20:24:21 +01:00
|
|
|
*
|
|
|
|
* Operation
|
2007-08-23 02:35:53 +02:00
|
|
|
* If Operation contains EXTRACT_FILLFILELIST, then FileList will be
|
|
|
|
* filled with all the files in the cabinet. If Operation contains
|
|
|
|
* EXTRACT_EXTRACTFILES, then only the files in the FileList will
|
2006-01-09 20:24:21 +01:00
|
|
|
* be extracted from the cabinet. EXTRACT_FILLFILELIST can be called
|
2007-08-23 02:35:53 +02:00
|
|
|
* by itself, but EXTRACT_EXTRACTFILES must have a valid FileList
|
|
|
|
* in order to succeed. If Operation contains both EXTRACT_FILLFILELIST
|
2006-01-09 20:24:21 +01:00
|
|
|
* and EXTRACT_EXTRACTFILES, then all the files in the cabinet
|
|
|
|
* will be extracted.
|
2002-12-19 22:16:56 +01:00
|
|
|
*/
|
2007-08-23 02:35:53 +02:00
|
|
|
HRESULT WINAPI Extract(SESSION *dest, LPCSTR szCabName)
|
2002-12-19 22:16:56 +01:00
|
|
|
{
|
2006-01-10 12:13:07 +01:00
|
|
|
HRESULT res = S_OK;
|
|
|
|
HFDI hfdi;
|
2011-02-21 18:19:11 +01:00
|
|
|
char *str, *end, *path = NULL, *name = NULL;
|
2002-12-19 22:16:56 +01:00
|
|
|
|
2016-07-25 10:47:15 +02:00
|
|
|
TRACE("(%p, %s)\n", dest, debugstr_a(szCabName));
|
2002-12-19 22:16:56 +01:00
|
|
|
|
2006-01-10 12:13:07 +01:00
|
|
|
hfdi = FDICreate(mem_alloc,
|
|
|
|
mem_free,
|
|
|
|
fdi_open,
|
|
|
|
fdi_read,
|
|
|
|
fdi_write,
|
|
|
|
fdi_close,
|
|
|
|
fdi_seek,
|
|
|
|
cpuUNKNOWN,
|
2007-08-23 23:20:52 +02:00
|
|
|
&dest->Error);
|
2002-12-19 22:16:56 +01:00
|
|
|
|
2006-01-10 12:13:07 +01:00
|
|
|
if (!hfdi)
|
|
|
|
return E_FAIL;
|
2002-12-19 22:16:56 +01:00
|
|
|
|
2007-08-23 02:35:53 +02:00
|
|
|
if (GetFileAttributesA(dest->Destination) == INVALID_FILE_ATTRIBUTES)
|
2008-07-19 19:54:10 +02:00
|
|
|
{
|
|
|
|
res = S_OK;
|
|
|
|
goto end;
|
|
|
|
}
|
2003-12-30 22:55:52 +01:00
|
|
|
|
2006-08-07 06:39:06 +02:00
|
|
|
/* split the cabinet name into path + name */
|
|
|
|
str = HeapAlloc(GetProcessHeap(), 0, lstrlenA(szCabName)+1);
|
|
|
|
if (!str)
|
|
|
|
{
|
|
|
|
res = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
lstrcpyA(str, szCabName);
|
|
|
|
|
2011-02-21 18:19:11 +01:00
|
|
|
if ((end = strrchr(str, '\\')))
|
|
|
|
{
|
2012-10-25 21:29:13 +02:00
|
|
|
path = str;
|
2011-02-21 18:19:11 +01:00
|
|
|
end++;
|
|
|
|
name = HeapAlloc( GetProcessHeap(), 0, strlen(end) + 1 );
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
res = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
strcpy( name, end );
|
|
|
|
*end = 0;
|
|
|
|
}
|
2006-08-07 06:39:06 +02:00
|
|
|
else
|
|
|
|
{
|
2011-02-21 18:19:11 +01:00
|
|
|
name = str;
|
2006-08-07 06:39:06 +02:00
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-23 23:42:27 +02:00
|
|
|
dest->FileSize = 0;
|
|
|
|
|
2006-08-07 06:39:06 +02:00
|
|
|
if (!FDICopy(hfdi, name, path, 0,
|
2006-01-10 12:13:07 +01:00
|
|
|
fdi_notify_extract, NULL, dest))
|
2007-08-24 00:46:52 +02:00
|
|
|
res = HRESULT_FROM_WIN32(GetLastError());
|
2002-12-19 22:16:56 +01:00
|
|
|
|
2006-08-07 06:39:06 +02:00
|
|
|
end:
|
2011-02-21 18:19:11 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, path);
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
2006-01-10 12:13:07 +01:00
|
|
|
FDIDestroy(hfdi);
|
|
|
|
return res;
|
2002-12-19 22:16:56 +01:00
|
|
|
}
|