예제 #1
0
        public virtual Status CheckPath(ref MString path, out Component targetDir, out MString fileName, bool usePattern)
        {
            targetDir = null;
            fileName  = "*";
            path      = path.Replace("\"", "").MultiReplace("\\", "\\");
            MString[] paths = path.MultiSplit('\\');

            MString rootName = paths[0];
            bool    isEnding = paths.Length < 2;
            Status  status   = CheckRootPath(ref targetDir, ref fileName, rootName, usePattern, isEnding);

            if (status != Status.Succeed || isEnding)
            {
                return(status);
            }

            for (int i = 1; i < paths.Length - 1; i++)
            {
                if (paths[i].Trim() == "")
                {
                    return(Status.Error_Path_Format);
                }

                if (nameRegex.IsMatch(paths[i]))
                {
                    return(Status.Error_Path_Format);
                }

                if (paths[i] == ".")
                {
                    continue;
                }
                else if (paths[i] == "..")
                {
                    if (targetDir.parent != null)
                    {
                        targetDir = targetDir.parent;
                    }

                    continue;
                }

                status = EnterDirectory(ref targetDir, paths[i]);
                if (status != Status.Succeed)
                {
                    return(status);
                }
            }


            string endName = paths[paths.Length - 1];

            return(CheckEndPath(ref targetDir, ref fileName, endName, usePattern));
        }
예제 #2
0
        public static void Test2()
        {
            string a = "1234567890yyyy1234567890yyyy";

            a = a.Replace("yy", "b");
            MString str   = new MString("ywyw1234567890yyyyyw1234567890yyyyyw");
            MString str11 = str.MultiReplace("yw", "b");
            MString str0  = str.MultiReplace("y", "y");
            MString str1  = str.Substring(4);
            MString str2  = str.Substring(4, 10);
            MString str3  = str.Trim();
            MString str4  = str.Trim(new char[] { 'y', 'w' });
            MString str5  = str.TrimStart(new char[] { 'y', 'w' });
            MString str6  = str.TrimEnd(new char[] { 'y', 'w' });
            bool    b0    = str.StartsWith("");
            bool    b1    = str.StartsWith("yw");
            bool    b2    = str.StartsWith("YW");
            bool    b3    = str.StartsWith("YW", true);
            bool    b4    = str.StartsWith(new string[] { "y", "w" });
            bool    b5    = str.StartsWith(new string[] { "Y", "W" });
            bool    b6    = str.StartsWith(new string[] { "Y", "W" }, true);
            int     idx1  = str.IndexOf("y");
            int     idx2  = str.IndexOf("w");
            int     idx3  = str.IndexOf("Y");
            int     idx4  = str.IndexOf("W");
            int     idx5  = str.IndexOf("W", true);
            int     idx6  = str.IndexOf("W", 10, true);
            int     idx7  = str.IndexOf("W", 10, 2, true);
            int     idx8  = str.IndexOf(new string[] { "W", "Y" });
            int     idx9  = str.IndexOf(new string[] { "W", "Y" }, true);
            int     idx0  = str.IndexOf(new string[] { "W", "Y" }, 10, true);
            MString mstr1 = str.Remove(4);
            MString mstr2 = str.Remove(4, 10);

            string[]  strs0 = ((string)str).Split('y');
            MString[] strs1 = str.Split('y');
            string[]  strs2 = ((string)str).Split('w');
            MString[] strs3 = str.Split('w');
            MString[] strs4 = str.MultiSplit('y');
        }
        protected override bool CreateCommand(MString cmdInfo)
        {
            if (CheckCommand(cmdInfo, CD, false))
            {
                MString newDir = cmdInfo.Substring(CD.Length).Trim();
                _cmd = new CdCommand(newDir);
            }
            else if (CheckCommand(cmdInfo, MKDIR, false))
            {
                MString newDir = cmdInfo.Substring(MKDIR.Length).Trim();
                _cmd = new MakeDirCommand(newDir);
            }
            else if (CheckCommand(cmdInfo, RMDIR, false))
            {
                MString   newDir  = cmdInfo.Substring(RMDIR.Length).Trim();
                MString[] attrs   = { "s" };
                bool[]    results = new bool[1];
                if (!CheckAttribute(ref newDir, attrs, results))
                {
                    return(false);
                }
                _cmd = new RemoveDirCommand(newDir, results[0]);
            }
            else if (CheckCommand(cmdInfo, DIR, true))
            {
                MString   newDir  = cmdInfo.Substring(DIR.Length).Trim();
                MString[] attrs   = { "ad", "s" };
                bool[]    results = new bool[2];
                if (!CheckAttribute(ref newDir, attrs, results))
                {
                    return(false);
                }
                _cmd = new DirCommand(newDir.Trim(), results[0], results[1]);
            }
            else if (CheckCommand(cmdInfo, COPY, false))
            {
                MString   newDir = cmdInfo.Substring(COPY.Length).Trim();
                MString[] paths  = newDir.MultiSplit(' ');
                _cmd = new CopyCommand(paths);
            }
            else if (CheckCommand(cmdInfo, DEL, false))
            {
                MString   newDir = cmdInfo.Substring(DEL.Length).Trim();
                MString[] paths  = newDir.MultiSplit(' ');
                _cmd = new DeleteFileCommand(paths);
            }
            else if (CheckCommand(cmdInfo, COMPARE, false))
            {
                MString   newDir = cmdInfo.Substring(COMPARE.Length).Trim();
                MString[] paths  = newDir.MultiSplit(' ');
                _cmd = new CompareCommand(paths);
            }
            else
            {
                int length = ((string)cmdInfo).IndexOf(" ");
                if (length == -1)
                {
                    length = cmdInfo.Length;
                }
                Logger.Log(Status.Error_Commond, cmdInfo.Substring(0, length));
                return(false);
            }

            return(true);
        }