Пример #1
0
        public override Disk Execute(Disk disk, string param)
        {
            string path   = "";
            string addPar = "";

            CmdStrTool.SplitParam(param, addParam, out path, out addPar);
            if (string.IsNullOrEmpty(path))
            {
                CmdStrTool.ShowTips(1);
                return(null);
            }
            else
            {
                string[] paths = CmdStrTool.SplitPathParamToPathList(path);
                if (paths.Length != 2) //参数不对
                {
                    CmdStrTool.ShowTips(1);
                }
                else
                {
                    bool cover = addPar == "/y";
                    bool isRealFile = paths[0].First() == '@';
                    Node n1, n2;
                    //n1为拷贝前结点,真路径就创建一个
                    if (isRealFile)  //真实源路径,
                    {
                        string[] namelist1 = CmdStrTool.SplitPathToNameList(paths[0]);
                        string   newname   = namelist1.Last(); //最后一个是name
                        n1 = disk.CreateNode(0, newname, disk.root);
                        n1 = RealDiskTool.Instance.CopyRealFileToNode(paths[0].Substring(1), n1, disk);
                    }
                    else
                    {
                        string[] namelist1 = CmdStrTool.SplitPathToNameList(paths[0]);
                        n1 = disk.NameListToNode(namelist1, IsSupportWildcard);
                    }
                    //n2为目标目录,需要存在
                    string[] namelist2 = CmdStrTool.SplitPathToNameList(paths[1]);
                    n2 = disk.NameListToNode(namelist2, IsSupportWildcard);

                    if (n1 == null || n2 == null || n2.nodeType != 1)
                    {
                        CmdStrTool.ShowTips(2);
                    }
                    else
                    {
                        if (isRealFile)
                        {
                            disk.MoveNode(n1, n2, cover);
                        }
                        else
                        {
                            disk.CopyNode(n1, n2, cover);
                        }
                    }
                }
            }
            return(null);
        }
Пример #2
0
        public override Disk Execute(Disk disk, string param)
        {
            string path   = "";
            string addPar = "";

            CmdStrTool.SplitParam(param, addParam, out path, out addPar);
            if (string.IsNullOrEmpty(path))
            {
                CmdStrTool.ShowTips(1);
                return(null);
            }
            else
            {
                string[] paths = CmdStrTool.SplitPathParamToPathList(path);
                if (paths.Length != 2) //参数不对
                {
                    CmdStrTool.ShowTips(1);
                }
                else
                {
                    string[] namelist1 = CmdStrTool.SplitPathToNameList(paths[0]);
                    string   newname   = namelist1.Last(); //最后一个是新name
                    Node     n1;                           //n1为新建文件的父节点
                    if (namelist1.Length > 1)
                    {
                        string[] namelist = new string[namelist1.Length - 1];
                        Array.Copy(namelist1, namelist, namelist1.Length - 1);

                        n1 = disk.NameListToNode(namelist, IsSupportWildcard);
                    }
                    else
                    {
                        n1 = disk.current;
                    }

                    //n2为link的目标结点
                    string[] namelist2 = CmdStrTool.SplitPathToNameList(paths[1]);
                    Node     n2        = disk.NameListToNode(namelist2, IsSupportWildcard);
                    if (n1 == null || n2 == null)
                    {
                        CmdStrTool.ShowTips(2);
                    }
                    else
                    {
                        Symlink s = disk.CreateNode(2, newname, n1) as Symlink;
                        s.SetLinkTarget(n2);
                        Console.WriteLine("创建链接{0}--->{1}", s.GetPath(), n2.GetPath());
                    }
                }
            }


            return(null);
        }
