Esempio n. 1
0
        public DiskFile(string name, DiskDirectory diskDirectory = null)
        {
            var p = EnsureNameAndPathSeparation(name, diskDirectory);

            Name   = p.Name;
            Parent = p.Path;
        }
Esempio n. 2
0
        public DiskFile(string name, DiskDirectory diskDirectory, Stream source,
                        bool overwrite = true, long offset = default, long length = default)
        {
            Name   = name;
            Parent = diskDirectory;
            if (!overwrite && File.Exists(Path))
            {
                throw new Exception("File already exists");
            }

            Write(source, offset, length);
        }
Esempio n. 3
0
        private (string Name, DiskDirectory Path) EnsureNameAndPathSeparation(string name,
                                                                              DiskDirectory dir)
        {
            var fi = new FileInfo(IoPath.Combine(dir?.Path ?? "", name));

            if (dir == null || fi.Name != name)
            {
                return(fi.Name, new DiskDirectory(fi.DirectoryName));
            }

            return(name, dir);
        }
Esempio n. 4
0
        public DiskDirectory(string name, IDirectory parent = null, bool createIfNotExists = false)
        {
            _dirInfo = new DirectoryInfo(IoPath.Combine(parent?.Path ?? string.Empty, name));

            if (_dirInfo.Parent != null)
            {
                Parent = new DiskDirectory(_dirInfo.Parent.FullName);
            }

            Name = _dirInfo.Name;

            if (!createIfNotExists || _dirInfo.Exists)
            {
                return;
            }

            Directory.CreateDirectory(_dirInfo.FullName);
            _dirInfo.Refresh();
        }