Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenstop_dependencies.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Services 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: base/applications/mscutils/servman/stop_dependencies.c 00005 * PURPOSE: Routines related to stopping dependent services 00006 * COPYRIGHT: Copyright 2006-2010 Ged Murphy <gedmurphy@reactos.org> 00007 * 00008 */ 00009 00010 #include "precomp.h" 00011 00012 00013 static LPWSTR 00014 AddServiceToList(LPWSTR *lpServiceList, 00015 LPWSTR lpServiceToAdd) 00016 { 00017 LPWSTR lpNewList = NULL; 00018 LPWSTR ptr; 00019 DWORD dwToAddSize; 00020 DWORD dwCurSize; 00021 00022 dwToAddSize = wcslen(lpServiceToAdd) + 1; 00023 00024 /* Is this is the first in the list? */ 00025 if (!*lpServiceList) 00026 { 00027 /* Add another char for double null */ 00028 dwToAddSize++; 00029 00030 lpNewList = HeapAlloc(GetProcessHeap(), 00031 0, 00032 dwToAddSize * sizeof(WCHAR)); 00033 if (lpNewList) 00034 { 00035 /* Copy the service name */ 00036 wcscpy_s(lpNewList, 00037 dwToAddSize, 00038 lpServiceToAdd); 00039 00040 /* Add the double null char */ 00041 lpNewList[dwToAddSize - 1] = L'\0'; 00042 } 00043 } 00044 else 00045 { 00046 ptr = *lpServiceList; 00047 dwCurSize = 0; 00048 00049 /* Get the list size */ 00050 while (TRUE) 00051 { 00052 /* Break when we hit the double null */ 00053 if (*ptr == L'\0' && *(ptr + 1) == L'\0') 00054 break; 00055 00056 ptr++; 00057 dwCurSize++; 00058 } 00059 dwCurSize++; 00060 00061 /* Add another char for double null */ 00062 dwCurSize++; 00063 00064 /* Extend the list size */ 00065 lpNewList = HeapReAlloc(GetProcessHeap(), 00066 0, 00067 *lpServiceList, 00068 (dwCurSize + dwToAddSize) * sizeof(WCHAR)); 00069 if (lpNewList) 00070 { 00071 /* Copy the service name */ 00072 wcscpy_s(&lpNewList[dwCurSize - 1], 00073 dwToAddSize, 00074 lpServiceToAdd); 00075 00076 /* Add the double null char */ 00077 lpNewList[dwCurSize + dwToAddSize - 1] = L'\0'; 00078 } 00079 } 00080 00081 return lpNewList; 00082 } 00083 00084 static BOOL 00085 BuildListOfServicesToStop(LPWSTR *lpServiceList, 00086 LPWSTR lpServiceName) 00087 { 00088 LPENUM_SERVICE_STATUS lpServiceStatus; 00089 DWORD dwCount, i; 00090 BOOL bRet = FALSE; 00091 00092 /* Get a list of service dependents */ 00093 lpServiceStatus = TV2_GetDependants(lpServiceName, &dwCount); 00094 if (lpServiceStatus) 00095 { 00096 for (i = 0; i < dwCount; i++) 00097 { 00098 /* Does this service need stopping? */ 00099 if (lpServiceStatus[i].ServiceStatus.dwCurrentState != SERVICE_STOPPED && 00100 lpServiceStatus[i].ServiceStatus.dwCurrentState != SERVICE_STOP_PENDING) 00101 { 00102 /* Does this service have any dependents? */ 00103 if (TV2_HasDependantServices(lpServiceStatus[i].lpServiceName)) 00104 { 00105 /* recall this function with the dependent */ 00106 BuildListOfServicesToStop(lpServiceList, lpServiceStatus[i].lpServiceName); 00107 } 00108 00109 /* Add the service to the list */ 00110 *lpServiceList = AddServiceToList(lpServiceList, lpServiceStatus[i].lpServiceName); 00111 00112 /* We've got one */ 00113 bRet = TRUE; 00114 } 00115 } 00116 00117 HeapFree(GetProcessHeap(), 00118 0, 00119 lpServiceStatus); 00120 } 00121 00122 return bRet; 00123 } 00124 00125 LPWSTR 00126 GetListOfServicesToStop(LPWSTR lpServiceName) 00127 { 00128 LPWSTR lpServiceList = NULL; 00129 00130 /* Call recursive function to get our list */ 00131 if (BuildListOfServicesToStop(&lpServiceList, lpServiceName)) 00132 return lpServiceList; 00133 else 00134 return NULL; 00135 } 00136 00137 00138 static VOID 00139 AddServiceNamesToStop(HWND hServiceListBox, 00140 LPWSTR lpServiceList) 00141 { 00142 LPQUERY_SERVICE_CONFIG lpServiceConfig; 00143 LPWSTR lpStr; 00144 00145 lpStr = lpServiceList; 00146 00147 /* Loop through all the services in the list */ 00148 while (TRUE) 00149 { 00150 /* Break when we hit the double null */ 00151 if (*lpStr == L'\0' && *(lpStr + 1) == L'\0') 00152 break; 00153 00154 /* If this isn't our first time in the loop we'll 00155 have been left on a null char */ 00156 if (*lpStr == L'\0') 00157 lpStr++; 00158 00159 /* Get the service's display name */ 00160 lpServiceConfig = GetServiceConfig(lpStr); 00161 if (lpServiceConfig) 00162 { 00163 /* Add the service to the listbox */ 00164 SendMessageW(hServiceListBox, 00165 LB_ADDSTRING, 00166 0, 00167 (LPARAM)lpServiceConfig->lpDisplayName); 00168 } 00169 00170 /* Move onto the next string */ 00171 while (*lpStr != L'\0') 00172 lpStr++; 00173 } 00174 } 00175 00176 static BOOL 00177 DoInitDependsDialog(PMAIN_WND_INFO pInfo, 00178 HWND hDlg) 00179 { 00180 HWND hServiceListBox; 00181 LPWSTR lpPartialStr, lpStr; 00182 DWORD fullLen; 00183 HICON hIcon = NULL; 00184 BOOL bRet = FALSE; 00185 00186 if (pInfo) 00187 { 00188 /* Tag the info to the window */ 00189 SetWindowLongPtrW(hDlg, 00190 GWLP_USERDATA, 00191 (LONG_PTR)pInfo); 00192 00193 /* Load the icon for the window */ 00194 hIcon = (HICON)LoadImageW(hInstance, 00195 MAKEINTRESOURCE(IDI_SM_ICON), 00196 IMAGE_ICON, 00197 GetSystemMetrics(SM_CXSMICON), 00198 GetSystemMetrics(SM_CXSMICON), 00199 0); 00200 if (hIcon) 00201 { 00202 /* Set it */ 00203 SendMessageW(hDlg, 00204 WM_SETICON, 00205 ICON_SMALL, 00206 (LPARAM)hIcon); 00207 DestroyIcon(hIcon); 00208 } 00209 00210 /* Load the stop depends note */ 00211 if (AllocAndLoadString(&lpPartialStr, 00212 hInstance, 00213 IDS_STOP_DEPENDS)) 00214 { 00215 /* Get the length required */ 00216 fullLen = wcslen(lpPartialStr) + wcslen(pInfo->pCurrentService->lpDisplayName) + 1; 00217 00218 lpStr = HeapAlloc(ProcessHeap, 00219 0, 00220 fullLen * sizeof(WCHAR)); 00221 if (lpStr) 00222 { 00223 /* Add the service name to the depends note */ 00224 _snwprintf(lpStr, 00225 fullLen, 00226 lpPartialStr, 00227 pInfo->pCurrentService->lpDisplayName); 00228 00229 /* Add the string to the dialog */ 00230 SendDlgItemMessageW(hDlg, 00231 IDC_STOP_DEPENDS, 00232 WM_SETTEXT, 00233 0, 00234 (LPARAM)lpStr); 00235 00236 HeapFree(ProcessHeap, 00237 0, 00238 lpStr); 00239 00240 bRet = TRUE; 00241 } 00242 00243 HeapFree(ProcessHeap, 00244 0, 00245 lpPartialStr); 00246 } 00247 00248 /* Display the list of services which need stopping */ 00249 hServiceListBox = GetDlgItem(hDlg, 00250 IDC_STOP_DEPENDS_LB); 00251 if (hServiceListBox) 00252 { 00253 AddServiceNamesToStop(hServiceListBox, 00254 (LPWSTR)pInfo->pTag); 00255 } 00256 } 00257 00258 return bRet; 00259 } 00260 00261 00262 INT_PTR CALLBACK 00263 StopDependsDialogProc(HWND hDlg, 00264 UINT message, 00265 WPARAM wParam, 00266 LPARAM lParam) 00267 { 00268 PMAIN_WND_INFO pInfo = NULL; 00269 00270 /* Get the window context */ 00271 pInfo = (PMAIN_WND_INFO)GetWindowLongPtrW(hDlg, 00272 GWLP_USERDATA); 00273 if (pInfo == NULL && message != WM_INITDIALOG) 00274 { 00275 return FALSE; 00276 } 00277 00278 switch (message) 00279 { 00280 case WM_INITDIALOG: 00281 { 00282 BOOL bRet = FALSE; 00283 00284 pInfo = (PMAIN_WND_INFO)lParam; 00285 if (pInfo != NULL) 00286 { 00287 bRet = DoInitDependsDialog(pInfo, hDlg); 00288 } 00289 00290 return bRet; 00291 } 00292 00293 case WM_COMMAND: 00294 { 00295 switch (LOWORD(wParam)) 00296 { 00297 case IDOK: 00298 case IDCANCEL: 00299 { 00300 EndDialog(hDlg, 00301 LOWORD(wParam)); 00302 return TRUE; 00303 } 00304 } 00305 } 00306 } 00307 00308 return FALSE; 00309 } Generated on Sat May 26 2012 04:15:58 for ReactOS by
1.7.6.1
|