Example #1
0
int CIISConfigHelper::PopulateTreeFromMetaBase(CTreeCtrl& cTree, HTREEITEM htParent, LPCWSTR pszMetaBasePath, LPCWSTR pszURI, IMSAdminBase* pAdminBase, const std::set<CStringW>& IgnoreDirNames, int nVirtualDirectoryIconIndex)
{
	if (htParent == NULL || pszMetaBasePath == NULL || pszURI == NULL || pAdminBase == NULL)
		return 0;	

	// we are going to enum the metabase...
	CIISMetaBase MetaBase(pAdminBase);
	
	// enum the given metabase path for child keys
	std::vector<std::wstring> saKeys;
	if (MetaBase.EnumKeys(CString(pszMetaBasePath), saKeys) == false || saKeys.size() == 0)
		return 0;

	// keep track of the number of child VRs we find
	int nTotalVRs = 0;

	// loop through all the child keys
	for (int i = 0; i < (int) saKeys.size(); i++)
	{
		// check to see whether we should ignore this dir
		if (IgnoreDirNames.find(saKeys[i].c_str()) != IgnoreDirNames.end())
			continue;

		CStringW sChildURI = pszURI;

		int nChildURILength = sChildURI.GetLength();
		if (nChildURILength > 0 && sChildURI[nChildURILength - 1] != '/')
			sChildURI += '/';

		sChildURI += saKeys[i].c_str();

		CStringW sChildMetaBasePath = pszMetaBasePath;
		sChildMetaBasePath += '/';
		sChildMetaBasePath += saKeys[i].c_str();

		// add the key to the tree (since children may need it)
		HTREEITEM htVR = cTree.InsertItem(CString(saKeys[i].c_str()), nVirtualDirectoryIconIndex, nVirtualDirectoryIconIndex, htParent);

		// drop down to enumerate the child key
		int nChildVRs = PopulateTreeFromMetaBase(cTree, htVR, sChildMetaBasePath, sChildURI, pAdminBase, IgnoreDirNames, nVirtualDirectoryIconIndex);

		// if the key doesn't have a VR itself or it didn't have any children with VRs then it's nothing
		// of interest. Delete the tree item and move to the next key.
		CIISMetaBaseData VRPath;		
		if (VRPath.ReadData(pAdminBase, sChildMetaBasePath, MD_VR_PATH) == false && nChildVRs <= 0)
		{
			cTree.DeleteItem(htVR);
			continue;		
		}		

		// we need an item data for this tree item
		IISURIItem* pItem = new IISURIItem;
		pItem->sMetaBasePath = sChildMetaBasePath;
		pItem->sURI = sChildURI;

		// get the VR_PATH (there may not be one)
		std::wstring sVRPath;
		if (VRPath.GetAsString(sVRPath) == true)
		{
			pItem->Type = IISURIItem::VirtualRoot;
			pItem->sFileSystemPath = sVRPath.c_str();
		}
		else
		{
			pItem->Type = IISURIItem::IncompleteFileSystemPath;
		}

		cTree.SetItemData(htVR, (DWORD_PTR) pItem);

		// keep track of the number of VRs in this branch
		nTotalVRs += nChildVRs;
		nTotalVRs++;
	}

	return nTotalVRs;
}