Пример #1
0
        private void AddFilesToList(FolderItem leftFolder, FolderItem rightFolder, Options options, List <string> fromList, List <string> toList, List <string> deleteList)
        {
            if (leftFolder != null && leftFolder.Files != null && (options.direction == Options.Direction.LeftToRight || options.direction == Options.Direction.Synchronize))
            {
                // Loop over the files in the left folder
                foreach (FileItem file in leftFolder.Files)
                {
                    if (
                        (file.State == CompareState.Added && options.addedFilesAction == Options.Action.Copy) ||
                        (file.State == CompareState.Newer && options.changedFilesAction == Options.Action.Copy) ||
                        (file.State == CompareState.Older && options.changedFilesAction == Options.Action.Delete)
                        )
                    {
                        fromList.Add(Path.Combine(leftFolder.Name, file.Name));
                        toList.Add(Path.Combine(rightFolder.Name, file.Name));
                    }
                    else if (
                        (file.State == CompareState.Added && options.addedFilesAction == Options.Action.Delete) ||
                        (file.State == CompareState.Unchanged && options.unchangedFilesAction == Options.Action.Delete)
                        )
                    {
                        deleteList.Add(Path.Combine(leftFolder.Name, file.Name));
                    }
                }
            }

            if (rightFolder != null && rightFolder.Files != null && (options.direction == Options.Direction.RightToLeft || options.direction == Options.Direction.Synchronize))
            {
                // Loop over the files in the RIGHT folder
                foreach (FileItem file in rightFolder.Files)
                {
                    if (
                        (file.State == CompareState.Added && options.addedFilesAction == Options.Action.Copy) ||
                        (file.State == CompareState.Newer && options.changedFilesAction == Options.Action.Copy) ||
                        (file.State == CompareState.Older && options.changedFilesAction == Options.Action.Delete)
                        )
                    {
                        fromList.Add(Path.Combine(rightFolder.Name, file.Name));
                        toList.Add(Path.Combine(leftFolder.Name, file.Name));
                    }
                    else if (
                        (file.State == CompareState.Added && options.addedFilesAction == Options.Action.Delete) ||
                        (file.State == CompareState.Unchanged && options.unchangedFilesAction == Options.Action.Delete)
                        )
                    {
                        deleteList.Add(Path.Combine(rightFolder.Name, file.Name));
                    }
                }
            }

            if (leftFolder != null && leftFolder.Folders != null && (options.direction == Options.Direction.LeftToRight || options.direction == Options.Direction.Synchronize))
            {
                foreach (FolderItem folder in leftFolder.Folders)
                {
                    // Find the corresponding folder on the right
                    FolderItem folder2 = null;
                    if (rightFolder.Folders != null)
                    {
                        folder2 = rightFolder.FindFolderByName(Path.GetFileName(folder.Name));
                    }
                    if (folder2 == null)
                    {
                        // The destination folder does not exist. Create a dummy folder for it:
                        folder2 = new FolderItem(rightFolder, Path.Combine(rightFolder.Name, Path.GetFileName(folder.Name)), DateTime.Now);
                    }
                    AddFilesToList(folder, folder2, options, fromList, toList, deleteList);
                }
            }

            if (rightFolder != null && rightFolder.Folders != null && (options.direction == Options.Direction.RightToLeft || options.direction == Options.Direction.Synchronize))
            {
                foreach (FolderItem folder in rightFolder.Folders)
                {
                    // Find the corresponding folder on the left
                    FolderItem folder2 = null;
                    if (leftFolder.Folders != null)
                    {
                        folder2 = leftFolder.FindFolderByName(Path.GetFileName(folder.Name));
                    }
                    if (folder2 == null)
                    {
                        // The destination folder does not exist. Create a dummy folder for it:
                        folder2 = new FolderItem(leftFolder, Path.Combine(leftFolder.Name, Path.GetFileName(folder.Name)), DateTime.Now);
                    }
                    AddFilesToList(folder2, folder, options, fromList, toList, deleteList);
                }
            }
        }