Ejemplo n.º 1
0
 public void Clear()
 {
     root    = null;
     current = null;
     allNodes.Clear();
     nodeCount = 0;
 }
Ejemplo n.º 2
0
        public Node CreateNode(int nodeType, string name, Node parent)
        {
            Node n;

            switch (nodeType)
            {
            case 0:
                n = new File(name, parent, this);
                CreateNodeIndex(n);
                return(n);

            case 1:
                n = new Floder(name, parent, this);
                CreateNodeIndex(n);
                return(n);

            case 2:
                n = new Symlink(name, parent, this);
                CreateNodeIndex(n);
                return(n);

            default:
                return(null);
            }
        }
Ejemplo n.º 3
0
        public void SetRoot(Node root)
        {
            Floder f = root as Floder;

            f.index = 0;
            allNodes.Add(f);
            this.root    = f;
            this.current = this.root;
            nodeCount++;
        }
Ejemplo n.º 4
0
        public Disk(Node root)
        {
            Floder f = root as Floder;

            allNodes = new List <Node>();
            f.index  = 0;
            allNodes.Add(f);
            this.root    = f;
            this.current = this.root;
            nodeCount++;
        }
Ejemplo n.º 5
0
        void CreateFloder(string[] names, int index, Floder f, int max)
        {
            if (index > max)
            {
                return;
            }
            if (f == null)
            {
                return;
            }

            Node n = f.GetChildByName(names[index]);

            if (n != null)
            {
                if (n is Floder childF)
                {
                    index++;
                    CreateFloder(names, index, childF, max);
                }
                else if (n is Symlink s)
                {
                    if (s.target.nodeType == 1)
                    {
                        Floder tarF = s.target as Floder;
                        index++;
                        CreateFloder(names, index, tarF, max);
                    }
                }
                else
                {
                    Console.WriteLine("不可在文件下创建目录");
                    return;
                }
            }
            else
            {
                Floder ff = CreateNode(1, names[index], f) as Floder;
                index++;
                CreateFloder(names, index, ff, max);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 从一个目录获得所有子结点(不包括n),返回list
        /// </summary>
        void GetAllNodes(ref List <Node> nodes, Node n)
        {
            if (n.nodeType != 1)
            {
                nodes.Add(n);
                return;
            }
            Floder f = n as Floder;

            if (f != null)
            {
                if (f.index != n.index)
                {
                    nodes.Add(f);
                }
                for (int i = 0; i < f.childs.Count; i++)
                {
                    GetAllNodes(ref nodes, f.childs[i]);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 用namelist找文件夹
        /// </summary>
        Node FindFloderWithName(Node start, string[] names, bool isFullPath, bool isMatch = false)
        {
            Floder fo = start as Floder;

            if (fo == null)
            {
                return(null);
            }

            int tmp   = isFullPath ? 1 : 0;
            int count = names.Length;

            if (count == 1 && isFullPath) //绝对路径只有一个结点
            {
                return(fo);
            }

            Node n = fo.GetChildByName(names[tmp], isMatch);

            if (names.Length > tmp + 1)
            {
                for (int i = tmp + 1; i < names.Length; i++)
                {
                    if (i == names.Length - 1)  //最后一个结点
                    {
                        if (n != null)
                        {
                            if (n is Floder f)  //找到文件夹继续找   如果是最后一个结点了,返回这个文件或者文件夹
                            {
                                n = f.GetChildByName(names[i], isMatch);
                                return(n);
                            }
                            else if (n is Symlink s && s.target != null)  //找到符号链接 看目标是不是文件夹
                            {
                                n = SymlinkFinalReturnNode(s);
                                if (n is Floder f1)
                                {
                                    n = f1.GetChildByName(names[i], isMatch);
                                    return(n);
                                }
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else          //不是最后一个
                    {
                        if (n != null)
                        {
                            if (n is Floder f)  //找到文件夹继续找
                            {
                                n = f.GetChildByName(names[i], isMatch);
                            }
                            else   //找到个文件,不正常情况,路径错误
                            {
                                Console.WriteLine("路径不存在");
                                return(null);
                            }
                        }
                        else    //没找到
                        {
                            return(null);
                        }
                    }
                }
            }
            else  //如果只有1个结点
            {
                if (n != null)
                {
                    return(n);   //如果是最后一个结点了,返回这个文件或者文件夹
                }
                else
                {
                    return(null);
                }
            }

            return(null);
        }