private UPath(UPathComponents path) { if (path.IsAbsolute) { _absolute = path; } else { _relative = path; } }
public UPath(string path) { if (IsPathRooted(path)) { _absolute = new UPathComponents(path, true); } else { _relative = new UPathComponents(path, false); } if (_absolute == null) { var resolved = FSystem.ResolvePath(path); if (resolved != null) { _absolute = new UPathComponents(resolved, true); } } }
private UPath MakeRelativeUPath(UPathComponents referal, UPathComponents referee) { if (referal.Drive != referee.Drive) { throw new InvalidOperationException("Making relative path between path on two differents drives " + referal + " <> " + referee); } var fileComponents = new Queue<string>(referee.Components.Take(referee.Components.Length - 1)); var components = new Queue<string>(referal.Components); var newComponents = new List<string>(); var differencefound = false; if (CheckDoubleDots(components, fileComponents)) { throw new InvalidOperationException("Cannot infer the name of a directory for relative path from " + referal + " to " + referee); } while (components.Count > 0 && fileComponents.Count > 0) { var fileComponent = fileComponents.Peek(); var component = components.Peek(); if (component != fileComponent || differencefound) { differencefound = true; newComponents.Add(".."); components.Dequeue(); } else { fileComponents.Dequeue(); components.Dequeue(); } } while (components.Count > 0) { newComponents.Add(".."); components.Dequeue(); } while (fileComponents.Count > 0) { newComponents.Add(fileComponents.Dequeue()); } newComponents.Add(referee.Components.Last()); return new UPath(new UPathComponents(referal.Drive, newComponents.ToArray(), false)); }