Example #1
0
 public void Copy(AbsoluteDirectoryPath source, AbsoluteDirectoryPath destination)
 {
     Directory.CreateDirectory(destination.NativePath);
     foreach (var fileInfo in new DirectoryInfo(source.NativePath).GetFiles())
     {
         fileInfo.CopyTo((destination / fileInfo.Name).NativePath, true);
     }
     foreach (var directoryInfo in new DirectoryInfo(source.NativePath).GetDirectories())
     {
         var sourceDir = (source / directoryInfo.Name);
         var destDir   = (destination / directoryInfo.Name);
         Copy(sourceDir, destDir);
     }
 }
        static AbsoluteDirectoryPath FindCommonAncestorBalanced(AbsoluteDirectoryPath left, AbsoluteDirectoryPath right)
        {
            while (left != null && right != null)
            {
                if (left == right)
                {
                    return(left);
                }
                left  = left.ContainingDirectory;
                right = right.ContainingDirectory;
            }

            return(null);
        }
Example #3
0
        /// <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);
            }
        }
Example #4
0
        //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;
        }
Example #5
0
 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");
 }
Example #6
0
        public void SetPermission(
            AbsoluteDirectoryPath dir,
            FileSystemPermission permission,
            FileSystemGroup group,
            bool recursive)
        {
            var dInfo = new DirectoryInfo(dir.NativePath);
            var dSec  = new DirectorySecurity();

            dSec.AddAccessRule(new FileSystemAccessRule(
                                   GetIdentity(group),
                                   CreateSystemRightsFile(permission),
                                   AccessControlType.Allow));
            dInfo.SetAccessControl(dSec);

            if (recursive)
            {
                ReplaceAllDescendantPermissionsFromObject(dInfo, dSec, permission, group);
            }
        }
Example #7
0
        public IObservable <FileSystemEventData> Watch(AbsoluteDirectoryPath path, Optional <string> filter = default(Optional <string>))
        {
            return(Observable.Create <FileSystemEventData>(observer =>
            {
                if (!Exists(path))
                {
                    observer.OnError(new FileNotFoundException("Directory not found", path.ContainingDirectory.NativePath));
                    return Disposable.Empty;
                }

                var fsw = filter.Select(f => new FileSystemWatcher(path.NativePath, f)).Or(new FileSystemWatcher(path.NativePath));
                fsw.IncludeSubdirectories = false;
                fsw.NotifyFilter = NotifyFilters.CreationTime
                                   | NotifyFilters.FileName
                                   | NotifyFilters.LastWrite
                                   | NotifyFilters.Size;

                var garbage = Disposable.Combine(
                    fsw,
                    Observable.FromEventPattern <ErrorEventArgs>(fsw, "Error")
                    .Subscribe(_ => observer.OnError(_.EventArgs.GetException())),
                    Observable.FromEventPattern <FileSystemEventArgs>(fsw, "Changed")
                    .Subscribe(e => observer.OnNext(new FileSystemEventData(AbsoluteFilePath.Parse(e.EventArgs.FullPath), FileSystemEvent.Changed))),
                    Observable.FromEventPattern <FileSystemEventArgs>(fsw, "Created")
                    .Subscribe(e => observer.OnNext(new FileSystemEventData(AbsoluteFilePath.Parse(e.EventArgs.FullPath), FileSystemEvent.Created))),
                    Observable.FromEventPattern <RenamedEventArgs>(fsw, "Renamed")
                    .Subscribe(e =>
                {
                    observer.OnNext(new FileSystemEventData(
                                        AbsoluteFilePath.Parse(e.EventArgs.FullPath),
                                        FileSystemEvent.Renamed,
                                        AbsoluteFilePath.Parse(e.EventArgs.OldFullPath)));
                }),
                    Observable.FromEventPattern <FileSystemEventArgs>(fsw, "Deleted")
                    .Subscribe(e => observer.OnNext(new FileSystemEventData(AbsoluteFilePath.Parse(e.EventArgs.FullPath), FileSystemEvent.Removed))));

                fsw.EnableRaisingEvents = true;

                return garbage;
            }));
        }
Example #8
0
        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);
                }
            }
        }
Example #9
0
 public void Create(AbsoluteDirectoryPath directory)
 {
     Directory.CreateDirectory(directory.NativePath);
 }
Example #10
0
 internal AbsoluteFilePath(FileName name, AbsoluteDirectoryPath containingDirectory)
 {
     ContainingDirectory = containingDirectory;
     Name = name;
 }
