Add full depth of dependencies for the first tree view

svn path=/trunk/; revision=44680
This commit is contained in:
Ged Murphy 2009-12-21 13:42:29 +00:00
parent 710b5b318b
commit 1ebe1b0e18
4 changed files with 210 additions and 144 deletions

View file

@ -80,84 +80,110 @@ TV1_GetDependants(PSERVICEPROPSHEET pDlgInfo,
return lpStr; return lpStr;
} }
static VOID VOID
TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo,
HTREEITEM hParent, HTREEITEM hParent,
SC_HANDLE hService) LPTSTR lpServiceName)
{ {
SC_HANDLE hSCManager;
SC_HANDLE hService;
LPQUERY_SERVICE_CONFIG lpServiceConfig; LPQUERY_SERVICE_CONFIG lpServiceConfig;
LPTSTR lpDependants; LPTSTR lpDependants;
LPTSTR lpStr; LPTSTR lpStr;
LPTSTR lpNoDepends; LPTSTR lpNoDepends;
BOOL bHasChildren; BOOL bHasChildren;
/* Get a list of service dependents */ hSCManager = OpenSCManager(NULL,
lpDependants = TV1_GetDependants(pDlgInfo, hService); NULL,
if (lpDependants) SC_MANAGER_ALL_ACCESS);
if (hSCManager)
{ {
lpStr = lpDependants; hService = OpenService(hSCManager,
lpServiceName,
/* Make sure this isn't the end of the list */ SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG);
while (*lpStr) if (hService)
{ {
/* Get the info for this service */ /* Get a list of service dependents */
lpServiceConfig = GetServiceConfig(lpStr); lpDependants = TV1_GetDependants(pDlgInfo, hService);
if (lpServiceConfig) if (lpDependants)
{ {
/* Does this item need a +/- box? */ lpStr = lpDependants;
bHasChildren = lpServiceConfig->lpDependencies ? TRUE : FALSE;
/* Add it */ /* Make sure this isn't the end of the list */
AddItemToTreeView(pDlgInfo->hDependsTreeView1, while (*lpStr)
hParent, {
lpServiceConfig->lpDisplayName, /* Get the info for this service */
lpStr, lpServiceConfig = GetServiceConfig(lpStr);
lpServiceConfig->dwServiceType, if (lpServiceConfig)
bHasChildren); {
/* 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(), HeapFree(GetProcessHeap(),
0, 0,
lpServiceConfig); 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);
}
} }
/* Move to the end of the string */ CloseServiceHandle(hService);
while (*lpStr++)
;
} }
HeapFree(GetProcessHeap(), CloseServiceHandle(hSCManager);
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);
}
} }
} }
BOOL BOOL
TV1_Initialize(PSERVICEPROPSHEET pDlgInfo, TV1_Initialize(PSERVICEPROPSHEET pDlgInfo,
SC_HANDLE hService) LPTSTR lpServiceName)
{ {
BOOL bRet = FALSE; BOOL bRet = FALSE;
@ -174,7 +200,7 @@ TV1_Initialize(PSERVICEPROPSHEET pDlgInfo,
TVSIL_NORMAL); TVSIL_NORMAL);
/* Set the first items in the control */ /* Set the first items in the control */
TV1_AddDependantsToTree(pDlgInfo, NULL, hService); TV1_AddDependantsToTree(pDlgInfo, NULL, lpServiceName);
return bRet; return bRet;
} }

View file

@ -106,62 +106,81 @@ TV2_GetDependants(SC_HANDLE hService,
} }
static VOID VOID
TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo,
HTREEITEM hParent, HTREEITEM hParent,
SC_HANDLE hService) LPTSTR lpServiceName)
{ {
SC_HANDLE hSCManager;
SC_HANDLE hService;
LPENUM_SERVICE_STATUS lpServiceStatus; LPENUM_SERVICE_STATUS lpServiceStatus;
LPTSTR lpNoDepends; LPTSTR lpNoDepends;
DWORD count, i; DWORD count, i;
BOOL bHasChildren; BOOL bHasChildren;
/* Get a list of service dependents */ /* Set the first items in each tree view */
lpServiceStatus = TV2_GetDependants(hService, &count); hSCManager = OpenSCManager(NULL,
if (lpServiceStatus) NULL,
SC_MANAGER_ALL_ACCESS);
if (hSCManager)
{ {
for (i = 0; i < count; i++) hService = OpenService(hSCManager,
lpServiceName,
SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG);
if (hService)
{ {
/* Does this item need a +/- box? */ /* Get a list of service dependents */
bHasChildren = HasDependantServices(lpServiceStatus[i].lpServiceName); 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 */ /* Add it */
AddItemToTreeView(pDlgInfo->hDependsTreeView2, AddItemToTreeView(pDlgInfo->hDependsTreeView2,
hParent, hParent,
lpServiceStatus[i].lpDisplayName, lpServiceStatus[i].lpDisplayName,
lpServiceStatus[i].lpServiceName, lpServiceStatus[i].lpServiceName,
lpServiceStatus[i].ServiceStatus.dwServiceType, lpServiceStatus[i].ServiceStatus.dwServiceType,
bHasChildren); 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, CloseServiceHandle(hSCManager);
NULL,
lpNoDepends,
NULL,
0,
FALSE);
HeapFree(ProcessHeap,
0,
lpNoDepends);
/* Disable the window */
EnableWindow(pDlgInfo->hDependsTreeView2, FALSE);
}
} }
} }
BOOL BOOL
TV2_Initialize(PSERVICEPROPSHEET pDlgInfo, TV2_Initialize(PSERVICEPROPSHEET pDlgInfo,
SC_HANDLE hService) LPTSTR lpServiceName)
{ {
BOOL bRet = FALSE; BOOL bRet = FALSE;
@ -178,7 +197,7 @@ TV2_Initialize(PSERVICEPROPSHEET pDlgInfo,
TVSIL_NORMAL); TVSIL_NORMAL);
/* Set the first items in the control */ /* Set the first items in the control */
TV2_AddDependantsToTree(pDlgInfo, NULL, hService); TV2_AddDependantsToTree(pDlgInfo, NULL, lpServiceName);
return bRet; return bRet;
} }

