Пример #1
0
        private void CompareDirectoryFiles(string beforePath, string afterPath)
        {
            listView1.Items.Clear();

            if (!Directory.Exists(beforePath))
            {
                MessageBox.Show("The before path is incorrect");
                return;
            }
            if (!Directory.Exists(afterPath))
            {
                MessageBox.Show("The after path is incorrect");
                return;
            }

            // we normalize the paths so that we remove the leading part (which will not be common anyway)
            var beforeFiles = Directory.GetFiles(beforePath, "*.*", SearchOption.AllDirectories).Select(file => file.Replace(beforePath, "")).ToArray();
            var afterFiles  = Directory.GetFiles(afterPath, "*.*", SearchOption.AllDirectories).Select(file => file.Replace(afterPath, "")).ToArray();

            // the changes are going to come in already sorted.
            foreach (var change in StringListDiff.Compare(beforeFiles, afterFiles))
            {
                var fileEntry = new FileEntry();

                switch (change.ChangeType)
                {
                case CodeDiffLib.Changes.ChangeType.Added:
                {
                    fileEntry.FileName = change.After.Substring(1);
                    fileEntry.Status   = EntryStateEnum.Added;
                    break;
                }

                case CodeDiffLib.Changes.ChangeType.Removed:
                {
                    fileEntry.FileName = change.Before.Substring(1);
                    fileEntry.Status   = EntryStateEnum.Removed;
                    break;
                }

                case CodeDiffLib.Changes.ChangeType.NoChange:
                {
                    // here we should actually do the file diff.
                    var beforeFilePath = beforePath + change.Before;
                    var afterFilePath  = afterPath + change.After;

                    fileEntry.FileName = change.Before.Substring(1);
                    fileEntry.Status   = EntryStateEnum.Modified;
                    fileEntry.Status   = TreeDiff.Compare(File.ReadAllText(beforeFilePath), File.ReadAllText(afterFilePath)).Any() ? EntryStateEnum.Modified : EntryStateEnum.NoChange;
                    break;
                }
                }

                listView1.Items.Add(new ListViewItem(new string[2] {
                    fileEntry.FileName, fileEntry.Status.ToString()
                })
                {
                    Tag = fileEntry, BackColor = GetBackColorFromState(fileEntry.Status)
                });
                Application.DoEvents();
            }
        }
Пример #2
0
 public static Changes <SyntaxNodeOrToken> GetDiff(string before, string after)
 {
     return(TreeDiff.Compare(GetSyntaxNode(before), GetSyntaxNode(after)));
 }
Пример #3
0
 public void Compare()
 {
     _codeDiff = TreeDiff.Compare(rtbBefore.Text, rtbAfter.Text);
     //PopulateDiffList();
     PaintTheTextBoxes();
 }