Example #11
0
 /// <exception cref="System.Security.SecurityException" />
 public static AbsoluteDirectoryPath GetTempPath()
 {
     return(AbsoluteDirectoryPath.Parse(Path.GetTempPath()));
 }
Example #12
0
 public IEnumerable <AbsoluteDirectoryPath> GetDirectories(AbsoluteDirectoryPath path)
 {
     return(_shellImpl.GetDirectories(path));
 }
Example #13
0
 public IEnumerable <AbsoluteDirectoryPath> GetDirectories(AbsoluteDirectoryPath path, string searchPattern)
 {
     return(_shellImpl.GetDirectories(path, searchPattern));
 }
Example #14
0
        public static AbsoluteDirectoryPath FindCommonAncestor(AbsoluteDirectoryPath path1, AbsoluteDirectoryPath path2)
        {
            var orderedPaths  = OrderByDepth(path1, path2);
            var balancedPaths = Balance(orderedPaths);

            if (balancedPaths == null)
            {
                return(null);
            }

            return(FindCommonAncestorBalanced(balancedPaths.Item1, balancedPaths.Item2));
        }
Example #15
0
 public static AbsoluteDirectoryPath ToAbsoluteDirectoryPath(this Uri uri)
 {
     return(AbsoluteDirectoryPath.Parse(Uri.UnescapeDataString(uri.LocalPath)));
 }
Example #16
0
 public IEnumerable <AbsoluteDirectoryPath> GetDirectories(AbsoluteDirectoryPath path)
 {
     return(Directory.GetDirectories(path.NativePath).Select(AbsoluteDirectoryPath.Parse));
 }
Example #17
0
 public static IDirectoryPath Parse(string relativeOrAbsolutePath)
 {
     return(Path.IsPathRooted(relativeOrAbsolutePath)
                         ? (IDirectoryPath)AbsoluteDirectoryPath.Parse(relativeOrAbsolutePath)
                         : (IDirectoryPath)RelativeDirectoryPath.Parse(relativeOrAbsolutePath));
 }
Example #18
0
 public void Move(AbsoluteDirectoryPath source, AbsoluteDirectoryPath destination)
 {
     _shellImpl.Move(source, destination);
 }
Example #19
0
 /// <exception cref="System.UnauthorizedAccessException" />
 public static AbsoluteDirectoryPath GetCurrentDirectory()
 {
     return(AbsoluteDirectoryPath.Parse(Directory.GetCurrentDirectory()));
 }
Example #20
0
 public static void Write(BinaryWriter writer, AbsoluteDirectoryPath path)
 {
     writer.Write(path.NativePath);
 }
Example #21
0
 public void OpenFolder(AbsoluteDirectoryPath path)
 {
     Process.Start((string)path.NativePath);
 }
Example #22
0
 public IObservable <FileSystemEventData> Watch(AbsoluteDirectoryPath path, Optional <string> filter = default(Optional <string>))
 {
     return(_shellImpl.Watch(path, filter));
 }
Example #23
0
 public void Create(AbsoluteDirectoryPath directory)
 {
     _shellImpl.Create(directory);
 }
Example #24
0
 public static AbsoluteFilePath ParseAndMakeAbsolute(IFilePath path, AbsoluteDirectoryPath root)
 {
     return(path as AbsoluteFilePath ?? ParseAndMakeAbsolute(((RelativeFilePath)path).NativeRelativePath, root));
 }
Example #25
0
 public IEnumerable <AbsoluteDirectoryPath> GetDirectories(AbsoluteDirectoryPath path, string searchPattern)
 {
     return(Directory.GetDirectories(path.NativePath, searchPattern).Select(AbsoluteDirectoryPath.Parse));
 }
Example #26
0
 public void OpenFolder(AbsoluteDirectoryPath path)
 {
     //TODO: is this needed ? ps.UpdatePathEnvironment();
     _shellImpl.OpenFolder(path);
 }
Example #27
0
 public static AbsoluteDirectoryPath MakeUnique(this IFileSystem fileSystem, AbsoluteDirectoryPath path)
 {
     return(fileSystem.MakeUnique(path, i => path.Rename(CreateNumberName(path.Name, i))));
 }
Example #28
0
 public void OpenTerminal(AbsoluteDirectoryPath containingDirectory)
 {
     _shellImpl.OpenTerminal(containingDirectory);
 }