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)); }
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)); }
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)); }
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)); }
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"); } }
public HarddiskDirectory CreateDirectory(string name, HarddiskDirectory directory) { try { items.Add(name, directory); } catch (ArgumentException) { throw new KOSPersistenceException("Already exists: " + name); } return(directory); }
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)); }
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); }
public Harddisk(int size) { Capacity = size; RootHarddiskDirectory = new HarddiskDirectory(this, VolumePath.EMPTY); }