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 )
msi_free( file_version );
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)
{
......
......@@ -103,7 +103,7 @@ static msi_file_state calculate_install_state( MSIPACKAGE *package, MSIFILE *fil
msi_free( file_version );
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));
......
......@@ -186,15 +186,22 @@ static WCHAR *font_name_from_file( const WCHAR *filename )
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;
int len;
if ((p = version = load_ttf_name_id( filename, NAME_ID_VERSION )))
{
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 );
if ((p = strchrW( p, '.' )) && !(p = strchrW( p + 1, '.' )))
{
strcatW( ret, dotzerodotzeroW );
}
msi_free( version );
}
return ret;
......
......@@ -3017,11 +3017,8 @@ end:
return ret;
}
/******************************************************************
* MsiGetFileVersionW [MSI.@]
*/
UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
WCHAR *langbuf, DWORD *langlen )
{
static const WCHAR szVersionResource[] = {'\\',0};
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','\\',
'T','r','a','n','s','l','a','t','i','o','n',0};
static const WCHAR szLangFormat[] = {'%','d',0};
UINT ret = 0;
DWORD dwVerLen, gle;
LPVOID lpVer = NULL;
UINT ret = ERROR_SUCCESS;
DWORD len, error;
LPVOID version;
VS_FIXEDFILEINFO *ffi;
USHORT *lang;
UINT puLen;
WCHAR tmp[32];
TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
if ((lpVersionBuf && !pcchVersionBuf) ||
(lpLangBuf && !pcchLangBuf))
return ERROR_INVALID_PARAMETER;
dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
if( !dwVerLen )
if (!(len = GetFileVersionInfoSizeW( path, NULL )))
{
gle = GetLastError();
if (gle == ERROR_BAD_PATHNAME)
return ERROR_FILE_NOT_FOUND;
else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
return ERROR_FILE_INVALID;
return gle;
error = GetLastError();
if (error == ERROR_BAD_PATHNAME) return ERROR_FILE_NOT_FOUND;
return error;
}
lpVer = msi_alloc(dwVerLen);
if( !lpVer )
if (!(version = msi_alloc( len ))) return ERROR_OUTOFMEMORY;
if (!GetFileVersionInfoW( path, 0, len, version ))
{
ret = ERROR_OUTOFMEMORY;
goto end;
msi_free( version );
return GetLastError();
}
if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
if (verlen)
{
ret = GetLastError();
goto end;
}
if (pcchVersionBuf)
{
if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
(puLen > 0) )
if (VerQueryValueW( version, szVersionResource, (LPVOID *)&ffi, &len ) && len > 0)
{
wsprintfW(tmp, szVersionFormat,
HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
if (strlenW(tmp) >= *pcchVersionBuf)
ret = ERROR_MORE_DATA;
*pcchVersionBuf = lstrlenW(tmp);
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 (lpVersionBuf) *lpVersionBuf = 0;
*pcchVersionBuf = 0;
if (verbuf) *verbuf = 0;
*verlen = 0;
}
}
if (pcchLangBuf)
if (langlen)
{
if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
(puLen > 0))
if (VerQueryValueW( version, szLangResource, (LPVOID *)&lang, &len ) && len > 0)
{
wsprintfW(tmp, szLangFormat, *lang);
if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
if (strlenW(tmp) >= *pcchLangBuf)
ret = ERROR_MORE_DATA;
*pcchLangBuf = lstrlenW(tmp);
sprintfW( tmp, szLangFormat, *lang );
if (langbuf) lstrcpynW( langbuf, tmp, *langlen );
len = strlenW( tmp );
if (len >= *langlen) ret = ERROR_MORE_DATA;
*langlen = len;
}
else
{
if (lpLangBuf) *lpLangBuf = 0;
*pcchLangBuf = 0;
if (langbuf) *langbuf = 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;
}
......
......@@ -1022,7 +1022,7 @@ extern MSIASSEMBLY *msi_load_assembly(MSIPACKAGE *, MSICOMPONENT *) DECLSPEC_HID
extern UINT msi_install_assembly(MSIPACKAGE *, MSICOMPONENT *) DECLSPEC_HIDDEN;
extern BOOL msi_init_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;
/* 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