Author: gedmurphy
Date: Tue Jan 5 21:41:14 2010
New Revision: 44961
URL: http://svn.reactos.org/svn/reactos?rev=44961&view=rev
Log:
[SERVMAN]
- Fully implement stopping all dependent services
- When stopping a service, only list other running services which require stopping
- Use the same progress dialog for stopping multiple services and make it smoother
Modified:
trunk/reactos/base/applications/mscutils/servman/control.c
trunk/reactos/base/applications/mscutils/servman/precomp.h
trunk/reactos/base/applications/mscutils/servman/progress.c
trunk/reactos/base/applications/mscutils/servman/start.c
trunk/reactos/base/applications/mscutils/servman/stop.c
trunk/reactos/base/applications/mscutils/servman/stop_dependencies.c
Modified: trunk/reactos/base/applications/mscutils/servman/control.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/control.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/control.c [iso-8859-1] Tue Jan 5 21:41:14 2010
@@ -121,10 +121,11 @@
HWND hProgDlg;
hProgDlg = CreateProgressDialog(Info->hMainWnd,
- Info->pCurrentService->lpServiceName,
IDS_PROGRESS_INFO_PAUSE);
if (hProgDlg)
{
+ InitializeProgressDialog(hProgDlg, Info->pCurrentService->lpServiceName);
+
ret = Control(Info,
hProgDlg,
SERVICE_CONTROL_PAUSE);
@@ -142,10 +143,11 @@
HWND hProgDlg;
hProgDlg = CreateProgressDialog(Info->hMainWnd,
- Info->pCurrentService->lpServiceName,
IDS_PROGRESS_INFO_RESUME);
if (hProgDlg)
{
+ InitializeProgressDialog(hProgDlg, Info->pCurrentService->lpServiceName);
+
ret = Control(Info,
hProgDlg,
SERVICE_CONTROL_CONTINUE);
Modified: trunk/reactos/base/applications/mscutils/servman/precomp.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/precomp.h [iso-8859-1] Tue Jan 5 21:41:14 2010
@@ -97,8 +97,9 @@
/* progress.c */
#define DEFAULT_STEP 0
-HWND CreateProgressDialog(HWND hParent, LPTSTR lpServiceName, UINT LabelId);
+HWND CreateProgressDialog(HWND hParent, UINT LabelId);
BOOL DestroyProgressDialog(HWND hProgDlg, BOOL bComplete);
+VOID InitializeProgressDialog(HWND hProgDlg, LPWSTR lpServiceName);
VOID IncrementProgressBar(HWND hProgDlg, UINT NewPos);
VOID CompleteProgressBar(HWND hProgDlg);
Modified: trunk/reactos/base/applications/mscutils/servman/progress.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/progress.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/progress.c [iso-8859-1] Tue Jan 5 21:41:14 2010
@@ -75,6 +75,25 @@
}
}
+VOID
+InitializeProgressDialog(HWND hProgDlg,
+ LPWSTR lpServiceName)
+{
+ /* Write the service name to the dialog */
+ SendDlgItemMessageW(hProgDlg,
+ IDC_SERVCON_NAME,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)lpServiceName);
+
+ /* Set the progress bar to the start */
+ SendDlgItemMessageW(hProgDlg,
+ IDC_SERVCON_PROGRESS,
+ PBM_SETPOS,
+ 0,
+ 0);
+}
+
INT_PTR CALLBACK
ProgressDialogProc(HWND hDlg,
UINT Message,
@@ -124,7 +143,6 @@
HWND
CreateProgressDialog(HWND hParent,
- LPTSTR lpServiceName,
UINT LabelId)
{
HWND hProgDlg;
@@ -153,13 +171,6 @@
0,
lpProgStr);
}
-
- /* Write the service name to the dialog */
- SendDlgItemMessageW(hProgDlg,
- IDC_SERVCON_NAME,
- WM_SETTEXT,
- 0,
- (LPARAM)lpServiceName);
}
return hProgDlg;
Modified: trunk/reactos/base/applications/mscutils/servman/start.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/start.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/start.c [iso-8859-1] Tue Jan 5 21:41:14 2010
@@ -116,12 +116,11 @@
BOOL bRet = FALSE;
hProgDlg = CreateProgressDialog(Info->hMainWnd,
- Info->pCurrentService->lpServiceName,
IDS_PROGRESS_INFO_START);
if (hProgDlg)
{
- IncrementProgressBar(hProgDlg, DEFAULT_STEP);
+ InitializeProgressDialog(hProgDlg, Info->pCurrentService->lpServiceName);
bRet = DoStartService(Info,
hProgDlg);
Modified: trunk/reactos/base/applications/mscutils/servman/stop.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/stop.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/stop.c [iso-8859-1] Tue Jan 5 21:41:14 2010
@@ -25,8 +25,8 @@
if (hProgress)
{
- /* Increment the progress bar */
- IncrementProgressBar(hProgress, DEFAULT_STEP);
+ /* Set the service name and reset the progress bag */
+ InitializeProgressDialog(hProgress, lpServiceName);
}
hSCManager = OpenSCManager(NULL,
@@ -62,6 +62,10 @@
while (ServiceStatus.dwCurrentState != SERVICE_STOPPED)
{
+ /* Don't sleep for more than 3 seconds */
+ if (ServiceStatus.dwWaitHint > 3000)
+ ServiceStatus.dwWaitHint = 3000;
+
Sleep(ServiceStatus.dwWaitHint);
if (hProgress)
@@ -103,11 +107,41 @@
static BOOL
StopDependantServices(PMAIN_WND_INFO pInfo,
- LPWSTR lpServiceName)
+ LPWSTR lpServiceList,
+ HWND hProgress OPTIONAL)
{
+ LPWSTR lpStr;
BOOL bRet = FALSE;
- MessageBox(NULL, L"Rewrite StopDependentServices", NULL, 0);
+ lpStr = lpServiceList;
+
+ /* Loop through all the services in the list */
+ while (TRUE)
+ {
+ /* Break when we hit the double null */
+ if (*lpStr == L'\0' && *(lpStr + 1) == L'\0')
+ break;
+
+ /* If this isn't our first time in the loop we'll
+ have been left on a null char */
+ if (*lpStr == L'\0')
+ lpStr++;
+
+ /* Stop the requested service */
+ bRet = StopService(pInfo,
+ lpStr,
+ hProgress);
+
+ /* Complete the progress bar if we succeeded */
+ if (bRet)
+ {
+ CompleteProgressBar(hProgress);
+ }
+
+ /* Move onto the next string */
+ while (*lpStr != L'\0')
+ lpStr++;
+ }
return bRet;
}
@@ -119,43 +153,57 @@
HWND hProgress;
LPWSTR lpServiceList;
BOOL bRet = FALSE;
- BOOL bStop = TRUE;
+ BOOL bStopMainService = TRUE;
if (pInfo)
{
- /* Does this service have anything which depends on it? */
- if (TV2_HasDependantServices(pInfo->pCurrentService->lpServiceName))
- {
- /* It does, get a list of all the services which need stopping */
- lpServiceList = GetListOfServicesToStop(pInfo->pCurrentService->lpServiceName);
- if (lpServiceList)
- {
- /* Tag the service list to the main wnd info */
- pInfo->pTag = (PVOID)lpServiceList;
-
- /* List them and ask the user if they want to stop them */
- if (DialogBoxParamW(hInstance,
- MAKEINTRESOURCEW(IDD_DLG_DEPEND_STOP),
- pInfo->hMainWnd,
- StopDependsDialogProc,
- (LPARAM)pInfo) == IDOK)
- {
- /* Stop all the dependant services */
- StopDependantServices(pInfo, pInfo->pCurrentService->lpServiceName);
- }
- else
- {
- /* Don't stop the main service if the user selected not to */
- bStop = FALSE;
- }
- }
- }
-
- if (bStop)
+ /* Does the service have any dependent services which need stopping first */
+ lpServiceList = GetListOfServicesToStop(pInfo->pCurrentService->lpServiceName);
+ if (lpServiceList)
+ {
+ /* Tag the service list to the main wnd info */
+ pInfo->pTag = (PVOID)lpServiceList;
+
+ /* List them and ask the user if they want to stop them */
+ if (DialogBoxParamW(hInstance,
+ MAKEINTRESOURCEW(IDD_DLG_DEPEND_STOP),
+ pInfo->hMainWnd,
+ StopDependsDialogProc,
+ (LPARAM)pInfo) == IDOK)
+ {
+ /* Create a progress window to track the progress of the stopping services */
+ hProgress = CreateProgressDialog(pInfo->hMainWnd,
+ IDS_PROGRESS_INFO_STOP);
+
+ /* Stop all the dependant services */
+ StopDependantServices(pInfo, lpServiceList, hProgress);
+
+ /* Now stop the requested one */
+ bRet = StopService(pInfo,
+ pInfo->pCurrentService->lpServiceName,
+ hProgress);
+
+ /* We've already stopped the main service, don't try to stop it again */
+ bStopMainService = FALSE;
+
+ if (hProgress)
+ {
+ /* Complete and destroy the progress bar */
+ DestroyProgressDialog(hProgress, TRUE);
+ }
+ }
+ else
+ {
+ /* Don't stop the main service if the user selected not to */
+ bStopMainService = FALSE;
+ }
+ }
+
+ /* If the service has no running dependents, then we stop it here */
+ if (bStopMainService)
{
/* Create a progress window to track the progress of the stopping service */
hProgress = CreateProgressDialog(pInfo->hMainWnd,
- pInfo->pCurrentService->lpServiceName,
IDS_PROGRESS_INFO_STOP);
/* Stop the requested service */
Modified: trunk/reactos/base/applications/mscutils/servman/stop_dependencies.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/stop_dependencies.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/stop_dependencies.c [iso-8859-1] Tue Jan 5 21:41:14 2010
@@ -95,18 +95,24 @@
{
for (i = 0; i < dwCount; i++)
{
- /* Does this service have any dependents? */
- if (TV2_HasDependantServices(lpServiceStatus[i].lpServiceName))
+ /* Does this service need stopping? */
+ if (lpServiceStatus[i].ServiceStatus.dwCurrentState != SERVICE_STOPPED &&
+ lpServiceStatus[i].ServiceStatus.dwCurrentState != SERVICE_STOP_PENDING)
{
- /* recall this function with the dependent */
- BuildListOfServicesToStop(lpServiceList, lpServiceStatus[i].lpServiceName);
+ /* Does this service have any dependents? */
+ if (TV2_HasDependantServices(lpServiceStatus[i].lpServiceName))
+ {
+ /* recall this function with the dependent */
+ BuildListOfServicesToStop(lpServiceList, lpServiceStatus[i].lpServiceName);
+ }
+
+ /* Add the service to the list */
+ *lpServiceList = AddServiceToList(lpServiceList, lpServiceStatus[i].lpServiceName);
+
+ /* We've got one */
+ bRet = TRUE;
}
-
- /* Add the service to the list */
- *lpServiceList = AddServiceToList(lpServiceList, lpServiceStatus[i].lpServiceName);
- }
-
- bRet = TRUE;
+ }
HeapFree(GetProcessHeap(),
0,