diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-04-13 06:52:14 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-04-13 09:03:03 +0200 |
commit | 3bd63cc5d6e24139d41f029993dc54d7b2e07e87 (patch) | |
tree | a0f48f40cdd44bdfc15f519a1713015f44eff83c /setup_native/source | |
parent | ed52ffb6ab840a1f4abdda8553fa9410793f4add (diff) |
I guess it's time to remove some Win9x code
Change-Id: I921207fb73b2dc1e0f55836fa87c3338ff4fe1a9
Reviewed-on: https://gerrit.libreoffice.org/52807
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'setup_native/source')
-rw-r--r-- | setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx | 58 |
1 files changed, 11 insertions, 47 deletions
diff --git a/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx b/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx index 4fad91039c7e..783198fdf08a 100644 --- a/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx +++ b/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx @@ -30,34 +30,16 @@ #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)(LPCWSTR, LPCWSTR, DWORD); -typedef SC_HANDLE (__stdcall * OpenService_t)(SC_HANDLE, LPCWSTR, DWORD); -typedef BOOL (__stdcall * QueryServiceStatus_t)(SC_HANDLE, LPSERVICE_STATUS); -typedef BOOL (__stdcall * StartService_t)(SC_HANDLE, DWORD, LPCWSTR*); - -static CloseServiceHandle_t CloseServiceHandle_ = nullptr; -static ControlService_t ControlService_ = nullptr; -static OpenSCManager_t OpenSCManager_ = nullptr; -static OpenService_t OpenService_ = nullptr; -static QueryServiceStatus_t QueryServiceStatus_ = nullptr; -static StartService_t StartService_ = nullptr; - const wchar_t * const INDEXING_SERVICE_NAME = L"cisvc"; bool StopIndexingService(SC_HANDLE hService) { SERVICE_STATUS status; - if (ControlService_(hService, SERVICE_CONTROL_STOP, &status)) + if (ControlService(hService, SERVICE_CONTROL_STOP, &status)) { // Check the status until the service is no longer stop pending. - if (QueryServiceStatus_(hService, &status)) + if (QueryServiceStatus(hService, &status)) { DWORD startTime = GetTickCount(); DWORD oldCheckPoint = status.dwCheckPoint; @@ -77,7 +59,7 @@ bool StopIndexingService(SC_HANDLE hService) Sleep(waitTime); // Check the status again. - if (!QueryServiceStatus_(hService, &status) || + if (!QueryServiceStatus(hService, &status) || (status.dwCurrentState == SERVICE_STOPPED)) break; @@ -98,12 +80,12 @@ bool StopIndexingService(SC_HANDLE hService) void StartIndexingService(SC_HANDLE hService) { - if (StartService_(hService, 0, nullptr)) + if (StartServiceW(hService, 0, nullptr)) { SERVICE_STATUS status; // Check the status until the service is no longer stop pending. - if (QueryServiceStatus_(hService, &status)) + if (QueryServiceStatus(hService, &status)) { DWORD startTime = GetTickCount(); DWORD oldCheckPoint = status.dwCheckPoint; @@ -123,7 +105,7 @@ void StartIndexingService(SC_HANDLE hService) Sleep(waitTime); // Check the status again. - if (!QueryServiceStatus_(hService, &status) || + if (!QueryServiceStatus(hService, &status) || (status.dwCurrentState == SERVICE_STOPPED)) break; @@ -144,32 +126,14 @@ void StartIndexingService(SC_HANDLE hService) extern "C" UINT __stdcall RestartIndexingService(MSIHANDLE) { - HMODULE hAdvapi32 = LoadLibraryW(L"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, "OpenSCManagerW")); - OpenService_ = reinterpret_cast<OpenService_t>(GetProcAddress(hAdvapi32, "OpenServiceW")); - QueryServiceStatus_ = reinterpret_cast<QueryServiceStatus_t>(GetProcAddress(hAdvapi32, "QueryServiceStatus")); - StartService_ = reinterpret_cast<StartService_t>(GetProcAddress(hAdvapi32, "StartServiceW")); - } - - /* 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_( + SC_HANDLE hSCManager = OpenSCManagerW( nullptr, // local machine nullptr, // ServicesActive database SC_MANAGER_ALL_ACCESS); if (hSCManager != nullptr) { - SC_HANDLE hIndexingService = OpenService_( + SC_HANDLE hIndexingService = OpenServiceW( hSCManager, INDEXING_SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START | SERVICE_STOP); if (hIndexingService) @@ -177,15 +141,15 @@ extern "C" UINT __stdcall RestartIndexingService(MSIHANDLE) SERVICE_STATUS status; ZeroMemory(&status, sizeof(status)); - if (QueryServiceStatus_(hIndexingService, &status) && + if (QueryServiceStatus(hIndexingService, &status) && (status.dwCurrentState == SERVICE_RUNNING)) { if (StopIndexingService(hIndexingService)) StartIndexingService(hIndexingService); } - CloseServiceHandle_(hIndexingService); + CloseServiceHandle(hIndexingService); } - CloseServiceHandle_(hSCManager); + CloseServiceHandle(hSCManager); } return ERROR_SUCCESS; } |