Пример #3
0
        public override Disk Execute(Disk disk, string param)
        {
            string path   = "";
            string addPar = "";

            if (param == ".")
            {
                Console.WriteLine(disk.current.GetPath() + ">");
                return(null);
            }
            else if (param == "/" || param == "\\")
            {
                disk.current = disk.root as Floder;
                Console.WriteLine(disk.current.GetPath() + ">");
                return(null);
            }

            CmdStrTool.SplitParam(param, addParam, out path, out addPar);

            if (path == "")
            {
                Console.WriteLine(disk.current.GetPath() + ">");
                return(null);
            }
            else
            {
                string[] paths = CmdStrTool.SplitPathParamToPathList(path);
                if (paths.Length != 1) //多个路径命令不正确
                {
                    CmdStrTool.ShowTips(2);
                }
                else
                {
                    string[] namelist = CmdStrTool.SplitPathToNameList(paths[0]);
                    Node     n        = disk.NameListToNode(namelist, IsSupportWildcard);
                    SetCurrentDir(n);
                }
            }

            void SetCurrentDir(Node n)
            {
                if (n != null && n is Floder f)   //正常情况
                {
                    disk.current = f as Floder;
                    Console.WriteLine(disk.current.GetPath() + ">");
                }
                else if (n != null && n is Symlink s)  //找到的是个符号链接
                {
                    Node tar = s.target;
                    SetCurrentDir(tar);
                }
                else   //没找到结点或找到了个文件不能cd
                {
                    CmdStrTool.ShowTips(2);
                }
            }

            return(null);
        }
Пример #4
0
        public override Disk Execute(Disk disk, string param)
        {
            string path   = "";
            string addPar = "";

            CmdStrTool.SplitParam(param, addParam, out path, out addPar);
            if (string.IsNullOrEmpty(path))
            {
                CmdStrTool.ShowTips(1);
                return(null);
            }
            else
            {
                string[] paths = CmdStrTool.SplitPathParamToPathList(path);
                if (paths.Length != 2) //参数不对
                {
                    CmdStrTool.ShowTips(1);
                }
                else
                {
                    bool cover = addPar == "/y";
                    Node n1, n2;
                    //n1为移动前结点,需要存在
                    string[] namelist1 = CmdStrTool.SplitPathToNameList(paths[0]);
                    n1 = disk.NameListToNode(namelist1, IsSupportWildcard);

                    //n2为目标目录,需要存在
                    string[] namelist2 = CmdStrTool.SplitPathToNameList(paths[1]);
                    n2 = disk.NameListToNode(namelist2, IsSupportWildcard);

                    if (n1 == null || n2 == null || n2.nodeType != 1)
                    {
                        CmdStrTool.ShowTips(2);
                    }
                    else
                    {
                        disk.MoveNode(n1, n2, cover);
                        Console.WriteLine("移动:{0}--->{1}", n1.name, n2.GetPath());
                    }
                }
            }
            return(null);
        }
Пример #5
0
        public override Disk Execute(Disk disk, string param)
        {
            string path   = "";
            string addPar = "";

            CmdStrTool.SplitParam(param, addParam, out path, out addPar);

            if (string.IsNullOrEmpty(path))
            {
                CmdStrTool.ShowTips(1);
                return(null);
            }
            else
            {
                string[] paths = CmdStrTool.SplitPathParamToPathList(path);
                if (paths.Length != 2) //参数数不对
                {
                    CmdStrTool.ShowTips(1);
                }
                else
                {
                    string[] namelist = CmdStrTool.SplitPathToNameList(paths[0]);
                    Node     n        = disk.NameListToNode(namelist, IsSupportWildcard);
                    if (n != null)
                    {
                        RenameNode(n, paths[1]);
                    }
                    else
                    {
                        CmdStrTool.ShowTips(2);
                    }
                }
            }

            return(null);
        }
