Example #1
0
        public static bool CompareSizeCriteria(this TreeNode node, SearchCriteria criteria)
        {
            if (!node.IsFileSystemNode())
            {
                return(false);
            }

            if (node.Tag.GetType() == typeof(MinimalDirectoryInfo))
            {
                return(true);
            }

            MinimalFileInfo info = (MinimalFileInfo)node.Tag;

            switch (criteria.SizeCriteria)
            {
            case SizeCriteria.LessThan:
                return(info.Length < criteria.FirstSize);

            case SizeCriteria.GreaterThan:
                return(info.Length > criteria.FirstSize);

            case SizeCriteria.Between:
                return(info.Length >= criteria.FirstSize &&
                       info.Length <= criteria.SecondSize);
            }

            return(true);
        }
        public void ShowToolTip(TreeNode targetNode, Point tipLocation)
        {
            if (targetNode == null && toolTip.Active)
            {
                toolTip.Hide(tipControl);
                DisplayedNode = null;
            }
            else if (DisplayedNode != targetNode)
            {
                DisplayedNode = targetNode;

                string tipText;
                if (DisplayedNode.Tag.GetType() == typeof(MinimalDirectoryInfo))
                {
                    MinimalDirectoryInfo dirInfo = (MinimalDirectoryInfo)DisplayedNode.Tag;
                    tipText = $"{BrowseForm.getNodeFilePath(DisplayedNode)}" +
                              $"\nCreated: {dirInfo.CreationTime.ToString()}" +
                              $"\nModified: {dirInfo.LastWriteTime.ToString()}";
                }
                else
                {
                    MinimalFileInfo fileInfo = (MinimalFileInfo)DisplayedNode.Tag;
                    tipText = $"{BrowseForm.getNodeFilePath(DisplayedNode)}" +
                              $"\nCreated: {fileInfo.CreationTime.ToString()}" +
                              $"\nModified: {fileInfo.LastWriteTime.ToString()}" +
                              $"\nSize: {FileSizeParser.ToString(fileInfo.Length)}";
                }

                tipLocation.Offset(10, 20);
                toolTip.Show(tipText, tipControl, tipLocation);
            }
        }
        private TreeNode createNodeFor(string rootPath, int depth)
        {
            TreeNode rootNode = new TreeNode(depth == 0 ? rootPath : Path.GetFileName(rootPath));

            rootNode.ImageIndex         = resultTreeImageList.Images.Count;
            rootNode.SelectedImageIndex = resultTreeImageList.Images.Count;

            MinimalDirectoryInfo rootInfo = new MinimalDirectoryInfo(rootPath);

            rootNode.Tag = rootInfo;

            if (!browsing)
            {
                rootNode.Nodes.AddNodeSorted(createNotSearchedNode());
                return(rootNode);
            }

            IEnumerable <string> folderContents;

            try
            {
                folderContents = Directory.EnumerateFileSystemEntries(rootPath);
            }
            catch
            {
                rootNode.Nodes.AddNodeSorted(createNoAccessNode());
                return(rootNode);
            }

            List <Task <TreeNode> > createNodeTasks = new List <Task <TreeNode> >();

            foreach (string content in folderContents)
            {
                if (!browsing)
                {
                    rootNode.Nodes.Clear();
                    rootNode.Nodes.AddNodeSorted(createNotSearchedNode());

                    return(rootNode);
                }

                if (Directory.Exists(content))
                {
                    if ((unlimitedDepthCheck.Checked || depth < searchDepthValue.Value) && browsing)
                    {
                        createNodeTasks.Add(Task.Run(() => createNodeFor(content, depth + 1)));
                    }
                    else
                    {
                        TreeNode folderNode = new TreeNode(Path.GetFileName(content));
                        folderNode.ImageIndex         = resultTreeImageList.Images.Count;
                        folderNode.SelectedImageIndex = resultTreeImageList.Images.Count;

                        MinimalDirectoryInfo folderInfo = new MinimalDirectoryInfo(content);
                        folderNode.Tag = folderInfo;

                        folderNode.Nodes.AddNodeSorted(createNotSearchedNode());
                        rootNode.Nodes.AddNodeSorted(folderNode);
                    }
                }
                else
                {
                    TreeNode fileNode = new TreeNode(Path.GetFileName(content));
                    fileNode.ImageIndex         = resultTreeImageList.Images.Count;
                    fileNode.SelectedImageIndex = resultTreeImageList.Images.Count;

                    MinimalFileInfo fileInfo = new MinimalFileInfo(content);
                    fileNode.Tag = fileInfo;

                    rootNode.Nodes.AddNodeSorted(fileNode);
                }
            }

            foreach (Task <TreeNode> createNodeTask in createNodeTasks)
            {
                createNodeTask.Wait();
                rootNode.Nodes.AddNodeSorted(createNodeTask.Result);
            }

            return(rootNode);
        }