Kaydet (Commit) 3bd63cc5 authored tarafından Mike Kaganski's avatar Mike Kaganski

I guess it's time to remove some Win9x code

Change-Id: I921207fb73b2dc1e0f55836fa87c3338ff4fe1a9
Reviewed-on: https://gerrit.libreoffice.org/52807Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst ed52ffb6
...@@ -32,6 +32,7 @@ $(eval $(call gb_Library_use_system_win32_libs,instooofiltmsi,\ ...@@ -32,6 +32,7 @@ $(eval $(call gb_Library_use_system_win32_libs,instooofiltmsi,\
libucrt \ libucrt \
libvcruntime \ libvcruntime \
kernel32 \ kernel32 \
advapi32 \
)) ))
# vim: set noet sw=4 ts=4: # vim: set noet sw=4 ts=4:
...@@ -30,34 +30,16 @@ ...@@ -30,34 +30,16 @@
#include <windows.h> #include <windows.h>
#include <msiquery.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"; const wchar_t * const INDEXING_SERVICE_NAME = L"cisvc";
bool StopIndexingService(SC_HANDLE hService) bool StopIndexingService(SC_HANDLE hService)
{ {
SERVICE_STATUS status; 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. // Check the status until the service is no longer stop pending.
if (QueryServiceStatus_(hService, &status)) if (QueryServiceStatus(hService, &status))
{ {
DWORD startTime = GetTickCount(); DWORD startTime = GetTickCount();
DWORD oldCheckPoint = status.dwCheckPoint; DWORD oldCheckPoint = status.dwCheckPoint;
...@@ -77,7 +59,7 @@ bool StopIndexingService(SC_HANDLE hService) ...@@ -77,7 +59,7 @@ bool StopIndexingService(SC_HANDLE hService)
Sleep(waitTime); Sleep(waitTime);
// Check the status again. // Check the status again.
if (!QueryServiceStatus_(hService, &status) || if (!QueryServiceStatus(hService, &status) ||
(status.dwCurrentState == SERVICE_STOPPED)) (status.dwCurrentState == SERVICE_STOPPED))
break; break;
...@@ -98,12 +80,12 @@ bool StopIndexingService(SC_HANDLE hService) ...@@ -98,12 +80,12 @@ bool StopIndexingService(SC_HANDLE hService)
void StartIndexingService(SC_HANDLE hService) void StartIndexingService(SC_HANDLE hService)
{ {
if (StartService_(hService, 0, nullptr)) if (StartServiceW(hService, 0, nullptr))
{ {
SERVICE_STATUS status; SERVICE_STATUS status;
// Check the status until the service is no longer stop pending. // Check the status until the service is no longer stop pending.
if (QueryServiceStatus_(hService, &status)) if (QueryServiceStatus(hService, &status))
{ {
DWORD startTime = GetTickCount(); DWORD startTime = GetTickCount();
DWORD oldCheckPoint = status.dwCheckPoint; DWORD oldCheckPoint = status.dwCheckPoint;
...@@ -123,7 +105,7 @@ void StartIndexingService(SC_HANDLE hService) ...@@ -123,7 +105,7 @@ void StartIndexingService(SC_HANDLE hService)
Sleep(waitTime); Sleep(waitTime);
// Check the status again. // Check the status again.
if (!QueryServiceStatus_(hService, &status) || if (!QueryServiceStatus(hService, &status) ||
(status.dwCurrentState == SERVICE_STOPPED)) (status.dwCurrentState == SERVICE_STOPPED))
break; break;
...@@ -144,32 +126,14 @@ void StartIndexingService(SC_HANDLE hService) ...@@ -144,32 +126,14 @@ void StartIndexingService(SC_HANDLE hService)
extern "C" UINT __stdcall RestartIndexingService(MSIHANDLE) extern "C" UINT __stdcall RestartIndexingService(MSIHANDLE)
{ {
HMODULE hAdvapi32 = LoadLibraryW(L"advapi32.dll"); SC_HANDLE hSCManager = OpenSCManagerW(
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_(
nullptr, // local machine nullptr, // local machine
nullptr, // ServicesActive database nullptr, // ServicesActive database
SC_MANAGER_ALL_ACCESS); SC_MANAGER_ALL_ACCESS);
if (hSCManager != nullptr) if (hSCManager != nullptr)
{ {
SC_HANDLE hIndexingService = OpenService_( SC_HANDLE hIndexingService = OpenServiceW(
hSCManager, INDEXING_SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START | SERVICE_STOP); hSCManager, INDEXING_SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START | SERVICE_STOP);
if (hIndexingService) if (hIndexingService)
...@@ -177,15 +141,15 @@ extern "C" UINT __stdcall RestartIndexingService(MSIHANDLE) ...@@ -177,15 +141,15 @@ extern "C" UINT __stdcall RestartIndexingService(MSIHANDLE)
SERVICE_STATUS status; SERVICE_STATUS status;
ZeroMemory(&status, sizeof(status)); ZeroMemory(&status, sizeof(status));
if (QueryServiceStatus_(hIndexingService, &status) && if (QueryServiceStatus(hIndexingService, &status) &&
(status.dwCurrentState == SERVICE_RUNNING)) (status.dwCurrentState == SERVICE_RUNNING))
{ {
if (StopIndexingService(hIndexingService)) if (StopIndexingService(hIndexingService))
StartIndexingService(hIndexingService); StartIndexingService(hIndexingService);
} }
CloseServiceHandle_(hIndexingService); CloseServiceHandle(hIndexingService);
} }
CloseServiceHandle_(hSCManager); CloseServiceHandle(hSCManager);
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment