ChangeSet ID: 21539 CVSROOT: /opt/cvs-commit Module name: wine Changes by: julliard@winehq.org 2005/11/29 05:07:43
Modified files: dlls/advpack : advpack.c dlls/advpack/tests: advpack.c
Log message: James Hawkins truiken@gmail.com 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.
Patch: http://cvs.winehq.org/patch.py?id=21539
Old revision New revision Changes Path 1.15 1.16 +68 -24 wine/dlls/advpack/advpack.c 1.10 1.11 +0 -1 wine/dlls/advpack/tests/advpack.c
Index: wine/dlls/advpack/advpack.c diff -u -p wine/dlls/advpack/advpack.c:1.15 wine/dlls/advpack/advpack.c:1.16 --- wine/dlls/advpack/advpack.c:1.15 29 Nov 2005 11: 7:43 -0000 +++ wine/dlls/advpack/advpack.c 29 Nov 2005 11: 7:43 -0000 @@ -182,49 +182,93 @@ HRESULT WINAPI GetVersionFromFile( LPSTR 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);
- if (bVersion) + *pdwLSVer = 0; + *pdwMSVer = 0; + + lstrcpynA(szFile, lpszFilename, MAX_PATH); + + dwInfoSize = GetFileVersionInfoSizeA(szFile, &dwHandle); + if (!dwInfoSize) { - retval = GetFileVersionInfoSizeA(lpszFilename, &hdl); - if (retval == 0 || hdl != 0) - return E_FAIL; + /* 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;
- pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval); - if (pVersionInfo == NULL) - return E_FAIL; - GetFileVersionInfoA( lpszFilename, 0, retval, pVersionInfo); + if (!GetFileVersionInfoA(szFile, dwHandle, dwInfoSize, pVersionInfo)) + goto done;
- boolret = VerQueryValueA(pVersionInfo, "\", - (LPVOID) &pFixedVersionInfo, &uiLength); + if (bVersion) + { + if (!VerQueryValueA(pVersionInfo, "\", + (LPVOID *)&pFixedVersionInfo, &uValueLen)) + goto done;
- HeapFree(GetProcessHeap(), 0, pVersionInfo); + if (!uValueLen) + goto done;
- 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; }
Index: wine/dlls/advpack/tests/advpack.c diff -u -p wine/dlls/advpack/tests/advpack.c:1.10 wine/dlls/advpack/tests/advpack.c:1.11 --- wine/dlls/advpack/tests/advpack.c:1.10 29 Nov 2005 11: 7:43 -0000 +++ wine/dlls/advpack/tests/advpack.c 29 Nov 2005 11: 7:43 -0000 @@ -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),