From a37bb2a0337c1e03065e2a9a5e642c641f39407a Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Tue, 29 Nov 2005 11:25:51 +0100 Subject: [PATCH] Returned versions are always initialized to zero, even on failure. Function always returns S_OK, even on failure. Copy the file to the temp directory if the file exists but isn't found by GetFileVersionInfoSize. If bVersion is FALSE, return the language and code page identifiers of the file, not the system. --- dlls/advpack/advpack.c | 94 ++++++++++++++++++++++++++---------- dlls/advpack/tests/advpack.c | 1 - 2 files changed, 69 insertions(+), 26 deletions(-) diff --git a/dlls/advpack/advpack.c b/dlls/advpack/advpack.c index ec166745e9..febababae9 100644 --- a/dlls/advpack/advpack.c +++ b/dlls/advpack/advpack.c @@ -182,49 +182,93 @@ HRESULT WINAPI GetVersionFromFile( LPSTR Filename, LPDWORD MajorVer, return GetVersionFromFileEx(Filename, MajorVer, MinorVer, Version); } +/* data for GetVersionFromFileEx */ +typedef struct tagLANGANDCODEPAGE +{ + WORD wLanguage; + WORD wCodePage; +} LANGANDCODEPAGE; + /*********************************************************************** * GetVersionFromFileEx (ADVPACK.@) */ HRESULT WINAPI GetVersionFromFileEx( LPSTR lpszFilename, LPDWORD pdwMSVer, LPDWORD pdwLSVer, BOOL bVersion ) { - DWORD hdl, retval; - LPVOID pVersionInfo; - BOOL boolret; VS_FIXEDFILEINFO *pFixedVersionInfo; - UINT uiLength; + LANGANDCODEPAGE *pLangAndCodePage; + DWORD dwHandle, dwInfoSize; + CHAR szWinDir[MAX_PATH]; + CHAR szFile[MAX_PATH]; + LPVOID pVersionInfo = NULL; + BOOL bFileCopied = FALSE; + UINT uValueLen; + TRACE("(%s, %p, %p, %d)\n", lpszFilename, pdwMSVer, pdwLSVer, bVersion); + *pdwLSVer = 0; + *pdwMSVer = 0; + + lstrcpynA(szFile, lpszFilename, MAX_PATH); + + dwInfoSize = GetFileVersionInfoSizeA(szFile, &dwHandle); + if (!dwInfoSize) + { + /* check that the file exists */ + if (GetFileAttributesA(szFile) == INVALID_FILE_ATTRIBUTES) + return S_OK; + + /* file exists, but won't be found by GetFileVersionInfoSize, + * so copy it to the temp dir where it will be found. + */ + GetWindowsDirectoryA(szWinDir, MAX_PATH); + GetTempFileNameA(szWinDir, NULL, 0, szFile); + CopyFileA(lpszFilename, szFile, FALSE); + bFileCopied = TRUE; + + dwInfoSize = GetFileVersionInfoSizeA(szFile, &dwHandle); + if (!dwInfoSize) + goto done; + } + + pVersionInfo = HeapAlloc(GetProcessHeap(), 0, dwInfoSize); + if (!pVersionInfo) + goto done; + + if (!GetFileVersionInfoA(szFile, dwHandle, dwInfoSize, pVersionInfo)) + goto done; + if (bVersion) { - retval = GetFileVersionInfoSizeA(lpszFilename, &hdl); - if (retval == 0 || hdl != 0) - return E_FAIL; + if (!VerQueryValueA(pVersionInfo, "\\", + (LPVOID *)&pFixedVersionInfo, &uValueLen)) + goto done; - pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval); - if (pVersionInfo == NULL) - return E_FAIL; - GetFileVersionInfoA( lpszFilename, 0, retval, pVersionInfo); + if (!uValueLen) + goto done; - boolret = VerQueryValueA(pVersionInfo, "\\", - (LPVOID) &pFixedVersionInfo, &uiLength); - - HeapFree(GetProcessHeap(), 0, pVersionInfo); - - if (boolret) - { - *pdwMSVer = pFixedVersionInfo->dwFileVersionMS; - *pdwLSVer = pFixedVersionInfo->dwFileVersionLS; - } - else - return E_FAIL; + *pdwMSVer = pFixedVersionInfo->dwFileVersionMS; + *pdwLSVer = pFixedVersionInfo->dwFileVersionLS; } else { - *pdwMSVer = GetUserDefaultUILanguage(); - *pdwLSVer = GetACP(); + if (!VerQueryValueA(pVersionInfo, "\\VarFileInfo\\Translation", + (LPVOID *)&pLangAndCodePage, &uValueLen)) + goto done; + + if (!uValueLen) + goto done; + + *pdwMSVer = pLangAndCodePage->wLanguage; + *pdwLSVer = pLangAndCodePage->wCodePage; } +done: + HeapFree(GetProcessHeap(), 0, pVersionInfo); + + if (bFileCopied) + DeleteFileA(szFile); + return S_OK; } diff --git a/dlls/advpack/tests/advpack.c b/dlls/advpack/tests/advpack.c index 685c658345..c5972cdc98 100644 --- a/dlls/advpack/tests/advpack.c +++ b/dlls/advpack/tests/advpack.c @@ -60,7 +60,6 @@ static void version_test(void) major = minor = 0; hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE); - todo_wine ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned " "0x%08lx\n", hr); trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),