public VolumeItem(Volume volume, VolumePath parentPath, String name) { Volume = volume; Path = VolumePath.FromString(name, parentPath); InitializeSuffixes(); }
public VolumeItem(Volume volume, VolumePath path) { Volume = volume; Path = path; InitializeSuffixes(); }
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); }
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 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 static GlobalPath FromVolumePath(VolumePath volumePath, int volumeId) { return new GlobalPath(volumeId, new List<string>(volumePath.Segments)); }
public bool IsRoomFor(VolumePath path, FileContent fileContent) { VolumeItem existing = Open(path); if (existing is VolumeDirectory) { throw new KOSPersistenceException("'" + path + "' is a directory"); } VolumeFile existingFile = existing as VolumeFile; int usedByThisFile = 0; if (existingFile != null) { usedByThisFile = existingFile.ReadAll().Size; } return INFINITE_CAPACITY == FreeSpace || FreeSpace + usedByThisFile >= fileContent.Size; }
public override VolumeDirectory CreateDirectory(VolumePath path) { string archivePath = GetArchivePath(path); if (Directory.Exists(archivePath)) { throw new KOSPersistenceException("Already exists: " + path); } try { Directory.CreateDirectory(archivePath); } catch (IOException) { throw new KOSPersistenceException("Could not create directory: " + path); } return new ArchiveDirectory(this, path); }
public ArchiveFile(Archive archive, FileInfo fileInfo, VolumePath path) : base(archive, path) { this.fileInfo = fileInfo; }
private GlobalPath(object volumeId, VolumePath path) : this(volumeId, new List <string>(path.Segments)) { }
public override VolumeFile SaveFile(VolumePath path, FileContent content, bool verifyFreeSpace = true) { Directory.CreateDirectory(ArchiveFolder); string archivePath = GetArchivePath(path); if (Directory.Exists(archivePath)) { throw new KOSPersistenceException("Can't save file over a directory: " + path); } string parentPath = Directory.GetParent(archivePath).FullName; if (!Directory.Exists(parentPath)) { Directory.CreateDirectory(parentPath); } byte[] fileBody = ConvertToWindowsNewlines(content.Bytes); using (var outfile = new BinaryWriter(File.Open(archivePath, FileMode.Create))) { outfile.Write(fileBody); } return Open(path) as VolumeFile; }
public abstract VolumeFile SaveFile(VolumePath path, FileContent content, bool verifyFreeSpace = true);
public ArchiveFile(Archive archive, FileInfo fileInfo, VolumePath path) : base(archive, path) { this.fileInfo = fileInfo; }
public VolumeFile OpenOrCreateFile(VolumePath path, bool ksmDefault = false) { VolumeFile file = Open(path, ksmDefault) as VolumeFile; if (file == null) { file = CreateFile(path); } return file; }
public VolumeDirectory OpenOrCreateDirectory(VolumePath path) { VolumeDirectory directory = Open(path) as VolumeDirectory; if (directory == null) { directory = CreateDirectory(path); } return directory; }
/// <summary> /// Get a file given its name /// </summary> /// <param name="name">filename to get. if it has no filename extension, one will be guessed at, ".ks" usually.</param> /// <param name="ksmDefault">in the scenario where there is no filename extension, do we prefer the .ksm over the .ks? The default is to prefer .ks</param> /// <returns>VolumeFile or VolumeDirectory. Null if not found.</returns> public abstract VolumeItem Open(VolumePath path, bool ksmDefault = false);
private static HarddiskDirectory ToHarddiskDirectory(this ConfigNode configNode, Harddisk harddisk, VolumePath path) { HarddiskDirectory directory = new HarddiskDirectory(harddisk, path); foreach (ConfigNode fileNode in configNode.GetNodes("file")) { directory.CreateFile(fileNode.GetValue(FilenameValueString), fileNode.ToHarddiskFile(harddisk, directory)); } foreach (ConfigNode dirNode in configNode.GetNodes("directory")) { string dirName = dirNode.GetValue(DirnameValueString); directory.CreateDirectory(dirName, dirNode.ToHarddiskDirectory(harddisk, VolumePath.FromString(dirName, path))); } return directory; }
public static GlobalPath FromVolumePath(VolumePath volumePath, int volumeId) { return(new GlobalPath(volumeId, new List <string>(volumePath.Segments))); }
public HarddiskDirectory CreateDirectory(string name) { return(CreateDirectory(name, new HarddiskDirectory(Volume as Harddisk, VolumePath.FromString(name, Path)))); }
public static VolumePath FromString(string pathString, VolumePath basePath) { if (IsAbsolute(pathString)) { throw new KOSInvalidPathException("Relative path expected", pathString); } List<string> mergedSegments = new List<string>(); mergedSegments.AddRange(basePath.Segments); mergedSegments.AddRange(GetSegmentsFromString(pathString)); return new VolumePath(mergedSegments); }
/// <summary> /// Get the file from the OS. /// </summary> /// <param name="name">filename to look for</param> /// <param name="ksmDefault">if true, it prefers to use the KSM filename over the KS. The default is to prefer KS.</param> /// <returns>the full fileinfo of the filename if found</returns> private FileSystemInfo Search(VolumePath volumePath, bool ksmDefault) { var path = GetArchivePath(volumePath); if (Directory.Exists(path)) { return new DirectoryInfo(path); } if (File.Exists(path)) { return new FileInfo(path); } var kerboscriptFile = new FileInfo(PersistenceUtilities.CookedFilename(path, KERBOSCRIPT_EXTENSION, true)); var kosMlFile = new FileInfo(PersistenceUtilities.CookedFilename(path, KOS_MACHINELANGUAGE_EXTENSION, true)); if (kerboscriptFile.Exists && kosMlFile.Exists) { return ksmDefault ? kosMlFile : kerboscriptFile; } if (kerboscriptFile.Exists) { return kerboscriptFile; } if (kosMlFile.Exists) { return kosMlFile; } return null; }
public ArchiveDirectory(Archive archive, VolumePath path) : base(archive, path) { this.archive = archive; this.archivePath = archive.GetArchivePath(path); }
public ArchiveDirectory(Archive archive, VolumePath path) : base(archive, path) { this.archive = archive; this.archivePath = archive.GetArchivePath(path); }
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 bool IsParent(VolumePath path) { return path.Segments.Count > Segments.Count && path.Segments.GetRange(0, Segments.Count).SequenceEqual(Segments); }
public bool IsParent(VolumePath path) { return(path.Segments.Count > Segments.Count && path.Segments.GetRange(0, Segments.Count).SequenceEqual(Segments)); }
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 Exists(VolumePath path, bool ksmDefault = false) { return(Search(path, ksmDefault) != null); }
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 override VolumeFile CreateFile(VolumePath path) { if (path.Depth == 0) { throw new KOSPersistenceException("Can't create a file over root directory"); } string archivePath = GetArchivePath(path); if (File.Exists(archivePath)) { throw new KOSPersistenceException("Already exists: " + path); } try { Directory.CreateDirectory(GetArchivePath(path.GetParent())); } catch (IOException) { throw new KOSPersistenceException("Parent directory for path does not exist: " + path.ToString()); } try { File.Create(archivePath).Dispose(); } catch (UnauthorizedAccessException) { throw new KOSPersistenceException("Could not create file: " + path); } return Open(path) as VolumeFile; }
public override bool Delete(VolumePath path, bool ksmDefault = false) { if (path.Depth == 0) { throw new KOSPersistenceException("Can't delete root directory"); } var fileSystemInfo = Search(path, ksmDefault); if (fileSystemInfo == null) { return false; } else if (fileSystemInfo is FileInfo) { File.Delete(fileSystemInfo.FullName); } else { Directory.Delete(fileSystemInfo.FullName, true); } return true; }
public override bool Exists(VolumePath path, bool ksmDefault = false) { return Search(path, ksmDefault) != null; }
protected VolumeFile(Volume volume, VolumePath path) : base(volume, path) { InitializeSuffixes(); }
public string GetArchivePath(VolumePath path) { if (path.PointsOutside) { throw new KOSInvalidPathException("Path refers to parent directory", path.ToString()); } string mergedPath = ArchiveFolder; foreach (string segment in path.Segments) { mergedPath = Path.Combine(mergedPath, segment); } return mergedPath; }
private GlobalPath(object volumeId, VolumePath path) : this(volumeId, new List<string>(path.Segments)) { }
public override VolumeItem Open(VolumePath path, bool ksmDefault = false) { try { var fileSystemInfo = Search(path, ksmDefault); if (fileSystemInfo == null) { return null; } else if (fileSystemInfo is FileInfo) { VolumePath filePath = VolumePath.FromString(fileSystemInfo.FullName.Substring(ArchiveFolder.Length).Replace(Path.DirectorySeparatorChar, VolumePath.PathSeparator)); return new ArchiveFile(this, fileSystemInfo as FileInfo, filePath); } else { // we can use 'path' here, default extensions are not added to directories return new ArchiveDirectory(this, path); } } catch (Exception e) { throw new KOSPersistenceException("Could not open path: " + path, e); } }
public PathValue FromPath(VolumePath volumePath, string volumeId) { return new PathValue(GlobalPath.FromVolumePath(volumePath, volumeId), sharedObjects); }
public HarddiskDirectory(Harddisk harddisk, VolumePath path) : base(harddisk, path) { items = new Dictionary <string, Structure>(StringComparer.InvariantCultureIgnoreCase); }