public static FiaTreeNode ArchiveNodeAdd(FiaTreeNode parentNode, string[] pathes, int pathDepth, FileInArchive fia) { FiaTreeNode childNode = null; if (pathes.Length > pathDepth + 1) //means we are not yet at filelevel { //We search the child nodes for the path part for (int j = 0; j < parentNode.Nodes.Count; j++) { if (parentNode.Nodes[j].Text == pathes[pathDepth]) { //If the node is found we get to the next level childNode = ArchiveNodeAdd((FiaTreeNode)parentNode.Nodes[j], pathes, pathDepth + 1, fia); } } } else { //We are at file level, we create the node childNode = new FiaTreeNode(pathes[pathDepth]); parentNode.Nodes.Add(childNode); childNode.ImageIndex = 4; childNode.SelectedImageIndex = 4; childNode.AddFia(fia); } if (childNode == null) { //If we did not find a node, we create one childNode = new FiaTreeNode(pathes[pathDepth]); childNode.ImageIndex = 1; childNode.SelectedImageIndex = 1; parentNode.Nodes.Add(childNode); //we add the node to the parent node //We keep going deeper ArchiveNodeAdd(childNode, pathes, pathDepth + 1, fia); } return(childNode); }
public static void PopulateArchiveTreeNode(string sourceFileName, List <FileInArchive> FIAList, TreeView tv) { FiaTreeNode root = new FiaTreeNode(sourceFileName.Substring(sourceFileName.LastIndexOf('\\') + 1)); root.Tag = sourceFileName; tv.Nodes.Add(root); for (int i = 0; i < FIAList.Count; i++) { FileInArchive fia = FIAList[i]; string filename = fia.Filename; if (!filename.Contains('.')) { filename = fia.Extension + "/" + filename; } string[] pathes = filename.Split('/'); FiaTreeNode tn = null; for (int j = 0; j < root.Nodes.Count && tn == null; j++) { //Check if the level 0 node already exists if (root.Nodes[j].Text == pathes[0]) { if (pathes.Length > 1) //Check that this node has childs nodes { //we assign the correct icon //we recursively go down the pathes. tn = ArchiveNodeAdd((FiaTreeNode)root.Nodes[j], pathes, 1, fia); } } } //If no node where found if (tn == null) { //We create the level 0 node tn = new FiaTreeNode(pathes[0]); tn.Tag = sourceFileName; root.Nodes.Add(tn); // add it to the treview if (pathes.Length > 1) //Check that this node has childs nodes { //we assign the correct icon tn.ImageIndex = 1; tn.SelectedImageIndex = 1; //we recursively go down the pathes. ArchiveNodeAdd(tn, pathes, 1, fia); } else { // this means it is actually a file at level 0, we change the icon tn.ImageIndex = 4; tn.SelectedImageIndex = 4; tn.AddFia(fia); } } } //tv.Sort(); //Thread t = new Thread(new ThreadStart(tv.Sort)); //t.Start(); }