public AbstractBrowserNode GetPath(string filename, AbstractBrowserNode root, bool create) { string directory = Path.GetDirectoryName(filename); string[] treepath = directory.Split(new char[] { Path.DirectorySeparatorChar }); AbstractBrowserNode curpathnode = root; foreach (string path in treepath) { if (path.Length == 0 || path[0] == '.') { continue; } AbstractBrowserNode node = null; //AbstractBrowserNode node = GetNodeFromCollection(curpathnode.Nodes, path); if (node == null) { if (create) { DirectoryNode newFolderNode = new DirectoryNode(fileUtilityService.GetDirectoryNameWithSeparator(ConstructFolderName(curpathnode)) + path); curpathnode.Nodes.Add(newFolderNode); curpathnode = newFolderNode; continue; } else { return null; } } curpathnode = node; } return curpathnode; }
public string ConstructFolderName(AbstractBrowserNode folderNode) { if (folderNode is DirectoryNode) { return ((DirectoryNode)folderNode).FolderName; } if (folderNode is ProjectBrowserNode) { return ((ProjectBrowserNode)folderNode).Project.BaseDirectory; } throw new ApplicationException("Folder name construction failed, got unexpected parent node :" + folderNode); }