Пример #1
0
 private void SetNodeColor(TreeNode Node, DirectoryDiffEntry Entry)
 {
     if (Entry.InA && Entry.InB)
     {
         if (Entry.Different)
         {
             Node.BackColor = DiffOptions.ChangedColor;
         }
         else
         {
             Node.BackColor = BackColor;
         }
     }
     else
     {
         if (Entry.InA)
         {
             Node.BackColor = DiffOptions.DeletedColor;
         }
         else
         {
             Node.BackColor = DiffOptions.InsertedColor;
         }
     }
 }
Пример #2
0
        public DirectoryDiffResults Execute(DirectoryInfo A, DirectoryInfo B)
        {
            //Create a faux base entry to pass to Execute
            DirectoryDiffEntry Entry = new DirectoryDiffEntry("", false, true, true, false);

            //If the base paths are the same, we don't need to check for file differences.
            bool bCheckIfFilesAreDifferent = String.Compare(A.FullName, B.FullName, true) != 0;

            Execute(A, B, Entry, bCheckIfFilesAreDifferent);

            DirectoryDiffResults Results = new DirectoryDiffResults(A, B, Entry.SubEntries, m_bRecursive, m_Filter);
            return Results;
        }
Пример #3
0
 private void SetNodeText(TreeNode Node, DirectoryDiffEntry Entry)
 {
     if ((Entry.InA && Entry.InB) || (m_bUseA && Entry.InA) || (!m_bUseA && Entry.InB))
     {
         if (Entry.Error == null)
         {
             Node.Text = Entry.Name;
         }
         else
         {
             Node.Text = String.Format("{0}: {1}", Entry.Name, Entry.Error);
         }
     }
 }
Пример #4
0
 private void SetNodeText(TreeNode node, DirectoryDiffEntry entry)
 {
     if ((entry.InA && entry.InB) || (this.useA && entry.InA) || (!this.useA && entry.InB))
     {
         if (entry.Error == null)
         {
             node.Text = entry.Name;
         }
         else
         {
             node.Text = string.Format("{0}: {1}", entry.Name, entry.Error);
         }
     }
 }
Пример #5
0
        public void ShowDifferences()
        {
            if (!CanShowDifferences)
            {
                return;
            }

            DirectoryDiffEntry Entry = SelectedEntry;

            string strFileA = TreeA.GetFullNameForNode(Entry.NodeA);
            string strFileB = TreeB.GetFullNameForNode(Entry.NodeB);

            ShowFileDifferences(this, new DifferenceEventArgs(strFileA, strFileB));
        }
Пример #6
0
        private void SetNodeImage(TreeNode Node, DirectoryDiffEntry Entry)
        {
            bool bPresent = (m_bUseA && Entry.InA) || (!m_bUseA && Entry.InB);
            int  iIndex   = -1;

            if (Entry.Error != null)
            {
                iIndex = c_iFileError;
            }
            else if (Entry.IsFile)
            {
                if (bPresent)
                {
                    iIndex = c_iFile;
                }
                else
                {
                    iIndex = c_iFileMissing;
                }
            }
            else
            {
                if (bPresent)
                {
                    //If a folder is only present on one side, then
                    //we should always show it closed since we haven't
                    //actually recursed into it.
                    //
                    //Also, we should only show a folder open if we're
                    //showing recursive differences.
                    if (m_Results.Recursive && Node.IsExpanded && Entry.InA && Entry.InB)
                    {
                        iIndex = c_iFolderOpen;
                    }
                    else
                    {
                        iIndex = c_iFolderClosed;
                    }
                }
                else
                {
                    iIndex = c_iFolderMissing;
                }
            }

            Node.ImageIndex         = iIndex;
            Node.SelectedImageIndex = iIndex;
        }
Пример #7
0
        private void SetNodeImage(TreeNode node, DirectoryDiffEntry entry)
        {
            bool present = (this.useA && entry.InA) || (!this.useA && entry.InB);
            int  index;

            if (entry.Error != null)
            {
                index = FileErrorIndex;
            }
            else if (entry.IsFile)
            {
                if (present)
                {
                    index = FileIndex;
                }
                else
                {
                    index = FileMissingIndex;
                }
            }
            else if (present)
            {
                // If a folder is only present on one side, then
                // we should always show it closed since we haven't
                // actually recursed into it.
                //
                // Also, we should only show a folder open if we're
                // showing recursive differences.
                if (this.results != null && this.results.Recursive && node.IsExpanded && entry.InA && entry.InB)
                {
                    index = FolderOpenIndex;
                }
                else
                {
                    index = FolderClosedIndex;
                }
            }
            else
            {
                index = FolderMissingIndex;
            }

            node.ImageIndex         = index;
            node.SelectedImageIndex = index;
        }
