Exemplo n.º 1
0
        public CTreeNode RemoveEmptyNode(int level)
        {
            level++;

            if (level < 20)
            {
                try
                {
                    for (int i = this.Nodes.Count - 1; i >= 0; i--)
                    {
                        CTreeNode childNode = (CTreeNode)this.Nodes[i];
                        // Directory
                        if (childNode.Tag.ToString() == "...")
                        {
                            if (childNode.Nodes.Count > 0)
                            {
                                childNode = childNode.RemoveEmptyNode(level);
                            }
                            if (childNode != null && childNode.Nodes.Count == 0)
                            {
                                childNode.Remove();
                            }
                        }
                    }
                }
                catch
                {
                    // ignore exception
                }
            }
            return(this);
        }
Exemplo n.º 2
0
        public void GetFiles(string dir, string filterInput)
        {
            try
            {
                string[] filters = filterInput.Split(',');
                string[] files   = { };
                foreach (string filter in filters)
                {
                    files = files.Concat(Directory.GetFiles(dir, filter.Trim())).ToArray();
                }
                files = files.Distinct().ToArray();

                foreach (string file in files)
                {
                    try
                    {
                        FileInfo  fi   = new FileInfo(file);
                        CTreeNode node = new CTreeNode(fi.Name, 0, 1);
                        node.Tag             = fi.FullName;
                        node.StateImageIndex = 1;
                        this.Nodes.Add(node);
                    }
                    catch
                    {
                        // ignore exception
                    }
                }
            }
            catch
            {
                // ignore exception
            }
        }
Exemplo n.º 3
0
 public void Update(string dir, string filter, CTreeNode parentNode)
 {
     try
     {
         if (Directory.Exists(dir))
         {
             this.BeginUpdate();
             this.Nodes.Clear();
             this.GetDirectories(parentNode, dir, filter, 0);
             if (parentNode == null)
             {
                 parentNode = new CTreeNode();
                 parentNode.GetFiles(dir, filter);
             }
             for (int i = this.Nodes.Count - 1; i >= 0; i--)
             {
                 ((CTreeNode)this.Nodes[i]).RemoveEmptyNode(0);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Directory Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         this.EndUpdate();
     }
 }
Exemplo n.º 4
0
        public void GetDirectories(TreeNode parent, string dir, string filter, int level)
        {
            level++;

            if (level < 20)
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(dir);

                    foreach (DirectoryInfo diChild in di.GetDirectories())
                    {
                        try
                        {
                            CTreeNode node = new CTreeNode(diChild.Name, 0, 1);
                            node.Tag = "...";
                            if (level > 1)
                            {
                                node.Expand();
                            }
                            if (diChild.GetDirectories().Length > 0)
                            {
                                GetDirectories(node, diChild.FullName, filter, level);
                            }
                            if (diChild.GetFiles().Length > 0)
                            {
                                node.GetFiles(diChild.FullName, filter);
                            }
                            if (parent == null)
                            {
                                this.Nodes.Add(node);
                            }
                            else
                            {
                                parent.Nodes.Add(node);
                            }
                        }
                        catch
                        {
                            // ignore exception
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Directory Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }