private void applyNodeStyle(TreeNode treeNode, string path, DirectorySearchStatusTypes statusType, string optionalErrorMsg) { var directory = new DirectoryInfo(path); // TODO: use enums for icon names treeNode.ForeColor = (statusType == DirectorySearchStatusTypes.Empty) ? Color.Red : Color.Gray; var iconKey = ""; if (statusType == DirectorySearchStatusTypes.Empty) { var fileCount = directory.GetFiles().Length; var containsTrash = (fileCount > 0); iconKey = containsTrash ? "folder_trash_files" : "folder"; // TODO: use data from scan thread if ((directory.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { iconKey = containsTrash ? "folder_hidden_trash_files" : "folder_hidden"; } if ((directory.Attributes & FileAttributes.Encrypted) == FileAttributes.Encrypted) { iconKey = containsTrash ? "folder_lock_trash_files" : "folder_lock"; } if ((directory.Attributes & FileAttributes.System) == FileAttributes.System) { iconKey = containsTrash ? "folder_lock_trash_files" : "folder_lock"; } if (containsTrash) { treeNode.Text += " (contains " + fileCount.ToString() + " empty files)"; } } else if (statusType == DirectorySearchStatusTypes.Error) { iconKey = "folder_warning"; if (optionalErrorMsg != "") { optionalErrorMsg = optionalErrorMsg.Replace("\r", "").Replace("\n", ""); if (optionalErrorMsg.Length > 55) { optionalErrorMsg = optionalErrorMsg.Substring(0, 55) + "..."; } treeNode.Text += " (" + optionalErrorMsg + ")"; } } else if (statusType == DirectorySearchStatusTypes.Ignore) { iconKey = "protected_icon"; treeNode.ForeColor = Color.Blue; } if (treeNode != this.rootNode) { treeNode.ImageKey = iconKey; treeNode.SelectedImageKey = iconKey; } }
public TreeNode AddOrUpdateDirectoryNode(string path, DirectorySearchStatusTypes statusType, string optionalErrorMsg) { if (directoryToTreeNodeMapping.ContainsKey(path)) { // Just update the style if the node already exists var n = directoryToTreeNodeMapping[path]; applyNodeStyle(n, path, statusType, optionalErrorMsg); return(n); } var directory = new DirectoryInfo(path); // Create new tree node var newTreeNode = new TreeNode(directory.Name); applyNodeStyle(newTreeNode, path, statusType, optionalErrorMsg); newTreeNode.Tag = directory; if (directory.Parent.FullName.Trim('\\') == this.rootPath) { this.rootNode.Nodes.Add(newTreeNode); } else { var parentNode = this.findOrCreateDirectoryNodeByPath(directory.Parent.FullName); parentNode.Nodes.Add(newTreeNode); } directoryToTreeNodeMapping.Add(path, newTreeNode); newTreeNode.EnsureVisible(); return(newTreeNode); }
public FoundEmptyDirInfoEventArgs(string Directory, DirectorySearchStatusTypes type, string ErrorMessage) { this.Directory = Directory; this.Type = type; this.ErrorMessage = ErrorMessage; }
public TreeNode AddOrUpdateDirectoryNode(string path, DirectorySearchStatusTypes statusType, string optionalErrorMsg) { if (directoryToTreeNodeMapping.ContainsKey(path)) { // Just update the style if the node already exists var n = directoryToTreeNodeMapping[path]; applyNodeStyle(n, path, statusType, optionalErrorMsg); return n; } var directory = new DirectoryInfo(path); // Create new tree node var newTreeNode = new TreeNode(directory.Name); applyNodeStyle(newTreeNode, path, statusType, optionalErrorMsg); newTreeNode.Tag = directory; if (directory.Parent.FullName.Trim('\\') == this.rootPath) { this.rootNode.Nodes.Add(newTreeNode); } else { var parentNode = this.findOrCreateDirectoryNodeByPath(directory.Parent.FullName); parentNode.Nodes.Add(newTreeNode); } directoryToTreeNodeMapping.Add(path, newTreeNode); newTreeNode.EnsureVisible(); return newTreeNode; }
private void applyNodeStyle(TreeNode treeNode, string path, DirectorySearchStatusTypes statusType, string optionalErrorMsg) { var directory = new DirectoryInfo(path); // TODO: use enums for icon names treeNode.ForeColor = (statusType == DirectorySearchStatusTypes.Empty) ? Color.Red : Color.Gray; var iconKey = ""; if (statusType == DirectorySearchStatusTypes.Empty) { var fileCount = directory.GetFiles().Length; var containsTrash = (fileCount > 0); iconKey = containsTrash ? "folder_trash_files" : "folder"; // TODO: use data from scan thread if ((directory.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) iconKey = containsTrash ? "folder_hidden_trash_files" : "folder_hidden"; if ((directory.Attributes & FileAttributes.Encrypted) == FileAttributes.Encrypted) iconKey = containsTrash ? "folder_lock_trash_files" : "folder_lock"; if ((directory.Attributes & FileAttributes.System) == FileAttributes.System) iconKey = containsTrash ? "folder_lock_trash_files" : "folder_lock"; if (containsTrash) treeNode.Text += " (contains " + fileCount.ToString() + " empty files)"; } else if (statusType == DirectorySearchStatusTypes.Error) { iconKey = "folder_warning"; if (optionalErrorMsg != "") { optionalErrorMsg = optionalErrorMsg.Replace("\r", "").Replace("\n", ""); if (optionalErrorMsg.Length > 55) optionalErrorMsg = optionalErrorMsg.Substring(0, 55) + "..."; treeNode.Text += " (" + optionalErrorMsg + ")"; } } else if (statusType == DirectorySearchStatusTypes.Ignore) { iconKey = "protected_icon"; treeNode.ForeColor = Color.Blue; } if (treeNode != this.rootNode) { treeNode.ImageKey = iconKey; treeNode.SelectedImageKey = iconKey; } }