132b1fd08SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
332b1fd08SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
432b1fd08SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
532b1fd08SAndrew Rist  * distributed with this work for additional information
632b1fd08SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
732b1fd08SAndrew Rist  * to you under the Apache License, Version 2.0 (the
832b1fd08SAndrew Rist  * "License"); you may not use this file except in compliance
932b1fd08SAndrew Rist  * with the License.  You may obtain a copy of the License at
1032b1fd08SAndrew Rist  *
1132b1fd08SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1232b1fd08SAndrew Rist  *
1332b1fd08SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1432b1fd08SAndrew Rist  * software distributed under the License is distributed on an
1532b1fd08SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1632b1fd08SAndrew Rist  * KIND, either express or implied.  See the License for the
1732b1fd08SAndrew Rist  * specific language governing permissions and limitations
1832b1fd08SAndrew Rist  * under the License.
1932b1fd08SAndrew Rist  *
2032b1fd08SAndrew Rist  *************************************************************/
2132b1fd08SAndrew Rist 
2232b1fd08SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifdef _MSC_VER
25cdf0e10cSrcweir #pragma warning(push,1) // disable warnings within system headers
26cdf0e10cSrcweir #pragma warning(disable: 4917)
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir #include <windows.h>
29cdf0e10cSrcweir #include <msiquery.h>
30cdf0e10cSrcweir #include <shlobj.h>
31cdf0e10cSrcweir #ifdef _MSC_VER
32cdf0e10cSrcweir #pragma warning(pop)
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <string.h>
36cdf0e10cSrcweir #include <malloc.h>
37cdf0e10cSrcweir #include <stdio.h>
38cdf0e10cSrcweir #include <strsafe.h>
39cdf0e10cSrcweir #include <string>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //----------------------------------------------------------
42cdf0e10cSrcweir #ifdef DEBUG
OutputDebugStringFormat(LPCTSTR pFormat,...)43cdf0e10cSrcweir inline void OutputDebugStringFormat( LPCTSTR pFormat, ... )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	TCHAR    buffer[1024];
46cdf0e10cSrcweir 	va_list  args;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	va_start( args, pFormat );
49cdf0e10cSrcweir 	StringCchVPrintf( buffer, sizeof(buffer), pFormat, args );
50cdf0e10cSrcweir 	OutputDebugString( buffer );
51cdf0e10cSrcweir }
52cdf0e10cSrcweir #else
OutputDebugStringFormat(LPCTSTR,...)53cdf0e10cSrcweir static inline void OutputDebugStringFormat( LPCTSTR, ... )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir }
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir 
58cdf0e10cSrcweir //----------------------------------------------------------
IsValidHandle(HANDLE handle)59cdf0e10cSrcweir inline bool IsValidHandle( HANDLE handle )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	return (NULL != handle) && (INVALID_HANDLE_VALUE != handle);
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //----------------------------------------------------------
GetMsiProp(MSIHANDLE handle,LPCTSTR name,std::wstring & value)65cdf0e10cSrcweir static bool GetMsiProp(MSIHANDLE handle, LPCTSTR name, /*out*/std::wstring& value)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     DWORD sz = 0;
68cdf0e10cSrcweir     LPTSTR dummy = TEXT("");
69cdf0e10cSrcweir     if (MsiGetProperty(handle, name, dummy, &sz) == ERROR_MORE_DATA)
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         sz++;
72cdf0e10cSrcweir         DWORD nbytes = sz * sizeof(TCHAR);
73cdf0e10cSrcweir         LPTSTR buff = reinterpret_cast<LPTSTR>(_alloca(nbytes));
74cdf0e10cSrcweir         ZeroMemory(buff, nbytes);
75cdf0e10cSrcweir         MsiGetProperty(handle, name, buff, &sz);
76cdf0e10cSrcweir         value = buff;
77cdf0e10cSrcweir         return true;
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir     return false;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir //----------------------------------------------------------
83cdf0e10cSrcweir //----------------------------------------------------------
84cdf0e10cSrcweir //----------------------------------------------------------
ShowReleaseNotes(TCHAR * pFileName,TCHAR * pFilePath)85cdf0e10cSrcweir UINT ShowReleaseNotes( TCHAR* pFileName, TCHAR* pFilePath )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     TCHAR sFullPath[ MAX_PATH ];
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     if ( FAILED( StringCchCopy( sFullPath, MAX_PATH, pFilePath ) ) )
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: ShowReleaseNotes: Could not copy path [%s]"), pFilePath );
92cdf0e10cSrcweir         return ERROR_SUCCESS;
93cdf0e10cSrcweir     }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     if ( FAILED( StringCchCat( sFullPath, MAX_PATH, pFileName ) ) )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: ShowReleaseNotes: Could not append filename [%s]"), pFileName );
98cdf0e10cSrcweir         return ERROR_SUCCESS;
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     HANDLE hFile = CreateFile( sFullPath, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     if ( IsValidHandle(hFile) )
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         CloseHandle( hFile );
106cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: ShowReleaseNotes: Found file [%s]"), sFullPath );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         SHELLEXECUTEINFOW aExecInf;
109cdf0e10cSrcweir         ZeroMemory( &aExecInf, sizeof( aExecInf ) );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         aExecInf.cbSize = sizeof( aExecInf );
112cdf0e10cSrcweir         aExecInf.fMask  = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI;
113cdf0e10cSrcweir         aExecInf.lpVerb = TEXT("open");
114cdf0e10cSrcweir         aExecInf.lpFile = sFullPath;
115cdf0e10cSrcweir         aExecInf.lpDirectory = NULL;
116cdf0e10cSrcweir         aExecInf.nShow = SW_SHOWNORMAL;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         SetLastError( 0 );
119cdf0e10cSrcweir         ShellExecuteEx( &aExecInf );
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir     else
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: ShowReleaseNotes: File not found [%s]"), sFullPath );
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	return ERROR_SUCCESS;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir //----------------------------------------------------------
ShowReleaseNotesBefore(MSIHANDLE)130cdf0e10cSrcweir extern "C" UINT __stdcall ShowReleaseNotesBefore( MSIHANDLE )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     TCHAR szPath[MAX_PATH];
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     if( FAILED( SHGetSpecialFolderPath( NULL, szPath, CSIDL_COMMON_DOCUMENTS, true ) ) )
135cdf0e10cSrcweir         return ERROR_SUCCESS;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     OutputDebugString( TEXT("DEBUG: ShowReleaseNotesBefore called") );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     return ShowReleaseNotes( TEXT("\\sun\\releasenote1.url"), szPath );
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir //----------------------------------------------------------
ShowReleaseNotesAfter(MSIHANDLE)143cdf0e10cSrcweir extern "C" UINT __stdcall ShowReleaseNotesAfter( MSIHANDLE )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     TCHAR szPath[MAX_PATH];
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     if( FAILED( SHGetSpecialFolderPath( NULL, szPath, CSIDL_COMMON_DOCUMENTS, true ) ) )
148cdf0e10cSrcweir         return ERROR_SUCCESS;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     OutputDebugString( TEXT("DEBUG: ShowReleaseNotesAfter called") );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     return ShowReleaseNotes( TEXT("\\sun\\releasenote2.url"), szPath );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir //----------------------------------------------------------
ShowSurveyAfter(MSIHANDLE handle)156cdf0e10cSrcweir extern "C" UINT __stdcall ShowSurveyAfter( MSIHANDLE handle )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     std::wstring prodname;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     GetMsiProp( handle, TEXT("ProductName"), prodname );
161*599cc5b4SOliver-Rainer Wittmann 	std::wstring::size_type nIndex = prodname.find( TEXT( "OpenOffice" ) );
162cdf0e10cSrcweir 	if( std::wstring::npos == nIndex )
163cdf0e10cSrcweir 	    return ERROR_SUCCESS;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     OutputDebugString( TEXT("DEBUG: ShowSurveyAfter called") );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     SHELLEXECUTEINFOW aExecInf;
168cdf0e10cSrcweir     ZeroMemory( &aExecInf, sizeof( aExecInf ) );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     aExecInf.cbSize = sizeof( aExecInf );
171cdf0e10cSrcweir     aExecInf.fMask  = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI;
172cdf0e10cSrcweir     aExecInf.lpVerb = TEXT("open");
173ff3f4ebcSOliver-Rainer Wittmann     //aExecInf.lpFile = TEXT("http://surveys.services.openoffice.org/deinstall");
174ff3f4ebcSOliver-Rainer Wittmann     aExecInf.lpFile = TEXT("http://www.openoffice.org/support/");
175cdf0e10cSrcweir     aExecInf.lpDirectory = NULL;
176cdf0e10cSrcweir     aExecInf.nShow = SW_SHOWNORMAL;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     SetLastError( 0 );
179cdf0e10cSrcweir     ShellExecuteEx( &aExecInf );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     return ERROR_SUCCESS;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184