Author: gedmurphy Date: Mon Dec 21 14:42:29 2009 New Revision: 44680
URL: http://svn.reactos.org/svn/reactos?rev=44680&view=rev Log: Add full depth of dependencies for the first tree view
Modified: trunk/reactos/base/applications/mscutils/servman/dependencies_tv1.c trunk/reactos/base/applications/mscutils/servman/dependencies_tv2.c trunk/reactos/base/applications/mscutils/servman/precomp.h trunk/reactos/base/applications/mscutils/servman/propsheet_depends.c
Modified: trunk/reactos/base/applications/mscutils/servman/dependencies_tv1.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/... ============================================================================== --- trunk/reactos/base/applications/mscutils/servman/dependencies_tv1.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mscutils/servman/dependencies_tv1.c [iso-8859-1] Mon Dec 21 14:42:29 2009 @@ -80,84 +80,110 @@ return lpStr; }
-static VOID +VOID TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, - SC_HANDLE hService) + LPTSTR lpServiceName) { + SC_HANDLE hSCManager; + SC_HANDLE hService; LPQUERY_SERVICE_CONFIG lpServiceConfig; LPTSTR lpDependants; LPTSTR lpStr; LPTSTR lpNoDepends; BOOL bHasChildren;
- /* Get a list of service dependents */ - lpDependants = TV1_GetDependants(pDlgInfo, hService); - if (lpDependants) + hSCManager = OpenSCManager(NULL, + NULL, + SC_MANAGER_ALL_ACCESS); + if (hSCManager) { - lpStr = lpDependants; - - /* Make sure this isn't the end of the list */ - while (*lpStr) + hService = OpenService(hSCManager, + lpServiceName, + SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG); + if (hService) { - /* Get the info for this service */ - lpServiceConfig = GetServiceConfig(lpStr); - if (lpServiceConfig) + /* Get a list of service dependents */ + lpDependants = TV1_GetDependants(pDlgInfo, hService); + if (lpDependants) { - /* Does this item need a +/- box? */ - bHasChildren = lpServiceConfig->lpDependencies ? TRUE : FALSE; - - /* Add it */ - AddItemToTreeView(pDlgInfo->hDependsTreeView1, - hParent, - lpServiceConfig->lpDisplayName, - lpStr, - lpServiceConfig->dwServiceType, - bHasChildren); + lpStr = lpDependants; + + /* Make sure this isn't the end of the list */ + while (*lpStr) + { + /* Get the info for this service */ + lpServiceConfig = GetServiceConfig(lpStr); + if (lpServiceConfig) + { + /* Does this item need a +/- box? */ + if (lpServiceConfig->lpDependencies && + *lpServiceConfig->lpDependencies != '\0') + { + bHasChildren = TRUE; + } + else + { + bHasChildren = FALSE; + } + + /* Add it */ + AddItemToTreeView(pDlgInfo->hDependsTreeView1, + hParent, + lpServiceConfig->lpDisplayName, + lpStr, + lpServiceConfig->dwServiceType, + bHasChildren); + + HeapFree(GetProcessHeap(), + 0, + lpServiceConfig); + } + + /* Move to the end of the string */ + while (*lpStr++) + ; + }
HeapFree(GetProcessHeap(), 0, - lpServiceConfig); + lpDependants); } - - /* Move to the end of the string */ - while (*lpStr++) - ; + else + { + /* If there is no parent, set the tree to 'no dependencies' */ + if (!hParent) + { + /* Load the 'No dependencies' string */ + AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS); + + AddItemToTreeView(pDlgInfo->hDependsTreeView1, + NULL, + lpNoDepends, + NULL, + 0, + FALSE); + + HeapFree(ProcessHeap, + 0, + lpNoDepends); + + /* Disable the window */ + EnableWindow(pDlgInfo->hDependsTreeView1, FALSE); + } + } + + CloseServiceHandle(hService); }
- HeapFree(GetProcessHeap(), - 0, - lpDependants); - } - else - { - /* If there is no parent, set the tree to 'no dependencies' */ - if (!hParent) - { - /* Load the 'No dependencies' string */ - AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS); - - AddItemToTreeView(pDlgInfo->hDependsTreeView1, - NULL, - lpNoDepends, - NULL, - 0, - FALSE); - - HeapFree(ProcessHeap, - 0, - lpNoDepends); - - /* Disable the window */ - EnableWindow(pDlgInfo->hDependsTreeView1, FALSE); - } + CloseServiceHandle(hSCManager); } }
BOOL TV1_Initialize(PSERVICEPROPSHEET pDlgInfo, - SC_HANDLE hService) + LPTSTR lpServiceName) { BOOL bRet = FALSE;
@@ -174,7 +200,7 @@ TVSIL_NORMAL);
/* Set the first items in the control */ - TV1_AddDependantsToTree(pDlgInfo, NULL, hService); + TV1_AddDependantsToTree(pDlgInfo, NULL, lpServiceName);
return bRet; }
Modified: trunk/reactos/base/applications/mscutils/servman/dependencies_tv2.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/... ============================================================================== --- trunk/reactos/base/applications/mscutils/servman/dependencies_tv2.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mscutils/servman/dependencies_tv2.c [iso-8859-1] Mon Dec 21 14:42:29 2009 @@ -106,62 +106,81 @@ }
-static VOID +VOID TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, - SC_HANDLE hService) -{ + LPTSTR lpServiceName) +{ + SC_HANDLE hSCManager; + SC_HANDLE hService; LPENUM_SERVICE_STATUS lpServiceStatus; LPTSTR lpNoDepends; DWORD count, i; BOOL bHasChildren;
- /* Get a list of service dependents */ - lpServiceStatus = TV2_GetDependants(hService, &count); - if (lpServiceStatus) - { - for (i = 0; i < count; i++) + /* Set the first items in each tree view */ + hSCManager = OpenSCManager(NULL, + NULL, + SC_MANAGER_ALL_ACCESS); + if (hSCManager) + { + hService = OpenService(hSCManager, + lpServiceName, + SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG); + if (hService) { - /* Does this item need a +/- box? */ - bHasChildren = HasDependantServices(lpServiceStatus[i].lpServiceName); - - /* Add it */ - AddItemToTreeView(pDlgInfo->hDependsTreeView2, - hParent, - lpServiceStatus[i].lpDisplayName, - lpServiceStatus[i].lpServiceName, - lpServiceStatus[i].ServiceStatus.dwServiceType, - bHasChildren); + /* Get a list of service dependents */ + lpServiceStatus = TV2_GetDependants(hService, &count); + if (lpServiceStatus) + { + for (i = 0; i < count; i++) + { + /* Does this item need a +/- box? */ + bHasChildren = HasDependantServices(lpServiceStatus[i].lpServiceName); + + /* Add it */ + AddItemToTreeView(pDlgInfo->hDependsTreeView2, + hParent, + lpServiceStatus[i].lpDisplayName, + lpServiceStatus[i].lpServiceName, + lpServiceStatus[i].ServiceStatus.dwServiceType, + bHasChildren); + } + } + else + { + /* If there is no parent, set the tree to 'no dependencies' */ + if (!hParent) + { + /* Load the 'No dependencies' string */ + AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS); + + AddItemToTreeView(pDlgInfo->hDependsTreeView2, + NULL, + lpNoDepends, + NULL, + 0, + FALSE); + + HeapFree(ProcessHeap, + 0, + lpNoDepends); + + /* Disable the window */ + EnableWindow(pDlgInfo->hDependsTreeView2, FALSE); + } + } + + CloseServiceHandle(hService); } - } - else - { - /* If there is no parent, set the tree to 'no dependencies' */ - if (!hParent) - { - /* Load the 'No dependencies' string */ - AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS); - - AddItemToTreeView(pDlgInfo->hDependsTreeView2, - NULL, - lpNoDepends, - NULL, - 0, - FALSE); - - HeapFree(ProcessHeap, - 0, - lpNoDepends); - - /* Disable the window */ - EnableWindow(pDlgInfo->hDependsTreeView2, FALSE); - } + + CloseServiceHandle(hSCManager); } }
BOOL TV2_Initialize(PSERVICEPROPSHEET pDlgInfo, - SC_HANDLE hService) + LPTSTR lpServiceName) { BOOL bRet = FALSE;
@@ -178,7 +197,7 @@ TVSIL_NORMAL);
/* Set the first items in the control */ - TV2_AddDependantsToTree(pDlgInfo, NULL, hService); + TV2_AddDependantsToTree(pDlgInfo, NULL, lpServiceName);
return bRet; }
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] Mon Dec 21 14:42:29 2009 @@ -121,15 +121,15 @@ HTREEITEM AddItemToTreeView(HWND hTreeView, HTREEITEM hRoot, LPTSTR lpDisplayName, LPTSTR lpServiceName, ULONG serviceType, BOOL bHasChildren);
/* dependencies */ -//LPENUM_SERVICE_STATUS GetServiceDependents(SC_HANDLE hService, LPDWORD lpdwCount); INT_PTR CALLBACK StopDependsDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); -//LPTSTR GetDependentServices(SC_HANDLE hService);
/* tv1_dependencies */ -BOOL TV1_Initialize(PSERVICEPROPSHEET pDlgInfo, SC_HANDLE hService); +BOOL TV1_Initialize(PSERVICEPROPSHEET pDlgInfo, LPTSTR lpServiceName); +VOID TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPTSTR lpServiceName);
/* tv2_dependencies */ -BOOL TV2_Initialize(PSERVICEPROPSHEET pDlgInfo, SC_HANDLE hService); +BOOL TV2_Initialize(PSERVICEPROPSHEET pDlgInfo, LPTSTR lpServiceName); +VOID TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPTSTR lpServiceName);
LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info);
Modified: trunk/reactos/base/applications/mscutils/servman/propsheet_depends.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/... ============================================================================== --- trunk/reactos/base/applications/mscutils/servman/propsheet_depends.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mscutils/servman/propsheet_depends.c [iso-8859-1] Mon Dec 21 14:42:29 2009 @@ -12,10 +12,10 @@
HTREEITEM AddItemToTreeView(HWND hTreeView, - HTREEITEM hRoot, + HTREEITEM hParent, LPTSTR lpDisplayName, LPTSTR lpServiceName, - ULONG serviceType, + ULONG ServiceType, BOOL bHasChildren) { TV_ITEM tvi; @@ -24,33 +24,50 @@ ZeroMemory(&tvi, sizeof(tvi)); ZeroMemory(&tvins, sizeof(tvins));
- tvi.mask = TVIF_TEXT | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_CHILDREN; + tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_CHILDREN; tvi.pszText = lpDisplayName; tvi.cchTextMax = _tcslen(lpDisplayName); tvi.cChildren = bHasChildren; //I_CHILDRENCALLBACK;
- if (serviceType == SERVICE_WIN32_OWN_PROCESS || - serviceType == SERVICE_WIN32_SHARE_PROCESS) - { - tvi.iImage = 1; - tvi.iSelectedImage = 1; - } - else if (serviceType == SERVICE_KERNEL_DRIVER || - serviceType == SERVICE_FILE_SYSTEM_DRIVER) - { - tvi.iImage = 2; - tvi.iSelectedImage = 2; - } - else - { - tvi.iImage = 0; - tvi.iSelectedImage = 0; + switch (ServiceType) + { + case SERVICE_WIN32_OWN_PROCESS: + case SERVICE_WIN32_SHARE_PROCESS: + tvi.iImage = 1; + tvi.iSelectedImage = 1; + break; + + case SERVICE_KERNEL_DRIVER: + case SERVICE_FILE_SYSTEM_DRIVER: + tvi.iImage = 2; + tvi.iSelectedImage = 2; + break; + + default: + tvi.iImage = 0; + tvi.iSelectedImage = 0; + break; + } + + /* Attach the service name */ + tvi.lParam = (LPARAM)(LPTSTR)HeapAlloc(GetProcessHeap(), + 0, + (_tcslen(lpServiceName) + 1) * sizeof(TCHAR)); + if (tvi.lParam) + { + _tcscpy((LPTSTR)tvi.lParam, lpServiceName); }
tvins.item = tvi; - tvins.hParent = hRoot; + tvins.hParent = hParent;
return TreeView_InsertItem(hTreeView, &tvins); +} + +static VOID +DestroyTreeView(HWND hTreeView) +{ + //FIXME: traverse the nodes and free the strings }
/* @@ -69,15 +86,30 @@
return TreeView_GetItem(hTreeView, &tv); } + + +static LPARAM +TreeView_GetItemParam(HWND hTreeView, + HTREEITEM hItem) +{ + LPARAM lParam = 0; + TVITEM tv = {0}; + + tv.mask = TVIF_PARAM | TVIF_HANDLE; + tv.hItem = hItem; + + if (TreeView_GetItem(hTreeView, &tv)) + { + lParam = tv.lParam; + } + + return lParam; +} */
-static BOOL +static VOID InitDependPage(PSERVICEPROPSHEET pDlgInfo) { - SC_HANDLE hSCManager; - SC_HANDLE hService; - BOOL bRet = FALSE; - /* Initialize the image list */ pDlgInfo->hDependsImageList = InitImageList(IDI_NODEPENDS, IDI_DRIVER, @@ -85,32 +117,11 @@ GetSystemMetrics(SM_CXSMICON), IMAGE_ICON);
- /* Set the first items in each tree view */ - hSCManager = OpenSCManager(NULL, - NULL, - SC_MANAGER_ALL_ACCESS); - if (hSCManager) - { - hService = OpenService(hSCManager, - pDlgInfo->pService->lpServiceName, - SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG); - if (hService) - { - /* Set the first tree view */ - TV1_Initialize(pDlgInfo, hService); - - /* Set the second tree view */ - TV2_Initialize(pDlgInfo, hService); - - bRet = TRUE; - - CloseServiceHandle(hService); - } - - CloseServiceHandle(hSCManager); - } - - return bRet; + /* Set the first tree view */ + TV1_Initialize(pDlgInfo, pDlgInfo->pService->lpServiceName); + + /* Set the second tree view */ + TV2_Initialize(pDlgInfo, pDlgInfo->pService->lpServiceName); }
@@ -162,7 +173,14 @@
if (lpnmtv->action == TVE_EXPAND) { - + if (lpnmtv->hdr.idFrom == IDC_DEPEND_TREE1) + { + TV1_AddDependantsToTree(pDlgInfo, lpnmtv->itemNew.hItem, (LPTSTR)lpnmtv->itemNew.lParam); + } + else if (lpnmtv->hdr.idFrom == IDC_DEPEND_TREE2) + { + TV2_AddDependantsToTree(pDlgInfo, lpnmtv->itemNew.hItem, (LPTSTR)lpnmtv->itemNew.lParam); + } } break; } @@ -178,6 +196,9 @@ break;
case WM_DESTROY: + DestroyTreeView(pDlgInfo->hDependsTreeView1); + DestroyTreeView(pDlgInfo->hDependsTreeView2); + if (pDlgInfo->hDependsImageList) ImageList_Destroy(pDlgInfo->hDependsImageList); }