mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 07:32:57 +00:00
- Improve start / stop control
- Use GetSelectedService exclusively svn path=/trunk/; revision=20995
This commit is contained in:
parent
56499760a8
commit
088390e90c
3 changed files with 63 additions and 15 deletions
|
@ -23,6 +23,7 @@ BOOL Control(HWND hProgDlg, DWORD Control)
|
||||||
LVITEM item;
|
LVITEM item;
|
||||||
DWORD BytesNeeded = 0;
|
DWORD BytesNeeded = 0;
|
||||||
DWORD Loop = 5; //FIXME: testing value. needs better control
|
DWORD Loop = 5; //FIXME: testing value. needs better control
|
||||||
|
DWORD dwStartTickCount, dwOldCheckPoint;
|
||||||
|
|
||||||
item.mask = LVIF_PARAM;
|
item.mask = LVIF_PARAM;
|
||||||
item.iItem = GetSelectedItem();
|
item.iItem = GetSelectedItem();
|
||||||
|
@ -72,15 +73,28 @@ BOOL Control(HWND hProgDlg, DWORD Control)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Save the tick count and initial checkpoint. */
|
||||||
|
dwStartTickCount = GetTickCount();
|
||||||
|
dwOldCheckPoint = ServiceStatus.dwCheckPoint;
|
||||||
|
|
||||||
/* loop whilst service is not running */
|
/* loop whilst service is not running */
|
||||||
/* FIXME: needs more control adding. 'Loop' is temparary */
|
/* FIXME: needs more control adding. 'Loop' is temparary */
|
||||||
while (ServiceStatus.dwCurrentState != Control || !Loop)
|
while (ServiceStatus.dwCurrentState != Control || !Loop)
|
||||||
{
|
{
|
||||||
|
DWORD dwWaitTime;
|
||||||
|
|
||||||
|
dwWaitTime = ServiceStatus.dwWaitHint / 10;
|
||||||
|
|
||||||
|
if( dwWaitTime < 500 )
|
||||||
|
dwWaitTime = 500;
|
||||||
|
else if ( dwWaitTime > 5000 )
|
||||||
|
dwWaitTime = 5000;
|
||||||
|
|
||||||
/* increment the progress bar */
|
/* increment the progress bar */
|
||||||
SendMessage(hProgBar, PBM_STEPIT, 0, 0);
|
SendMessage(hProgBar, PBM_STEPIT, 0, 0);
|
||||||
|
|
||||||
/* wait before checking status */
|
/* wait before checking status */
|
||||||
Sleep(ServiceStatus.dwWaitHint / 8);
|
Sleep(dwWaitTime);
|
||||||
|
|
||||||
/* check status again */
|
/* check status again */
|
||||||
if (! QueryServiceStatusEx(
|
if (! QueryServiceStatusEx(
|
||||||
|
@ -93,7 +107,22 @@ BOOL Control(HWND hProgDlg, DWORD Control)
|
||||||
GetError(0);
|
GetError(0);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
Loop--;
|
|
||||||
|
if (ServiceStatus.dwCheckPoint > dwOldCheckPoint)
|
||||||
|
{
|
||||||
|
/* The service is making progress. increment the progress bar */
|
||||||
|
SendMessage(hProgBar, PBM_STEPIT, 0, 0);
|
||||||
|
dwStartTickCount = GetTickCount();
|
||||||
|
dwOldCheckPoint = ServiceStatus.dwCheckPoint;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(GetTickCount() - dwStartTickCount > ServiceStatus.dwWaitHint)
|
||||||
|
{
|
||||||
|
/* No progress made within the wait hint */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseServiceHandle(hSc);
|
CloseServiceHandle(hSc);
|
||||||
|
|
|
@ -96,15 +96,10 @@ BOOL GetExecutablePath(LPTSTR *ExePath)
|
||||||
SC_HANDLE hSc = NULL;
|
SC_HANDLE hSc = NULL;
|
||||||
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
|
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
|
||||||
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
|
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
|
||||||
LVITEM item;
|
|
||||||
DWORD BytesNeeded = 0;
|
DWORD BytesNeeded = 0;
|
||||||
|
|
||||||
item.mask = LVIF_PARAM;
|
|
||||||
item.iItem = GetSelectedItem();
|
|
||||||
SendMessage(hListView, LVM_GETITEM, 0, (LPARAM)&item);
|
|
||||||
|
|
||||||
/* copy pointer to selected service */
|
/* copy pointer to selected service */
|
||||||
Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;
|
Service = GetSelectedService();
|
||||||
|
|
||||||
/* open handle to the SCM */
|
/* open handle to the SCM */
|
||||||
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
|
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
|
||||||
|
|
|
@ -19,17 +19,13 @@ BOOL DoStartService(HWND hProgDlg)
|
||||||
SC_HANDLE hSc;
|
SC_HANDLE hSc;
|
||||||
SERVICE_STATUS_PROCESS ServiceStatus;
|
SERVICE_STATUS_PROCESS ServiceStatus;
|
||||||
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
|
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
|
||||||
LVITEM item;
|
|
||||||
DWORD BytesNeeded = 0;
|
DWORD BytesNeeded = 0;
|
||||||
INT ArgCount = 0;
|
INT ArgCount = 0;
|
||||||
DWORD Loop = 5; //FIXME: testing value. needs better control
|
DWORD Loop = 5; //FIXME: testing value. needs better control
|
||||||
|
DWORD dwStartTickCount, dwOldCheckPoint;
|
||||||
item.mask = LVIF_PARAM;
|
|
||||||
item.iItem = GetSelectedItem();
|
|
||||||
SendMessage(hListView, LVM_GETITEM, 0, (LPARAM)&item);
|
|
||||||
|
|
||||||
/* copy pointer to selected service */
|
/* copy pointer to selected service */
|
||||||
Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;
|
Service = GetSelectedService();
|
||||||
|
|
||||||
/* set the progress bar range and step */
|
/* set the progress bar range and step */
|
||||||
hProgBar = GetDlgItem(hProgDlg, IDC_SERVCON_PROGRESS);
|
hProgBar = GetDlgItem(hProgDlg, IDC_SERVCON_PROGRESS);
|
||||||
|
@ -70,10 +66,23 @@ BOOL DoStartService(HWND hProgDlg)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Save the tick count and initial checkpoint. */
|
||||||
|
dwStartTickCount = GetTickCount();
|
||||||
|
dwOldCheckPoint = ServiceStatus.dwCheckPoint;
|
||||||
|
|
||||||
/* loop whilst service is not running */
|
/* loop whilst service is not running */
|
||||||
/* FIXME: needs more control adding. 'Loop' is temparary */
|
/* FIXME: needs more control adding. 'Loop' is temparary */
|
||||||
while (ServiceStatus.dwCurrentState != SERVICE_RUNNING || !Loop)
|
while (ServiceStatus.dwCurrentState != SERVICE_RUNNING || !Loop)
|
||||||
{
|
{
|
||||||
|
DWORD dwWaitTime;
|
||||||
|
|
||||||
|
dwWaitTime = ServiceStatus.dwWaitHint / 10;
|
||||||
|
|
||||||
|
if( dwWaitTime < 500 )
|
||||||
|
dwWaitTime = 500;
|
||||||
|
else if ( dwWaitTime > 5000 )
|
||||||
|
dwWaitTime = 5000;
|
||||||
|
|
||||||
/* increment the progress bar */
|
/* increment the progress bar */
|
||||||
SendMessage(hProgBar, PBM_STEPIT, 0, 0);
|
SendMessage(hProgBar, PBM_STEPIT, 0, 0);
|
||||||
|
|
||||||
|
@ -91,7 +100,22 @@ BOOL DoStartService(HWND hProgDlg)
|
||||||
GetError(0);
|
GetError(0);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
Loop--;
|
|
||||||
|
if (ServiceStatus.dwCheckPoint > dwOldCheckPoint)
|
||||||
|
{
|
||||||
|
/* The service is making progress. increment the progress bar */
|
||||||
|
SendMessage(hProgBar, PBM_STEPIT, 0, 0);
|
||||||
|
dwStartTickCount = GetTickCount();
|
||||||
|
dwOldCheckPoint = ServiceStatus.dwCheckPoint;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(GetTickCount() - dwStartTickCount > ServiceStatus.dwWaitHint)
|
||||||
|
{
|
||||||
|
/* No progress made within the wait hint */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseServiceHandle(hSc);
|
CloseServiceHandle(hSc);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue