コード例 #1
0
        private static List <string> EqualNavigationDirectories(string pathSource, string pathNew, IOutputService output)
        {
            string fileWildcard     = @"*.*";
            var    searchSubDirsArg = System.IO.SearchOption.AllDirectories;

            string[]      FilesDirectorySource = System.IO.Directory.GetFiles(pathSource, fileWildcard, searchSubDirsArg);
            List <string> Diffs = new List <string>();

            foreach (string fileSourcePath in FilesDirectorySource)
            {
                string fileNewPath = Path.Combine(pathNew, Path.GetFileName(fileSourcePath));
                if (File.Exists(fileNewPath))
                {
                    FileInfo fileNew    = new FileInfo(fileNewPath);
                    FileInfo fileSource = new FileInfo(fileSourcePath);
                    if (!Utility.FilesAreEqual(fileSource, fileNew))
                    {
                        StreamReader sr          = new StreamReader(fileNewPath);
                        string       datalineNew = sr.ReadLine();
                        string       namelineNew = sr.ReadLine();
                        Encoding     encnew      = sr.CurrentEncoding;
                        sr.Close();
                        DeleteFirstLines(2, fileNewPath);
                        string textnew = File.ReadAllText(fileNewPath);

                        sr = new StreamReader(fileSourcePath);
                        string   datalineSource = sr.ReadLine();
                        string   namelineSource = sr.ReadLine();
                        Encoding encSource      = sr.CurrentEncoding;
                        sr.Close();
                        DeleteFirstLines(2, fileSourcePath);
                        string textsource = File.ReadAllText(fileSourcePath);

                        FileInfo fileNewReplace    = new FileInfo(fileNewPath);
                        FileInfo fileSourceReplace = new FileInfo(fileSourcePath);
                        if (!Utility.FilesAreEqual(fileSourceReplace, fileNewReplace))
                        {
                            Diffs.Add(fileSourcePath);
                        }

                        File.WriteAllText(fileNewPath, datalineNew + "\r\n" + namelineNew + "\r\n" + textnew, encnew);
                        File.WriteAllText(fileSourcePath, datalineSource + "\r\n" + namelineSource + "\r\n" + textsource, encSource);
                    }
                }
                else
                {
                    output.AddLine("-- Nuevo: " + fileNewPath);
                }
            }
            return(Diffs);
        }