public static void UpdateDirectory(FileSystemObjectInfo root, string path) { if (root.Children == null) { return; } var copyChildren = new List <FileSystemObjectInfo>(root.Children); root.Explore(); foreach (var child in copyChildren) { if (child.FileSystemInfo == null) { continue; } if (child.FileSystemInfo.FullName == path.Trim()) { child.Parent.Explore(); child.Explore(); } //Task.Factory.StartNew(()=>UpdateDirectory(child, path)); Application.Current.Dispatcher.Invoke(() => UpdateDirectory(child, path)); } }
public static FileSystemObjectInfo UpdateSpying(FileSystemObjectInfo root, string path) { if (root.Children == null) { return(null); } root.Explore(); foreach (var child in root.Children) { if (child.FileSystemInfo == null) { continue; } if (child.FileSystemInfo.FullName == path.Trim()) { child.IsSpyOn = true; return(child); } //Task.Factory.StartNew(() => UpdateSpying(child, path)); Application.Current.Dispatcher.Invoke(() => UpdateDirectory(child, path)); } return(null); }
private void Explore() { if (FileSystemInfo is DirectoryInfo) { var systemObjects = new List <FileSystemInfo>(); try { systemObjects.AddRange(((DirectoryInfo)FileSystemInfo).GetDirectories().OrderBy(d => d.Name)); systemObjects.AddRange((FileSystemInfo as DirectoryInfo).GetFiles().OrderBy(d => d.Name)); } catch (Exception e) { // ignored } var filesPaths = Children.Select((i) => i.FileSystemInfo?.FullName).ToList(); foreach (var systemInfo in systemObjects) { if (!Equals((systemInfo.Attributes & FileAttributes.System), FileAttributes.System) && !Equals((systemInfo.Attributes & FileAttributes.Hidden), FileAttributes.Hidden)) { if (!filesPaths.Contains(systemInfo.FullName)) { filesPaths.Add(systemInfo.FullName); var newFile = new FileSystemObjectInfo(systemInfo); newFile.Parent = this; Application.Current.Dispatcher.Invoke(() => Children.Add(newFile)); } } } var childrenCopy = Children.Select((i) => i).ToList(); foreach (var info in childrenCopy) { if (info.FileSystemInfo == null) { continue; } if (!(File.Exists(info.FileSystemInfo.FullName) || Directory.Exists(info.FileSystemInfo.FullName))) { Application.Current.Dispatcher.Invoke(() => Children.Remove(info)); } } RaisePropertyChanged("Children"); } }
public static void Delete(this FileSystemObjectInfo file) { if (file.FileSystemInfo.Extension != "") { File.Delete(file.FileSystemInfo.FullName); } else { Directory.Delete(file.FileSystemInfo.FullName, true); } //_logs.Enqueue($"{file.FileSystemInfo.FullName} has been deleted"); var parent = file.Parent; parent.Children.Remove(file); file.RemoveDummy(); parent.UpdateParentDirectory(); }