protected IEnumerable <DiffItem> GetDiff(DirItem other, string pathSoFar) { List <DiffItem> diffs = new List <DiffItem>(); // added or updated files var otherFilesMap = other.Files.ToDictionary(x => x, x => x); foreach (var file in Files) { FileItem otherFile; if (!otherFilesMap.TryGetValue(file, out otherFile)) { diffs.Add(new DiffItem() { Name = string.Format(@"{0}\{1}", pathSoFar, file.Name), Size = file.Size, Status = DiffItemStatus.New }); } else if (file.Size != otherFile.Size) { diffs.Add(new DiffItem() { Name = string.Format(@"{0}\{1}", pathSoFar, file.Name), Size = file.Size - otherFile.Size, Status = DiffItemStatus.Old }); } } // removed files var thisFilesSet = new HashSet <FileItem>(Files); foreach (var file in other.Files) { if (!thisFilesSet.Contains(file)) { diffs.Add(new DiffItem() { Name = string.Format(@"{0}\{1}", pathSoFar, file.Name), Size = -file.Size, Status = DiffItemStatus.Removed, }); } } // removed directories var thisDirsSet = new HashSet <DirItem>(Directories); foreach (var dir in other.Directories) { if (!thisDirsSet.Contains(dir)) { diffs.Add(new DiffItem() { Name = string.Format(@"{0}\{1}", pathSoFar, dir.Name), Size = -dir.Size, Status = DiffItemStatus.Removed, }); } } // new or changed dirs var otherDirsMap = other.Directories.ToDictionary(x => x, x => x); foreach (var dir in Directories) { DirItem otherDir; if (!otherDirsMap.TryGetValue(dir, out otherDir)) { diffs.Add(new DiffItem() { Name = string.Format(@"{0}\{1}", pathSoFar, dir.Name), Size = dir.Size, Status = DiffItemStatus.New, }); } else if (otherDir.Size != dir.Size) { diffs.AddRange(dir.GetDiff(otherDir, string.Format(@"{0}\{1}", pathSoFar, dir.Name))); } } return(diffs); }
public void AddDir(DirItem dirItem) { dirItems[dirsCount++] = dirItem; Size += dirItem.Size; }