2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/stop_dependencies.c
5 * PURPOSE: Routines related to stopping dependent services
6 * COPYRIGHT: Copyright 2006-2010 Ged Murphy <gedmurphy@reactos.org>
14 AddServiceToList(LPWSTR
*lpServiceList
,
15 LPWSTR lpServiceToAdd
)
17 LPWSTR lpNewList
= NULL
;
22 dwToAddSize
= wcslen(lpServiceToAdd
) + 1;
24 /* Is this is the first in the list? */
27 /* Add another char for double null */
30 lpNewList
= HeapAlloc(GetProcessHeap(),
32 dwToAddSize
* sizeof(WCHAR
));
35 /* Copy the service name */
40 /* Add the double null char */
41 lpNewList
[dwToAddSize
- 1] = L
'\0';
49 /* Get the list size */
52 /* Break when we hit the double null */
53 if (*ptr
== L
'\0' && *(ptr
+ 1) == L
'\0')
61 /* Add another char for double null */
64 /* Extend the list size */
65 lpNewList
= HeapReAlloc(GetProcessHeap(),
68 (dwCurSize
+ dwToAddSize
) * sizeof(WCHAR
));
71 /* Copy the service name */
72 wcscpy_s(&lpNewList
[dwCurSize
- 1],
76 /* Add the double null char */
77 lpNewList
[dwCurSize
+ dwToAddSize
- 1] = L
'\0';
85 BuildListOfServicesToStop(LPWSTR
*lpServiceList
,
88 LPENUM_SERVICE_STATUS lpServiceStatus
;
92 /* Get a list of service dependents */
93 lpServiceStatus
= TV2_GetDependants(lpServiceName
, &dwCount
);
96 for (i
= 0; i
< dwCount
; i
++)
98 /* Does this service need stopping? */
99 if (lpServiceStatus
[i
].ServiceStatus
.dwCurrentState
!= SERVICE_STOPPED
&&
100 lpServiceStatus
[i
].ServiceStatus
.dwCurrentState
!= SERVICE_STOP_PENDING
)
102 /* Does this service have any dependents? */
103 if (TV2_HasDependantServices(lpServiceStatus
[i
].lpServiceName
))
105 /* recall this function with the dependent */
106 BuildListOfServicesToStop(lpServiceList
, lpServiceStatus
[i
].lpServiceName
);
109 /* Add the service to the list */
110 *lpServiceList
= AddServiceToList(lpServiceList
, lpServiceStatus
[i
].lpServiceName
);
117 HeapFree(GetProcessHeap(),
126 GetListOfServicesToStop(LPWSTR lpServiceName
)
128 LPWSTR lpServiceList
= NULL
;
130 /* Call recursive function to get our list */
131 if (BuildListOfServicesToStop(&lpServiceList
, lpServiceName
))
132 return lpServiceList
;
139 AddServiceNamesToStop(HWND hServiceListBox
,
140 LPWSTR lpServiceList
)
142 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
145 lpStr
= lpServiceList
;
147 /* Loop through all the services in the list */
150 /* Break when we hit the double null */
151 if (*lpStr
== L
'\0' && *(lpStr
+ 1) == L
'\0')
154 /* If this isn't our first time in the loop we'll
155 have been left on a null char */
159 /* Get the service's display name */
160 lpServiceConfig
= GetServiceConfig(lpStr
);
163 /* Add the service to the listbox */
164 SendMessageW(hServiceListBox
,
167 (LPARAM
)lpServiceConfig
->lpDisplayName
);
170 /* Move onto the next string */
171 while (*lpStr
!= L
'\0')
177 DoInitDependsDialog(PMAIN_WND_INFO pInfo
,
180 HWND hServiceListBox
;
181 LPWSTR lpPartialStr
, lpStr
;
188 /* Tag the info to the window */
189 SetWindowLongPtrW(hDlg
,
193 /* Load the icon for the window */
194 hIcon
= (HICON
)LoadImageW(hInstance
,
195 MAKEINTRESOURCE(IDI_SM_ICON
),
197 GetSystemMetrics(SM_CXSMICON
),
198 GetSystemMetrics(SM_CXSMICON
),
210 /* Load the stop depends note */
211 if (AllocAndLoadString(&lpPartialStr
,
215 /* Get the length required */
216 fullLen
= wcslen(lpPartialStr
) + wcslen(pInfo
->pCurrentService
->lpDisplayName
) + 1;
218 lpStr
= HeapAlloc(ProcessHeap
,
220 fullLen
* sizeof(WCHAR
));
223 /* Add the service name to the depends note */
227 pInfo
->pCurrentService
->lpDisplayName
);
229 /* Add the string to the dialog */
230 SendDlgItemMessageW(hDlg
,
236 HeapFree(ProcessHeap
,
243 HeapFree(ProcessHeap
,
248 /* Display the list of services which need stopping */
249 hServiceListBox
= GetDlgItem(hDlg
,
250 IDC_STOP_DEPENDS_LB
);
253 AddServiceNamesToStop(hServiceListBox
,
254 (LPWSTR
)pInfo
->pTag
);
263 StopDependsDialogProc(HWND hDlg
,
268 PMAIN_WND_INFO pInfo
= NULL
;
270 /* Get the window context */
271 pInfo
= (PMAIN_WND_INFO
)GetWindowLongPtrW(hDlg
,
273 if (pInfo
== NULL
&& message
!= WM_INITDIALOG
)
284 pInfo
= (PMAIN_WND_INFO
)lParam
;
287 bRet
= DoInitDependsDialog(pInfo
, hDlg
);
295 switch (LOWORD(wParam
))