private void ScanDirectory(DirectoryInfo startdir, SnapDir knowndir) { if (startdir.Attributes.HasFlag(System.IO.FileAttributes.ReparsePoint)) { return; } status = startdir.Name; foreach (var dir in startdir.EnumerateDirectories()) { try { //var new_knowndir = new VDir(dir); //knowndir.dirs.Add(new_knowndir); //ScanDirectory(dir,new_knowndir); } catch (SecurityException e) { } catch (UnauthorizedAccessException e) { } try { ScanFiles(dir, knowndir); } catch (SecurityException e) { } catch (UnauthorizedAccessException e) { } } }
public SnapDir AddSubdir(string name) { SnapDir vd = new SnapDir(name, this.volume, this); dirs.Add(vd); return(vd); }
/* * /// <summary> * /// Create a Volume from a specified <paramref name="drive"/> (local or network), using its label for a name, and <paramref name="dir"/> as its root point. * /// </summary> * public Volume(DriveInfo drive, DirectoryInfo dir) : this(drive, dir.FullName) { } * * /// <summary> * /// Create a Volume from a specified <paramref name="drive"/> (local or network), using its label for a name, at its root. * /// </summary> * public Volume(DriveInfo drive) : this(drive, "X:\\") { } // X: gets cut off anyway * * /// <summary> * /// Create a Volume from a specified <paramref name="drive"/> (local or network), using its label for a name, and <paramref name="rootpoint"/> - in a "X:\folder\folder" form - as its root point. * /// </summary> * public Volume(DriveInfo drive) { * this.Label = drive.VolumeLabel; * this.driveinfo = drive; * Refresh(); * } */ /// <summary> /// Create a Volume in "offline" mode, for later recognition using methods provided. /// </summary> /// <param name="label"></param> public Volume(string label) { this.Label = label; this.knownLocations = new List <KnownLocation>(); this.mappings = new List <Mapping>(); root = SnapDir.CreateRoot(this); }
internal void Render() { HDir hd_map = GetMasterRoot(); SnapDir sd = GetSnapshotRoot(); sd.RenderTo(hd_map); }
private void ScanFiles(DirectoryInfo startdir, SnapDir knowndir) { if (startdir.Attributes.HasFlag(System.IO.FileAttributes.ReparsePoint)) { return; } foreach (var filesi in startdir.EnumerateFiles()) { knowndir.AddFile(filesi); } }
internal void AddScanned(SnapDir subsd) { var hd = this; while (hd != null) { if (!hd.on_volumes.Contains(subsd.volume)) { hd.on_volumes.Add(subsd.volume); } hd = hd.parent; } }
private SnapDir(string name, Volume volume, SnapDir parent) { this.name = name; this.volume = volume; this.parent = parent; if (parent != null) { this.fullpath = parent.fullpath + (parent.name == @"\" ? "" : @"\") + this.name; } else { this.fullpath = @"\"; } dirs = new List <SnapDir>(); files = new List <SnapFile>(); }
/// <exception cref="SnapDirNotFoundException">Thrown when folder is not found.</exception> internal SnapDir GetPath(string path, bool allow_creation) { // trim trailing backslashes while (path.EndsWith(@"\")) { path = path.Substring(0, path.Length - 1); } if (path.StartsWith(@"\")) { if (this.name != @"\") { throw new SnapDirNotFoundException("Searching for " + path + " on " + this.fullpath + " which is not root!"); } else { path = path.Substring(1); } } string[] path_tokens = path.Split(@"\".ToCharArray(), 2); string first_token = path_tokens[0]; SnapDir dir = this.GetSubdir(first_token, allow_creation); if (dir == null) { throw new SnapDirNotFoundException(first_token, this.fullpath, path); } if (path_tokens.Length > 1) { string remainder = path_tokens[1]; return(dir.GetPath(remainder, allow_creation)); } else { return(dir); } }
internal bool FillWithSnapshot(DirectoryInfo dir) { mtime = dir.LastWriteTime; try { foreach (DirectoryInfo di in dir.EnumerateDirectories()) { try { if (di.Attributes.HasFlag(FileAttributes.ReparsePoint) && Utils.JunctionPoint.Exists(di.FullName)) { Console.WriteLine("Snapshot: d " + di.FullName + " is a junction."); continue; } Console.WriteLine("Snapshot: d " + di.FullName); SnapDir sub = AddSubdirWithSnapshot(di); } catch (System.IO.IOException e) { Console.WriteLine("ERROR snapshotting " + di.FullName); } } files.Clear(); foreach (FileInfo fi in dir.EnumerateFiles()) { Console.WriteLine("Snapshot: f " + fi.FullName); AddFile(fi); } } catch (System.UnauthorizedAccessException) { Console.WriteLine("Snapshot: d " + dir.FullName + " got UnauthorizedAccess"); } catch (System.IO.DirectoryNotFoundException) { Console.WriteLine("Snapshot: d " + dir.FullName + " got DirectoryNotFound"); } catch (System.IO.FileNotFoundException) { Console.WriteLine("Snapshot: d " + dir.FullName + " got FileNotFound"); } return(true); }