コード例 #1
0
        public void CopyAll(FileInfo[] sourceFileInfos, Component targetDir)
        {
            string result = "";

            foreach (FileInfo fi in sourceFileInfos)
            {
                Console.WriteLine(fi.FullName);
                Component file = targetDir.GetChild(fi.Name);
                if (file != null)
                {
                    if (file.IsDirectory())
                    {
                        Console.WriteLine("拒绝访问。");
                        continue;
                    }
                    else
                    {
                        if (Logger.ChooseDialogYNA(ref result, "覆盖 {0} 吗?", fi.Name))
                        {
                            file.Remove();
                        }
                        else
                        {
                            continue;
                        }
                    }
                }

                file = new VsFile(fi.Name.Remove(fi.Name.Length - fi.Extension.Length, fi.Extension.Length), fi.Extension);
                (file as VsFile).Read(fi.FullName);
                targetDir.Add(file);
            }
        }
コード例 #2
0
        private Status ExcuteByPattern(Component target, string pattern)
        {
            if (pattern == "*") //删除目录下所有文件
            {
                for (int i = 0; i < target.childs.Count; i++)
                {
                    Component child = target.childs[i];
                    if (child.IsDirectory())
                    {
                        continue;
                    }

                    child.Remove();
                }
            }
            else if (pattern.StartsWith("*.")) //删除指定后缀名的文件
            {
                string matchStr = pattern.Substring(2);

                if (nameRegex.IsMatch(matchStr))
                {
                    return(Status.Error_Path_Format);
                }

                for (int i = 0; i < target.childs.Count; i++)
                {
                    Component child = target.childs[i];
                    if (child.IsDirectory())
                    {
                        continue;
                    }

                    if (child.GetName().EndsWith(matchStr))
                    {
                        child.Remove();
                        i--;
                    }
                }
            }
            else  //删除单个文件
            {
                if (nameRegex.IsMatch(pattern))
                {
                    return(Status.Error_Path_Format);
                }

                VsFile file = target.GetFile(pattern);
                if (file != null)
                {
                    file.Remove();
                }
            }

            return(Status.Succeed);
        }
コード例 #3
0
        public void CopyAllWithChangeExName(FileInfo[] sourceFileInfos, Component targetDir, string lastDestPath)
        {
            string result = "";
            string exName = lastDestPath.Substring(1);

            if (exName == ".")
            {
                exName = "";
            }

            foreach (FileInfo fi in sourceFileInfos)
            {
                Console.WriteLine(fi.FullName);
                string    name = fi.Name.Remove(fi.Name.Length - fi.Extension.Length, fi.Extension.Length) + exName;
                Component file = targetDir.GetChild(name);
                if (file != null)
                {
                    if (file.IsDirectory())
                    {
                        Console.WriteLine("拒绝访问。");
                        continue;
                    }
                    else
                    {
                        if (Logger.ChooseDialogYNA(ref result, "覆盖 {0} 吗?", fi.Name))
                        {
                            file.Remove();
                        }
                        else
                        {
                            continue;
                        }
                    }
                }

                string newExName = "";
                if (name.LastIndexOf('.') != -1)
                {
                    newExName = name.Substring(name.LastIndexOf('.'), name.Length - name.LastIndexOf('.'));
                }
                string newName = name.Remove(name.Length - newExName.Length, newExName.Length);
                file = new VsFile(newName, newExName);
                (file as VsFile).Read(fi.FullName);
                targetDir.Add(file);
            }
        }
コード例 #4
0
        public void CopyWithChangeNameAndExName(FileInfo[] sourceFileInfos, Component targetDir, string lastDestPath)
        {
            string result = "";
            string exName = "";

            if (lastDestPath.LastIndexOf('.') != -1)
            {
                exName = lastDestPath.Substring(lastDestPath.LastIndexOf('.'), lastDestPath.Length - lastDestPath.LastIndexOf('.'));
            }
            string    name = lastDestPath.Remove(lastDestPath.Length - exName.Length, exName.Length);
            Component file = targetDir.GetChild(lastDestPath);

            if (file != null)
            {
                if (file.IsDirectory())
                {
                    Console.WriteLine("拒绝访问。");
                    return;
                }
                else
                {
                    if (Logger.ChooseDialogYNA(ref result, "覆盖 {0} 吗?", name))
                    {
                        file.Remove();
                    }
                    else
                    {
                        return;
                    }
                }
            }

            file = new VsFile(name, exName);
            foreach (FileInfo fi in sourceFileInfos)
            {
                Console.WriteLine(fi.FullName);
                (file as VsFile).Read(fi.FullName);
            }
            targetDir.Add(file);
        }
コード例 #5
0
        public override void Excute()
        {
            if (_paths.Length < 2)
            {
                Logger.Log(Status.Error_Commond_Format);
                return;
            }

            MString sourcePath = _paths[0].Replace("\"", "").MultiReplace("\\", "\\");

            if (!File.Exists(sourcePath))
            {
                Logger.Log(Status.Error_Path_Not_Found);
                return;
            }

            MString   destPath = _paths[1];
            Component destDir;
            MString   lastDestPath;
            Status    status = CheckPath(ref destPath, out destDir, out lastDestPath, false);

            if (status != Status.Succeed)
            {
                Logger.Log(status);
                return;
            }
            if (lastDestPath == "*")
            {
                Logger.Log(Status.Error_Path_Format);
            }

            VsFile destFile = destDir.GetFile(lastDestPath);

            if (destFile == null)
            {
                Logger.Log(Status.Error_Path_Not_Found);
            }


            Console.WriteLine("正在比较文件 " + sourcePath + " 和 " + destPath);
            byte[] sourceBuffer = FileUtils.GetFileBuffer(sourcePath);
            byte[] destBuffer   = destFile.Buffer;

            int differentIndex = -1;
            int index          = 0;

            while (index < sourceBuffer.Length && index < destBuffer.Length)
            {
                if (sourceBuffer[index] != destBuffer[index])
                {
                    differentIndex = index;
                    break;
                }
                index++;
            }

            if (sourceBuffer.Length == index && destBuffer.Length == index)
            {
                Console.WriteLine("内容比较一致。");
            }
            else
            {
                Console.WriteLine("***** " + sourcePath);
                OutputFileContent(sourceBuffer, differentIndex);
                Console.WriteLine("***** " + destPath);
                OutputFileContent(destBuffer, differentIndex);
            }
        }