public DirectoryRecord Read(DirectoryInfo di) { if (!di.Exists) throw new DirectoryNotFoundException(); var dr = new DirectoryRecord() { FullName = di.FullName }; foreach (var file in di.GetFiles()) { if (AllowedExtensions.Contains(file.Extension)) { var vi = new VideoRecord() { FullName = file.FullName, }; dr.Videos.Add(vi); } } dr.Videos.Sort((left, right) => left.Name.CompareTo(right.Name)); foreach (var subdirectory in di.GetDirectories()) { var subdr = Read(subdirectory); if (!subdr.Empty) { dr.Directories.Add(subdr); } } dr.Directories.Sort((left, right) => left.FullName.CompareTo(right.FullName)); return dr; }
private void ValidateDirectory(DirectoryRecord validated, DirectoryRecord info) { validated.IsExpanded = info.IsExpanded; validated.IsSelected = info.IsSelected; foreach (var videoInfo in validated.Videos) { var storedInfo = info.Videos.FirstOrDefault(vr => vr.FullName == videoInfo.FullName); if (storedInfo != null) { videoInfo.Watched = storedInfo.Watched; videoInfo.WatchedTime = storedInfo.WatchedTime; } } foreach (var directoryInfo in validated.Directories) { var storedDirectory = info.Directories.FirstOrDefault(dr => dr.FullName == directoryInfo.FullName); if (storedDirectory != null) ValidateDirectory(directoryInfo, storedDirectory); } }