Exemplo n.º 1
0
        public HarddiskDirectory GetSubdirectory(VolumePath path, bool create = false)
        {
            if (Path.Equals(path))
            {
                return(this);
            }

            if (!Path.IsParent(path))
            {
                throw new KOSException("This directory does not contain path: " + path.ToString());
            }

            string subdirectory = path.Segments[Path.Segments.Count];

            if (!items.ContainsKey(subdirectory))
            {
                if (create)
                {
                    CreateDirectory(subdirectory);
                }
                else
                {
                    return(null);
                }
            }

            HarddiskDirectory directory = items[subdirectory] as HarddiskDirectory;

            if (directory == null)
            {
                throw new KOSPersistenceException("Directory does not exist: " + path.ToString());
            }

            return(directory.GetSubdirectory(path, create));
        }
Exemplo n.º 2
0
        public override VolumeFile CreateFile(VolumePath path)
        {
            if (path.Depth == 0)
            {
                throw new KOSPersistenceException("Can't create a file over root directory");
            }

            HarddiskDirectory directory = ParentDirectoryForPath(path, true);

            return(directory.CreateFile(path.Name));
        }
Exemplo n.º 3
0
        public override VolumeItem Open(VolumePath path, bool ksmDefault = false)
        {
            if (path.Depth == 0)
            {
                return(Root);
            }

            HarddiskDirectory directory = ParentDirectoryForPath(path);

            return(directory == null ? null : directory.Open(path.Name, ksmDefault));
        }
Exemplo n.º 4
0
        public override bool Delete(VolumePath path, bool ksmDefault = false)
        {
            if (path.Depth == 0)
            {
                throw new KOSPersistenceException("Can't delete root directory");
            }

            HarddiskDirectory directory = ParentDirectoryForPath(path);

            return(directory.Delete(path.Name, ksmDefault));
        }
Exemplo n.º 5
0
        private HarddiskDirectory ParentDirectoryForPath(VolumePath path, bool create = false)
        {
            HarddiskDirectory directory = RootHarddiskDirectory;

            if (path.Depth > 0)
            {
                return(RootHarddiskDirectory.GetSubdirectory(path.GetParent(), create));
            }
            else
            {
                throw new Exception("This directory does not have a parent");
            }
        }
Exemplo n.º 6
0
        public HarddiskDirectory CreateDirectory(string name, HarddiskDirectory directory)
        {
            try
            {
                items.Add(name, directory);
            }
            catch (ArgumentException)
            {
                throw new KOSPersistenceException("Already exists: " + name);
            }

            return(directory);
        }
Exemplo n.º 7
0
        public override bool Exists(VolumePath path, bool ksmDefault = false)
        {
            if (path.Depth == 0)
            {
                return(true);
            }

            HarddiskDirectory directory = ParentDirectoryForPath(path);

            if (directory == null)
            {
                return(false);
            }

            return(directory.Exists(path.Name, ksmDefault));
        }
Exemplo n.º 8
0
        public override VolumeFile SaveFile(VolumePath path, FileContent content, bool verifyFreeSpace = true)
        {
            try
            {
                if (verifyFreeSpace && !IsRoomFor(path, content))
                {
                    return(null);
                }
            }
            catch (KOSPersistenceException)
            {
                throw new KOSPersistenceException("Can't save file over a directory: " + path);
            }

            HarddiskDirectory directory = ParentDirectoryForPath(path, true);

            return(directory.Save(path.Name, content) as VolumeFile);
        }
Exemplo n.º 9
0
 public Harddisk(int size)
 {
     Capacity = size;
     RootHarddiskDirectory = new HarddiskDirectory(this, VolumePath.EMPTY);
 }