Пример #8
0
        private void TreeNode_SelectChanged(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            DirDiffTreeView    Tree  = (DirDiffTreeView)sender;
            DirectoryDiffEntry Entry = Tree.GetEntryForNode(e.Node);

            if (Entry != null)
            {
                TreeNode NodeA = Entry.NodeA;
                TreeNode NodeB = Entry.NodeB;
                if (NodeA != null && NodeB != null)
                {
                    TreeA.SelectedNode = NodeA;
                    TreeB.SelectedNode = NodeB;
                }
            }

            UpdateButtons();
        }
Пример #9
0
        private void TreeNode_StateChange(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            DirDiffTreeView    Tree  = (DirDiffTreeView)sender;
            DirectoryDiffEntry Entry = Tree.GetEntryForNode(e.Node);

            if (Entry != null)
            {
                TreeNode NodeA = Entry.NodeA;
                TreeNode NodeB = Entry.NodeB;
                if (NodeA != null && NodeB != null)
                {
                    if (e.Action == TreeViewAction.Collapse)
                    {
                        //Although the Docs say that Collapse() isn't recursive,
                        //it actually is.  Since clicking the +/- isn't recursive
                        //we have to simulate that by calling Collapse even on the
                        //node that fired the event.
                        if (NodeA.IsExpanded || e.Node == NodeA)
                        {
                            NodeA.Collapse();
                        }
                        if (NodeB.IsExpanded || e.Node == NodeB)
                        {
                            NodeB.Collapse();
                        }
                    }
                    else if (e.Action == TreeViewAction.Expand)
                    {
                        if (!NodeA.IsExpanded || e.Node == NodeA)
                        {
                            NodeA.Expand();
                        }
                        if (!NodeB.IsExpanded || e.Node == NodeB)
                        {
                            NodeB.Expand();
                        }
                    }
                }
            }
        }
Пример #10
0
        private void AddEntry(DirectoryDiffEntry entry, TreeNode?parentNode)
        {
            TreeNode node = new()
            {
                Tag = entry,
            };

            if (this.useA)
            {
                entry.TagA = node;
            }
            else
            {
                entry.TagB = node;
            }

            node.Expand();

            this.SetNodeText(node, entry);
            this.SetNodeImage(node, entry);
            this.SetNodeColor(node, entry);

            if (parentNode != null)
            {
                parentNode.Nodes.Add(node);
            }
            else
            {
                this.Nodes.Add(node);
            }

            if (!entry.IsFile)
            {
                foreach (DirectoryDiffEntry subEntry in entry.Subentries !)
                {
                    this.AddEntry(subEntry, node);
                }
            }
        }
Пример #11
0
        private void AddEntry(DirectoryDiffEntry Entry, TreeNode ParentNode)
        {
            TreeNode Node = new TreeNode();

            Node.Tag = Entry;

            if (m_bUseA)
            {
                Entry.NodeA = Node;
            }
            else
            {
                Entry.NodeB = Node;
            }
            Node.Expand();

            SetNodeText(Node, Entry);
            SetNodeImage(Node, Entry);
            SetNodeColor(Node, Entry);

            if (ParentNode != null)
            {
                ParentNode.Nodes.Add(Node);
            }
            else
            {
                Nodes.Add(Node);
            }

            if (!Entry.IsFile)
            {
                foreach (DirectoryDiffEntry SubEntry in Entry.SubEntries)
                {
                    AddEntry(SubEntry, Node);
                }
            }
        }
Пример #12
0
        public void View()
        {
            if (!CanView)
            {
                return;
            }

            TreeNode Node        = SelectedNode;
            string   strFullName = GetFullNameForNode(Node);

            DirectoryDiffEntry Entry   = GetEntryForNode(Node);
            string             strVerb = "open";

            if (!Entry.IsFile)
            {
                string strDefaultVerb = Utilities.DefaultFolderOpenAction;
                if (strDefaultVerb.Length > 0)
                {
                    strVerb = strDefaultVerb;
                }
            }

            Utilities.ShellExecute(this, strFullName, strVerb);
        }
Пример #13
0
 private static void GetNodes(DirectoryDiffEntry entry, out TreeNode?nodeA, out TreeNode?nodeB)
 {
     nodeA = (TreeNode?)entry.TagA;
     nodeB = (TreeNode?)entry.TagB;
 }
