diff options
author | Pascal Junck <pjunck@openoffice.org> | 2004-11-03 07:03:49 +0000 |
---|---|---|
committer | Pascal Junck <pjunck@openoffice.org> | 2004-11-03 07:03:49 +0000 |
commit | 28edcc739fd04ee562d2177da83aadf52fbfafad (patch) | |
tree | e74b641c7370be68a66075cf4f0a396f8288f474 /setup_native/source/win32 | |
parent | 3c072a751bef6432cd3b4c65d5bb4fe00b3251a1 (diff) |
INTEGRATION: CWS desktintgr03 (1.1.2); FILE ADDED
2004/10/22 13:10:28 tra 1.1.2.2: #i34294#out commented debug message box
2004/10/22 10:47:29 tra 1.1.2.1: #i34294#we need a custom action to restart the indexing service after at the end of the installation
Diffstat (limited to 'setup_native/source/win32')
-rw-r--r-- | setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx | 237 |
1 files changed, 237 insertions, 0 deletions
diff --git a/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx b/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx new file mode 100644 index 000000000000..50db524fa7e1 --- /dev/null +++ b/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx @@ -0,0 +1,237 @@ +/************************************************************************* + * + * $RCSfile: restartindexingservice.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: pjunck $ $Date: 2004-11-03 08:03:49 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +/* + After installation of the OOo filter for the indexing service + it is necessary to restart the indexing service in order to + activate the filter. This is the most reliable way to get the + indexing service working. We only restart the service if it is + already running. If we have insufficient privileges to restart + the service we do nothing. +*/ + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#include <msiquery.h> + +/* + Advapi.dll needs to be loaded dynamically because the service + control functions are not available under Windows 9x. +*/ +typedef BOOL (__stdcall * CloseServiceHandle_t)(SC_HANDLE); +typedef BOOL (__stdcall * ControlService_t)(SC_HANDLE, DWORD, LPSERVICE_STATUS); +typedef SC_HANDLE (__stdcall * OpenSCManager_t)(LPCSTR, LPCSTR, DWORD); +typedef SC_HANDLE (__stdcall * OpenService_t)(SC_HANDLE, LPCSTR, DWORD); +typedef BOOL (__stdcall * QueryServiceStatus_t)(SC_HANDLE, LPSERVICE_STATUS); +typedef BOOL (__stdcall * StartService_t)(SC_HANDLE, DWORD, LPCSTR*); + +CloseServiceHandle_t CloseServiceHandle_ = NULL; +ControlService_t ControlService_ = NULL; +OpenSCManager_t OpenSCManager_ = NULL; +OpenService_t OpenService_ = NULL; +QueryServiceStatus_t QueryServiceStatus_ = NULL; +StartService_t StartService_ = NULL; + +const LPTSTR INDEXING_SERVICE_NAME = TEXT("cisvc"); + +bool StopIndexingService(SC_HANDLE hService) +{ + SERVICE_STATUS status; + + if (ControlService_(hService, SERVICE_CONTROL_STOP, &status)) + { + // Check the status until the service is no longer stop pending. + if (QueryServiceStatus_(hService, &status)) + { + DWORD startTime = GetTickCount(); + DWORD oldCheckPoint = status.dwCheckPoint; + + while (status.dwCurrentState == SERVICE_STOP_PENDING) + { + // Do not wait longer than the wait hint. A good interval is + // one tenth the wait hint, but no less than 1 second and no + // more than 10 seconds. + DWORD waitTime = status.dwWaitHint / 10; + + if (waitTime < 1000) + waitTime = 1000; + else if (waitTime > 10000) + waitTime = 10000; + + Sleep(waitTime); + + // Check the status again. + if (!QueryServiceStatus_(hService, &status) || + (status.dwCurrentState == SERVICE_STOPPED)) + break; + + if (status.dwCheckPoint > oldCheckPoint) + { + startTime = GetTickCount(); + oldCheckPoint = status.dwCheckPoint; + } + else if ((GetTickCount() - startTime) > status.dwWaitHint) + { + break; // service doesn't react anymore + } + } + } + } + return (status.dwCurrentState == SERVICE_STOPPED); +} + +bool StartIndexingService(SC_HANDLE hService) +{ + SERVICE_STATUS status; + + if (StartService_(hService, 0, NULL)) + { + // Check the status until the service is no longer stop pending. + if (QueryServiceStatus_(hService, &status)) + { + DWORD startTime = GetTickCount(); + DWORD oldCheckPoint = status.dwCheckPoint; + + while (status.dwCurrentState == SERVICE_START_PENDING) + { + // Do not wait longer than the wait hint. A good interval is + // one tenth the wait hint, but no less than 1 second and no + // more than 10 seconds. + DWORD waitTime = status.dwWaitHint / 10; + + if (waitTime < 1000) + waitTime = 1000; + else if (waitTime > 10000) + waitTime = 10000; + + Sleep(waitTime); + + // Check the status again. + if (!QueryServiceStatus_(hService, &status) || + (status.dwCurrentState == SERVICE_STOPPED)) + break; + + if (status.dwCheckPoint > oldCheckPoint) + { + startTime = GetTickCount(); + oldCheckPoint = status.dwCheckPoint; + } + else if ((GetTickCount() - startTime) > status.dwWaitHint) + { + // service doesn't react anymore + break; + } + } + } + } + return (status.dwCurrentState == SERVICE_RUNNING); +} + +extern "C" UINT __stdcall RestartIndexingService(MSIHANDLE handle) +{ + //MessageBox(NULL, TEXT("Restarting Indexing Service"), TEXT("Message"), MB_OK | MB_ICONINFORMATION); + + HMODULE hAdvapi32 = LoadLibrary("advapi32.dll"); + + if (hAdvapi32) + { + CloseServiceHandle_ = reinterpret_cast<CloseServiceHandle_t>(GetProcAddress(hAdvapi32, "CloseServiceHandle")); + ControlService_ = reinterpret_cast<ControlService_t>(GetProcAddress(hAdvapi32, "ControlService")); + OpenSCManager_ = reinterpret_cast<OpenSCManager_t>(GetProcAddress(hAdvapi32, "OpenSCManagerA")); + OpenService_ = reinterpret_cast<OpenService_t>(GetProcAddress(hAdvapi32, "OpenServiceA")); + QueryServiceStatus_ = reinterpret_cast<QueryServiceStatus_t>(GetProcAddress(hAdvapi32, "QueryServiceStatus")); + StartService_ = reinterpret_cast<StartService_t>(GetProcAddress(hAdvapi32, "StartServiceA")); + } + + /* On systems other than Windows 2000/XP the service API + functions might not be available */ + if (!hAdvapi32 || + !(CloseServiceHandle_ && ControlService_ && OpenSCManager_ && OpenService_ && QueryServiceStatus_ && StartService_)) + return ERROR_SUCCESS; + + SC_HANDLE hSCManager = OpenSCManager_( + NULL, // local machine + NULL, // ServicesActive database + SC_MANAGER_ALL_ACCESS); + + if (hSCManager != NULL) + { + SC_HANDLE hIndexingService = OpenService_( + hSCManager, INDEXING_SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START | SERVICE_STOP); + + if (hIndexingService) + { + SERVICE_STATUS status; + ZeroMemory(&status, sizeof(status)); + + if (QueryServiceStatus_(hIndexingService, &status) && + (status.dwCurrentState == SERVICE_RUNNING)) + { + if (StopIndexingService(hIndexingService)) + StartIndexingService(hIndexingService); + } + CloseServiceHandle_(hIndexingService); + } + CloseServiceHandle_(hSCManager); + } + return ERROR_SUCCESS; +} + |