1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifdef _MSC_VER 29*cdf0e10cSrcweir #pragma warning(push,1) // disable warnings within system headers 30*cdf0e10cSrcweir #pragma warning(disable: 4917) 31*cdf0e10cSrcweir #endif 32*cdf0e10cSrcweir #include <windows.h> 33*cdf0e10cSrcweir #include <msiquery.h> 34*cdf0e10cSrcweir #include <shlobj.h> 35*cdf0e10cSrcweir #ifdef _MSC_VER 36*cdf0e10cSrcweir #pragma warning(pop) 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <string.h> 40*cdf0e10cSrcweir #include <malloc.h> 41*cdf0e10cSrcweir #include <stdio.h> 42*cdf0e10cSrcweir #include <strsafe.h> 43*cdf0e10cSrcweir #include <string> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir //---------------------------------------------------------- 46*cdf0e10cSrcweir #ifdef DEBUG 47*cdf0e10cSrcweir inline void OutputDebugStringFormat( LPCTSTR pFormat, ... ) 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir TCHAR buffer[1024]; 50*cdf0e10cSrcweir va_list args; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir va_start( args, pFormat ); 53*cdf0e10cSrcweir StringCchVPrintf( buffer, sizeof(buffer), pFormat, args ); 54*cdf0e10cSrcweir OutputDebugString( buffer ); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir #else 57*cdf0e10cSrcweir static inline void OutputDebugStringFormat( LPCTSTR, ... ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir #endif 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir //---------------------------------------------------------- 63*cdf0e10cSrcweir inline bool IsValidHandle( HANDLE handle ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir return (NULL != handle) && (INVALID_HANDLE_VALUE != handle); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //---------------------------------------------------------- 69*cdf0e10cSrcweir static bool GetMsiProp(MSIHANDLE handle, LPCTSTR name, /*out*/std::wstring& value) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir DWORD sz = 0; 72*cdf0e10cSrcweir LPTSTR dummy = TEXT(""); 73*cdf0e10cSrcweir if (MsiGetProperty(handle, name, dummy, &sz) == ERROR_MORE_DATA) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir sz++; 76*cdf0e10cSrcweir DWORD nbytes = sz * sizeof(TCHAR); 77*cdf0e10cSrcweir LPTSTR buff = reinterpret_cast<LPTSTR>(_alloca(nbytes)); 78*cdf0e10cSrcweir ZeroMemory(buff, nbytes); 79*cdf0e10cSrcweir MsiGetProperty(handle, name, buff, &sz); 80*cdf0e10cSrcweir value = buff; 81*cdf0e10cSrcweir return true; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir return false; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir //---------------------------------------------------------- 87*cdf0e10cSrcweir //---------------------------------------------------------- 88*cdf0e10cSrcweir //---------------------------------------------------------- 89*cdf0e10cSrcweir UINT ShowReleaseNotes( TCHAR* pFileName, TCHAR* pFilePath ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir TCHAR sFullPath[ MAX_PATH ]; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir if ( FAILED( StringCchCopy( sFullPath, MAX_PATH, pFilePath ) ) ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir OutputDebugStringFormat( TEXT("DEBUG: ShowReleaseNotes: Could not copy path [%s]"), pFilePath ); 96*cdf0e10cSrcweir return ERROR_SUCCESS; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir if ( FAILED( StringCchCat( sFullPath, MAX_PATH, pFileName ) ) ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir OutputDebugStringFormat( TEXT("DEBUG: ShowReleaseNotes: Could not append filename [%s]"), pFileName ); 102*cdf0e10cSrcweir return ERROR_SUCCESS; 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir HANDLE hFile = CreateFile( sFullPath, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir if ( IsValidHandle(hFile) ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir CloseHandle( hFile ); 110*cdf0e10cSrcweir OutputDebugStringFormat( TEXT("DEBUG: ShowReleaseNotes: Found file [%s]"), sFullPath ); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir SHELLEXECUTEINFOW aExecInf; 113*cdf0e10cSrcweir ZeroMemory( &aExecInf, sizeof( aExecInf ) ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir aExecInf.cbSize = sizeof( aExecInf ); 116*cdf0e10cSrcweir aExecInf.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI; 117*cdf0e10cSrcweir aExecInf.lpVerb = TEXT("open"); 118*cdf0e10cSrcweir aExecInf.lpFile = sFullPath; 119*cdf0e10cSrcweir aExecInf.lpDirectory = NULL; 120*cdf0e10cSrcweir aExecInf.nShow = SW_SHOWNORMAL; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir SetLastError( 0 ); 123*cdf0e10cSrcweir ShellExecuteEx( &aExecInf ); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir else 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir OutputDebugStringFormat( TEXT("DEBUG: ShowReleaseNotes: File not found [%s]"), sFullPath ); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir return ERROR_SUCCESS; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir //---------------------------------------------------------- 134*cdf0e10cSrcweir extern "C" UINT __stdcall ShowReleaseNotesBefore( MSIHANDLE ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir TCHAR szPath[MAX_PATH]; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir if( FAILED( SHGetSpecialFolderPath( NULL, szPath, CSIDL_COMMON_DOCUMENTS, true ) ) ) 139*cdf0e10cSrcweir return ERROR_SUCCESS; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir OutputDebugString( TEXT("DEBUG: ShowReleaseNotesBefore called") ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir return ShowReleaseNotes( TEXT("\\sun\\releasenote1.url"), szPath ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir //---------------------------------------------------------- 147*cdf0e10cSrcweir extern "C" UINT __stdcall ShowReleaseNotesAfter( MSIHANDLE ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir TCHAR szPath[MAX_PATH]; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir if( FAILED( SHGetSpecialFolderPath( NULL, szPath, CSIDL_COMMON_DOCUMENTS, true ) ) ) 152*cdf0e10cSrcweir return ERROR_SUCCESS; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir OutputDebugString( TEXT("DEBUG: ShowReleaseNotesAfter called") ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir return ShowReleaseNotes( TEXT("\\sun\\releasenote2.url"), szPath ); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir //---------------------------------------------------------- 160*cdf0e10cSrcweir extern "C" UINT __stdcall ShowSurveyAfter( MSIHANDLE handle ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir std::wstring prodname; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir GetMsiProp( handle, TEXT("ProductName"), prodname ); 165*cdf0e10cSrcweir std::wstring::size_type nIndex = prodname.find( TEXT( "OpenOffice.org" ) ); 166*cdf0e10cSrcweir if( std::wstring::npos == nIndex ) 167*cdf0e10cSrcweir return ERROR_SUCCESS; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir OutputDebugString( TEXT("DEBUG: ShowSurveyAfter called") ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir SHELLEXECUTEINFOW aExecInf; 172*cdf0e10cSrcweir ZeroMemory( &aExecInf, sizeof( aExecInf ) ); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir aExecInf.cbSize = sizeof( aExecInf ); 175*cdf0e10cSrcweir aExecInf.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI; 176*cdf0e10cSrcweir aExecInf.lpVerb = TEXT("open"); 177*cdf0e10cSrcweir aExecInf.lpFile = TEXT("http://surveys.services.openoffice.org/deinstall"); 178*cdf0e10cSrcweir aExecInf.lpDirectory = NULL; 179*cdf0e10cSrcweir aExecInf.nShow = SW_SHOWNORMAL; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir SetLastError( 0 ); 182*cdf0e10cSrcweir ShellExecuteEx( &aExecInf ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir return ERROR_SUCCESS; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187