private static TreeNode FindOrCreateNodePath(TreeNode rootNode, string path) { if (path.Length == 0) { return(rootNode); } int startIndex = 0; while (path[startIndex] == '/' || path[startIndex] == '\\') { startIndex++; } int separatorIndex = path.IndexOfAny(new char[] { '/', '\\' }, startIndex); string name; if (separatorIndex >= 0) { name = path.Substring(startIndex, separatorIndex - startIndex); } else { name = path.Substring(startIndex); } TreeNode finalNode = null; foreach (object obj in rootNode.Nodes) { TreeNode node = (TreeNode)obj; if (string.Compare(node.Name, name, StringComparison.OrdinalIgnoreCase) == 0) { finalNode = node; break; } } if (finalNode == null) { finalNode = new TreeNode(name); finalNode.Name = name; rootNode.Nodes.Add(finalNode); } if (separatorIndex >= 0) { return(FolderTreeView.FindOrCreateNodePath(finalNode, path.Substring(separatorIndex + 1))); } return(finalNode); }
public void LoadArchive(NexonArchive archive) { base.Nodes.Clear(); if (archive == null) { return; } TreeNode rootNode = new TreeNode("(root)"); foreach (NexonArchiveFileEntry entry in archive.FileEntries) { TreeNode node = FolderTreeView.FindOrCreateNodePath(rootNode, Path.GetDirectoryName(entry.Path)); IList <NexonArchiveFileEntry> nodeList = node.Tag as IList <NexonArchiveFileEntry>; if (nodeList == null) { nodeList = new List <NexonArchiveFileEntry>(); node.Tag = nodeList; } nodeList.Add(entry); } rootNode.Expand(); base.Nodes.Add(rootNode); base.SelectedNode = rootNode; }