LPSTR pReadEulaFromFile( MSIHANDLE hInstall) { XTL::AutoProcessHeapPtr<TCHAR> sourceDir; UINT ret = pMsiGetProperty(hInstall, _T("SourceDir"), &sourceDir, NULL); if (ERROR_SUCCESS != ret) { pMsiLogMessage( hInstall, _T("EULACA: MsiGetProperty(SourceDir) failed, error=0x%X"), ret); return NULL; } // // EULA from the property EulaFileName // XTL::AutoProcessHeapPtr<CHAR> eulaText = pReadEulaFromFileEx(hInstall, sourceDir, _T("EulaFileName")); if (NULL == static_cast<LPSTR>(eulaText)) { // // try again with EulaFallbackFileName // eulaText = pReadEulaFromFileEx( hInstall, sourceDir, _T("EulaFallbackFileName")); if (NULL == static_cast<LPSTR>(eulaText)) { // // Once more with EulaFallbackFileName2 // eulaText = pReadEulaFromFileEx( hInstall, sourceDir, _T("EulaFallbackFileName2")); } } // // If eulaText is still NULL, every attempt has been failed. // if (NULL == static_cast<LPSTR>(eulaText)) { pMsiLogMessage( hInstall, _T("EULACA: EULA files are not available!")); return NULL; } // // Now we have the EULA Text! // return eulaText.Detach(); }
LPSTR pReadEulaFromFileEx( MSIHANDLE hInstall, LPCTSTR SourceDir, LPCTSTR PropertyName) { TCHAR fullPath[MAX_PATH]; XTL::AutoProcessHeapPtr<TCHAR> eulaFileName; UINT ret = pMsiGetProperty(hInstall, PropertyName, &eulaFileName, NULL); if (ERROR_SUCCESS != ret) { pMsiLogMessage( hInstall, _T("EULACA: MsiGetProperty(%s) failed, error=0x%X"), PropertyName, ret); return NULL; } StringCchCopy(fullPath, MAX_PATH, SourceDir); StringCchCat(fullPath, MAX_PATH, eulaFileName); pMsiLogMessage( hInstall, _T("EULACA: EulaFile=%s"), fullPath); // // RTF file is an ANSI text file not unicode. // RTF has the CodePage tag inside, so we don't have to // worry about displaying non-English text. // XTL::AutoProcessHeapPtr<CHAR> eulaText = pReadTextFromFile(fullPath); if (NULL == (LPSTR) eulaText) { pMsiLogMessage( hInstall, _T("EULACA: ReadTextFromFile(%s) failed, error=0x%X"), fullPath, GetLastError()); return NULL; } pMsiLogMessage( hInstall, _T("EULACA: Read EULA text from %s"), fullPath); return eulaText.Detach(); }
LPSTR pReadEulaFromFileA( MSIHANDLE hInstall) { DWORD cchEulaFileName; AutoProcessHeapPtr<LPTSTR> pszEulaFileName = pMsiGetProperty(hInstall, _T("EulaFileName"), &cchEulaFileName); if (NULL == (LPTSTR) pszEulaFileName) { _RPT0(_CRT_ERROR, "MsiGetProperty(EulaFileName) failed\n"); return NULL; } _RPT1(_CRT_WARN, "MsiGetProperty(EulaFileName=%ws)\n", pszEulaFileName); DWORD cchEulaSourceDir; AutoProcessHeapPtr<LPTSTR> pszEulaSourceDir = pMsiGetProperty(hInstall, _T("EulaSourceDir"), &cchEulaSourceDir); if (NULL == (LPTSTR) cchEulaSourceDir) { _RPT0(_CRT_ERROR, "MsiGetProperty(EulaSourceDir) failed\n"); return NULL; } _RPT1(_CRT_WARN, "MsiGetProperty(EulaSourceDir=%ws)\n", pszEulaSourceDir); DWORD cchEulaFilePath = cchEulaFileName + cchEulaSourceDir + 1; AutoProcessHeapPtr<LPTSTR> pszEulaFilePath = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cchEulaFilePath * sizeof(TCHAR)); if (NULL == (LPTSTR) pszEulaFilePath) { _RPT0(_CRT_ERROR, "MsiGetProperty(EulaSourceDir) failed\n"); return NULL; } HRESULT hr = StringCchCopy(pszEulaFilePath, cchEulaFilePath, pszEulaSourceDir); if (FAILED(hr)) { _RPT0(_CRT_ERROR, "StringCchCopy(pszEulaFilePath) failed\n"); return NULL; } hr = StringCchCat(pszEulaFilePath, cchEulaFilePath, pszEulaFileName); if (FAILED(hr)) { _RPT0(_CRT_ERROR, "StringCchCat(pszEulaFilePath) failed\n"); return NULL; } _RPT1(_CRT_WARN, "MsiGetProperty(EulaFilePath=%ws)\n", pszEulaFilePath); AutoProcessHeapPtr<LPSTR> lpEula = pReadTextFromFileA(pszEulaFilePath); if (NULL == (LPSTR) lpEula) { _RPT0(_CRT_ERROR, "pReadTextFromFile(pszEulaFilePath) failed\n"); return NULL; } return lpEula.Detach(); }