public IAbsolutePath ResolveAbsolutePath(string nativePath) { try { var absPath = Path.IsPathRooted(nativePath) ? nativePath : Path.GetFullPath(nativePath); var isDirectory = Directory.Exists(nativePath); return(isDirectory ? (IAbsolutePath)AbsoluteDirectoryPath.Parse(absPath) : (IAbsolutePath)AbsoluteFilePath.Parse(absPath)); } catch (ArgumentException e) { throw new InvalidPath(nativePath, e); } catch (NotSupportedException e) { throw new InvalidPath(nativePath, e); } catch (PathTooLongException e) { throw new InvalidPath(nativePath, e); } }
/// <exception cref="InvalidPath"></exception> /// <exception cref="ArgumentException"></exception> public static AbsoluteFilePath Parse(string nativePath) { if (string.IsNullOrEmpty(nativePath)) { throw new ArgumentException("nativePath"); } try { return(new AbsoluteFilePath( new FileName(Path.GetFileName(nativePath)), AbsoluteDirectoryPath.Parse(Path.GetDirectoryName(nativePath)))); } catch (Exception e) { throw new InvalidPath(nativePath, e); } }
//Unused method, but maybe someone wants it for manual testing or something? #pragma warning disable 0219 public void Execute() { var root = AbsoluteDirectoryPath.Parse("root"); var file1 = root.Combine("Templates").Combine("Projects").Combine(new FileName("example.exe")); var file2 = root / "Templates" / "Projects" / new FileName("example.exe"); IAbsolutePath absFileOrDirectory = file2; absFileOrDirectory.Do( (AbsoluteFilePath file) => Console.Out.WriteLine("File " + file), (AbsoluteDirectoryPath dir) => Console.Out.WriteLine("Dir " + dir)); IFilePath absOrRelFile = file2; absOrRelFile.Do( (AbsoluteFilePath abs) => Console.Out.WriteLine("Abs " + abs), (RelativeFilePath rel) => Console.Out.WriteLine("Rel " + rel)); var relativePath = RelativeDirectoryPath.Empty / ".." / "Programs" / "Fuse" / "Data"; var rebased = root / relativePath; var common = root / "a" / "b"; var nop = common.RelativeTo(common); var downUp = (common / "left").RelativeTo(common / "right"); var downDownUpUp = (common / "left" / "left2").RelativeTo(common / "right" / "right2"); var downDownDownUpUpUp = (common / "left" / "left2" / "left3").RelativeTo(common / "right" / "right2" / "right3"); var left = common / "lc" / "ld"; var right = common / "rc" / "rd" / "re"; var rightToLeft = left.RelativeTo(right); var leftToRight = right.RelativeTo(left); var leftToLeft = left.RelativeTo(left); var a = common / leftToLeft; var b = a == common; }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (objectType == typeof(AbsoluteFilePath)) { return(AbsoluteFilePath.Parse((string)reader.Value)); } if (objectType == typeof(RelativeFilePath)) { return(RelativeFilePath.Parse((string)reader.Value)); } if (objectType == typeof(AbsoluteDirectoryPath)) { return(AbsoluteDirectoryPath.Parse((string)reader.Value)); } if (objectType == typeof(RelativeDirectoryPath)) { return(RelativeDirectoryPath.Parse((string)reader.Value)); } throw new ArgumentException("The type '" + objectType.FullName + "' was not recognized by this converter"); }
public void SetPermission( AbsoluteDirectoryPath dir, FileSystemPermission permission, FileSystemGroup group, bool recursive) { var permissionBits = GetPermissionBits(permission, group); Syscall.chmod(dir.NativePath, (FilePermissions)permissionBits); if (recursive) { foreach (var file in Directory.GetFiles(dir.NativePath)) { var filePermission = (int)permission & ~(int)FileSystemPermission.Execute; SetPermission(AbsoluteFilePath.Parse(file), (FileSystemPermission)filePermission, group); } foreach (var directory in Directory.GetDirectories(dir.NativePath)) { SetPermission(AbsoluteDirectoryPath.Parse(directory), permission, group, recursive); } } }
public static AbsoluteDirectoryPath ToAbsoluteDirectoryPath(this Uri uri) { return(AbsoluteDirectoryPath.Parse(Uri.UnescapeDataString(uri.LocalPath))); }
/// <exception cref="System.UnauthorizedAccessException" /> public static AbsoluteDirectoryPath GetCurrentDirectory() { return(AbsoluteDirectoryPath.Parse(Directory.GetCurrentDirectory())); }
public static IDirectoryPath Parse(string relativeOrAbsolutePath) { return(Path.IsPathRooted(relativeOrAbsolutePath) ? (IDirectoryPath)AbsoluteDirectoryPath.Parse(relativeOrAbsolutePath) : (IDirectoryPath)RelativeDirectoryPath.Parse(relativeOrAbsolutePath)); }
/// <exception cref="System.Security.SecurityException" /> public static AbsoluteDirectoryPath GetTempPath() { return(AbsoluteDirectoryPath.Parse(Path.GetTempPath())); }