Merged version.dll with WINE 12-29-03

svn path=/trunk/; revision=7307
This commit is contained in:
Steven Edwards 2003-12-29 22:50:59 +00:00
parent 46376679ce
commit 3372617d7f
5 changed files with 1840 additions and 226 deletions

735
reactos/lib/version/info.c Normal file
View file

@ -0,0 +1,735 @@
/*
* Implementation of VERSION.DLL - Version Info access
*
* Copyright 1996,1997 Marcus Meissner
* Copyright 1997 David Cuthbert
* Copyright 1999 Ulrich Weigand
*
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* TODO
* o Verify VerQueryValue()
*/
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "winver.h"
#include "wine/debug.h"
#include "wine/unicode.h"
WINE_DEFAULT_DEBUG_CHANNEL(ver);
/******************************************************************************
*
* This function will print via dprintf[_]ver to stddeb debug info regarding
* the file info structure vffi.
* 15-Feb-1998 Dimitrie Paun (dimi@cs.toronto.edu)
* Added this function to clean up the code.
*
*****************************************************************************/
static void print_vffi_debug(VS_FIXEDFILEINFO *vffi)
{
TRACE(" structversion=%u.%u, fileversion=%u.%u.%u.%u, productversion=%u.%u.%u.%u, flagmask=0x%lx, flags=%s%s%s%s%s%s\n",
HIWORD(vffi->dwStrucVersion),LOWORD(vffi->dwStrucVersion),
HIWORD(vffi->dwFileVersionMS),LOWORD(vffi->dwFileVersionMS),
HIWORD(vffi->dwFileVersionLS),LOWORD(vffi->dwFileVersionLS),
HIWORD(vffi->dwProductVersionMS),LOWORD(vffi->dwProductVersionMS),
HIWORD(vffi->dwProductVersionLS),LOWORD(vffi->dwProductVersionLS),
vffi->dwFileFlagsMask,
(vffi->dwFileFlags & VS_FF_DEBUG) ? "DEBUG," : "",
(vffi->dwFileFlags & VS_FF_PRERELEASE) ? "PRERELEASE," : "",
(vffi->dwFileFlags & VS_FF_PATCHED) ? "PATCHED," : "",
(vffi->dwFileFlags & VS_FF_PRIVATEBUILD) ? "PRIVATEBUILD," : "",
(vffi->dwFileFlags & VS_FF_INFOINFERRED) ? "INFOINFERRED," : "",
(vffi->dwFileFlags & VS_FF_SPECIALBUILD) ? "SPECIALBUILD," : ""
);
TRACE("(");
TRACE(" OS=0x%x.0x%x ",
HIWORD(vffi->dwFileOS),
LOWORD(vffi->dwFileOS)
);
switch (vffi->dwFileOS&0xFFFF0000) {
case VOS_DOS:TRACE("DOS,");break;
case VOS_OS216:TRACE("OS/2-16,");break;
case VOS_OS232:TRACE("OS/2-32,");break;
case VOS_NT:TRACE("NT,");break;
case VOS_UNKNOWN:
default:
TRACE("UNKNOWN(0x%lx),",vffi->dwFileOS&0xFFFF0000);break;
}
switch (LOWORD(vffi->dwFileOS)) {
case VOS__BASE:TRACE("BASE");break;
case VOS__WINDOWS16:TRACE("WIN16");break;
case VOS__WINDOWS32:TRACE("WIN32");break;
case VOS__PM16:TRACE("PM16");break;
case VOS__PM32:TRACE("PM32");break;
default:TRACE("UNKNOWN(0x%x)",LOWORD(vffi->dwFileOS));break;
}
TRACE(")\n");
switch (vffi->dwFileType) {
default:
case VFT_UNKNOWN:
TRACE("filetype=Unknown(0x%lx)",vffi->dwFileType);
break;
case VFT_APP:TRACE("filetype=APP,");break;
case VFT_DLL:TRACE("filetype=DLL,");break;
case VFT_DRV:
TRACE("filetype=DRV,");
switch(vffi->dwFileSubtype) {
default:
case VFT2_UNKNOWN:
TRACE("UNKNOWN(0x%lx)",vffi->dwFileSubtype);
break;
case VFT2_DRV_PRINTER:
TRACE("PRINTER");
break;
case VFT2_DRV_KEYBOARD:
TRACE("KEYBOARD");
break;
case VFT2_DRV_LANGUAGE:
TRACE("LANGUAGE");
break;
case VFT2_DRV_DISPLAY:
TRACE("DISPLAY");
break;
case VFT2_DRV_MOUSE:
TRACE("MOUSE");
break;
case VFT2_DRV_NETWORK:
TRACE("NETWORK");
break;
case VFT2_DRV_SYSTEM:
TRACE("SYSTEM");
break;
case VFT2_DRV_INSTALLABLE:
TRACE("INSTALLABLE");
break;
case VFT2_DRV_SOUND:
TRACE("SOUND");
break;
case VFT2_DRV_COMM:
TRACE("COMM");
break;
case VFT2_DRV_INPUTMETHOD:
TRACE("INPUTMETHOD");
break;
}
break;
case VFT_FONT:
TRACE("filetype=FONT.");
switch (vffi->dwFileSubtype) {
default:
TRACE("UNKNOWN(0x%lx)",vffi->dwFileSubtype);
break;
case VFT2_FONT_RASTER:TRACE("RASTER");break;
case VFT2_FONT_VECTOR:TRACE("VECTOR");break;
case VFT2_FONT_TRUETYPE:TRACE("TRUETYPE");break;
}
break;
case VFT_VXD:TRACE("filetype=VXD");break;
case VFT_STATIC_LIB:TRACE("filetype=STATIC_LIB");break;
}
TRACE("\n");
TRACE(" filedata=0x%lx.0x%lx\n",
vffi->dwFileDateMS,vffi->dwFileDateLS);
}
/***********************************************************************
* Version Info Structure
*/
typedef struct
{
WORD wLength;
WORD wValueLength;
CHAR szKey[1];
#if 0 /* variable length structure */
/* DWORD aligned */
BYTE Value[];
/* DWORD aligned */
VS_VERSION_INFO_STRUCT16 Children[];
#endif
} VS_VERSION_INFO_STRUCT16;
typedef struct
{
WORD wLength;
WORD wValueLength;
WORD bText;
WCHAR szKey[1];
#if 0 /* variable length structure */
/* DWORD aligned */
BYTE Value[];
/* DWORD aligned */
VS_VERSION_INFO_STRUCT32 Children[];
#endif
} VS_VERSION_INFO_STRUCT32;
#define VersionInfoIs16( ver ) \
( ((VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
#define DWORD_ALIGN( base, ptr ) \
( (LPBYTE)(base) + ((((LPBYTE)(ptr) - (LPBYTE)(base)) + 3) & ~3) )
#define VersionInfo16_Value( ver ) \
DWORD_ALIGN( (ver), (ver)->szKey + strlen((ver)->szKey) + 1 )
#define VersionInfo32_Value( ver ) \
DWORD_ALIGN( (ver), (ver)->szKey + strlenW((ver)->szKey) + 1 )
#define VersionInfo16_Children( ver ) \
(VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
( ( (ver)->wValueLength + 3 ) & ~3 ) )
#define VersionInfo32_Children( ver ) \
(VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
( ( (ver)->wValueLength * \
((ver)->bText? 2 : 1) + 3 ) & ~3 ) )
#define VersionInfo16_Next( ver ) \
(VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
#define VersionInfo32_Next( ver ) \
(VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
/***********************************************************************
* ConvertVersionInfo32To16 [internal]
*/
void ConvertVersionInfo32To16( VS_VERSION_INFO_STRUCT32 *info32,
VS_VERSION_INFO_STRUCT16 *info16 )
{
/* Copy data onto local stack to prevent overwrites */
WORD wLength = info32->wLength;
WORD wValueLength = info32->wValueLength;
WORD bText = info32->bText;
LPBYTE lpValue = VersionInfo32_Value( info32 );
VS_VERSION_INFO_STRUCT32 *child32 = VersionInfo32_Children( info32 );
VS_VERSION_INFO_STRUCT16 *child16;
TRACE("Converting %p to %p\n", info32, info16 );
TRACE("wLength %d, wValueLength %d, bText %d, value %p, child %p\n",
wLength, wValueLength, bText, lpValue, child32 );
/* Convert key */
WideCharToMultiByte( CP_ACP, 0, info32->szKey, -1, info16->szKey, 0x7fffffff, NULL, NULL );
TRACE("Copied key from %p to %p: %s\n", info32->szKey, info16->szKey,
debugstr_a(info16->szKey) );
/* Convert value */
if ( wValueLength == 0 )
{
info16->wValueLength = 0;
TRACE("No value present\n" );
}
else if ( bText )
{
info16->wValueLength = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lpValue, -1, NULL, 0, NULL, NULL );
WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lpValue, -1,
VersionInfo16_Value( info16 ), info16->wValueLength, NULL, NULL );
TRACE("Copied value from %p to %p: %s\n", lpValue,
VersionInfo16_Value( info16 ),
debugstr_a(VersionInfo16_Value( info16 )) );
}
else
{
info16->wValueLength = wValueLength;
memmove( VersionInfo16_Value( info16 ), lpValue, wValueLength );
TRACE("Copied value from %p to %p: %d bytes\n", lpValue,
VersionInfo16_Value( info16 ), wValueLength );
}
/* Convert children */
child16 = VersionInfo16_Children( info16 );
while ( (DWORD)child32 < (DWORD)info32 + wLength && child32->wLength != 0 )
{
VS_VERSION_INFO_STRUCT32 *nextChild = VersionInfo32_Next( child32 );
ConvertVersionInfo32To16( child32, child16 );
child16 = VersionInfo16_Next( child16 );
child32 = nextChild;
}
/* Fixup length */
info16->wLength = (DWORD)child16 - (DWORD)info16;
TRACE("Finished, length is %d (%p - %p)\n",
info16->wLength, info16, child16 );
}
/***********************************************************************
* VERSION_GetFileVersionInfo_PE [internal]
*
* NOTE: returns size of the PE VERSION resource or 0xFFFFFFFF
* in the case if file exists, but VERSION_INFO not found.
* FIXME: handle is not used.
*/
static DWORD VERSION_GetFileVersionInfo_PE( LPCSTR filename, LPDWORD handle,
DWORD datasize, LPVOID data )
{
VS_FIXEDFILEINFO *vffi;
DWORD len;
BYTE *buf;
HMODULE hModule;
HRSRC hRsrc;
HGLOBAL hMem;
TRACE("(%s,%p)\n", debugstr_a(filename), handle );
hModule = GetModuleHandleA(filename);
if(!hModule)
hModule = LoadLibraryExA(filename, 0, LOAD_LIBRARY_AS_DATAFILE);
else
hModule = LoadLibraryExA(filename, 0, 0);
if(!hModule)
{
WARN("Could not load %s\n", debugstr_a(filename));
return 0;
}
hRsrc = FindResourceW(hModule,
MAKEINTRESOURCEW(VS_VERSION_INFO),
MAKEINTRESOURCEW(VS_FILE_INFO));
if(!hRsrc)
{
WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_a(filename));
FreeLibrary(hModule);
return 0xFFFFFFFF;
}
len = SizeofResource(hModule, hRsrc);
hMem = LoadResource(hModule, hRsrc);
if(!hMem)
{
WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_a(filename));
FreeLibrary(hModule);
return 0xFFFFFFFF;
}
buf = LockResource(hMem);
vffi = (VS_FIXEDFILEINFO *)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32 *)buf );
if ( vffi->dwSignature != VS_FFI_SIGNATURE )
{
WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
vffi->dwSignature, VS_FFI_SIGNATURE );
len = 0xFFFFFFFF;
goto END;
}
if ( TRACE_ON(ver) )
print_vffi_debug( vffi );
if(data)
{
if(datasize < len)
len = datasize; /* truncate data */
if(len)
memcpy(data, buf, len);
else
len = 0xFFFFFFFF;
}
END:
FreeResource(hMem);
FreeLibrary(hModule);
return len;
}
/***********************************************************************
* VERSION_GetFileVersionInfo_16 [internal]
*
* NOTE: returns size of the 16-bit VERSION resource or 0xFFFFFFFF
* in the case if file exists, but VERSION_INFO not found.
* FIXME: handle is not used.
*/
static DWORD VERSION_GetFileVersionInfo_16( LPCSTR filename, LPDWORD handle,
DWORD datasize, LPVOID data )
{
#ifndef __MINGW32__
VS_FIXEDFILEINFO *vffi;
DWORD len;
BYTE *buf;
HMODULE16 hModule;
HRSRC16 hRsrc;
HGLOBAL16 hMem;
TRACE("(%s,%p)\n", debugstr_a(filename), handle );
hModule = LoadLibrary16(filename);
if(hModule < 32)
{
WARN("Could not load %s\n", debugstr_a(filename));
return 0;
}
hRsrc = FindResource16(hModule,
MAKEINTRESOURCEA(VS_VERSION_INFO),
MAKEINTRESOURCEA(VS_FILE_INFO));
if(!hRsrc)
{
WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_a(filename));
FreeLibrary16(hModule);
return 0xFFFFFFFF;
}
len = SizeofResource16(hModule, hRsrc);
hMem = LoadResource16(hModule, hRsrc);
if(!hMem)
{
WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_a(filename));
FreeLibrary16(hModule);
return 0xFFFFFFFF;
}
buf = LockResource16(hMem);
if(!VersionInfoIs16(buf))
goto END;
vffi = (VS_FIXEDFILEINFO *)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16 *)buf );
if ( vffi->dwSignature != VS_FFI_SIGNATURE )
{
WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
vffi->dwSignature, VS_FFI_SIGNATURE );
len = 0xFFFFFFFF;
goto END;
}
if ( TRACE_ON(ver) )
print_vffi_debug( vffi );
if(data)
{
if(datasize < len)
len = datasize; /* truncate data */
if(len)
memcpy(data, buf, len);
else
len = 0xFFFFFFFF;
}
END:
FreeResource16(hMem);
FreeLibrary16(hModule);
return len;
#else /* __MINGW32__ */
FIXME("No Support for 16bit version information on ReactOS\n");
#endif /* __MINGW32__ */
}
/***********************************************************************
* GetFileVersionInfoSizeA [VERSION.@]
*/
DWORD WINAPI GetFileVersionInfoSizeA( LPCSTR filename, LPDWORD handle )
{
VS_FIXEDFILEINFO *vffi;
DWORD len, ret, offset;
BYTE buf[144];
TRACE("(%s,%p)\n", debugstr_a(filename), handle );
len = VERSION_GetFileVersionInfo_PE(filename, handle, 0, NULL);
/* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
if(len == 0xFFFFFFFF)
{
SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
return 0;
}
if(len) return len;
len = VERSION_GetFileVersionInfo_16(filename, handle, 0, NULL);
/* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
if(len == 0xFFFFFFFF)
{
SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
return 0;
}
if(len) return len;
len = GetFileResourceSize16( filename,
MAKEINTRESOURCEA(VS_FILE_INFO),
MAKEINTRESOURCEA(VS_VERSION_INFO),
&offset );
if (!len) return 0;
ret = GetFileResource16( filename,
MAKEINTRESOURCEA(VS_FILE_INFO),
MAKEINTRESOURCEA(VS_VERSION_INFO),
offset, sizeof( buf ), buf );
if (!ret) return 0;
if ( handle ) *handle = offset;
if ( VersionInfoIs16( buf ) )
vffi = (VS_FIXEDFILEINFO *)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16 *)buf );
else
vffi = (VS_FIXEDFILEINFO *)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32 *)buf );
if ( vffi->dwSignature != VS_FFI_SIGNATURE )
{
WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
vffi->dwSignature, VS_FFI_SIGNATURE );
return 0;
}
if ( ((VS_VERSION_INFO_STRUCT16 *)buf)->wLength < len )
len = ((VS_VERSION_INFO_STRUCT16 *)buf)->wLength;
if ( TRACE_ON(ver) )
print_vffi_debug( vffi );
return len;
}
/***********************************************************************
* GetFileVersionInfoSizeW [VERSION.@]
*/
DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle )
{
DWORD ret, len = WideCharToMultiByte( CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL );
LPSTR fn = HeapAlloc( GetProcessHeap(), 0, len );
WideCharToMultiByte( CP_ACP, 0, filename, -1, fn, len, NULL, NULL );
ret = GetFileVersionInfoSizeA( fn, handle );
HeapFree( GetProcessHeap(), 0, fn );
return ret;
}
/***********************************************************************
* GetFileVersionInfoA [VERSION.@]
*/
BOOL WINAPI GetFileVersionInfoA( LPCSTR filename, DWORD handle,
DWORD datasize, LPVOID data )
{
DWORD len;
TRACE("(%s,%ld,size=%ld,data=%p)\n",
debugstr_a(filename), handle, datasize, data );
len = VERSION_GetFileVersionInfo_PE(filename, &handle, datasize, data);
/* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
if(len == 0xFFFFFFFF) return FALSE;
if(len)
goto DO_CONVERT;
len = VERSION_GetFileVersionInfo_16(filename, &handle, datasize, data);
/* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
if(len == 0xFFFFFFFF) return FALSE;
if(len)
goto DO_CONVERT;
if ( !GetFileResource16( filename, MAKEINTRESOURCEA(VS_FILE_INFO),
MAKEINTRESOURCEA(VS_VERSION_INFO),
handle, datasize, data ) )
return FALSE;
DO_CONVERT:
if ( datasize >= sizeof(VS_VERSION_INFO_STRUCT16)
&& datasize >= ((VS_VERSION_INFO_STRUCT16 *)data)->wLength
&& !VersionInfoIs16( data ) )
{
/* convert resource from PE format to NE format */
ConvertVersionInfo32To16( (VS_VERSION_INFO_STRUCT32 *)data,
(VS_VERSION_INFO_STRUCT16 *)data );
}
return TRUE;
}
/***********************************************************************
* GetFileVersionInfoW [VERSION.@]
*/
BOOL WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle,
DWORD datasize, LPVOID data )
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL );
LPSTR fn = HeapAlloc( GetProcessHeap(), 0, len );
DWORD retv = TRUE;
WideCharToMultiByte( CP_ACP, 0, filename, -1, fn, len, NULL, NULL );
TRACE("(%s,%ld,size=%ld,data=%p)\n",
debugstr_w(filename), handle, datasize, data );
if(VERSION_GetFileVersionInfo_PE(fn, &handle, datasize, data))
goto END;
if(VERSION_GetFileVersionInfo_16(fn, &handle, datasize, data))
goto END;
if ( !GetFileResource16( fn, MAKEINTRESOURCEA(VS_FILE_INFO),
MAKEINTRESOURCEA(VS_VERSION_INFO),
handle, datasize, data ) )
retv = FALSE;
else if ( datasize >= sizeof(VS_VERSION_INFO_STRUCT16)
&& datasize >= ((VS_VERSION_INFO_STRUCT16 *)data)->wLength
&& VersionInfoIs16( data ) )
{
ERR("Cannot access NE resource in %s\n", debugstr_a(fn) );
retv = FALSE;
}
END:
HeapFree( GetProcessHeap(), 0, fn );
return retv;
}
/***********************************************************************
* VersionInfo16_FindChild [internal]
*/
static VS_VERSION_INFO_STRUCT16 *VersionInfo16_FindChild( VS_VERSION_INFO_STRUCT16 *info,
LPCSTR szKey, UINT cbKey )
{
VS_VERSION_INFO_STRUCT16 *child = VersionInfo16_Children( info );
while ( (DWORD)child < (DWORD)info + info->wLength )
{
if ( !strncasecmp( child->szKey, szKey, cbKey ) )
return child;
if (!(child->wLength)) return NULL;
child = VersionInfo16_Next( child );
}
return NULL;
}
/***********************************************************************
* VersionInfo32_FindChild [internal]
*/
static VS_VERSION_INFO_STRUCT32 *VersionInfo32_FindChild( VS_VERSION_INFO_STRUCT32 *info,
LPCWSTR szKey, UINT cbKey )
{
VS_VERSION_INFO_STRUCT32 *child = VersionInfo32_Children( info );
while ( (DWORD)child < (DWORD)info + info->wLength )
{
if ( !strncmpiW( child->szKey, szKey, cbKey ) )
return child;
child = VersionInfo32_Next( child );
}
return NULL;
}
/***********************************************************************
* VerQueryValueA [VERSION.@]
*/
DWORD WINAPI VerQueryValueA( LPVOID pBlock, LPCSTR lpSubBlock,
LPVOID *lplpBuffer, UINT *puLen )
{
VS_VERSION_INFO_STRUCT16 *info = (VS_VERSION_INFO_STRUCT16 *)pBlock;
if ( !VersionInfoIs16( info ) )
{
INT len;
LPWSTR wide_str;
DWORD give;
/* <lawson_whitney@juno.com> Feb 2001 */
/* AOL 5.0 does this, expecting to get this: */
len = MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, NULL, 0);
wide_str = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, wide_str, len);
give = VerQueryValueW(pBlock, wide_str, lplpBuffer, puLen);
HeapFree(GetProcessHeap(), 0, wide_str);
return give;
}
TRACE("(%p,%s,%p,%p)\n",
pBlock, debugstr_a(lpSubBlock), lplpBuffer, puLen );
while ( *lpSubBlock )
{
/* Find next path component */
LPCSTR lpNextSlash;
for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
if ( *lpNextSlash == '\\' )
break;
/* Skip empty components */
if ( lpNextSlash == lpSubBlock )
{
lpSubBlock++;
continue;
}
/* We have a non-empty component: search info for key */
info = VersionInfo16_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
if ( !info ) return FALSE;
/* Skip path component */
lpSubBlock = lpNextSlash;
}
/* Return value */
*lplpBuffer = VersionInfo16_Value( info );
*puLen = info->wValueLength;
return TRUE;
}
/***********************************************************************
* VerQueryValueW [VERSION.@]
*/
DWORD WINAPI VerQueryValueW( LPVOID pBlock, LPCWSTR lpSubBlock,
LPVOID *lplpBuffer, UINT *puLen )
{
VS_VERSION_INFO_STRUCT32 *info = (VS_VERSION_INFO_STRUCT32 *)pBlock;
if ( VersionInfoIs16( info ) )
{
ERR("called on NE resource!\n" );
return FALSE;
}
TRACE("(%p,%s,%p,%p)\n",
pBlock, debugstr_w(lpSubBlock), lplpBuffer, puLen );
while ( *lpSubBlock )
{
/* Find next path component */
LPCWSTR lpNextSlash;
for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
if ( *lpNextSlash == '\\' )
break;
/* Skip empty components */
if ( lpNextSlash == lpSubBlock )
{
lpSubBlock++;
continue;
}
/* We have a non-empty component: search info for key */
info = VersionInfo32_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
if ( !info ) return FALSE;
/* Skip path component */
lpSubBlock = lpNextSlash;
}
/* Return value */
*lplpBuffer = VersionInfo32_Value( info );
*puLen = info->wValueLength;
return TRUE;
}

