[HEADERS]
[reactos.git] / reactos / base / applications / mscutils / servman / stop_dependencies.c
index 5820a34..a29d43c 100644 (file)
@@ -47,8 +47,12 @@ AddServiceToList(LPWSTR *lpServiceList,
         dwCurSize = 0;
 
         /* Get the list size */
-        while (*ptr != L'\0' || *(ptr + 1) != L'\0')
+        while (TRUE)
         {
+            /* Break when we hit the double null */
+            if (*ptr == L'\0' && *(ptr + 1) == L'\0')
+                break;
+
             ptr++;
             dwCurSize++;
         }
@@ -91,18 +95,24 @@ BuildListOfServicesToStop(LPWSTR *lpServiceList,
     {
         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);
-        }
+                /* Add the service to the list */
+                *lpServiceList = AddServiceToList(lpServiceList, lpServiceStatus[i].lpServiceName);
 
-        bRet = TRUE;
+                /* We've got one */
+                bRet = TRUE;
+            }
+        }
 
         HeapFree(GetProcessHeap(),
                  0,
@@ -125,10 +135,49 @@ GetListOfServicesToStop(LPWSTR lpServiceName)
 }
 
 
+static VOID
+AddServiceNamesToStop(HWND hServiceListBox,
+                      LPWSTR lpServiceList)
+{
+    LPQUERY_SERVICE_CONFIG lpServiceConfig;
+    LPWSTR lpStr;
+
+    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++;
+
+        /* Get the service's display name */
+        lpServiceConfig = GetServiceConfig(lpStr);
+        if (lpServiceConfig)
+        {
+            /* Add the service to the listbox */
+            SendMessageW(hServiceListBox,
+                         LB_ADDSTRING,
+                         0,
+                         (LPARAM)lpServiceConfig->lpDisplayName);
+        }
+
+        /* Move onto the next string */
+        while (*lpStr != L'\0')
+            lpStr++;
+    }
+}
+
 static BOOL
 DoInitDependsDialog(PMAIN_WND_INFO pInfo,
                     HWND hDlg)
 {
+    HWND hServiceListBox;
     LPWSTR lpPartialStr, lpStr;
     DWORD fullLen;
     HICON hIcon = NULL;
@@ -196,8 +245,14 @@ DoInitDependsDialog(PMAIN_WND_INFO pInfo,
                      lpPartialStr);
         }
 
-        /* FIXME: Load the list of services which need stopping */
-
+        /* Display the list of services which need stopping */
+        hServiceListBox = GetDlgItem(hDlg,
+                                     IDC_STOP_DEPENDS_LB);
+        if (hServiceListBox)
+        {
+            AddServiceNamesToStop(hServiceListBox,
+                                  (LPWSTR)pInfo->pTag);
+        }
     }
 
     return bRet;