View file

@ -121,15 +121,15 @@ typedef struct _SERVICEPROPSHEET
HTREEITEM AddItemToTreeView(HWND hTreeView, HTREEITEM hRoot, LPTSTR lpDisplayName, LPTSTR lpServiceName, ULONG serviceType, BOOL bHasChildren); HTREEITEM AddItemToTreeView(HWND hTreeView, HTREEITEM hRoot, LPTSTR lpDisplayName, LPTSTR lpServiceName, ULONG serviceType, BOOL bHasChildren);
/* dependencies */ /* dependencies */
//LPENUM_SERVICE_STATUS GetServiceDependents(SC_HANDLE hService, LPDWORD lpdwCount);
INT_PTR CALLBACK StopDependsDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK StopDependsDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
//LPTSTR GetDependentServices(SC_HANDLE hService);
/* tv1_dependencies */ /* 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 */ /* 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); LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info);

View file

@ -12,10 +12,10 @@
HTREEITEM HTREEITEM
AddItemToTreeView(HWND hTreeView, AddItemToTreeView(HWND hTreeView,
HTREEITEM hRoot, HTREEITEM hParent,
LPTSTR lpDisplayName, LPTSTR lpDisplayName,
LPTSTR lpServiceName, LPTSTR lpServiceName,
ULONG serviceType, ULONG ServiceType,
BOOL bHasChildren) BOOL bHasChildren)
{ {
TV_ITEM tvi; TV_ITEM tvi;
@ -24,35 +24,52 @@ AddItemToTreeView(HWND hTreeView,
ZeroMemory(&tvi, sizeof(tvi)); ZeroMemory(&tvi, sizeof(tvi));
ZeroMemory(&tvins, sizeof(tvins)); 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.pszText = lpDisplayName;
tvi.cchTextMax = _tcslen(lpDisplayName); tvi.cchTextMax = _tcslen(lpDisplayName);
tvi.cChildren = bHasChildren; //I_CHILDRENCALLBACK; tvi.cChildren = bHasChildren; //I_CHILDRENCALLBACK;
if (serviceType == SERVICE_WIN32_OWN_PROCESS || switch (ServiceType)
serviceType == SERVICE_WIN32_SHARE_PROCESS)
{ {
tvi.iImage = 1; case SERVICE_WIN32_OWN_PROCESS:
tvi.iSelectedImage = 1; 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;
} }
else if (serviceType == SERVICE_KERNEL_DRIVER ||
serviceType == SERVICE_FILE_SYSTEM_DRIVER) /* Attach the service name */
tvi.lParam = (LPARAM)(LPTSTR)HeapAlloc(GetProcessHeap(),
0,
(_tcslen(lpServiceName) + 1) * sizeof(TCHAR));
if (tvi.lParam)
{ {
tvi.iImage = 2; _tcscpy((LPTSTR)tvi.lParam, lpServiceName);
tvi.iSelectedImage = 2;
}
else
{
tvi.iImage = 0;
tvi.iSelectedImage = 0;
} }
tvins.item = tvi; tvins.item = tvi;
tvins.hParent = hRoot; tvins.hParent = hParent;
return TreeView_InsertItem(hTreeView, &tvins); return TreeView_InsertItem(hTreeView, &tvins);
} }
static VOID
DestroyTreeView(HWND hTreeView)
{
//FIXME: traverse the nodes and free the strings
}
/* /*
static BOOL static BOOL
TreeView_GetItemText(HWND hTreeView, TreeView_GetItemText(HWND hTreeView,
@ -69,15 +86,30 @@ TreeView_GetItemText(HWND hTreeView,
return TreeView_GetItem(hTreeView, &tv); 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) InitDependPage(PSERVICEPROPSHEET pDlgInfo)
{ {
SC_HANDLE hSCManager;
SC_HANDLE hService;
BOOL bRet = FALSE;
/* Initialize the image list */ /* Initialize the image list */
pDlgInfo->hDependsImageList = InitImageList(IDI_NODEPENDS, pDlgInfo->hDependsImageList = InitImageList(IDI_NODEPENDS,
IDI_DRIVER, IDI_DRIVER,
@ -85,32 +117,11 @@ InitDependPage(PSERVICEPROPSHEET pDlgInfo)
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CXSMICON),
IMAGE_ICON); IMAGE_ICON);
/* Set the first items in each tree view */ /* Set the first tree view */
hSCManager = OpenSCManager(NULL, TV1_Initialize(pDlgInfo, pDlgInfo->pService->lpServiceName);
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 */ /* Set the second tree view */
TV2_Initialize(pDlgInfo, hService); TV2_Initialize(pDlgInfo, pDlgInfo->pService->lpServiceName);
bRet = TRUE;
CloseServiceHandle(hService);
}
CloseServiceHandle(hSCManager);
}
return bRet;
} }
@ -162,7 +173,14 @@ DependenciesPageProc(HWND hwndDlg,
if (lpnmtv->action == TVE_EXPAND) 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; break;
} }
@ -178,6 +196,9 @@ DependenciesPageProc(HWND hwndDlg,
break; break;
case WM_DESTROY: case WM_DESTROY:
DestroyTreeView(pDlgInfo->hDependsTreeView1);
DestroyTreeView(pDlgInfo->hDependsTreeView2);
if (pDlgInfo->hDependsImageList) if (pDlgInfo->hDependsImageList)
ImageList_Destroy(pDlgInfo->hDependsImageList); ImageList_Destroy(pDlgInfo->hDependsImageList);
} }