2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-31 11:11:54 +01:00
|
|
|
* Implementation of VERSION.DLL - File Installer routines
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-31 11:11:54 +01:00
|
|
|
* Copyright 1996,1997 Marcus Meissner
|
|
|
|
* Copyright 1997 David Cuthbert
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
2003-09-27 04:22:21 +02:00
|
|
|
*
|
|
|
|
* TODO
|
|
|
|
* o Check the installation functions.
|
1999-01-31 11:11:54 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-02-10 23:15:21 +01:00
|
|
|
#include <stdio.h>
|
1999-01-31 11:11:54 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
1999-02-17 14:51:06 +01:00
|
|
|
#include "windef.h"
|
2000-11-16 01:28:52 +01:00
|
|
|
#include "winbase.h"
|
1999-02-17 14:51:06 +01:00
|
|
|
#include "winver.h"
|
2000-11-16 01:28:52 +01:00
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/unicode.h"
|
1999-01-31 11:11:54 +01:00
|
|
|
#include "winerror.h"
|
|
|
|
#include "lzexpand.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ver);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
2000-11-16 01:28:52 +01:00
|
|
|
* testFileExistenceA
|
1999-01-31 11:11:54 +01:00
|
|
|
*
|
|
|
|
* Tests whether a given path/file combination exists. If the file does
|
|
|
|
* not exist, the return value is zero. If it does exist, the return
|
|
|
|
* value is non-zero.
|
|
|
|
*
|
|
|
|
* Revision history
|
|
|
|
* 30-May-1997 Dave Cuthbert (dacut@ece.cmu.edu)
|
|
|
|
* Original implementation
|
|
|
|
*
|
2000-11-16 01:28:52 +01:00
|
|
|
*/
|
|
|
|
static int testFileExistenceA( char const * path, char const * file, BOOL excl )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
|
|
|
char filename[1024];
|
|
|
|
int filenamelen;
|
|
|
|
OFSTRUCT fileinfo;
|
|
|
|
|
|
|
|
fileinfo.cBytes = sizeof(OFSTRUCT);
|
|
|
|
|
|
|
|
strcpy(filename, path);
|
|
|
|
filenamelen = strlen(filename);
|
|
|
|
|
|
|
|
/* Add a trailing \ if necessary */
|
|
|
|
if(filenamelen) {
|
|
|
|
if(filename[filenamelen - 1] != '\\')
|
|
|
|
strcat(filename, "\\");
|
|
|
|
}
|
|
|
|
else /* specify the current directory */
|
|
|
|
strcpy(filename, ".\\");
|
|
|
|
|
|
|
|
/* Create the full pathname */
|
|
|
|
strcat(filename, file);
|
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
return (OpenFile(filename, &fileinfo,
|
|
|
|
OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0)) != HFILE_ERROR);
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2000-11-16 01:28:52 +01:00
|
|
|
* testFileExistenceW
|
|
|
|
*/
|
|
|
|
static int testFileExistenceW( const WCHAR *path, const WCHAR *file, BOOL excl )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
2000-11-16 01:28:52 +01:00
|
|
|
char *filename;
|
|
|
|
DWORD pathlen, filelen;
|
|
|
|
int ret;
|
|
|
|
OFSTRUCT fileinfo;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
fileinfo.cBytes = sizeof(OFSTRUCT);
|
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
pathlen = WideCharToMultiByte( CP_ACP, 0, path, -1, NULL, 0, NULL, NULL );
|
|
|
|
filelen = WideCharToMultiByte( CP_ACP, 0, file, -1, NULL, 0, NULL, NULL );
|
|
|
|
filename = HeapAlloc( GetProcessHeap(), 0, pathlen+filelen+2 );
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, path, -1, filename, pathlen, NULL, NULL );
|
1999-01-31 11:11:54 +01:00
|
|
|
/* Add a trailing \ if necessary */
|
2000-11-16 01:28:52 +01:00
|
|
|
if (pathlen > 1)
|
|
|
|
{
|
|
|
|
if (filename[pathlen-2] != '\\') strcpy( &filename[pathlen-1], "\\" );
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
else /* specify the current directory */
|
2000-11-16 01:28:52 +01:00
|
|
|
strcpy(filename, ".\\");
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, file, -1, filename+strlen(filename), filelen, NULL, NULL );
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
ret = (OpenFile(filename, &fileinfo,
|
|
|
|
OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0)) != HFILE_ERROR);
|
|
|
|
HeapFree( GetProcessHeap(), 0, filename );
|
|
|
|
return ret;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* VerFindFileA [VERSION.@]
|
1999-01-31 11:11:54 +01:00
|
|
|
*
|
|
|
|
* Determines where to install a file based on whether it locates another
|
|
|
|
* version of the file in the system. The values VerFindFile returns are
|
|
|
|
* used in a subsequent call to the VerInstallFile function.
|
|
|
|
*
|
|
|
|
* Revision history:
|
|
|
|
* 30-May-1997 Dave Cuthbert (dacut@ece.cmu.edu)
|
|
|
|
* Reimplementation of VerFindFile from original stub.
|
2000-11-16 01:28:52 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI VerFindFileA(
|
|
|
|
UINT flags,
|
2005-11-03 12:35:11 +01:00
|
|
|
LPSTR lpszFilename,
|
|
|
|
LPSTR lpszWinDir,
|
|
|
|
LPSTR lpszAppDir,
|
1999-01-31 11:11:54 +01:00
|
|
|
LPSTR lpszCurDir,
|
1999-02-26 12:11:13 +01:00
|
|
|
UINT *lpuCurDirLen,
|
1999-01-31 11:11:54 +01:00
|
|
|
LPSTR lpszDestDir,
|
1999-02-26 12:11:13 +01:00
|
|
|
UINT *lpuDestDirLen )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
2000-11-16 01:28:52 +01:00
|
|
|
DWORD retval = 0;
|
|
|
|
const char *curDir;
|
|
|
|
const char *destDir;
|
1999-01-31 11:11:54 +01:00
|
|
|
unsigned int curDirSizeReq;
|
|
|
|
unsigned int destDirSizeReq;
|
2000-11-16 01:28:52 +01:00
|
|
|
char systemDir[MAX_PATH];
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
/* Print out debugging information */
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
|
2000-11-16 01:28:52 +01:00
|
|
|
flags, debugstr_a(lpszFilename), debugstr_a(lpszWinDir), debugstr_a(lpszAppDir),
|
|
|
|
lpuCurDirLen, lpuCurDirLen ? *lpuCurDirLen : 0,
|
|
|
|
lpuDestDirLen, lpuDestDirLen ? *lpuDestDirLen : 0 );
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
/* Figure out where the file should go; shared files default to the
|
|
|
|
system directory */
|
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
GetSystemDirectoryA(systemDir, sizeof(systemDir));
|
|
|
|
curDir = "";
|
|
|
|
destDir = "";
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
if(flags & VFFF_ISSHAREDFILE)
|
|
|
|
{
|
|
|
|
destDir = systemDir;
|
|
|
|
/* Were we given a filename? If so, try to find the file. */
|
|
|
|
if(lpszFilename)
|
|
|
|
{
|
|
|
|
if(testFileExistenceA(destDir, lpszFilename, FALSE)) curDir = destDir;
|
|
|
|
else if(lpszAppDir && testFileExistenceA(lpszAppDir, lpszFilename, FALSE))
|
|
|
|
{
|
|
|
|
curDir = lpszAppDir;
|
|
|
|
retval |= VFF_CURNEDEST;
|
|
|
|
}
|
|
|
|
}
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
2000-11-16 01:28:52 +01:00
|
|
|
else /* not a shared file */
|
|
|
|
{
|
|
|
|
if(lpszAppDir)
|
|
|
|
{
|
|
|
|
destDir = lpszAppDir;
|
|
|
|
if(lpszFilename)
|
|
|
|
{
|
|
|
|
if(testFileExistenceA(destDir, lpszFilename, FALSE)) curDir = destDir;
|
|
|
|
else if(testFileExistenceA(systemDir, lpszFilename, FALSE))
|
|
|
|
{
|
|
|
|
curDir = systemDir;
|
|
|
|
retval |= VFF_CURNEDEST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
|
2005-10-28 12:42:09 +02:00
|
|
|
/* Check to see if the file exists and is inuse by another application */
|
|
|
|
if (lpszFilename && testFileExistenceA(curDir, lpszFilename, FALSE)) {
|
|
|
|
if (lpszFilename && !testFileExistenceA(curDir, lpszFilename, TRUE))
|
|
|
|
retval |= VFF_FILEINUSE;
|
|
|
|
}
|
2000-11-16 01:28:52 +01:00
|
|
|
|
1999-01-31 11:11:54 +01:00
|
|
|
curDirSizeReq = strlen(curDir) + 1;
|
|
|
|
destDirSizeReq = strlen(destDir) + 1;
|
|
|
|
|
|
|
|
/* Make sure that the pointers to the size of the buffers are
|
|
|
|
valid; if not, do NOTHING with that buffer. If that pointer
|
|
|
|
is valid, then make sure that the buffer pointer is valid, too! */
|
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
if(lpuDestDirLen && lpszDestDir)
|
|
|
|
{
|
|
|
|
if (*lpuDestDirLen < destDirSizeReq) retval |= VFF_BUFFTOOSMALL;
|
|
|
|
lstrcpynA(lpszDestDir, destDir, *lpuDestDirLen);
|
|
|
|
*lpuDestDirLen = destDirSizeReq;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
2000-11-16 01:28:52 +01:00
|
|
|
if(lpuCurDirLen && lpszCurDir)
|
|
|
|
{
|
|
|
|
if(*lpuCurDirLen < curDirSizeReq) retval |= VFF_BUFFTOOSMALL;
|
|
|
|
lstrcpynA(lpszCurDir, curDir, *lpuCurDirLen);
|
|
|
|
*lpuCurDirLen = curDirSizeReq;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
|
2006-10-08 19:35:18 +02:00
|
|
|
TRACE("ret = %u (%s%s%s) curdir=%s destdir=%s\n", retval,
|
2000-11-16 01:28:52 +01:00
|
|
|
(retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
|
|
|
|
(retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
|
|
|
|
(retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "",
|
|
|
|
debugstr_a(lpszCurDir), debugstr_a(lpszDestDir));
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2000-03-24 21:46:04 +01:00
|
|
|
/*****************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* VerFindFileW [VERSION.@]
|
2000-03-24 21:46:04 +01:00
|
|
|
*/
|
2005-11-03 12:35:11 +01:00
|
|
|
DWORD WINAPI VerFindFileW( UINT flags,LPWSTR lpszFilename,LPWSTR lpszWinDir,
|
|
|
|
LPWSTR lpszAppDir, LPWSTR lpszCurDir,UINT *lpuCurDirLen,
|
2000-11-16 01:28:52 +01:00
|
|
|
LPWSTR lpszDestDir,UINT *lpuDestDirLen )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
2000-11-16 01:28:52 +01:00
|
|
|
static const WCHAR emptyW;
|
|
|
|
DWORD retval = 0;
|
|
|
|
const WCHAR *curDir;
|
|
|
|
const WCHAR *destDir;
|
|
|
|
unsigned int curDirSizeReq;
|
|
|
|
unsigned int destDirSizeReq;
|
|
|
|
WCHAR systemDir[MAX_PATH];
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
/* Print out debugging information */
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
|
2000-11-16 01:28:52 +01:00
|
|
|
flags, debugstr_w(lpszFilename), debugstr_w(lpszWinDir), debugstr_w(lpszAppDir),
|
|
|
|
lpuCurDirLen, lpuCurDirLen ? *lpuCurDirLen : 0,
|
|
|
|
lpuDestDirLen, lpuDestDirLen ? *lpuDestDirLen : 0 );
|
|
|
|
|
|
|
|
/* Figure out where the file should go; shared files default to the
|
|
|
|
system directory */
|
|
|
|
|
|
|
|
GetSystemDirectoryW(systemDir, sizeof(systemDir)/sizeof(WCHAR));
|
|
|
|
curDir = &emptyW;
|
|
|
|
destDir = &emptyW;
|
|
|
|
|
|
|
|
if(flags & VFFF_ISSHAREDFILE)
|
|
|
|
{
|
|
|
|
destDir = systemDir;
|
|
|
|
/* Were we given a filename? If so, try to find the file. */
|
|
|
|
if(lpszFilename)
|
|
|
|
{
|
|
|
|
if(testFileExistenceW(destDir, lpszFilename, FALSE)) curDir = destDir;
|
|
|
|
else if(lpszAppDir && testFileExistenceW(lpszAppDir, lpszFilename, FALSE))
|
|
|
|
{
|
|
|
|
curDir = lpszAppDir;
|
|
|
|
retval |= VFF_CURNEDEST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* not a shared file */
|
|
|
|
{
|
|
|
|
if(lpszAppDir)
|
|
|
|
{
|
|
|
|
destDir = lpszAppDir;
|
|
|
|
if(lpszFilename)
|
|
|
|
{
|
|
|
|
if(testFileExistenceW(destDir, lpszFilename, FALSE)) curDir = destDir;
|
|
|
|
else if(testFileExistenceW(systemDir, lpszFilename, FALSE))
|
|
|
|
{
|
|
|
|
curDir = systemDir;
|
|
|
|
retval |= VFF_CURNEDEST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpszFilename && !testFileExistenceW(curDir, lpszFilename, TRUE))
|
|
|
|
retval |= VFF_FILEINUSE;
|
|
|
|
|
|
|
|
curDirSizeReq = strlenW(curDir) + 1;
|
|
|
|
destDirSizeReq = strlenW(destDir) + 1;
|
|
|
|
|
|
|
|
/* Make sure that the pointers to the size of the buffers are
|
|
|
|
valid; if not, do NOTHING with that buffer. If that pointer
|
|
|
|
is valid, then make sure that the buffer pointer is valid, too! */
|
|
|
|
|
|
|
|
if(lpuDestDirLen && lpszDestDir)
|
|
|
|
{
|
|
|
|
if (*lpuDestDirLen < destDirSizeReq) retval |= VFF_BUFFTOOSMALL;
|
|
|
|
lstrcpynW(lpszDestDir, destDir, *lpuDestDirLen);
|
|
|
|
*lpuDestDirLen = destDirSizeReq;
|
|
|
|
}
|
|
|
|
if(lpuCurDirLen && lpszCurDir)
|
|
|
|
{
|
|
|
|
if(*lpuCurDirLen < curDirSizeReq) retval |= VFF_BUFFTOOSMALL;
|
|
|
|
lstrcpynW(lpszCurDir, curDir, *lpuCurDirLen);
|
|
|
|
*lpuCurDirLen = curDirSizeReq;
|
|
|
|
}
|
|
|
|
|
2006-10-08 19:35:18 +02:00
|
|
|
TRACE("ret = %u (%s%s%s) curdir=%s destdir=%s\n", retval,
|
2000-11-16 01:28:52 +01:00
|
|
|
(retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
|
|
|
|
(retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
|
|
|
|
(retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "",
|
|
|
|
debugstr_w(lpszCurDir), debugstr_w(lpszDestDir));
|
|
|
|
return retval;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static LPBYTE
|
|
|
|
_fetch_versioninfo(LPSTR fn,VS_FIXEDFILEINFO **vffi) {
|
|
|
|
DWORD alloclen;
|
|
|
|
LPBYTE buf;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
alloclen = 1000;
|
2000-04-24 19:33:06 +02:00
|
|
|
buf=HeapAlloc(GetProcessHeap(), 0, alloclen);
|
|
|
|
if(buf == NULL) {
|
2001-05-09 19:31:31 +02:00
|
|
|
WARN("Memory exausted while fetching version info!\n");
|
2000-04-24 19:33:06 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
1999-01-31 11:11:54 +01:00
|
|
|
while (1) {
|
1999-02-26 12:11:13 +01:00
|
|
|
ret = GetFileVersionInfoA(fn,0,alloclen,buf);
|
1999-01-31 11:11:54 +01:00
|
|
|
if (!ret) {
|
2000-04-24 19:33:06 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
return NULL;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
if (alloclen<*(WORD*)buf) {
|
|
|
|
alloclen = *(WORD*)buf;
|
2000-04-24 19:33:06 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, alloclen);
|
|
|
|
if(buf == NULL) {
|
2001-05-09 19:31:31 +02:00
|
|
|
WARN("Memory exausted while fetching version info!\n");
|
2000-04-24 19:33:06 +02:00
|
|
|
return NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
1999-01-31 11:11:54 +01:00
|
|
|
} else {
|
|
|
|
*vffi = (VS_FIXEDFILEINFO*)(buf+0x14);
|
|
|
|
if ((*vffi)->dwSignature == 0x004f0049) /* hack to detect unicode */
|
|
|
|
*vffi = (VS_FIXEDFILEINFO*)(buf+0x28);
|
|
|
|
if ((*vffi)->dwSignature != VS_FFI_SIGNATURE)
|
2006-10-08 19:35:18 +02:00
|
|
|
WARN("Bad VS_FIXEDFILEINFO signature 0x%08x\n",(*vffi)->dwSignature);
|
1999-01-31 11:11:54 +01:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
_error2vif(DWORD error) {
|
|
|
|
switch (error) {
|
|
|
|
case ERROR_ACCESS_DENIED:
|
|
|
|
return VIF_ACCESSVIOLATION;
|
|
|
|
case ERROR_SHARING_VIOLATION:
|
|
|
|
return VIF_SHARINGVIOLATION;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* VerInstallFileA [VERSION.@]
|
1999-01-31 11:11:54 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI VerInstallFileA(
|
2005-11-03 12:35:11 +01:00
|
|
|
UINT flags,LPSTR srcfilename,LPSTR destfilename,LPSTR srcdir,
|
|
|
|
LPSTR destdir,LPSTR curdir,LPSTR tmpfile,UINT *tmpfilelen )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
|
|
|
LPCSTR pdest;
|
|
|
|
char destfn[260],tmpfn[260],srcfn[260];
|
1999-02-26 12:11:13 +01:00
|
|
|
HFILE hfsrc,hfdst;
|
1999-01-31 11:11:54 +01:00
|
|
|
DWORD attr,ret,xret,tmplast;
|
|
|
|
LPBYTE buf1,buf2;
|
|
|
|
OFSTRUCT ofs;
|
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("(%x,%s,%s,%s,%s,%s,%p,%d)\n",
|
1999-01-31 11:11:54 +01:00
|
|
|
flags,srcfilename,destfilename,srcdir,destdir,curdir,tmpfile,*tmpfilelen
|
|
|
|
);
|
|
|
|
xret = 0;
|
|
|
|
sprintf(srcfn,"%s\\%s",srcdir,srcfilename);
|
|
|
|
if (!destdir || !*destdir) pdest = srcdir;
|
|
|
|
else pdest = destdir;
|
|
|
|
sprintf(destfn,"%s\\%s",pdest,destfilename);
|
1999-02-26 12:11:13 +01:00
|
|
|
hfsrc=LZOpenFileA(srcfn,&ofs,OF_READ);
|
2001-01-02 20:56:21 +01:00
|
|
|
if (hfsrc < 0)
|
1999-01-31 11:11:54 +01:00
|
|
|
return VIF_CANNOTREADSRC;
|
|
|
|
sprintf(tmpfn,"%s\\%s",pdest,destfilename);
|
|
|
|
tmplast=strlen(pdest)+1;
|
1999-02-26 12:11:13 +01:00
|
|
|
attr = GetFileAttributesA(tmpfn);
|
2003-10-16 21:12:49 +02:00
|
|
|
if (attr != INVALID_FILE_ATTRIBUTES) {
|
1999-01-31 11:11:54 +01:00
|
|
|
if (attr & FILE_ATTRIBUTE_READONLY) {
|
1999-02-26 12:11:13 +01:00
|
|
|
LZClose(hfsrc);
|
1999-01-31 11:11:54 +01:00
|
|
|
return VIF_WRITEPROT;
|
|
|
|
}
|
|
|
|
/* FIXME: check if file currently in use and return VIF_FILEINUSE */
|
|
|
|
}
|
2003-10-16 21:12:49 +02:00
|
|
|
attr = INVALID_FILE_ATTRIBUTES;
|
1999-01-31 11:11:54 +01:00
|
|
|
if (flags & VIFF_FORCEINSTALL) {
|
|
|
|
if (tmpfile[0]) {
|
|
|
|
sprintf(tmpfn,"%s\\%s",pdest,tmpfile);
|
|
|
|
tmplast = strlen(pdest)+1;
|
1999-02-26 12:11:13 +01:00
|
|
|
attr = GetFileAttributesA(tmpfn);
|
1999-01-31 11:11:54 +01:00
|
|
|
/* if it exists, it has been copied by the call before.
|
2002-06-01 01:06:46 +02:00
|
|
|
* we jump over the copy part...
|
1999-01-31 11:11:54 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
2003-10-16 21:12:49 +02:00
|
|
|
if (attr == INVALID_FILE_ATTRIBUTES) {
|
1999-01-31 11:11:54 +01:00
|
|
|
char *s;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
GetTempFileNameA(pdest,"ver",0,tmpfn); /* should not fail ... */
|
1999-01-31 11:11:54 +01:00
|
|
|
s=strrchr(tmpfn,'\\');
|
|
|
|
if (s)
|
|
|
|
tmplast = s-tmpfn;
|
|
|
|
else
|
|
|
|
tmplast = 0;
|
1999-02-26 12:11:13 +01:00
|
|
|
hfdst = OpenFile(tmpfn,&ofs,OF_CREATE);
|
|
|
|
if (hfdst == HFILE_ERROR) {
|
|
|
|
LZClose(hfsrc);
|
1999-01-31 11:11:54 +01:00
|
|
|
return VIF_CANNOTCREATE; /* | translated dos error */
|
|
|
|
}
|
1999-02-26 12:11:13 +01:00
|
|
|
ret = LZCopy(hfsrc,hfdst);
|
|
|
|
_lclose(hfdst);
|
2005-09-13 17:00:32 +02:00
|
|
|
if (((LONG)ret) < 0) {
|
1999-01-31 11:11:54 +01:00
|
|
|
/* translate LZ errors into VIF_xxx */
|
|
|
|
switch (ret) {
|
|
|
|
case LZERROR_BADINHANDLE:
|
|
|
|
case LZERROR_READ:
|
|
|
|
case LZERROR_BADVALUE:
|
|
|
|
case LZERROR_UNKNOWNALG:
|
|
|
|
ret = VIF_CANNOTREADSRC;
|
|
|
|
break;
|
|
|
|
case LZERROR_BADOUTHANDLE:
|
|
|
|
case LZERROR_WRITE:
|
2000-08-07 04:34:47 +02:00
|
|
|
ret = VIF_OUTOFSPACE;
|
1999-01-31 11:11:54 +01:00
|
|
|
break;
|
|
|
|
case LZERROR_GLOBALLOC:
|
|
|
|
case LZERROR_GLOBLOCK:
|
2000-08-07 04:34:47 +02:00
|
|
|
ret = VIF_OUTOFMEMORY;
|
1999-01-31 11:11:54 +01:00
|
|
|
break;
|
|
|
|
default: /* unknown error, should not happen */
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret) {
|
1999-02-26 12:11:13 +01:00
|
|
|
LZClose(hfsrc);
|
1999-01-31 11:11:54 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xret = 0;
|
|
|
|
if (!(flags & VIFF_FORCEINSTALL)) {
|
|
|
|
VS_FIXEDFILEINFO *destvffi,*tmpvffi;
|
|
|
|
buf1 = _fetch_versioninfo(destfn,&destvffi);
|
|
|
|
if (buf1) {
|
|
|
|
buf2 = _fetch_versioninfo(tmpfn,&tmpvffi);
|
|
|
|
if (buf2) {
|
2007-02-22 22:48:14 +01:00
|
|
|
char *tbuf1,*tbuf2;
|
|
|
|
static const CHAR trans_array[] = "\\VarFileInfo\\Translation";
|
1999-02-26 12:11:13 +01:00
|
|
|
UINT len1,len2;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
len1=len2=40;
|
|
|
|
|
|
|
|
/* compare file versions */
|
|
|
|
if ((destvffi->dwFileVersionMS > tmpvffi->dwFileVersionMS)||
|
|
|
|
((destvffi->dwFileVersionMS==tmpvffi->dwFileVersionMS)&&
|
|
|
|
(destvffi->dwFileVersionLS > tmpvffi->dwFileVersionLS)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
xret |= VIF_MISMATCH|VIF_SRCOLD;
|
|
|
|
/* compare filetypes and filesubtypes */
|
|
|
|
if ((destvffi->dwFileType!=tmpvffi->dwFileType) ||
|
|
|
|
(destvffi->dwFileSubtype!=tmpvffi->dwFileSubtype)
|
|
|
|
)
|
|
|
|
xret |= VIF_MISMATCH|VIF_DIFFTYPE;
|
2006-08-11 15:53:25 +02:00
|
|
|
if (VerQueryValueA(buf1,trans_array,(LPVOID*)&tbuf1,&len1) &&
|
|
|
|
VerQueryValueA(buf2,trans_array,(LPVOID*)&tbuf2,&len2)
|
1999-01-31 11:11:54 +01:00
|
|
|
) {
|
2006-04-13 10:16:37 +02:00
|
|
|
/* Do something with tbuf1 and tbuf2
|
|
|
|
* generates DIFFLANG|MISMATCH
|
1999-01-31 11:11:54 +01:00
|
|
|
*/
|
|
|
|
}
|
2000-04-24 19:33:06 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, buf2);
|
1999-01-31 11:11:54 +01:00
|
|
|
} else
|
|
|
|
xret=VIF_MISMATCH|VIF_SRCOLD;
|
2000-04-24 19:33:06 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, buf1);
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xret) {
|
|
|
|
if (*tmpfilelen<strlen(tmpfn+tmplast)) {
|
|
|
|
xret|=VIF_BUFFTOOSMALL;
|
1999-02-26 12:11:13 +01:00
|
|
|
DeleteFileA(tmpfn);
|
1999-01-31 11:11:54 +01:00
|
|
|
} else {
|
|
|
|
strcpy(tmpfile,tmpfn+tmplast);
|
|
|
|
*tmpfilelen = strlen(tmpfn+tmplast)+1;
|
|
|
|
xret|=VIF_TEMPFILE;
|
|
|
|
}
|
|
|
|
} else {
|
2005-03-19 18:03:43 +01:00
|
|
|
if (INVALID_FILE_ATTRIBUTES!=GetFileAttributesA(destfn))
|
1999-02-26 12:11:13 +01:00
|
|
|
if (!DeleteFileA(destfn)) {
|
1999-01-31 11:11:54 +01:00
|
|
|
xret|=_error2vif(GetLastError())|VIF_CANNOTDELETE;
|
1999-02-26 12:11:13 +01:00
|
|
|
DeleteFileA(tmpfn);
|
|
|
|
LZClose(hfsrc);
|
1999-01-31 11:11:54 +01:00
|
|
|
return xret;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
if ((!(flags & VIFF_DONTDELETEOLD)) &&
|
|
|
|
curdir &&
|
1999-01-31 11:11:54 +01:00
|
|
|
*curdir &&
|
1999-02-26 12:11:13 +01:00
|
|
|
lstrcmpiA(curdir,pdest)
|
1999-01-31 11:11:54 +01:00
|
|
|
) {
|
|
|
|
char curfn[260];
|
|
|
|
|
|
|
|
sprintf(curfn,"%s\\%s",curdir,destfilename);
|
2003-10-16 21:12:49 +02:00
|
|
|
if (INVALID_FILE_ATTRIBUTES != GetFileAttributesA(curfn)) {
|
1999-01-31 11:11:54 +01:00
|
|
|
/* FIXME: check if in use ... if it is, VIF_CANNOTDELETECUR */
|
1999-02-26 12:11:13 +01:00
|
|
|
if (!DeleteFileA(curfn))
|
1999-01-31 11:11:54 +01:00
|
|
|
xret|=_error2vif(GetLastError())|VIF_CANNOTDELETECUR;
|
|
|
|
}
|
|
|
|
}
|
1999-02-26 12:11:13 +01:00
|
|
|
if (!MoveFileA(tmpfn,destfn)) {
|
1999-01-31 11:11:54 +01:00
|
|
|
xret|=_error2vif(GetLastError())|VIF_CANNOTRENAME;
|
1999-02-26 12:11:13 +01:00
|
|
|
DeleteFileA(tmpfn);
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
1999-02-26 12:11:13 +01:00
|
|
|
LZClose(hfsrc);
|
1999-01-31 11:11:54 +01:00
|
|
|
return xret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-24 21:46:04 +01:00
|
|
|
/******************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* VerInstallFileW [VERSION.@]
|
2000-03-24 21:46:04 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI VerInstallFileW(
|
2005-11-03 12:35:11 +01:00
|
|
|
UINT flags,LPWSTR srcfilename,LPWSTR destfilename,LPWSTR srcdir,
|
|
|
|
LPWSTR destdir,LPWSTR curdir,LPWSTR tmpfile,UINT *tmpfilelen )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
2000-11-16 01:28:52 +01:00
|
|
|
LPSTR wsrcf = NULL, wsrcd = NULL, wdestf = NULL, wdestd = NULL, wtmpf = NULL, wcurd = NULL;
|
1999-01-31 11:11:54 +01:00
|
|
|
DWORD ret;
|
2000-11-16 01:28:52 +01:00
|
|
|
UINT len;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
if (srcfilename)
|
|
|
|
{
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, srcfilename, -1, NULL, 0, NULL, NULL );
|
|
|
|
if ((wsrcf = HeapAlloc( GetProcessHeap(), 0, len )))
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, srcfilename, -1, wsrcf, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
if (srcdir)
|
|
|
|
{
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, srcdir, -1, NULL, 0, NULL, NULL );
|
|
|
|
if ((wsrcd = HeapAlloc( GetProcessHeap(), 0, len )))
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, srcdir, -1, wsrcd, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
if (destfilename)
|
|
|
|
{
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, destfilename, -1, NULL, 0, NULL, NULL );
|
|
|
|
if ((wdestf = HeapAlloc( GetProcessHeap(), 0, len )))
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, destfilename, -1, wdestf, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
if (destdir)
|
|
|
|
{
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, destdir, -1, NULL, 0, NULL, NULL );
|
|
|
|
if ((wdestd = HeapAlloc( GetProcessHeap(), 0, len )))
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, destdir, -1, wdestd, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
if (curdir)
|
|
|
|
{
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, curdir, -1, NULL, 0, NULL, NULL );
|
|
|
|
if ((wcurd = HeapAlloc( GetProcessHeap(), 0, len )))
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, curdir, -1, wcurd, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
len = *tmpfilelen * sizeof(WCHAR);
|
|
|
|
wtmpf = HeapAlloc( GetProcessHeap(), 0, len );
|
|
|
|
ret = VerInstallFileA(flags,wsrcf,wdestf,wsrcd,wdestd,wcurd,wtmpf,&len);
|
1999-01-31 11:11:54 +01:00
|
|
|
if (!ret)
|
2000-11-16 01:28:52 +01:00
|
|
|
*tmpfilelen = MultiByteToWideChar( CP_ACP, 0, wtmpf, -1, tmpfile, *tmpfilelen );
|
|
|
|
else if (ret & VIF_BUFFTOOSMALL)
|
|
|
|
*tmpfilelen = len; /* FIXME: not correct */
|
|
|
|
|
1999-01-31 11:11:54 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, wsrcf );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wsrcd );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wdestf );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wdestd );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wtmpf );
|
2000-11-16 01:28:52 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, wcurd );
|
1999-01-31 11:11:54 +01:00
|
|
|
return ret;
|
|
|
|
}
|