msi: Support TrueType font files in MsiGetFileVersion.

This commit is contained in:
Hans Leidekker 2011-09-20 11:31:41 +02:00 committed by Alexandre Julliard
parent 7200072622
commit 2788a95c8e
5 changed files with 91 additions and 84 deletions

View File

@ -2196,7 +2196,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package )
msi_free( file_version ); msi_free( file_version );
continue; continue;
} }
else if ((font_version = font_version_from_file( file->TargetPath ))) else if ((font_version = msi_font_version_from_file( file->TargetPath )))
{ {
if (msi_compare_font_versions( font_version, file->Version ) < 0) if (msi_compare_font_versions( font_version, file->Version ) < 0)
{ {

View File

@ -103,7 +103,7 @@ static msi_file_state calculate_install_state( MSIPACKAGE *package, MSIFILE *fil
msi_free( file_version ); msi_free( file_version );
return state; return state;
} }
else if ((font_version = font_version_from_file( file->TargetPath ))) else if ((font_version = msi_font_version_from_file( file->TargetPath )))
{ {
TRACE("new %s old %s\n", debugstr_w(file->Version), debugstr_w(font_version)); TRACE("new %s old %s\n", debugstr_w(file->Version), debugstr_w(font_version));

View File

@ -186,15 +186,22 @@ static WCHAR *font_name_from_file( const WCHAR *filename )
return ret; return ret;
} }
WCHAR *font_version_from_file( const WCHAR *filename ) WCHAR *msi_font_version_from_file( const WCHAR *filename )
{ {
static const WCHAR dotzerodotzeroW[] = {'.','0','.','0',0};
WCHAR *version, *p, *ret = NULL; WCHAR *version, *p, *ret = NULL;
int len;
if ((p = version = load_ttf_name_id( filename, NAME_ID_VERSION ))) if ((p = version = load_ttf_name_id( filename, NAME_ID_VERSION )))
{ {
while (*p && !isdigitW( *p )) p++; while (*p && !isdigitW( *p )) p++;
ret = msi_alloc( (strlenW( p ) + 1) * sizeof(WCHAR) ); len = strlenW( p ) + strlenW(dotzerodotzeroW) + 1;
ret = msi_alloc( len * sizeof(WCHAR) );
strcpyW( ret, p ); strcpyW( ret, p );
if ((p = strchrW( p, '.' )) && !(p = strchrW( p + 1, '.' )))
{
strcatW( ret, dotzerodotzeroW );
}
msi_free( version ); msi_free( version );
} }
return ret; return ret;

View File

@ -3017,11 +3017,8 @@ end:
return ret; return ret;
} }
/****************************************************************** static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
* MsiGetFileVersionW [MSI.@] WCHAR *langbuf, DWORD *langlen )
*/
UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
{ {
static const WCHAR szVersionResource[] = {'\\',0}; static const WCHAR szVersionResource[] = {'\\',0};
static const WCHAR szVersionFormat[] = { static const WCHAR szVersionFormat[] = {
@ -3030,91 +3027,94 @@ UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
'\\','V','a','r','F','i','l','e','I','n','f','o','\\', '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
'T','r','a','n','s','l','a','t','i','o','n',0}; 'T','r','a','n','s','l','a','t','i','o','n',0};
static const WCHAR szLangFormat[] = {'%','d',0}; static const WCHAR szLangFormat[] = {'%','d',0};
UINT ret = 0; UINT ret = ERROR_SUCCESS;
DWORD dwVerLen, gle; DWORD len, error;
LPVOID lpVer = NULL; LPVOID version;
VS_FIXEDFILEINFO *ffi; VS_FIXEDFILEINFO *ffi;
USHORT *lang; USHORT *lang;
UINT puLen;
WCHAR tmp[32]; WCHAR tmp[32];
TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath), if (!(len = GetFileVersionInfoSizeW( path, NULL )))
lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0, {
lpLangBuf, pcchLangBuf?*pcchLangBuf:0); error = GetLastError();
if (error == ERROR_BAD_PATHNAME) return ERROR_FILE_NOT_FOUND;
return error;
}
if (!(version = msi_alloc( len ))) return ERROR_OUTOFMEMORY;
if (!GetFileVersionInfoW( path, 0, len, version ))
{
msi_free( version );
return GetLastError();
}
if (verlen)
{
if (VerQueryValueW( version, szVersionResource, (LPVOID *)&ffi, &len ) && len > 0)
{
sprintfW( tmp, szVersionFormat,
HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS) );
if (verbuf) lstrcpynW( verbuf, tmp, *verlen );
len = strlenW( tmp );
if (len >= *verlen) ret = ERROR_MORE_DATA;
*verlen = len;
}
else
{
if (verbuf) *verbuf = 0;
*verlen = 0;
}
}
if (langlen)
{
if (VerQueryValueW( version, szLangResource, (LPVOID *)&lang, &len ) && len > 0)
{
sprintfW( tmp, szLangFormat, *lang );
if (langbuf) lstrcpynW( langbuf, tmp, *langlen );
len = strlenW( tmp );
if (len >= *langlen) ret = ERROR_MORE_DATA;
*langlen = len;
}
else
{
if (langbuf) *langbuf = 0;
*langlen = 0;
}
}
msi_free( version );
return ret;
}
if ((lpVersionBuf && !pcchVersionBuf) ||
(lpLangBuf && !pcchLangBuf)) /******************************************************************
* MsiGetFileVersionW [MSI.@]
*/
UINT WINAPI MsiGetFileVersionW( LPCWSTR path, LPWSTR verbuf, LPDWORD verlen,
LPWSTR langbuf, LPDWORD langlen )
{
UINT ret;
TRACE("%s %p %u %p %u\n", debugstr_w(path), verbuf, verlen ? *verlen : 0,
langbuf, langlen ? *langlen : 0);
if ((verbuf && !verlen) || (langbuf && !langlen))
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL); ret = get_file_version( path, verbuf, verlen, langbuf, langlen );
if( !dwVerLen ) if (ret == ERROR_RESOURCE_DATA_NOT_FOUND)
{ {
gle = GetLastError(); int len;
if (gle == ERROR_BAD_PATHNAME) WCHAR *version = msi_font_version_from_file( path );
return ERROR_FILE_NOT_FOUND; if (!version) return ERROR_FILE_INVALID;
else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND) len = strlenW( version );
return ERROR_FILE_INVALID; if (*verlen > len)
return gle;
}
lpVer = msi_alloc(dwVerLen);
if( !lpVer )
{
ret = ERROR_OUTOFMEMORY;
goto end;
}
if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
{
ret = GetLastError();
goto end;
}
if (pcchVersionBuf)
{
if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
(puLen > 0) )
{ {
wsprintfW(tmp, szVersionFormat, strcpyW( verbuf, version );
HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS), ret = ERROR_SUCCESS;
HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
if (strlenW(tmp) >= *pcchVersionBuf)
ret = ERROR_MORE_DATA;
*pcchVersionBuf = lstrlenW(tmp);
}
else
{
if (lpVersionBuf) *lpVersionBuf = 0;
*pcchVersionBuf = 0;
} }
else ret = ERROR_MORE_DATA;
*verlen = len;
msi_free( version );
} }
if (pcchLangBuf)
{
if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
(puLen > 0))
{
wsprintfW(tmp, szLangFormat, *lang);
if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
if (strlenW(tmp) >= *pcchLangBuf)
ret = ERROR_MORE_DATA;
*pcchLangBuf = lstrlenW(tmp);
}
else
{
if (lpLangBuf) *lpLangBuf = 0;
*pcchLangBuf = 0;
}
}
end:
msi_free(lpVer);
return ret; return ret;
} }

