1999-01-31 11:11:54 +01:00
|
|
|
/*
|
|
|
|
* Implementation of VERSION.DLL - File Installer routines
|
|
|
|
*
|
|
|
|
* Copyright 1996,1997 Marcus Meissner
|
|
|
|
* Copyright 1997 David Cuthbert
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.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"
|
|
|
|
#include "winver.h"
|
|
|
|
#include "wine/winestring.h"
|
1999-01-31 11:11:54 +01:00
|
|
|
#include "winerror.h"
|
|
|
|
#include "heap.h"
|
|
|
|
#include "lzexpand.h"
|
1999-05-14 10:17:14 +02:00
|
|
|
#include "debugtools.h"
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-02-10 23:15:21 +01:00
|
|
|
DEFAULT_DEBUG_CHANNEL(ver);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* void ver_dstring(
|
|
|
|
* char const * prologue,
|
|
|
|
* char const * teststring,
|
|
|
|
* char const * epilogue )
|
|
|
|
*
|
|
|
|
* This function will print via dprintf[_]ver to stddeb the prologue string,
|
|
|
|
* followed by the address of teststring and the string it contains if
|
|
|
|
* teststring is non-null or "(null)" otherwise, and then the epilogue
|
|
|
|
* string followed by a new line.
|
|
|
|
*
|
|
|
|
* Revision history
|
|
|
|
* 30-May-1997 Dave Cuthbert (dacut@ece.cmu.edu)
|
|
|
|
* Original implementation as dprintf[_]ver_string
|
|
|
|
* 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
|
|
|
|
* Fixed problem that caused bug with tools/make_debug -- renaming
|
|
|
|
* this function should fix the problem.
|
|
|
|
* 15-Feb-1998 Dimitrie Paun (dimi@cs.toronto.edu)
|
|
|
|
* Modified it to make it print the message using only one
|
|
|
|
* dprintf[_]ver call.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static void ver_dstring(
|
|
|
|
char const * prologue,
|
|
|
|
char const * teststring,
|
|
|
|
char const * epilogue )
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("%s %p (\"%s\") %s\n", prologue,
|
1999-01-31 11:11:54 +01:00
|
|
|
(void const *) teststring,
|
|
|
|
teststring ? teststring : "(null)",
|
|
|
|
epilogue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* int testFileExistence(
|
|
|
|
* char const * path,
|
|
|
|
* char const * file )
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static int testFileExistence(
|
|
|
|
char const * path,
|
|
|
|
char const * file )
|
|
|
|
{
|
|
|
|
char filename[1024];
|
|
|
|
int filenamelen;
|
|
|
|
OFSTRUCT fileinfo;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if(OpenFile(filename, &fileinfo, OF_EXIST) == HFILE_ERROR)
|
1999-01-31 11:11:54 +01:00
|
|
|
retval = 0;
|
|
|
|
else
|
|
|
|
retval = 1;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* int testFileExclusiveExistence(
|
|
|
|
* char const * path,
|
|
|
|
* char const * file )
|
|
|
|
*
|
|
|
|
* Tests whether a given path/file combination exists and ensures that no
|
|
|
|
* other programs have handles to the given file. If the file does not
|
|
|
|
* exist or is open, 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static int testFileExclusiveExistence(
|
|
|
|
char const * path,
|
|
|
|
char const * file )
|
|
|
|
{
|
|
|
|
char filename[1024];
|
|
|
|
int filenamelen;
|
|
|
|
OFSTRUCT fileinfo;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if(OpenFile(filename, &fileinfo, OF_EXIST | OF_SHARE_EXCLUSIVE) ==
|
|
|
|
HFILE_ERROR)
|
1999-01-31 11:11:54 +01:00
|
|
|
retval = 0;
|
|
|
|
else
|
|
|
|
retval = 1;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2000-03-24 21:46:04 +01:00
|
|
|
* VerFindFileA() [VER.8]
|
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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* VerFindFile32A [VERSION.5] */
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI VerFindFileA(
|
|
|
|
UINT flags,
|
1999-01-31 11:11:54 +01:00
|
|
|
LPCSTR lpszFilename,
|
|
|
|
LPCSTR lpszWinDir,
|
|
|
|
LPCSTR lpszAppDir,
|
|
|
|
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
|
|
|
{
|
|
|
|
DWORD retval;
|
|
|
|
char curDir[256];
|
|
|
|
char destDir[256];
|
|
|
|
unsigned int curDirSizeReq;
|
|
|
|
unsigned int destDirSizeReq;
|
|
|
|
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
/* Print out debugging information */
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("called with parameters:\n"
|
1999-01-31 11:11:54 +01:00
|
|
|
"\tflags = %x", flags);
|
|
|
|
if(flags & VFFF_ISSHAREDFILE)
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE(" (VFFF_ISSHAREDFILE)\n");
|
1999-01-31 11:11:54 +01:00
|
|
|
else
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("\n");
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
ver_dstring("\tlpszFilename = ", lpszFilename, "");
|
|
|
|
ver_dstring("\tlpszWinDir = ", lpszWinDir, "");
|
|
|
|
ver_dstring("\tlpszAppDir = ", lpszAppDir, "");
|
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("\tlpszCurDir = %p\n", lpszCurDir);
|
1999-01-31 11:11:54 +01:00
|
|
|
if(lpuCurDirLen)
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("\tlpuCurDirLen = %p (%u)\n",
|
1999-01-31 11:11:54 +01:00
|
|
|
lpuCurDirLen, *lpuCurDirLen);
|
|
|
|
else
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("\tlpuCurDirLen = (null)\n");
|
1999-01-31 11:11:54 +01:00
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("\tlpszDestDir = %p\n", lpszDestDir);
|
1999-01-31 11:11:54 +01:00
|
|
|
if(lpuDestDirLen)
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("\tlpuDestDirLen = %p (%u)\n",
|
1999-01-31 11:11:54 +01:00
|
|
|
lpuDestDirLen, *lpuDestDirLen);
|
|
|
|
|
|
|
|
/* Figure out where the file should go; shared files default to the
|
|
|
|
system directory */
|
|
|
|
|
|
|
|
strcpy(curDir, "");
|
|
|
|
strcpy(destDir, "");
|
|
|
|
|
|
|
|
if(flags & VFFF_ISSHAREDFILE) {
|
1999-02-26 12:11:13 +01:00
|
|
|
GetSystemDirectoryA(destDir, 256);
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
/* Were we given a filename? If so, try to find the file. */
|
|
|
|
if(lpszFilename) {
|
|
|
|
if(testFileExistence(destDir, lpszFilename)) {
|
|
|
|
strcpy(curDir, destDir);
|
|
|
|
|
|
|
|
if(!testFileExclusiveExistence(destDir, lpszFilename))
|
|
|
|
retval |= VFF_FILEINUSE;
|
|
|
|
}
|
|
|
|
else if(lpszAppDir && testFileExistence(lpszAppDir,
|
|
|
|
lpszFilename)) {
|
|
|
|
strcpy(curDir, lpszAppDir);
|
|
|
|
retval |= VFF_CURNEDEST;
|
|
|
|
|
|
|
|
if(!testFileExclusiveExistence(lpszAppDir, lpszFilename))
|
|
|
|
retval |= VFF_FILEINUSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!(flags & VFFF_ISSHAREDFILE)) { /* not a shared file */
|
|
|
|
if(lpszAppDir) {
|
|
|
|
char systemDir[256];
|
1999-02-26 12:11:13 +01:00
|
|
|
GetSystemDirectoryA(systemDir, 256);
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
strcpy(destDir, lpszAppDir);
|
|
|
|
|
|
|
|
if(lpszFilename) {
|
|
|
|
if(testFileExistence(lpszAppDir, lpszFilename)) {
|
|
|
|
strcpy(curDir, lpszAppDir);
|
|
|
|
|
|
|
|
if(!testFileExclusiveExistence(lpszAppDir, lpszFilename))
|
|
|
|
retval |= VFF_FILEINUSE;
|
|
|
|
}
|
|
|
|
else if(testFileExistence(systemDir, lpszFilename)) {
|
|
|
|
strcpy(curDir, systemDir);
|
|
|
|
retval |= VFF_CURNEDEST;
|
|
|
|
|
|
|
|
if(!testFileExclusiveExistence(systemDir, lpszFilename))
|
|
|
|
retval |= VFF_FILEINUSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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! */
|
|
|
|
|
|
|
|
if(lpuDestDirLen && lpszDestDir) {
|
|
|
|
if(*lpuDestDirLen < destDirSizeReq) {
|
|
|
|
retval |= VFF_BUFFTOOSMALL;
|
1999-03-17 16:10:40 +01:00
|
|
|
if (*lpuDestDirLen) {
|
1999-12-27 06:24:06 +01:00
|
|
|
lstrcpynA(lpszDestDir, destDir, *lpuDestDirLen);
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
1999-03-17 16:10:40 +01:00
|
|
|
}
|
1999-01-31 11:11:54 +01:00
|
|
|
else
|
|
|
|
strcpy(lpszDestDir, destDir);
|
|
|
|
|
|
|
|
*lpuDestDirLen = destDirSizeReq;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(lpuCurDirLen && lpszCurDir) {
|
|
|
|
if(*lpuCurDirLen < curDirSizeReq) {
|
|
|
|
retval |= VFF_BUFFTOOSMALL;
|
1999-03-17 16:10:40 +01:00
|
|
|
if (*lpuCurDirLen) {
|
1999-12-27 06:24:06 +01:00
|
|
|
lstrcpynA(lpszCurDir, curDir, *lpuCurDirLen);
|
1999-03-17 16:10:40 +01:00
|
|
|
}
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
strcpy(lpszCurDir, curDir);
|
|
|
|
|
|
|
|
*lpuCurDirLen = curDirSizeReq;
|
|
|
|
}
|
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("ret = %lu (%s%s%s)\n", retval,
|
1999-01-31 11:11:54 +01:00
|
|
|
(retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
|
|
|
|
(retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
|
|
|
|
(retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "");
|
|
|
|
|
|
|
|
ver_dstring("\t(Exit) lpszCurDir = ", lpszCurDir, "");
|
|
|
|
if(lpuCurDirLen)
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("\t(Exit) lpuCurDirLen = %p (%u)\n",
|
1999-01-31 11:11:54 +01:00
|
|
|
lpuCurDirLen, *lpuCurDirLen);
|
|
|
|
else
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("\t(Exit) lpuCurDirLen = (null)\n");
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
ver_dstring("\t(Exit) lpszDestDir = ", lpszDestDir, "");
|
|
|
|
if(lpuDestDirLen)
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("\t(Exit) lpuDestDirLen = %p (%u)\n",
|
1999-01-31 11:11:54 +01:00
|
|
|
lpuDestDirLen, *lpuDestDirLen);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2000-03-24 21:46:04 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* VerFindFileW [VERSION.6]
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI VerFindFileW(
|
|
|
|
UINT flags,LPCWSTR filename,LPCWSTR windir,LPCWSTR appdir,
|
|
|
|
LPWSTR curdir,UINT *pcurdirlen,LPWSTR destdir,UINT *pdestdirlen )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
UINT curdirlen, destdirlen;
|
1999-01-31 11:11:54 +01:00
|
|
|
LPSTR wfn,wwd,wad,wdd,wcd;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
wfn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
|
|
|
|
wwd = HEAP_strdupWtoA( GetProcessHeap(), 0, windir );
|
|
|
|
wad = HEAP_strdupWtoA( GetProcessHeap(), 0, appdir );
|
|
|
|
wcd = HeapAlloc( GetProcessHeap(), 0, *pcurdirlen );
|
|
|
|
wdd = HeapAlloc( GetProcessHeap(), 0, *pdestdirlen );
|
1999-02-26 12:11:13 +01:00
|
|
|
ret = VerFindFileA(flags,wfn,wwd,wad,wcd,&curdirlen,wdd,&destdirlen);
|
1999-01-31 11:11:54 +01:00
|
|
|
lstrcpynAtoW(curdir,wcd,*pcurdirlen);
|
|
|
|
lstrcpynAtoW(destdir,wdd,*pdestdirlen);
|
|
|
|
*pcurdirlen = strlen(wcd);
|
|
|
|
*pdestdirlen = strlen(wdd);
|
|
|
|
HeapFree( GetProcessHeap(), 0, wfn );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wwd );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wad );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wcd );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wdd );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
WARN("Memory exausted while fetching version info!");
|
|
|
|
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) {
|
|
|
|
WARN("Memory exausted while fetching version info!");
|
|
|
|
return NULL;
|
|
|
|
}
|
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)
|
1999-05-14 10:17:14 +02:00
|
|
|
WARN("Bad VS_FIXEDFILEINFO signature 0x%08lx\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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2000-03-24 21:46:04 +01:00
|
|
|
* VerInstallFileA [VERSION.7]
|
1999-01-31 11:11:54 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI VerInstallFileA(
|
|
|
|
UINT flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
|
|
|
|
LPCSTR destdir,LPCSTR 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);
|
|
|
|
if (hfsrc==HFILE_ERROR)
|
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);
|
1999-01-31 11:11:54 +01:00
|
|
|
if (attr!=-1) {
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
attr = -1;
|
|
|
|
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.
|
|
|
|
* we jump over the copy part...
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (attr == -1) {
|
|
|
|
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);
|
1999-01-31 11:11:54 +01:00
|
|
|
if (((long) ret) < 0) {
|
|
|
|
/* 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) {
|
|
|
|
char *tbuf1,*tbuf2;
|
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;
|
1999-02-26 12:11:13 +01:00
|
|
|
if (VerQueryValueA(buf1,"\\VarFileInfo\\Translation",(LPVOID*)&tbuf1,&len1) &&
|
|
|
|
VerQueryValueA(buf2,"\\VarFileInfo\\Translation",(LPVOID*)&tbuf2,&len2)
|
1999-01-31 11:11:54 +01:00
|
|
|
) {
|
|
|
|
/* irgendwas mit tbuf1 und tbuf2 machen
|
|
|
|
* generiert DIFFLANG|MISMATCH
|
|
|
|
*/
|
|
|
|
}
|
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 {
|
1999-02-26 12:11:13 +01:00
|
|
|
if (-1!=GetFileAttributesA(destfn))
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if ((!(flags & VIFF_DONTDELETEOLD)) &&
|
|
|
|
curdir &&
|
|
|
|
*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);
|
1999-02-26 12:11:13 +01:00
|
|
|
if (-1!=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
|
|
|
/******************************************************************************
|
|
|
|
* VerInstallFileW [VERSION.8]
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI VerInstallFileW(
|
|
|
|
UINT flags,LPCWSTR srcfilename,LPCWSTR destfilename,LPCWSTR srcdir,
|
|
|
|
LPCWSTR destdir,LPCWSTR curdir,LPWSTR tmpfile,UINT *tmpfilelen )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
|
|
|
LPSTR wsrcf,wsrcd,wdestf,wdestd,wtmpf,wcurd;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
wsrcf = HEAP_strdupWtoA( GetProcessHeap(), 0, srcfilename );
|
|
|
|
wsrcd = HEAP_strdupWtoA( GetProcessHeap(), 0, srcdir );
|
|
|
|
wdestf = HEAP_strdupWtoA( GetProcessHeap(), 0, destfilename );
|
|
|
|
wdestd = HEAP_strdupWtoA( GetProcessHeap(), 0, destdir );
|
|
|
|
wtmpf = HEAP_strdupWtoA( GetProcessHeap(), 0, tmpfile );
|
|
|
|
wcurd = HEAP_strdupWtoA( GetProcessHeap(), 0, curdir );
|
1999-02-26 12:11:13 +01:00
|
|
|
ret = VerInstallFileA(flags,wsrcf,wdestf,wsrcd,wdestd,wcurd,wtmpf,tmpfilelen);
|
1999-01-31 11:11:54 +01:00
|
|
|
if (!ret)
|
|
|
|
lstrcpynAtoW(tmpfile,wtmpf,*tmpfilelen);
|
|
|
|
HeapFree( GetProcessHeap(), 0, wsrcf );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wsrcd );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wdestf );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wdestd );
|
|
|
|
HeapFree( GetProcessHeap(), 0, wtmpf );
|
|
|
|
if (wcurd)
|
|
|
|
HeapFree( GetProcessHeap(), 0, wcurd );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|