Exemplo n.º 1
0
 public static PathName operator/(PathName left, PathName right)
 {
     if (left != null)
     {
         if (right != null) // left != null && right != null;
         {
             return(left.Join(right));
         }
         else // left != null &&  right == null
         {
             return(left);
         }
     }
     else // left == null
     {
         if (right != null) // left == null && right != null
         {
             return(right);
         }
         else // left == null && right == null
         {
             return(PathName.Path(null));
         }
     }
 }
Exemplo n.º 2
0
 public static void TouchFile(this PathName path)
 {
     if (!File.Exists(path.Full))
     {
         using (var stream = File.OpenWrite(path.Full))
         {
             stream.Close();
         }
     }
     Debug.Assert(File.Exists(path.Full));
     File.SetLastWriteTime(path.Full, DateTime.Now);
 }
Exemplo n.º 3
0
 internal override PathName Join(PathName right)
 {
     if (right is PosixPathName other)
     {
         if (other.IsAbsolute)
         {
             return(right);
         }
         return(new PosixPathName(this.lead, this.segments.Concat(other.segments)));
     }
     else
     {
         throw new InvalidOperationException("can't join posix-path with non-posix-path");
     }
 }
Exemplo n.º 4
0
        public static void RemoveDirectory(PathName directory)
        {
            if (!directory.ExistsDirectory())
            {
                if (directory.ExistsFile())
                {
                    throw PathNameErrors.EntityExistsButIsNotDirectory(directory);
                }
                throw PathNameErrors.DirectoryNotFoundException(directory);
            }

            using (var progress = new Progress())
            {
                RemoveDirectory(directory, progress);
            }
        }
Exemplo n.º 5
0
        private static void RemoveDirectory(PathName directory, Progress progress)
        {
            foreach (var file in directory.EnumerateFiles())
            {
                file.DeleteFile();
                progress.Advance();
            }

            foreach (var child in directory.EnumerateDirectories())
            {
                RemoveDirectory(child, progress);
            }

            directory.DeleteDirectory();
            progress.Advance();
        }
Exemplo n.º 6
0
 internal override PathName Join(PathName right)
 {
     if (right is WindowsPathName other)
     {
         if (other.IsAbsolute)
         {
             return(other);
         }
         else if (other.IsAnchored)
         {
             throw new InvalidOperationException("can't join windows-path with anchored windows-path");
         }
         return(new WindowsPathName(this.lead, this.segments.Concat(other.segments)));
     }
     else
     {
         throw new InvalidOperationException("can't join windows-path with non-windows-path");
     }
 }
Exemplo n.º 7
0
 public static IEnumerable <PathName> EnumerateDirectories(this PathName path)
 {
     return(Directory.EnumerateDirectories(path.Full).Select(filePath => PathName.Path(filePath)));
 }
Exemplo n.º 8
0
 public static bool ExistsDirectory(this PathName path)
 {
     return(Directory.Exists(path.Full));
 }
Exemplo n.º 9
0
 public static void CreateDirectory(this PathName path)
 {
     Directory.CreateDirectory(path.Full);
 }
Exemplo n.º 10
0
 public static void MoveDirectory(this PathName source, PathName destination)
 {
     Directory.Move(source.Full, destination.Full);
 }
Exemplo n.º 11
0
 public static FileNotFoundException EntityDoesntExists(PathName path)
 {
     return(new FileNotFoundException($"'{path}' doesn't exists as expected"));
 }
Exemplo n.º 12
0
 public static void CopyFileFrom(this PathName destination, PathName source)
 {
     File.Copy(source.Full, destination.Full);
 }
Exemplo n.º 13
0
 public static DirectoryNotFoundException DirectoryNotFoundException(PathName path)
 {
     return(new DirectoryNotFoundException($"expected directory '{path}', but it doesn't exists"));
 }
Exemplo n.º 14
0
 public static void WriteAllBytes(this PathName path, byte[] bytes)
 {
     File.WriteAllBytes(path.Full, bytes);
 }
Exemplo n.º 15
0
 internal abstract PathName Join(PathName other);
Exemplo n.º 16
0
 public static bool ExistsFile(this PathName path)
 {
     return(File.Exists(path.Full));
 }
Exemplo n.º 17
0
 public static string[] ReadAllLines(this PathName path)
 {
     return(File.ReadAllLines(path.Full));
 }
Exemplo n.º 18
0
 public static FileNotFoundException EntityExistsButIsNotDirectory(PathName path)
 {
     return(new FileNotFoundException($"'{path}' exists, but isn't a directory as expected"));
 }
Exemplo n.º 19
0
 public static void DeleteDirectory(this PathName path, bool recursive = false)
 {
     Directory.Delete(path.Full, recursive);
 }
Exemplo n.º 20
0
 public static FileNotFoundException FileNotFoundException(PathName path)
 {
     return(new FileNotFoundException($"expected file '{path}', but it doesn't exists"));
 }
Exemplo n.º 21
0
 public static void DeleteFile(this PathName path)
 {
     File.Delete(path.Full);
 }