View File

@ -1022,7 +1022,7 @@ extern MSIASSEMBLY *msi_load_assembly(MSIPACKAGE *, MSICOMPONENT *) DECLSPEC_HID
extern UINT msi_install_assembly(MSIPACKAGE *, MSICOMPONENT *) DECLSPEC_HIDDEN; extern UINT msi_install_assembly(MSIPACKAGE *, MSICOMPONENT *) DECLSPEC_HIDDEN;
extern BOOL msi_init_assembly_caches(MSIPACKAGE *) DECLSPEC_HIDDEN; extern BOOL msi_init_assembly_caches(MSIPACKAGE *) DECLSPEC_HIDDEN;
extern void msi_destroy_assembly_caches(MSIPACKAGE *) DECLSPEC_HIDDEN; extern void msi_destroy_assembly_caches(MSIPACKAGE *) DECLSPEC_HIDDEN;
extern WCHAR *font_version_from_file(const WCHAR *) DECLSPEC_HIDDEN; extern WCHAR *msi_font_version_from_file(const WCHAR *) DECLSPEC_HIDDEN;
extern WCHAR **msi_split_string(const WCHAR *, WCHAR) DECLSPEC_HIDDEN; extern WCHAR **msi_split_string(const WCHAR *, WCHAR) DECLSPEC_HIDDEN;
/* media */ /* media */