View file

@ -0,0 +1,589 @@
/*
* Implementation of VERSION.DLL - File Installer routines
*
* Copyright 1996,1997 Marcus Meissner
* Copyright 1997 David Cuthbert
*
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* TODO
* o Check the installation functions.
*/
#include "config.h"
#include "wine/port.h"
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winver.h"
#include "winnls.h"
#include "wine/unicode.h"
#include "winerror.h"
#include "lzexpand.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ver);
/* Couple of Hacks */
extern inline DWORD WINAPI GetLastError(void)
{
DWORD ret;
__asm__ __volatile__( ".byte 0x64\n\tmovl 0x60,%0" : "=r" (ret) );
return ret;
}
/******************************************************************************
* testFileExistenceA
*
* 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 testFileExistenceA( char const * path, char const * file, BOOL excl )
{
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);
return (OpenFile(filename, &fileinfo,
OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0)) != HFILE_ERROR);
}
/******************************************************************************
* testFileExistenceW
*/
static int testFileExistenceW( const WCHAR *path, const WCHAR *file, BOOL excl )
{
char *filename;
DWORD pathlen, filelen;
int ret;
OFSTRUCT fileinfo;
fileinfo.cBytes = sizeof(OFSTRUCT);
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 );
WideCharToMultiByte( CP_ACP, 0, path, -1, filename, pathlen, NULL, NULL );
/* Add a trailing \ if necessary */
if (pathlen > 1)
{
if (filename[pathlen-2] != '\\') strcpy( &filename[pathlen-1], "\\" );
}
else /* specify the current directory */
strcpy(filename, ".\\");
WideCharToMultiByte( CP_ACP, 0, file, -1, filename+strlen(filename), filelen, NULL, NULL );
ret = (OpenFile(filename, &fileinfo,
OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0)) != HFILE_ERROR);
HeapFree( GetProcessHeap(), 0, filename );
return ret;
}
/*****************************************************************************
* VerFindFileA [VERSION.@]
*
* 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.
*/
DWORD WINAPI VerFindFileA(
UINT flags,
LPCSTR lpszFilename,
LPCSTR lpszWinDir,
LPCSTR lpszAppDir,
LPSTR lpszCurDir,
UINT *lpuCurDirLen,
LPSTR lpszDestDir,
UINT *lpuDestDirLen )
{
DWORD retval = 0;
const char *curDir;
const char *destDir;
unsigned int curDirSizeReq;
unsigned int destDirSizeReq;
char systemDir[MAX_PATH];
/* Print out debugging information */
TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
flags, debugstr_a(lpszFilename), debugstr_a(lpszWinDir), debugstr_a(lpszAppDir),
lpuCurDirLen, lpuCurDirLen ? *lpuCurDirLen : 0,
lpuDestDirLen, lpuDestDirLen ? *lpuDestDirLen : 0 );
/* Figure out where the file should go; shared files default to the
system directory */
GetSystemDirectoryA(systemDir, sizeof(systemDir));
curDir = "";
destDir = "";
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;
}
}
}
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;
}
}
}
}
if (lpszFilename && !testFileExistenceA(curDir, lpszFilename, TRUE))
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;
lstrcpynA(lpszDestDir, destDir, *lpuDestDirLen);
*lpuDestDirLen = destDirSizeReq;
}
if(lpuCurDirLen && lpszCurDir)
{
if(*lpuCurDirLen < curDirSizeReq) retval |= VFF_BUFFTOOSMALL;
lstrcpynA(lpszCurDir, curDir, *lpuCurDirLen);
*lpuCurDirLen = curDirSizeReq;
}
TRACE("ret = %lu (%s%s%s) curdir=%s destdir=%s\n", retval,
(retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
(retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
(retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "",
debugstr_a(lpszCurDir), debugstr_a(lpszDestDir));
return retval;
}
/*****************************************************************************
* VerFindFileW [VERSION.@]
*/
DWORD WINAPI VerFindFileW( UINT flags,LPCWSTR lpszFilename,LPCWSTR lpszWinDir,
LPCWSTR lpszAppDir, LPWSTR lpszCurDir,UINT *lpuCurDirLen,
LPWSTR lpszDestDir,UINT *lpuDestDirLen )
{
static const WCHAR emptyW;
DWORD retval = 0;
const WCHAR *curDir;
const WCHAR *destDir;
unsigned int curDirSizeReq;
unsigned int destDirSizeReq;
WCHAR systemDir[MAX_PATH];
/* Print out debugging information */
TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
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;
}
TRACE("ret = %lu (%s%s%s) curdir=%s destdir=%s\n", retval,
(retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
(retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
(retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "",
debugstr_w(lpszCurDir), debugstr_w(lpszDestDir));
return retval;
}
static LPBYTE
_fetch_versioninfo(LPSTR fn,VS_FIXEDFILEINFO **vffi) {
DWORD alloclen;
LPBYTE buf;
DWORD ret;
alloclen = 1000;
buf=HeapAlloc(GetProcessHeap(), 0, alloclen);
if(buf == NULL) {
WARN("Memory exausted while fetching version info!\n");
return NULL;
}
while (1) {
ret = GetFileVersionInfoA(fn,0,alloclen,buf);
if (!ret) {
HeapFree(GetProcessHeap(), 0, buf);
return NULL;
}
if (alloclen<*(WORD*)buf) {
alloclen = *(WORD*)buf;
HeapFree(GetProcessHeap(), 0, buf);
buf = HeapAlloc(GetProcessHeap(), 0, alloclen);
if(buf == NULL) {
WARN("Memory exausted while fetching version info!\n");
return NULL;
}
} 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)
WARN("Bad VS_FIXEDFILEINFO signature 0x%08lx\n",(*vffi)->dwSignature);
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;
}
}
/******************************************************************************
* VerInstallFileA [VERSION.@]
*/
DWORD WINAPI VerInstallFileA(
UINT flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
LPCSTR destdir,LPCSTR curdir,LPSTR tmpfile,UINT *tmpfilelen )
{
LPCSTR pdest;
char destfn[260],tmpfn[260],srcfn[260];
HFILE hfsrc,hfdst;
DWORD attr,ret,xret,tmplast;
LPBYTE buf1,buf2;
OFSTRUCT ofs;
TRACE("(%x,%s,%s,%s,%s,%s,%p,%d)\n",
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);
hfsrc=LZOpenFileA(srcfn,&ofs,OF_READ);
if (hfsrc < 0)
return VIF_CANNOTREADSRC;
sprintf(tmpfn,"%s\\%s",pdest,destfilename);
tmplast=strlen(pdest)+1;
attr = GetFileAttributesA(tmpfn);
if (attr != INVALID_FILE_ATTRIBUTES) {
if (attr & FILE_ATTRIBUTE_READONLY) {
LZClose(hfsrc);
return VIF_WRITEPROT;
}
/* FIXME: check if file currently in use and return VIF_FILEINUSE */
}
attr = INVALID_FILE_ATTRIBUTES;
if (flags & VIFF_FORCEINSTALL) {
if (tmpfile[0]) {
sprintf(tmpfn,"%s\\%s",pdest,tmpfile);
tmplast = strlen(pdest)+1;
attr = GetFileAttributesA(tmpfn);
/* if it exists, it has been copied by the call before.
* we jump over the copy part...
*/
}
}
if (attr == INVALID_FILE_ATTRIBUTES) {
char *s;
GetTempFileNameA(pdest,"ver",0,tmpfn); /* should not fail ... */
s=strrchr(tmpfn,'\\');
if (s)
tmplast = s-tmpfn;
else
tmplast = 0;
hfdst = OpenFile(tmpfn,&ofs,OF_CREATE);
if (hfdst == HFILE_ERROR) {
LZClose(hfsrc);
return VIF_CANNOTCREATE; /* | translated dos error */
}
ret = LZCopy(hfsrc,hfdst);
_lclose(hfdst);
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:
ret = VIF_OUTOFSPACE;
break;
case LZERROR_GLOBALLOC:
case LZERROR_GLOBLOCK:
ret = VIF_OUTOFMEMORY;
break;
default: /* unknown error, should not happen */
ret = 0;
break;
}
if (ret) {
LZClose(hfsrc);
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;
UINT len1,len2;
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;
if (VerQueryValueA(buf1,"\\VarFileInfo\\Translation",(LPVOID*)&tbuf1,&len1) &&
VerQueryValueA(buf2,"\\VarFileInfo\\Translation",(LPVOID*)&tbuf2,&len2)
) {
/* irgendwas mit tbuf1 und tbuf2 machen
* generiert DIFFLANG|MISMATCH
*/
}
HeapFree(GetProcessHeap(), 0, buf2);
} else
xret=VIF_MISMATCH|VIF_SRCOLD;
HeapFree(GetProcessHeap(), 0, buf1);
}
}
if (xret) {
if (*tmpfilelen<strlen(tmpfn+tmplast)) {
xret|=VIF_BUFFTOOSMALL;
DeleteFileA(tmpfn);
} else {
strcpy(tmpfile,tmpfn+tmplast);
*tmpfilelen = strlen(tmpfn+tmplast)+1;
xret|=VIF_TEMPFILE;
}
} else {
if (-1!=GetFileAttributesA(destfn))
if (!DeleteFileA(destfn)) {
xret|=_error2vif(GetLastError())|VIF_CANNOTDELETE;
DeleteFileA(tmpfn);
LZClose(hfsrc);
return xret;
}
if ((!(flags & VIFF_DONTDELETEOLD)) &&
curdir &&
*curdir &&
lstrcmpiA(curdir,pdest)
) {
char curfn[260];
sprintf(curfn,"%s\\%s",curdir,destfilename);
if (INVALID_FILE_ATTRIBUTES != GetFileAttributesA(curfn)) {
/* FIXME: check if in use ... if it is, VIF_CANNOTDELETECUR */
if (!DeleteFileA(curfn))
xret|=_error2vif(GetLastError())|VIF_CANNOTDELETECUR;
}
}
if (!MoveFileA(tmpfn,destfn)) {
xret|=_error2vif(GetLastError())|VIF_CANNOTRENAME;
DeleteFileA(tmpfn);
}
}
LZClose(hfsrc);
return xret;
}
/******************************************************************************
* VerInstallFileW [VERSION.@]
*/
DWORD WINAPI VerInstallFileW(
UINT flags,LPCWSTR srcfilename,LPCWSTR destfilename,LPCWSTR srcdir,
LPCWSTR destdir,LPCWSTR curdir,LPWSTR tmpfile,UINT *tmpfilelen )
{
LPSTR wsrcf = NULL, wsrcd = NULL, wdestf = NULL, wdestd = NULL, wtmpf = NULL, wcurd = NULL;
DWORD ret;
UINT len;
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);
if (!ret)
*tmpfilelen = MultiByteToWideChar( CP_ACP, 0, wtmpf, -1, tmpfile, *tmpfilelen );
else if (ret & VIF_BUFFTOOSMALL)
*tmpfilelen = len; /* FIXME: not correct */
HeapFree( GetProcessHeap(), 0, wsrcf );
HeapFree( GetProcessHeap(), 0, wsrcd );
HeapFree( GetProcessHeap(), 0, wdestf );
HeapFree( GetProcessHeap(), 0, wdestd );
HeapFree( GetProcessHeap(), 0, wtmpf );
HeapFree( GetProcessHeap(), 0, wcurd );
return ret;
}

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.13 2003/09/12 17:51:48 vizzini Exp $
# $Id: makefile,v 1.14 2003/12/29 22:50:59 sedwards Exp $
PATH_TO_TOP = ../..
@ -8,18 +8,33 @@ TARGET_NAME = version
TARGET_BASE = 0x77a90000
TARGET_CFLAGS = -fno-builtin -Werror -Wall
TARGET_CFLAGS = -fno-builtin -Wall
# require os code to explicitly request A/W version of structs/functions
TARGET_CFLAGS += -D_DISABLE_TIDENTS
DEFINES = \
-D_DISABLE_TIDENTS \
-D__USE_W32API \
-D__REACTOS__ \
-D_WIN32_IE=0x600 \
-D_WIN32_WINNT=0x501 \
-DWINVER=0x501
TARGET_CFLAGS += \
$(DEFINES) \
-I$(PATH_TO_TOP)/include/wine
TARGET_RCFLAGS += -D__REACTOS__ -D_WIN32_IE=0x600 -D_WIN32_WINNT=0x501
TARGET_LFLAGS = -nostdlib -nostartfiles
TARGET_SDKLIBS = kernel32.a ntdll.a
TARGET_SDKLIBS = libwine.a kernel32.a ntdll.a
TARGET_OBJECTS = misc/libmain.o misc/stubs.o
TARGET_CLEAN = misc/*.o
TARGET_OBJECTS = \
misc/libmain.o \
misc/stubs.o \
info.o \
install.o \
resource.o
include $(PATH_TO_TOP)/rules.mak

View file

@ -1,4 +1,4 @@
/* $Id: stubs.c,v 1.4 2003/07/10 21:07:14 chorns Exp $
/* $Id: stubs.c,v 1.5 2003/12/29 22:50:59 sedwards Exp $
*
* version.dll stubs: remove from this file if
* you implement one of these functions.
@ -7,223 +7,6 @@
#ifndef HAVE_DLL_FORWARD
/*
* @unimplemented
*/
DWORD
STDCALL
GetFileVersionInfoSizeA (
LPSTR lptstrFilename,
LPDWORD lpdwHandle
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
/*
* @unimplemented
*/
WINBOOL
STDCALL
GetFileVersionInfoA (
LPSTR lptstrFilename,
DWORD dwHandle,
DWORD dwLen,
LPVOID lpData
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
/*
* @unimplemented
*/
DWORD
STDCALL
GetFileVersionInfoSizeW (
LPWSTR lptstrFilename,
LPDWORD lpdwHandle
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
/*
* @unimplemented
*/
WINBOOL
STDCALL
GetFileVersionInfoW (
LPWSTR lptstrFilename,
DWORD dwHandle,
DWORD dwLen,
LPVOID lpData
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
#endif /* ndef HAVE_DLL_FORWARD */
/*
* @unimplemented
*/
DWORD
STDCALL
VerFindFileA (
DWORD uFlags,
LPSTR szFileName,
LPSTR szWinDir,
LPSTR szAppDir,
LPSTR szCurDir,
PUINT lpuCurDirLen,
LPSTR szDestDir,
PUINT lpuDestDirLen
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
/*
* @unimplemented
*/
DWORD
STDCALL
VerFindFileW (
DWORD uFlags,
LPWSTR szFileName,
LPWSTR szWinDir,
LPWSTR szAppDir,
LPWSTR szCurDir,
PUINT lpuCurDirLen,
LPWSTR szDestDir,
PUINT lpuDestDirLen
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
/*
* @unimplemented
*/
DWORD
STDCALL
VerInstallFileA (
DWORD uFlags,
LPSTR szSrcFileName,
LPSTR szDestFileName,
LPSTR szSrcDir,
LPSTR szDestDir,
LPSTR szCurDir,
LPSTR szTmpFile,
PUINT lpuTmpFileLen
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
/*
* @unimplemented
*/
DWORD
STDCALL
VerInstallFileW (
DWORD uFlags,
LPWSTR szSrcFileName,
LPWSTR szDestFileName,
LPWSTR szSrcDir,
LPWSTR szDestDir,
LPWSTR szCurDir,
LPWSTR szTmpFile,
PUINT lpuTmpFileLen
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
/*
* @unimplemented
*/
DWORD
STDCALL
VerLanguageNameA (
DWORD wLang,
LPSTR szLang,
DWORD nSize
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
/*
* @unimplemented
*/
DWORD
STDCALL
VerLanguageNameW (
DWORD wLang,
LPWSTR szLang,
DWORD nSize
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
/*
* @unimplemented
*/
WINBOOL
STDCALL
VerQueryValueA (
const LPVOID pBlock,
LPSTR lpSubBlock,
LPVOID * lplpBuffer,
PUINT puLen
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
/*
* @unimplemented
*/
WINBOOL
STDCALL
VerQueryValueW (
const LPVOID pBlock,
LPWSTR lpSubBlock,
LPVOID * lplpBuffer,
PUINT puLen
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
/* VerQueryValueIndex seems undocumented */
/*
@ -262,5 +45,5 @@ VerQueryValueIndexW (
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
#endif
/* EOF */

View file

@ -0,0 +1,492 @@
/*
* Implementation of VERSION.DLL - Resource Access routines
*
* Copyright 1996,1997 Marcus Meissner
* Copyright 1997 David Cuthbert
* Copyright 1999 Ulrich Weigand
*
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
//#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "windef.h"
#include "winbase.h"
#include "lzexpand.h"
#include "wine/unicode.h"
#include "winver.h"
#include "winnls.h"
#include "wine/debug.h"
/*
* Quick and dirty hacking
* -sedwards
*/
/* winnt.h */
#define IMAGE_FILE_RESOURCE_DIRECTORY 2
WINE_DEFAULT_DEBUG_CHANNEL(ver);
/**********************************************************************
* find_entry_by_id
*
* Find an entry by id in a resource directory
* Copied from loader/pe_resource.c
*/
static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_id( const IMAGE_RESOURCE_DIRECTORY *dir,
WORD id, const void *root )
{
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
int min, max, pos;
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
min = dir->NumberOfNamedEntries;
max = min + dir->NumberOfIdEntries - 1;
while (min <= max)
{
pos = (min + max) / 2;
if (entry[pos].Id == id)
return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].OffsetToDirectory);
if (entry[pos].Id > id) max = pos - 1;
}
return NULL;
}
/**********************************************************************
* find_entry_default
*
* Find a default entry in a resource directory
* Copied from loader/pe_resource.c
*/
static const IMAGE_RESOURCE_DIRECTORY *find_entry_default( const IMAGE_RESOURCE_DIRECTORY *dir,
const void *root )
{
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry->OffsetToDirectory);
}
/**********************************************************************
* find_entry_by_name
*
* Find an entry by name in a resource directory
* Copied from loader/pe_resource.c
*/
static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_name( const IMAGE_RESOURCE_DIRECTORY *dir,
LPCSTR name, const void *root )
{
const IMAGE_RESOURCE_DIRECTORY *ret = NULL;
LPWSTR nameW;
DWORD namelen;
if (!HIWORD(name)) return find_entry_by_id( dir, LOWORD(name), root );
if (name[0] == '#')
{
return find_entry_by_id( dir, atoi(name+1), root );
}
namelen = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
if ((nameW = HeapAlloc( GetProcessHeap(), 0, namelen * sizeof(WCHAR) )))
{
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
const IMAGE_RESOURCE_DIR_STRING_U *str;
int min, max, res, pos;
MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, namelen );
namelen--; /* remove terminating null */
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
min = 0;
max = dir->NumberOfNamedEntries - 1;
while (min <= max)
{
pos = (min + max) / 2;
str = (IMAGE_RESOURCE_DIR_STRING_U *)((char *)root + entry[pos].NameOffset);
res = strncmpiW( nameW, str->NameString, str->Length );
if (!res && namelen == str->Length)
{
ret = (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].OffsetToDirectory);
break;
}
if (res < 0) max = pos - 1;
else min = pos + 1;
}
HeapFree( GetProcessHeap(), 0, nameW );
}
return ret;
}
/***********************************************************************
* read_xx_header [internal]
*/
static int read_xx_header( HFILE lzfd )
{
IMAGE_DOS_HEADER mzh;
char magic[3];
LZSeek( lzfd, 0, SEEK_SET );
if ( sizeof(mzh) != LZRead( lzfd, (LPSTR)&mzh, sizeof(mzh) ) )
return 0;
if ( mzh.e_magic != IMAGE_DOS_SIGNATURE )
return 0;
LZSeek( lzfd, mzh.e_lfanew, SEEK_SET );
if ( 2 != LZRead( lzfd, magic, 2 ) )
return 0;
LZSeek( lzfd, mzh.e_lfanew, SEEK_SET );
if ( magic[0] == 'N' && magic[1] == 'E' )
return IMAGE_OS2_SIGNATURE;
if ( magic[0] == 'P' && magic[1] == 'E' )
return IMAGE_NT_SIGNATURE;
magic[2] = '\0';
WARN("Can't handle %s files.\n", magic );
return 0;
}
#ifndef __REACTOS__
/***********************************************************************
* load_ne_resource [internal]
*/
static BOOL find_ne_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
DWORD *resLen, DWORD *resOff )
{
IMAGE_OS2_HEADER nehd;
NE_TYPEINFO *typeInfo;
NE_NAMEINFO *nameInfo;
DWORD nehdoffset;
LPBYTE resTab;
DWORD resTabSize;
int count;
/* Read in NE header */
nehdoffset = LZSeek( lzfd, 0, SEEK_CUR );
if ( sizeof(nehd) != LZRead( lzfd, (LPSTR)&nehd, sizeof(nehd) ) ) return 0;
resTabSize = nehd.ne_restab - nehd.ne_rsrctab;
if ( !resTabSize )
{
TRACE("No resources in NE dll\n" );
return FALSE;
}
/* Read in resource table */
resTab = HeapAlloc( GetProcessHeap(), 0, resTabSize );
if ( !resTab ) return FALSE;
LZSeek( lzfd, nehd.ne_rsrctab + nehdoffset, SEEK_SET );
if ( resTabSize != LZRead( lzfd, resTab, resTabSize ) )
{
HeapFree( GetProcessHeap(), 0, resTab );
return FALSE;
}
/* Find resource */
typeInfo = (NE_TYPEINFO *)(resTab + 2);
if (HIWORD(typeid) != 0) /* named type */
{
BYTE len = strlen( typeid );
while (typeInfo->type_id)
{
if (!(typeInfo->type_id & 0x8000))
{
BYTE *p = resTab + typeInfo->type_id;
if ((*p == len) && !strncasecmp( p+1, typeid, len )) goto found_type;
}
typeInfo = (NE_TYPEINFO *)((char *)(typeInfo + 1) +
typeInfo->count * sizeof(NE_NAMEINFO));
}
}
else /* numeric type id */
{
WORD id = LOWORD(typeid) | 0x8000;
while (typeInfo->type_id)
{
if (typeInfo->type_id == id) goto found_type;
typeInfo = (NE_TYPEINFO *)((char *)(typeInfo + 1) +
typeInfo->count * sizeof(NE_NAMEINFO));
}
}
TRACE("No typeid entry found for %p\n", typeid );
HeapFree( GetProcessHeap(), 0, resTab );
return FALSE;
found_type:
nameInfo = (NE_NAMEINFO *)(typeInfo + 1);
if (HIWORD(resid) != 0) /* named resource */
{
BYTE len = strlen( resid );
for (count = typeInfo->count; count > 0; count--, nameInfo++)
{
BYTE *p = resTab + nameInfo->id;
if (nameInfo->id & 0x8000) continue;
if ((*p == len) && !strncasecmp( p+1, resid, len )) goto found_name;
}
}
else /* numeric resource id */
{
WORD id = LOWORD(resid) | 0x8000;
for (count = typeInfo->count; count > 0; count--, nameInfo++)
if (nameInfo->id == id) goto found_name;
}
TRACE("No resid entry found for %p\n", typeid );
HeapFree( GetProcessHeap(), 0, resTab );
return FALSE;
found_name:
/* Return resource data */
if ( resLen ) *resLen = nameInfo->length << *(WORD *)resTab;
if ( resOff ) *resOff = nameInfo->offset << *(WORD *)resTab;
HeapFree( GetProcessHeap(), 0, resTab );
return TRUE;
}
#endif /* __REACTOS__ */
/***********************************************************************
* load_pe_resource [internal]
*/
static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
DWORD *resLen, DWORD *resOff )
{
IMAGE_NT_HEADERS pehd;
DWORD pehdoffset;
PIMAGE_DATA_DIRECTORY resDataDir;
PIMAGE_SECTION_HEADER sections;
LPBYTE resSection;
DWORD resSectionSize;
const void *resDir;
const IMAGE_RESOURCE_DIRECTORY *resPtr;
const IMAGE_RESOURCE_DATA_ENTRY *resData;
int i, nSections;
BOOL ret = FALSE;
/* Read in PE header */
pehdoffset = LZSeek( lzfd, 0, SEEK_CUR );
if ( sizeof(pehd) != LZRead( lzfd, (LPSTR)&pehd, sizeof(pehd) ) ) return 0;
resDataDir = pehd.OptionalHeader.DataDirectory+IMAGE_FILE_RESOURCE_DIRECTORY;
if ( !resDataDir->Size )
{
TRACE("No resources in PE dll\n" );
return FALSE;
}
/* Read in section table */
nSections = pehd.FileHeader.NumberOfSections;
sections = HeapAlloc( GetProcessHeap(), 0,
nSections * sizeof(IMAGE_SECTION_HEADER) );
if ( !sections ) return FALSE;
LZSeek( lzfd, pehdoffset +
sizeof(DWORD) + /* Signature */
sizeof(IMAGE_FILE_HEADER) +
pehd.FileHeader.SizeOfOptionalHeader, SEEK_SET );
if ( nSections * sizeof(IMAGE_SECTION_HEADER) !=
LZRead( lzfd, (LPSTR)sections, nSections * sizeof(IMAGE_SECTION_HEADER) ) )
{
HeapFree( GetProcessHeap(), 0, sections );
return FALSE;
}
/* Find resource section */
for ( i = 0; i < nSections; i++ )
if ( resDataDir->VirtualAddress >= sections[i].VirtualAddress
&& resDataDir->VirtualAddress < sections[i].VirtualAddress +
sections[i].SizeOfRawData )
break;
if ( i == nSections )
{
HeapFree( GetProcessHeap(), 0, sections );
TRACE("Couldn't find resource section\n" );
return FALSE;
}
/* Read in resource section */
resSectionSize = sections[i].SizeOfRawData;
resSection = HeapAlloc( GetProcessHeap(), 0, resSectionSize );
if ( !resSection )
{
HeapFree( GetProcessHeap(), 0, sections );
return FALSE;
}
LZSeek( lzfd, sections[i].PointerToRawData, SEEK_SET );
if ( resSectionSize != LZRead( lzfd, resSection, resSectionSize ) ) goto done;
/* Find resource */
resDir = resSection + (resDataDir->VirtualAddress - sections[i].VirtualAddress);
resPtr = (PIMAGE_RESOURCE_DIRECTORY)resDir;
resPtr = find_entry_by_name( resPtr, typeid, resDir );
if ( !resPtr )
{
TRACE("No typeid entry found for %p\n", typeid );
goto done;
}
resPtr = find_entry_by_name( resPtr, resid, resDir );
if ( !resPtr )
{
TRACE("No resid entry found for %p\n", resid );
goto done;
}
resPtr = find_entry_default( resPtr, resDir );
if ( !resPtr )
{
TRACE("No default language entry found for %p\n", resid );
goto done;
}
/* Find resource data section */
resData = (PIMAGE_RESOURCE_DATA_ENTRY)resPtr;
for ( i = 0; i < nSections; i++ )
if ( resData->OffsetToData >= sections[i].VirtualAddress
&& resData->OffsetToData < sections[i].VirtualAddress +
sections[i].SizeOfRawData )
break;
if ( i == nSections )
{
TRACE("Couldn't find resource data section\n" );
goto done;
}
/* Return resource data */
if ( resLen ) *resLen = resData->Size;
if ( resOff ) *resOff = resData->OffsetToData - sections[i].VirtualAddress
+ sections[i].PointerToRawData;
ret = TRUE;
done:
HeapFree( GetProcessHeap(), 0, resSection );
HeapFree( GetProcessHeap(), 0, sections );
return ret;
}
/*************************************************************************
* GetFileResourceSize [VER.2]
*/
DWORD WINAPI GetFileResourceSize16( LPCSTR lpszFileName, LPCSTR lpszResType,
LPCSTR lpszResId, LPDWORD lpdwFileOffset )
{
BOOL retv = FALSE;
HFILE lzfd;
OFSTRUCT ofs;
DWORD reslen;
TRACE("(%s,type=0x%lx,id=0x%lx,off=%p)\n",
debugstr_a(lpszFileName), (LONG)lpszResType, (LONG)lpszResId,
lpszResId );
lzfd = LZOpenFileA( (LPSTR)lpszFileName, &ofs, OF_READ );
if ( lzfd < 0 ) return 0;
switch ( read_xx_header( lzfd ) )
{
case IMAGE_OS2_SIGNATURE:
#ifdef __REACTOS__
ERR("OS2 Images not supported under ReactOS at this time.");
#else
retv = find_ne_resource( lzfd, lpszResType, lpszResId,
&reslen, lpdwFileOffset );
#endif
break;
case IMAGE_NT_SIGNATURE:
retv = find_pe_resource( lzfd, lpszResType, lpszResId,
&reslen, lpdwFileOffset );
break;
}
LZClose( lzfd );
return retv? reslen : 0;
}
/*************************************************************************
* GetFileResource [VER.3]
*/
DWORD WINAPI GetFileResource16( LPCSTR lpszFileName, LPCSTR lpszResType,
LPCSTR lpszResId, DWORD dwFileOffset,
DWORD dwResLen, LPVOID lpvData )
{
BOOL retv = FALSE;
HFILE lzfd;
OFSTRUCT ofs;
DWORD reslen = dwResLen;
TRACE("(%s,type=0x%lx,id=0x%lx,off=%ld,len=%ld,data=%p)\n",
debugstr_a(lpszFileName), (LONG)lpszResType, (LONG)lpszResId,
dwFileOffset, dwResLen, lpvData );
lzfd = LZOpenFileA( (LPSTR)lpszFileName, &ofs, OF_READ );
if ( lzfd < 0 ) return 0;
if ( !dwFileOffset )
{
switch ( read_xx_header( lzfd ) )
{
case IMAGE_OS2_SIGNATURE:
#ifdef __REACTOS__
ERR("OS2 Images not supported under ReactOS at this time.");
#else
retv = find_ne_resource( lzfd, lpszResType, lpszResId,
&reslen, &dwFileOffset );
#endif
break;
case IMAGE_NT_SIGNATURE:
retv = find_pe_resource( lzfd, lpszResType, lpszResId,
&reslen, &dwFileOffset );
break;
}
if ( !retv )
{
LZClose( lzfd );
return 0;
}
}
LZSeek( lzfd, dwFileOffset, SEEK_SET );
reslen = LZRead( lzfd, lpvData, min( reslen, dwResLen ) );
LZClose( lzfd );
return reslen;
}