Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendependencies_tv1.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/tv1_dependencies.c 00005 * PURPOSE: Helper functions for service dependents 00006 * COPYRIGHT: Copyright 2009 Ged Murphy <gedmurphy@reactos.org> 00007 * 00008 */ 00009 00010 #include "precomp.h" 00011 00012 00013 LPTSTR 00014 TV1_GetDependants(PSERVICEPROPSHEET pDlgInfo, 00015 SC_HANDLE hService) 00016 { 00017 LPQUERY_SERVICE_CONFIG lpServiceConfig; 00018 LPTSTR lpStr = NULL; 00019 DWORD bytesNeeded; 00020 DWORD bytes; 00021 00022 /* Get the info for this service */ 00023 if (!QueryServiceConfig(hService, 00024 NULL, 00025 0, 00026 &bytesNeeded) && 00027 GetLastError() == ERROR_INSUFFICIENT_BUFFER) 00028 { 00029 lpServiceConfig = HeapAlloc(ProcessHeap, 00030 0, 00031 bytesNeeded); 00032 if (lpServiceConfig) 00033 { 00034 if (QueryServiceConfig(hService, 00035 lpServiceConfig, 00036 bytesNeeded, 00037 &bytesNeeded)) 00038 { 00039 /* Does this service have any dependencies? */ 00040 if (lpServiceConfig->lpDependencies && 00041 *lpServiceConfig->lpDependencies != '\0') 00042 { 00043 lpStr = lpServiceConfig->lpDependencies; 00044 bytes = 0; 00045 00046 /* Work out how many bytes we need to hold the list */ 00047 while (TRUE) 00048 { 00049 bytes++; 00050 00051 if (!*lpStr && !*(lpStr + 1)) 00052 { 00053 bytes++; 00054 break; 00055 } 00056 00057 lpStr++; 00058 } 00059 00060 /* Allocate and copy the list */ 00061 bytes *= sizeof(TCHAR); 00062 lpStr = HeapAlloc(ProcessHeap, 00063 0, 00064 bytes); 00065 if (lpStr) 00066 { 00067 CopyMemory(lpStr, 00068 lpServiceConfig->lpDependencies, 00069 bytes); 00070 } 00071 } 00072 } 00073 00074 HeapFree(GetProcessHeap(), 00075 0, 00076 lpServiceConfig); 00077 } 00078 } 00079 00080 return lpStr; 00081 } 00082 00083 VOID 00084 TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, 00085 HTREEITEM hParent, 00086 LPTSTR lpServiceName) 00087 { 00088 SC_HANDLE hSCManager; 00089 SC_HANDLE hService; 00090 LPQUERY_SERVICE_CONFIG lpServiceConfig; 00091 LPTSTR lpDependants; 00092 LPTSTR lpStr; 00093 LPTSTR lpNoDepends; 00094 BOOL bHasChildren; 00095 00096 hSCManager = OpenSCManager(NULL, 00097 NULL, 00098 SC_MANAGER_ALL_ACCESS); 00099 if (hSCManager) 00100 { 00101 hService = OpenService(hSCManager, 00102 lpServiceName, 00103 SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG); 00104 if (hService) 00105 { 00106 /* Get a list of service dependents */ 00107 lpDependants = TV1_GetDependants(pDlgInfo, hService); 00108 if (lpDependants) 00109 { 00110 lpStr = lpDependants; 00111 00112 /* Make sure this isn't the end of the list */ 00113 while (*lpStr) 00114 { 00115 /* Get the info for this service */ 00116 lpServiceConfig = GetServiceConfig(lpStr); 00117 if (lpServiceConfig) 00118 { 00119 /* Does this item need a +/- box? */ 00120 if (lpServiceConfig->lpDependencies && 00121 *lpServiceConfig->lpDependencies != '\0') 00122 { 00123 bHasChildren = TRUE; 00124 } 00125 else 00126 { 00127 bHasChildren = FALSE; 00128 } 00129 00130 /* Add it */ 00131 AddItemToTreeView(pDlgInfo->hDependsTreeView1, 00132 hParent, 00133 lpServiceConfig->lpDisplayName, 00134 lpStr, 00135 lpServiceConfig->dwServiceType, 00136 bHasChildren); 00137 00138 HeapFree(GetProcessHeap(), 00139 0, 00140 lpServiceConfig); 00141 } 00142 00143 /* Move to the end of the string */ 00144 while (*lpStr++) 00145 ; 00146 } 00147 00148 HeapFree(GetProcessHeap(), 00149 0, 00150 lpDependants); 00151 } 00152 else 00153 { 00154 /* If there is no parent, set the tree to 'no dependencies' */ 00155 if (!hParent) 00156 { 00157 /* Load the 'No dependencies' string */ 00158 AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS); 00159 00160 AddItemToTreeView(pDlgInfo->hDependsTreeView1, 00161 NULL, 00162 lpNoDepends, 00163 NULL, 00164 0, 00165 FALSE); 00166 00167 HeapFree(ProcessHeap, 00168 0, 00169 lpNoDepends); 00170 00171 /* Disable the window */ 00172 EnableWindow(pDlgInfo->hDependsTreeView1, FALSE); 00173 } 00174 } 00175 00176 CloseServiceHandle(hService); 00177 } 00178 00179 CloseServiceHandle(hSCManager); 00180 } 00181 } 00182 00183 00184 BOOL 00185 TV1_Initialize(PSERVICEPROPSHEET pDlgInfo, 00186 LPTSTR lpServiceName) 00187 { 00188 BOOL bRet = FALSE; 00189 00190 /* Accociate the imagelist with TV1 */ 00191 pDlgInfo->hDependsTreeView1 = GetDlgItem(pDlgInfo->hDependsWnd, IDC_DEPEND_TREE1); 00192 if (!pDlgInfo->hDependsTreeView1) 00193 { 00194 ImageList_Destroy(pDlgInfo->hDependsImageList); 00195 pDlgInfo->hDependsImageList = NULL; 00196 return FALSE; 00197 } 00198 (void)TreeView_SetImageList(pDlgInfo->hDependsTreeView1, 00199 pDlgInfo->hDependsImageList, 00200 TVSIL_NORMAL); 00201 00202 /* Set the first items in the control */ 00203 TV1_AddDependantsToTree(pDlgInfo, NULL, lpServiceName); 00204 00205 return bRet; 00206 } Generated on Sun May 27 2012 04:16:59 for ReactOS by
1.7.6.1
|