Пример #6
0
        public override Disk Execute(Disk disk, string param)
        {
            string path   = "";
            string addPar = "";

            CmdStrTool.SplitParam(param, addParam, out path, out addPar);

            if (string.IsNullOrEmpty(path))
            {
                CmdStrTool.ShowTips(1);
                return(null);
            }
            else
            {
                string[] paths  = CmdStrTool.SplitPathParamToPathList(path);
                bool     alldel = addPar == "/s";
                if (paths.Length > 0)
                {
                    for (int i = 0; i < paths.Length; i++)
                    {
                        string[] namelist = CmdStrTool.SplitPathToNameList(paths[i]);
                        Node     n        = disk.NameListToNode(namelist, IsSupportWildcard);
                        if (n != null)
                        {
                            List <Node> dels = new List <Node>();
                            Del(DelNode(n, alldel, ref dels));
                        }
                        else
                        {
                            CmdStrTool.ShowTips(2);
                        }
                    }
                }
            }

            List <Node> DelNode(Node d, bool alldel, ref List <Node> dels)
            {
                if (d is File fl)
                {
                    dels.Add(fl);
                }
                else if (d is Floder f)
                {
                    foreach (Node item in f.childs)
                    {
                        if (item is Floder)
                        {
                            if (alldel)
                            {
                                DelNode(item, alldel, ref dels);
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            dels.Add(item);
                        }
                    }
                }
                else if (d is Symlink s)
                {
                    dels.Add(s);
                }
                return(dels);
            }

            void Del(List <Node> indexs)
            {
                for (int i = 0; i < indexs.Count; i++)
                {
                    disk.RemoveNode(indexs[i]);
                }
            }

            GC.Collect(); //手动gc

            return(null);
        }
Пример #7
0
        public override Disk Execute(Disk disk, string param)
        {
            string path   = "";
            string addPar = "";

            CmdStrTool.SplitParam(param, addParam, out path, out addPar);

            bool onlyDir   = addPar == "/ad";
            bool allChilds = addPar == "/s";

            if (string.IsNullOrEmpty(path))
            {
                if (onlyDir)
                {
                    ShowChildsFloderInfo(disk.current);
                }
                else if (allChilds)
                {
                    ShowNodeInfo(disk.current);
                }
                else
                {
                    ShowChildsInfo(disk.current);
                }
            }
            else
            {
                string[] paths = CmdStrTool.SplitPathParamToPathList(path);
                if (paths.Length == 1)   //必须一个路径
                {
                    string[] namelist = CmdStrTool.SplitPathToNameList(paths[0]);
                    Node     n        = disk.NameListToNode(namelist, IsSupportWildcard);
                    if (n == null)
                    {
                        CmdStrTool.ShowTips(2);
                        return(null);
                    }

                    if (allChilds)
                    {
                        ShowNodeInfo(n);
                    }
                    else if (onlyDir)
                    {
                        ShowChildsFloderInfo(n);
                    }
                    else
                    {
                        ShowChildsInfo(n);
                    }
                }
                else
                {
                    CmdStrTool.ShowTips(2);
                }
            }



            return(null);
        }
Пример #8
0
        public override Disk Execute(Disk disk, string param)
        {
            string path   = "";
            string addPar = "";

            CmdStrTool.SplitParam(param, addParam, out path, out addPar);

            if (string.IsNullOrEmpty(path))
            {
                CmdStrTool.ShowTips(1);
                return(null);
            }
            else
            {
                string[] paths  = CmdStrTool.SplitPathParamToPathList(path);
                bool     alldel = addPar == "/s";
                if (paths.Length > 0)
                {
                    for (int i = 0; i < paths.Length; i++)
                    {
                        string[] namelist = CmdStrTool.SplitPathToNameList(paths[i]);
                        Node     n        = disk.NameListToNode(namelist, IsSupportWildcard);
                        if (n.index == disk.current.index)
                        {
                            Console.WriteLine("无法删除正在使用的当前路径");
                            return(null);
                        }
                        if (n != null)
                        {
                            List <Node> dels = new List <Node>();
                            Rd(RdNode(n, alldel, ref dels), alldel);
                        }
                        else
                        {
                            CmdStrTool.ShowTips(2);
                        }
                    }
                }
            }

            List <Node> RdNode(Node d, bool alldel, ref List <Node> dels)
            {
                if (d is File fl)
                {
                    if (alldel)
                    {
                        dels.Add(fl);
                    }
                }
                else if (d is Floder f)
                {
                    if (!alldel && f.childs.Count != 0)
                    {
                        Console.WriteLine("目录非空");
                        return(dels);
                    }
                    dels.Add(f);
                    foreach (Node item in f.childs)
                    {
                        if (item is Floder)
                        {
                            if (alldel)
                            {
                                RdNode(item, alldel, ref dels);
                            }
                            else
                            {
                                dels.Add(item);
                            }
                        }
                        else if (alldel)
                        {
                            dels.Add(item);
                        }
                    }
                }
                else if (d is Symlink s)
                {
                    if (alldel)
                    {
                        dels.Add(s);
                    }
                }
                return(dels);
            }

            void Rd(List <Node> indexs, bool alldel)
            {
                for (int i = 0; i < indexs.Count; i++)
                {
                    if (alldel)
                    {
                        disk.RemoveNode(indexs[i]);
                    }
                    else if (indexs[i] is Floder f)
                    {
                        if (f.childs.Count == 0)
                        {
                            disk.RemoveNode(f);
                        }
                        else
                        {
                            Console.WriteLine("目录非空");
                            return;
                        }
                    }
                }
            }

            GC.Collect(); //手动gc

            return(null);
        }