Пример #14
0
        private void DiffFileSystemInfos(FileSystemInfo[] arA, FileSystemInfo[] arB, DirectoryDiffEntry Entry, bool bIsFile, bool bCheckIfFilesAreDifferent)
        {
            int iAIndex = 0;
            int iBIndex = 0;
            int iNumA = arA.Length;
            int iNumB = arB.Length;
            while (iAIndex < iNumA && iBIndex < iNumB)
            {
                FileSystemInfo A = arA[iAIndex];
                FileSystemInfo B = arB[iBIndex];

                int iCompareResult = String.Compare(A.Name, B.Name, true);

                if (iCompareResult == 0)
                {
                    //The item is in both directories
                    if (m_bShowDifferent || m_bShowSame)
                    {
                        bool bDifferent = false;
                        DirectoryDiffEntry NewEntry = new DirectoryDiffEntry(A.Name, bIsFile, true, true, false);

                        if (bIsFile)
                        {
                            if (bCheckIfFilesAreDifferent)
                            {
                                try
                                {
                                    bDifferent = Functions.AreFilesDifferent((FileInfo)A, (FileInfo)B);
                                }
                                catch (Exception ex)
                                {
                                    NewEntry.Error = ex.Message;
                                }
                                NewEntry.Different = bDifferent;
                            }

                            if ((bDifferent && m_bShowDifferent) || (!bDifferent && m_bShowSame))
                            {
                                Entry.SubEntries.Add(NewEntry);
                            }
                        }
                        else
                        {
                            if (m_bRecursive)
                            {
                                Execute((DirectoryInfo)A, (DirectoryInfo)B, NewEntry, bCheckIfFilesAreDifferent);
                            }

                            if (m_bIgnoreDirectoryComparison)
                            {
                                NewEntry.Different = false;
                            }
                            else
                            {
                                bDifferent = NewEntry.Different;
                            }

                            if (m_bIgnoreDirectoryComparison || (bDifferent && m_bShowDifferent) || (!bDifferent && m_bShowSame))
                            {
                                Entry.SubEntries.Add(NewEntry);
                            }
                        }

                        if (bDifferent)
                        {
                            Entry.Different = true;
                        }
                    }
                    iAIndex++;
                    iBIndex++;
                }
                else if (iCompareResult < 0)
                {
                    //The item is only in A
                    if (m_bShowOnlyInA)
                    {
                        Entry.SubEntries.Add(new DirectoryDiffEntry(A.Name, bIsFile, true, false, false));
                        Entry.Different = true;
                    }
                    iAIndex++;
                }
                else //iCompareResult > 0
                {
                    //The item is only in B
                    if (m_bShowOnlyInB)
                    {
                        Entry.SubEntries.Add(new DirectoryDiffEntry(B.Name, bIsFile, false, true, false));
                        Entry.Different = true;
                    }
                    iBIndex++;
                }
            }

            //Add any remaining entries
            if (iAIndex < iNumA && m_bShowOnlyInA)
            {
                for (int i = iAIndex; i < iNumA; i++)
                {
                    Entry.SubEntries.Add(new DirectoryDiffEntry(arA[i].Name, bIsFile, true, false, false));
                    Entry.Different = true;
                }
            }
            else if (iBIndex < iNumB && m_bShowOnlyInB)
            {
                for (int i = iBIndex; i < iNumB; i++)
                {
                    Entry.SubEntries.Add(new DirectoryDiffEntry(arB[i].Name, bIsFile, false, true, false));
                    Entry.Different = true;
                }
            }
        }
Пример #15
0
        private void Execute(DirectoryInfo A, DirectoryInfo B, DirectoryDiffEntry Entry, bool bCheckIfFilesAreDifferent)
        {
            //Get the arrays of files
            FileInfo[] arAFileInfos, arBFileInfos;
            if (m_Filter == null)
            {
                arAFileInfos = A.GetFiles();
                arBFileInfos = B.GetFiles();
                //Sort them
                Array.Sort(arAFileInfos, FileSystemInfoComparer.Comparer);
                Array.Sort(arBFileInfos, FileSystemInfoComparer.Comparer);
            }
            else
            {
                arAFileInfos = m_Filter.Filter(A);
                arBFileInfos = m_Filter.Filter(B);
            }

            //Diff them
            DiffFileSystemInfos(arAFileInfos, arBFileInfos, Entry, true, bCheckIfFilesAreDifferent);

            //Get the arrays of subdirectories
            DirectoryInfo[] arADirInfos = A.GetDirectories();
            DirectoryInfo[] arBDirInfos = B.GetDirectories();
            //Sort them
            Array.Sort(arADirInfos, FileSystemInfoComparer.Comparer);
            Array.Sort(arBDirInfos, FileSystemInfoComparer.Comparer);
            //Diff them
            DiffFileSystemInfos(arADirInfos, arBDirInfos, Entry, false, bCheckIfFilesAreDifferent);
        }