INTEGRATION: CWS nativefixer6 (1.1.2); FILE ADDED

2005/04/19 13:06:24 is 1.1.2.2: #121395# Custom Actions for Deinstallation
2005/04/13 08:31:52 hro 1.1.2.1: #121395# New custom action for patch postunistall action
This commit is contained in:
Oliver Bolte 2005-04-20 10:42:39 +00:00
parent d2fba4d639
commit 13d461a008

View file

@ -0,0 +1,185 @@
/*************************************************************************
*
* $RCSfile: postuninstall.cxx,v $
*
* $Revision: 1.2 $
*
* last change: $Author: obo $ $Date: 2005-04-20 11:42:39 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
#include <malloc.h>
#ifdef UNICODE
#define _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
#include <tchar.h>
#include <string>
#ifdef _WIN32_WINNT
#error YES
#endif
#include <io.h>
static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
{
std::_tstring result;
TCHAR szDummy[1] = TEXT("");
DWORD nChars = 0;
if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
{
DWORD nBytes = ++nChars * sizeof(TCHAR);
LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes );
MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
result = buffer;
}
return result;
}
static BOOL ExecuteCommand( LPCTSTR lpCommand, BOOL bSync )
{
BOOL fSuccess = FALSE;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
fSuccess = CreateProcess(
NULL,
(LPTSTR)lpCommand,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi
);
if ( fSuccess )
{
if ( bSync )
WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
return fSuccess;
}
extern "C" UINT __stdcall ExecutePostUninstallScript( MSIHANDLE handle )
{
TCHAR szValue[8192];
DWORD nValueSize = sizeof(szValue);
HKEY hKey;
std::_tstring sInstDir;
std::_tstring sProductKey = GetMsiProperty( handle, TEXT("FINDPRODUCT") );
// MessageBox( NULL, sProductKey.c_str(), "Titel", MB_OK );
if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey.c_str(), &hKey ) )
{
if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) )
{
sInstDir = szValue;
}
RegCloseKey( hKey );
}
else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey.c_str(), &hKey ) )
{
if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) )
{
sInstDir = szValue;
}
RegCloseKey( hKey );
}
else
return ERROR_SUCCESS;
std::_tstring sInfFile = sInstDir + TEXT("program\\postuninstall.inf");
std::_tstring sCommand = _T("RUNDLL32.EXE ");
// MessageBox( NULL, sInfFile.c_str(), "Titel", MB_OK );
if ( (LONG)GetVersion() < 0 )
sCommand += _T("setupx.dll");
else
sCommand += _T("setupapi.dll");
sCommand += _T(",InstallHinfSection PostUninstall 132 ");
sCommand += sInfFile;
if ( 0 == _taccess( sInfFile.c_str(), 2 ) )
ExecuteCommand( sCommand.c_str(), TRUE );
DeleteFile( sInfFile.c_str() );
return ERROR_SUCCESS;
}