1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 #define _WIN32_WINDOWS 0x0410
35 #pragma warning(push, 1) /* disable warnings within system headers */
36 #define WIN32_LEAN_AND_MEAN
51 #define _tstring wstring
53 #define _tstring string
58 static std::_tstring
GetMsiProperty( MSIHANDLE handle
, const std::_tstring
& sProperty
)
61 TCHAR szDummy
[1] = TEXT("");
64 if ( MsiGetProperty( handle
, sProperty
.c_str(), szDummy
, &nChars
) == ERROR_MORE_DATA
)
66 DWORD nBytes
= ++nChars
* sizeof(TCHAR
);
67 LPTSTR buffer
= reinterpret_cast<LPTSTR
>(_alloca(nBytes
));
68 ZeroMemory( buffer
, nBytes
);
69 MsiGetProperty(handle
, sProperty
.c_str(), buffer
, &nChars
);
76 /* creates a child process which is specified in lpCommand.
78 out_exitCode is the exit code of the child process
80 static BOOL
ExecuteCommand( LPCTSTR lpCommand
, DWORD
* out_exitCode
)
82 BOOL fSuccess
= FALSE
;
84 PROCESS_INFORMATION pi
;
86 ZeroMemory( &si
, sizeof(si
) );
89 fSuccess
= CreateProcess(
104 WaitForSingleObject( pi
.hProcess
, INFINITE
);
106 if (!GetExitCodeProcess( pi
.hProcess
, out_exitCode
))
109 CloseHandle( pi
.hProcess
);
110 CloseHandle( pi
.hThread
);
116 static BOOL
RemoveCompleteDirectory( std::_tstring sPath
)
118 bool bDirectoryRemoved
= true;
120 std::_tstring sPattern
= sPath
+ TEXT("\\") + TEXT("*.*");
121 WIN32_FIND_DATA aFindData
;
123 // Finding all content in sPath
125 HANDLE hFindContent
= FindFirstFile( sPattern
.c_str(), &aFindData
);
127 if ( hFindContent
!= INVALID_HANDLE_VALUE
)
129 bool fNextFile
= false;
133 std::_tstring sFileName
= aFindData
.cFileName
;
134 std::_tstring sCurrentDir
= TEXT(".");
135 std::_tstring sParentDir
= TEXT("..");
137 if (( strcmp(sFileName
.c_str(),sCurrentDir
.c_str()) != 0 ) &&
138 ( strcmp(sFileName
.c_str(),sParentDir
.c_str()) != 0 ))
140 std::_tstring sCompleteFileName
= sPath
+ TEXT("\\") + sFileName
;
142 if ( aFindData
.dwFileAttributes
== FILE_ATTRIBUTE_DIRECTORY
)
144 RemoveCompleteDirectory(sCompleteFileName
);
148 DeleteFile( sCompleteFileName
.c_str() );
152 fNextFile
= FindNextFile( hFindContent
, &aFindData
);
154 } while ( fNextFile
);
156 FindClose( hFindContent
);
158 // empty directory can be removed now
159 // RemoveDirectory is only successful, if the last handle to the directory is closed
160 // -> first removing content -> closing handle -> remove empty directory
162 if ( ! ( RemoveDirectory(sPath
.c_str()) ) )
164 bDirectoryRemoved
= false;
168 return bDirectoryRemoved
;
171 extern "C" UINT __stdcall
RegisterExtensions(MSIHANDLE handle
)
173 std::_tstring sInstDir
= GetMsiProperty( handle
, TEXT("CustomActionData") );
174 std::_tstring sUnoPkgFile
= sInstDir
+ TEXT("program\\unopkg.exe");
177 WIN32_FIND_DATA aFindFileData
;
178 bool registrationError
= false;
181 HANDLE hFindUnopkg
= FindFirstFile( sUnoPkgFile
.c_str(), &aFindFileData
);
183 if ( hFindUnopkg
!= INVALID_HANDLE_VALUE
)
185 // unopkg.exe exists in program directory
186 std::_tstring sCommand
= sUnoPkgFile
+ " sync";
189 bool fSuccess
= ExecuteCommand( sCommand
.c_str(), & exitCode
);
192 mystr
= "ERROR: An error occured during registration of extensions!";
193 MessageBox(NULL
, mystr
.c_str(), "ERROR", MB_OK
);
194 registrationError
= true;
197 FindClose( hFindUnopkg
);
200 if ( registrationError
)
206 return ERROR_SUCCESS
;
211 extern "C" UINT __stdcall
RemoveExtensions(MSIHANDLE handle
)
213 std::_tstring sInstDir
= GetMsiProperty( handle
, TEXT("CustomActionData") );
215 // Removing complete directory "share\prereg\bundled"
216 RemoveCompleteDirectory( sInstDir
+ TEXT("share\\prereg\\bundled") );
218 // At this point we need to take care about removing upper directories,
219 // because we are after InstallFinalize. We remove only empty directories.
220 RemoveDirectory( (sInstDir
+ TEXT("share\\prereg")).c_str() );
221 RemoveDirectory( (sInstDir
+ TEXT("share")).c_str() );
222 RemoveDirectory( sInstDir
.c_str() );
224 return ERROR_SUCCESS
;
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */