Commit 2788a95c authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

msi: Support TrueType font files in MsiGetFileVersion.

parent 72000726
...@@ -2196,7 +2196,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package ) ...@@ -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)
{ {
......
...@@ -103,7 +103,7 @@ static msi_file_state calculate_install_state( MSIPACKAGE *package, MSIFILE *fil ...@@ -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));
......
...@@ -186,15 +186,22 @@ static WCHAR *font_name_from_file( const WCHAR *filename ) ...@@ -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;
......
...@@ -3017,11 +3017,8 @@ end: ...@@ -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, ...@@ -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);
if ((lpVersionBuf && !pcchVersionBuf) ||
(lpLangBuf && !pcchLangBuf))
return ERROR_INVALID_PARAMETER;
dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
if( !dwVerLen )
{ {
gle = GetLastError(); error = GetLastError();
if (gle == ERROR_BAD_PATHNAME) if (error == ERROR_BAD_PATHNAME) return ERROR_FILE_NOT_FOUND;
return ERROR_FILE_NOT_FOUND; return error;
else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
return ERROR_FILE_INVALID;
return gle;
} }
if (!(version = msi_alloc( len ))) return ERROR_OUTOFMEMORY;
lpVer = msi_alloc(dwVerLen); if (!GetFileVersionInfoW( path, 0, len, version ))
if( !lpVer )
{ {
ret = ERROR_OUTOFMEMORY; msi_free( version );
goto end; return GetLastError();
} }
if (verlen)
if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
{ {
ret = GetLastError(); if (VerQueryValueW( version, szVersionResource, (LPVOID *)&ffi, &len ) && len > 0)
goto end;
}
if (pcchVersionBuf)
{
if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
(puLen > 0) )
{ {
wsprintfW(tmp, szVersionFormat, sprintfW( tmp, szVersionFormat,
HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS), HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS)); HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS) );
if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf); if (verbuf) lstrcpynW( verbuf, tmp, *verlen );
len = strlenW( tmp );
if (strlenW(tmp) >= *pcchVersionBuf) if (len >= *verlen) ret = ERROR_MORE_DATA;
ret = ERROR_MORE_DATA; *verlen = len;
*pcchVersionBuf = lstrlenW(tmp);
} }
else else
{ {
if (lpVersionBuf) *lpVersionBuf = 0; if (verbuf) *verbuf = 0;
*pcchVersionBuf = 0; *verlen = 0;
} }
} }
if (langlen)
if (pcchLangBuf)
{ {
if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) && if (VerQueryValueW( version, szLangResource, (LPVOID *)&lang, &len ) && len > 0)
(puLen > 0))
{ {
wsprintfW(tmp, szLangFormat, *lang); sprintfW( tmp, szLangFormat, *lang );
if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf); if (langbuf) lstrcpynW( langbuf, tmp, *langlen );
len = strlenW( tmp );
if (strlenW(tmp) >= *pcchLangBuf) if (len >= *langlen) ret = ERROR_MORE_DATA;
ret = ERROR_MORE_DATA; *langlen = len;
*pcchLangBuf = lstrlenW(tmp);
} }
else else
{ {
if (lpLangBuf) *lpLangBuf = 0; if (langbuf) *langbuf = 0;
*pcchLangBuf = 0; *langlen = 0;
} }
} }
msi_free( version );
return ret;
}
end:
msi_free(lpVer); /******************************************************************
* 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;
ret = get_file_version( path, verbuf, verlen, langbuf, langlen );
if (ret == ERROR_RESOURCE_DATA_NOT_FOUND)
{
int len;
WCHAR *version = msi_font_version_from_file( path );
if (!version) return ERROR_FILE_INVALID;
len = strlenW( version );
if (*verlen > len)
{
strcpyW( verbuf, version );
ret = ERROR_SUCCESS;
}
else ret = ERROR_MORE_DATA;
*verlen = len;
msi_free( version );
}
return ret; return ret;
} }
......
...@@ -1022,7 +1022,7 @@ extern MSIASSEMBLY *msi_load_assembly(MSIPACKAGE *, MSICOMPONENT *) DECLSPEC_HID ...@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment