private void GroupEqualFileInfosAtTop(int start, int length, IFileInfoEqualityComparer fileInfoComparer) { for (var i = 0; i < length;) { var equalFiles = 1; for (var j = i + 1; j < length; j++) { var f1 = _files[start + i]; var f2 = _files[start + j]; if (fileInfoComparer.Equals(f1, f2)) { equalFiles++; _files.Swap(start + i, start + j); } } if (equalFiles > 1) { OnDuplicateFound(start + i, equalFiles); } i += equalFiles; } }
private void FindDuplicates(int start, int length, IFileInfoEqualityComparer fileInfoComparer) { try { if (length == 2) { if (fileInfoComparer.Equals(_files[start], _files[start + 1])) { OnDuplicateFound(start, length); } } else { if (fileInfoComparer is IFileEqualityComprarer fileComparer) { new MultiFileEqualityComparer(this, start, length, fileComparer).FindDuplicates(); } else { GroupEqualFileInfosAtTop(start, length, fileInfoComparer); } } } catch (FileSystemInfoException ex) { OnError(ex); } }
private void CompareFileSystenInfo(FileSystemInfo srcFsi, FileSystemInfo dstFsi, IFileInfoEqualityComparer fileInfoComparer) { if (srcFsi is FileInfo srcFile) { if (dstFsi is FileInfo dstFile) { try { if (!fileInfoComparer.Equals(srcFile, dstFile)) { OnOperationFound(new EditFileOperation(srcFile, dstFile)); } else if (!AttributesEqual(srcFile.Attributes, dstFile.Attributes)) { OnOperationFound(new EditAttributesOperation(dstFile, srcFile.Attributes)); } } catch (FileSystemInfoException ex) { OnError(ex); } } else if (dstFsi is DirectoryInfo dstDir) { _deleter.DeleteDirectory(dstDir); OnOperationFound(new CopyFileOperation(srcFile, new FileInfo(dstFsi.FullName))); } } else if (srcFsi is DirectoryInfo srcDir) { if (dstFsi is FileInfo dstFile) { OnOperationFound(new DeleteFileOperation(dstFile)); _copier.CopyDirectory(srcDir, new DirectoryInfo(dstFsi.FullName)); } else if (dstFsi is DirectoryInfo dstDir) { _stack.Add(srcDir); _stack.Add(dstDir); } } }