/// <summary> /// Create a virtual node of directories only based on its fullpath /// </summary> /// <param name="tree"></param> /// <param name="parent"></param> /// <param name="controller"></param> /// <param name="delimiter"></param> /// <param name="fullPath"></param> /// <param name="verifyFilename"></param> /// <param name="VirtualImageIndex"></param> /// <param name="NonVirtualImageIndex"></param> /// <param name="VirtualFileImageIndex"></param> /// <param name="NonVirtualFileImageIndex"></param> /// <returns></returns> private TreeNode CreateTreeNodeFullPath(TreeView tree, TreeNode parent, MOG_ControllerSyncData controller, string delimiter, string fullPath, string verifyFilename, DirectorySetInfo fileInfo, int VirtualImageIndex, int NonVirtualImageIndex, int VirtualFileImageIndex, int NonVirtualFileImageIndex, bool directoriesOnly) { TreeNodeCollection topNodes = null; // Get our collections to search if (parent != null) { topNodes = parent.Nodes; } else { topNodes = tree.Nodes; } // Split the full path by the delimiter passed in string[] lastNodeParts = fullPath.Split(delimiter.ToCharArray()); // find the first name TreeNode alreadyExistNode = null; if (parent != null && string.Compare(parent.Text, lastNodeParts[0], true) == 0) { alreadyExistNode = parent; } else { alreadyExistNode = FindTreeNode(topNodes, lastNodeParts[0]); } // if exist find then next from the children of the first if (alreadyExistNode != null) { // Is this a file or directory if (fileInfo.Type == DirectorySetInfo.TYPE.Folder || fileInfo.Type == DirectorySetInfo.TYPE.FolderName) { // Must be a directory if (Directory.Exists(verifyFilename)) { alreadyExistNode.ImageIndex = NonVirtualImageIndex; alreadyExistNode.SelectedImageIndex = NonVirtualImageIndex; alreadyExistNode.ForeColor = SystemColors.ControlText; } else { alreadyExistNode.ImageIndex = VirtualImageIndex; alreadyExistNode.SelectedImageIndex = VirtualImageIndex; alreadyExistNode.ForeColor = SystemColors.GrayText; } } else { // Must be a file if (File.Exists(verifyFilename)) { alreadyExistNode.ImageIndex = NonVirtualFileImageIndex; alreadyExistNode.SelectedImageIndex = NonVirtualFileImageIndex; alreadyExistNode.ForeColor = SystemColors.ControlText; } else { alreadyExistNode.ImageIndex = VirtualFileImageIndex; alreadyExistNode.SelectedImageIndex = VirtualFileImageIndex; alreadyExistNode.ForeColor = SystemColors.GrayText; } } string LastNodePath = ""; // Update our path to be less than what it was for (int i = 1; i < lastNodeParts.Length; i++) { if (LastNodePath.Length == 0) { LastNodePath = lastNodeParts[i]; } else { LastNodePath = LastNodePath + "\\" + lastNodeParts[i]; } } if (LastNodePath.Length > 0) { // recurse into this function for the next node parent = CreateTreeNodeFullPath(tree, alreadyExistNode, controller, delimiter, LastNodePath, verifyFilename, fileInfo, VirtualImageIndex, NonVirtualImageIndex, VirtualFileImageIndex, NonVirtualFileImageIndex, directoriesOnly); } } // if not, create it and all its children right here else { foreach (string nodeLeafName in lastNodeParts) { if (nodeLeafName.Length > 0) { // If we are a file and this is a directoriesOnly create, skip if (fileInfo.Type == DirectorySetInfo.TYPE.File && directoriesOnly) { break; } // Create a node TreeNode newChild = new TreeNode(nodeLeafName); guiAssetTreeTag info = new guiAssetTreeTag(verifyFilename, newChild, controller, true); // Is this a file or directory if (fileInfo.Type == DirectorySetInfo.TYPE.Folder || fileInfo.Type == DirectorySetInfo.TYPE.FolderName) { // Set our type info.TagType = guiAssetTreeTag.TREE_FOCUS.FOLDER; // Must be a directory if (Directory.Exists(verifyFilename)) { newChild.ImageIndex = NonVirtualImageIndex; newChild.SelectedImageIndex = NonVirtualImageIndex; newChild.ForeColor = SystemColors.ControlText; } else { newChild.ImageIndex = VirtualImageIndex; newChild.SelectedImageIndex = VirtualImageIndex; newChild.ForeColor = SystemColors.GrayText; } } else { // Set our type info.TagType = guiAssetTreeTag.TREE_FOCUS.FILE; // Must be a file if (File.Exists(verifyFilename)) { newChild.ImageIndex = NonVirtualFileImageIndex; newChild.SelectedImageIndex = NonVirtualFileImageIndex; newChild.ForeColor = SystemColors.ControlText; } else { newChild.ImageIndex = VirtualFileImageIndex; newChild.SelectedImageIndex = VirtualFileImageIndex; newChild.ForeColor = SystemColors.GrayText; } } if (parent != null) { parent.Nodes.Add(newChild); parent = newChild; } else { int index = tree.Nodes.Add(newChild); parent = tree.Nodes[index]; } newChild.Tag = info; } } // If we are a file and this is a directoriesOnly create, skip if (fileInfo.Type == DirectorySetInfo.TYPE.File && directoriesOnly) { return(null); } return(parent); } return(null); }
/// <summary> /// Fetch the next set of files and folders for this parent folder /// </summary> /// <param name="parent"></param> /// <param name="fullPath"></param> /// <param name="targetGameData"></param> private void VirtualExpand(TreeNode parent, string fullPath, MOG_ControllerSyncData targetGameData) { try { // If we have a gameData target we need to remove it from our path prepatory to the Dictionary lookup of the children of this folder if (targetGameData != null) { // Also remove any begininng backslashes fullPath = fullPath.Replace(targetGameData.GetSyncDirectory(), "").TrimStart("\\".ToCharArray()); } // Search our btree for the children of this folder IDictionaryEnumerator file = this.mSyncTargetFiles.GetFiles(fullPath).GetEnumerator(); // Now itterate through those children while (file.MoveNext()) { string fullDirectoryName = ""; // we now need to reconstruct the full path to this file or folder if (fullPath.Length == 0) { fullDirectoryName = targetGameData.GetSyncDirectory() + "\\" + file.Key as string; } else { fullDirectoryName = targetGameData.GetSyncDirectory() + "\\" + fullPath + "\\" + file.Key as string; } DirectorySetInfo fileInfo = (DirectorySetInfo)file.Value; // Create the node TreeNode newNode = CreateTreeNodeFullPath(GameDataTreeView, parent, targetGameData, "\\", file.Key as string, fullDirectoryName, fileInfo, 0, 0, 0, 0, true); // If this is a newly created node and it is a folder, we assume it has children and create a black node beneath it if (newNode != null && newNode.Nodes.Count == 0) { guiAssetTreeTag info = (guiAssetTreeTag)newNode.Tag; string relationalPath = ""; // Get a relational path to this folder if (fullPath.Length == 0) { relationalPath = file.Key as string; } else { relationalPath = fullPath + "\\" + file.Key as string; } // If this file is a folder and has children, create a place holder 'blank' if (info != null && info.TagType == guiAssetTreeTag.TREE_FOCUS.FOLDER && mSyncTargetFiles.HasFolderChildren(relationalPath, false)) { newNode.Nodes.Add("BLANK"); } } } } catch { } }