public AllorsDirectoryInfo(DirectoryInfo directoryInfo) { this.directoryInfo = directoryInfo; if (directoryInfo.Parent != null) { this.parent = new AllorsDirectoryInfo(directoryInfo.Parent); } }
public string GetRelativeName(DirectoryInfo baseDirectoryInfo) { var baseDirectory = new AllorsDirectoryInfo(baseDirectoryInfo); var directory = new AllorsDirectoryInfo(this.fileInfo.Directory); var relativePath = directory.GetRelativeName(baseDirectory); return(relativePath == null ? null : Path.Combine(relativePath, this.fileInfo.Name)); }
private AllorsDirectoryInfo GetCommonAncestor(AllorsDirectoryInfo destination) { if (destination.IsAncestor(this)) { return(this); } return(this.parent.GetCommonAncestor(destination)); }
private void BuildAncestors(AllorsDirectoryInfo root, List <AllorsDirectoryInfo> ancestors) { if (!this.directoryInfo.FullName.Equals(this.directoryInfo.Root.FullName)) { if (!this.directoryInfo.FullName.Equals(root.directoryInfo.FullName)) { ancestors.Add(this); this.parent.BuildAncestors(root, ancestors); } } }
public string GetRelativeName(DirectoryInfo baseDirectoryInfo) { var baseDirectory = new AllorsDirectoryInfo(baseDirectoryInfo); var directory = new AllorsDirectoryInfo(fileInfo.Directory); string relativePath = directory.GetRelativeName(baseDirectory); if (relativePath == null) { return null; } return Path.Combine(relativePath, this.fileInfo.Name); }
private bool IsAncestor(AllorsDirectoryInfo ancestor) { if (this.directoryInfo.FullName.Equals(ancestor.directoryInfo.FullName)) { return(true); } if (this.parent != null) { return(this.parent.IsAncestor(ancestor)); } return(false); }
public string GetRelativeName(DirectoryInfo baseDirectoryInfo) { var baseDirectory = new AllorsDirectoryInfo(baseDirectoryInfo); var directory = new AllorsDirectoryInfo(fileInfo.Directory); string relativePath = directory.GetRelativeName(baseDirectory); if (relativePath == null) { return(null); } return(Path.Combine(relativePath, this.fileInfo.Name)); }
internal string GetRelativeName(AllorsDirectoryInfo baseDirectory) { if (this.directoryInfo.Root.FullName.Equals(baseDirectory.directoryInfo.Root.FullName)) { AllorsDirectoryInfo commonAncestor = this.GetCommonAncestor(baseDirectory); var ancestors = new List <AllorsDirectoryInfo>(); this.BuildAncestors(commonAncestor, ancestors); var baseAncestors = new List <AllorsDirectoryInfo>(); baseDirectory.BuildAncestors(commonAncestor, baseAncestors); var relativePath = new StringBuilder(); foreach (AllorsDirectoryInfo baseAncestor in baseAncestors) { if (relativePath.Length > 0) { relativePath.Append(Path.DirectorySeparatorChar); } relativePath.Append(".."); } for (int i = ancestors.Count - 1; i >= 0; --i) { AllorsDirectoryInfo ancestor = ancestors[i]; if (relativePath.Length > 0) { relativePath.Append(Path.DirectorySeparatorChar); } relativePath.Append(ancestor.directoryInfo.Name); } return(relativePath.ToString()); } return(null); }
internal string GetRelativeName(AllorsDirectoryInfo baseDirectory) { if (this.directoryInfo.Root.FullName.Equals(baseDirectory.directoryInfo.Root.FullName)) { AllorsDirectoryInfo commonAncestor = this.GetCommonAncestor(baseDirectory); var ancestors = new List<AllorsDirectoryInfo>(); this.BuildAncestors(commonAncestor, ancestors); var baseAncestors = new List<AllorsDirectoryInfo>(); baseDirectory.BuildAncestors(commonAncestor, baseAncestors); var relativePath = new StringBuilder(); foreach (AllorsDirectoryInfo baseAncestor in baseAncestors) { if (relativePath.Length > 0) { relativePath.Append(Path.DirectorySeparatorChar); } relativePath.Append(".."); } for (int i = ancestors.Count - 1; i >= 0; --i) { AllorsDirectoryInfo ancestor = ancestors[i]; if (relativePath.Length > 0) { relativePath.Append(Path.DirectorySeparatorChar); } relativePath.Append(ancestor.directoryInfo.Name); } return relativePath.ToString(); } return null; }
private AllorsDirectoryInfo GetCommonAncestor(AllorsDirectoryInfo destination) => destination.IsAncestor(this) ? this : this.Parent.GetCommonAncestor(destination);
private bool IsAncestor(AllorsDirectoryInfo ancestor) { if (this.directoryInfo.FullName.Equals(ancestor.directoryInfo.FullName)) { return true; } if (this.parent != null) { return this.parent.IsAncestor(ancestor); } return false; }
private AllorsDirectoryInfo GetCommonAncestor(AllorsDirectoryInfo destination) { if (destination.IsAncestor(this)) { return this; } return this.parent.GetCommonAncestor(destination); }
private void BuildAncestors(AllorsDirectoryInfo root, List<AllorsDirectoryInfo> ancestors) { if (!this.directoryInfo.FullName.Equals(this.directoryInfo.Root.FullName)) { if (!this.directoryInfo.FullName.Equals(root.directoryInfo.FullName)) { ancestors.Add(this); this.parent.BuildAncestors(root, ancestors); } } }