Exemple #1
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;
        }
 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);
         }
     }
 }
        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;
        }
 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;
         }
     }
 }
        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);
                }
            }
        }
Exemple #6
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;
                }
            }
        }
Exemple #7
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);
        }
 internal int Add(DirectoryDiffEntry E)
 {
     return InnerList.Add(E);
 }