2002-12-19 21:16:56 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-12-19 21:16:56 +00:00
|
|
|
*/
|
2003-09-05 23:08:26 +00:00
|
|
|
|
2002-12-19 21:16:56 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2002-12-19 21:16:56 +00: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 11:13:07 +00:00
|
|
|
|
2002-12-19 21:16:56 +00: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 17:35:28 +00:00
|
|
|
HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
|
2002-12-19 21:16:56 +00: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 11:13:07 +00:00
|
|
|
/* FDI callback functions */
|
|
|
|
|
|
|
|
static void *mem_alloc(ULONG cb)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mem_free(void *memory)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, memory);
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR fdi_open(char *pszFile, int oflag, int pmode)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
DWORD dwAccess = 0;
|
|
|
|
DWORD dwShareMode = 0;
|
2007-08-22 09:55:01 +00:00
|
|
|
DWORD dwCreateDisposition;
|
2006-01-10 11:13:07 +00: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 09:55:01 +00: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 11:13:07 +00:00
|
|
|
else
|
2007-08-22 09:55:01 +00:00
|
|
|
{
|
|
|
|
dwCreateDisposition = OPEN_EXISTING;
|
|
|
|
if (oflag & _O_TRUNC) dwCreateDisposition = TRUNCATE_EXISTING;
|
|
|
|
}
|
2006-01-10 11:13:07 +00:00
|
|
|
|
|
|
|
handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
|
|
|
|
dwCreateDisposition, 0, NULL);
|
|
|
|
|
|
|
|
return (INT_PTR) handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT fdi_read(INT_PTR hf, void *pv, UINT cb)
|
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE) hf;
|
|
|
|
DWORD dwRead;
|
|
|
|
|
|
|
|
if (ReadFile(handle, pv, cb, &dwRead, NULL))
|
|
|
|
return dwRead;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT fdi_write(INT_PTR hf, void *pv, UINT cb)
|
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE) hf;
|
|
|
|
DWORD dwWritten;
|
|
|
|
|
|
|
|
if (WriteFile(handle, pv, cb, &dwWritten, NULL))
|
|
|
|
return dwWritten;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fdi_close(INT_PTR hf)
|
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE) hf;
|
|
|
|
return CloseHandle(handle) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long fdi_seek(INT_PTR hf, long dist, int seektype)
|
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE) hf;
|
|
|
|
return SetFilePointer(handle, dist, NULL, seektype);
|
|
|
|
}
|
|
|
|
|
2007-08-23 00:35:53 +00:00
|
|
|
static void fill_file_node(struct FILELIST *pNode, LPCSTR szFilename)
|
2006-01-10 11:13:07 +00:00
|
|
|
{
|
|
|
|
pNode->next = NULL;
|
2007-08-23 00:35:53 +00:00
|
|
|
pNode->Extracted = FALSE;
|
2006-01-10 11:13:07 +00:00
|
|
|
|
2007-08-23 00:35:53 +00:00
|
|
|
pNode->FileName = HeapAlloc(GetProcessHeap(), 0, strlen(szFilename) + 1);
|
|
|
|
lstrcpyA(pNode->FileName, szFilename);
|
2006-01-10 11:13:07 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 00:35:53 +00:00
|
|
|
static BOOL file_in_list(const struct FILELIST *pNode, LPCSTR szFilename)
|
2006-01-10 11:13:07 +00:00
|
|
|
{
|
|
|
|
while (pNode)
|
|
|
|
{
|
2007-08-23 00:35:53 +00:00
|
|
|
if (!lstrcmpiA(pNode->FileName, szFilename))
|
2006-01-10 11:13:07 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
pNode = pNode->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR fdi_notify_extract(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
|
|
|
|
{
|
|
|
|
switch (fdint)
|
|
|
|
{
|
|
|
|
case fdintCOPY_FILE:
|
|
|
|
{
|
2007-08-23 00:35:53 +00:00
|
|
|
struct FILELIST **fileList;
|
|
|
|
SESSION *pDestination = pfdin->pv;
|
2006-01-10 11:13:07 +00:00
|
|
|
LPSTR szFullPath, szDirectory;
|
|
|
|
HANDLE hFile = 0;
|
|
|
|
DWORD dwSize;
|
|
|
|
|
2007-08-23 00:35:53 +00:00
|
|
|
dwSize = lstrlenA(pDestination->Destination) +
|
2006-01-10 11:13:07 +00:00
|
|
|
lstrlenA("\\") + lstrlenA(pfdin->psz1) + 1;
|
|
|
|
szFullPath = HeapAlloc(GetProcessHeap(), 0, dwSize);
|
|
|
|
|
2007-08-23 00:35:53 +00:00
|
|
|
lstrcpyA(szFullPath, pDestination->Destination);
|
2006-01-10 11:13:07 +00: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 00:35:53 +00:00
|
|
|
if (pDestination->Operation & EXTRACT_FILLFILELIST)
|
2006-01-10 11:13:07 +00:00
|
|
|
{
|
2007-08-23 00:35:53 +00:00
|
|
|
fileList = &pDestination->FileList;
|
2006-01-10 11:13:07 +00:00
|
|
|
|
|
|
|
while (*fileList)
|
|
|
|
fileList = &((*fileList)->next);
|
|
|
|
|
|
|
|
*fileList = HeapAlloc(GetProcessHeap(), 0,
|
2007-08-23 00:35:53 +00:00
|
|
|
sizeof(struct FILELIST));
|
2006-01-10 11:13:07 +00:00
|
|
|
|
|
|
|
fill_file_node(*fileList, pfdin->psz1);
|
2007-08-23 00:35:53 +00:00
|
|
|
lstrcpyA(pDestination->CurrentFile, szFullPath);
|
|
|
|
pDestination->FileCount++;
|
2006-01-10 11:13:07 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 00:35:53 +00:00
|
|
|
if ((pDestination->Operation & EXTRACT_EXTRACTFILES) ||
|
|
|
|
file_in_list(pDestination->FilterList, pfdin->psz1))
|
2006-01-10 11:13:07 +00:00
|
|
|
{
|
2006-10-15 15:05:01 +00:00
|
|
|
/* skip this file if it is not in the file list */
|
2007-08-23 00:35:53 +00:00
|
|
|
if (!file_in_list(pDestination->FileList, pfdin->psz1))
|
2006-01-10 11:13:07 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* create the destination directory if it doesn't exist */
|
|
|
|
if (GetFileAttributesA(szDirectory) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
CreateDirectoryA(szDirectory, NULL);
|
|
|
|
|
|
|
|
hFile = CreateFileA(szFullPath, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
hFile = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 21:16:56 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Extract (CABINET.3)
|
|
|
|
*
|
2006-01-09 19:24:21 +00:00
|
|
|
* Extracts the contents of the cabinet file to the specified
|
|
|
|
* destination.
|
2002-12-19 21:16:56 +00:00
|
|
|
*
|
|
|
|
* PARAMS
|
2006-01-09 19:24:21 +00:00
|
|
|
* dest [I/O] Controls the operation of Extract. See NOTES.
|
2006-01-09 19:23:26 +00:00
|
|
|
* szCabName [I] Filename of the cabinet to extract.
|
2002-12-19 21:16:56 +00:00
|
|
|
*
|
|
|
|
* RETURNS
|
2006-01-09 19:24:21 +00:00
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: E_FAIL.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The following members of the dest struct control the operation
|
|
|
|
* of Extract:
|
2007-08-23 00:35:53 +00: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 19:24:21 +00:00
|
|
|
*
|
|
|
|
* Operation
|
2007-08-23 00:35:53 +00: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 19:24:21 +00:00
|
|
|
* be extracted from the cabinet. EXTRACT_FILLFILELIST can be called
|
2007-08-23 00:35:53 +00:00
|
|
|
* by itself, but EXTRACT_EXTRACTFILES must have a valid FileList
|
|
|
|
* in order to succeed. If Operation contains both EXTRACT_FILLFILELIST
|
2006-01-09 19:24:21 +00:00
|
|
|
* and EXTRACT_EXTRACTFILES, then all the files in the cabinet
|
|
|
|
* will be extracted.
|
2002-12-19 21:16:56 +00:00
|
|
|
*/
|
2007-08-23 00:35:53 +00:00
|
|
|
HRESULT WINAPI Extract(SESSION *dest, LPCSTR szCabName)
|
2002-12-19 21:16:56 +00:00
|
|
|
{
|
2006-01-10 11:13:07 +00:00
|
|
|
HRESULT res = S_OK;
|
|
|
|
HFDI hfdi;
|
2006-08-07 04:39:06 +00:00
|
|
|
char *str, *path, *name;
|
2002-12-19 21:16:56 +00:00
|
|
|
|
2006-01-10 11:13:07 +00:00
|
|
|
TRACE("(%p, %s)\n", dest, szCabName);
|
2002-12-19 21:16:56 +00:00
|
|
|
|
2006-01-10 11:13:07 +00:00
|
|
|
hfdi = FDICreate(mem_alloc,
|
|
|
|
mem_free,
|
|
|
|
fdi_open,
|
|
|
|
fdi_read,
|
|
|
|
fdi_write,
|
|
|
|
fdi_close,
|
|
|
|
fdi_seek,
|
|
|
|
cpuUNKNOWN,
|
2007-08-23 21:20:52 +00:00
|
|
|
&dest->Error);
|
2002-12-19 21:16:56 +00:00
|
|
|
|
2006-01-10 11:13:07 +00:00
|
|
|
if (!hfdi)
|
|
|
|
return E_FAIL;
|
2002-12-19 21:16:56 +00:00
|
|
|
|
2007-08-23 00:35:53 +00:00
|
|
|
if (GetFileAttributesA(dest->Destination) == INVALID_FILE_ATTRIBUTES)
|
2006-01-10 11:13:07 +00:00
|
|
|
return S_OK;
|
2003-12-30 21:55:52 +00:00
|
|
|
|
2006-08-07 04:39:06 +00: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);
|
|
|
|
|
|
|
|
path = str;
|
|
|
|
name = strrchr(path, '\\');
|
|
|
|
if (name)
|
|
|
|
*name++ = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = path;
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FDICopy(hfdi, name, path, 0,
|
2006-01-10 11:13:07 +00:00
|
|
|
fdi_notify_extract, NULL, dest))
|
|
|
|
res = E_FAIL;
|
2002-12-19 21:16:56 +00:00
|
|
|
|
2006-08-07 04:39:06 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, str);
|
|
|
|
end:
|
|
|
|
|
2006-01-10 11:13:07 +00:00
|
|
|
FDIDestroy(hfdi);
|
2002-12-19 21:16:56 +00:00
|
|
|
|
2006-01-10 11:13:07 +00:00
|
|
|
return res;
|
2002-12-19 21:16:56 +00:00
|
|
|
}
|