// // Copyright (c) 2008-2011, Kenneth Bell // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // using System; using System.IO; using DiscUtils.Streams; namespace DiscUtils { /// /// Base class for file systems that are by their nature read-only, causes NotSupportedException to be thrown /// from all methods that are always invalid. /// public abstract class ReadOnlyDiscFileSystem : DiscFileSystem { /// /// Initializes a new instance of the ReadOnlyDiscFileSystem class. /// protected ReadOnlyDiscFileSystem() {} /// /// Initializes a new instance of the ReadOnlyDiscFileSystem class. /// /// The options instance to use for this file system instance. protected ReadOnlyDiscFileSystem(DiscFileSystemOptions defaultOptions) : base(defaultOptions) {} /// /// Indicates whether the file system is read-only or read-write. /// /// Always false. public override bool CanWrite { get { return false; } } /// /// Copies a file - not supported on read-only file systems. /// /// The source file. /// The destination file. /// Whether to permit over-writing of an existing file. public override void CopyFile(string sourceFile, string destinationFile, bool overwrite) { throw new NotSupportedException(); } /// /// Creates a directory - not supported on read-only file systems. /// /// The path of the new directory. public override void CreateDirectory(string path) { throw new NotSupportedException(); } /// /// Deletes a directory - not supported on read-only file systems. /// /// The path of the directory to delete. public override void DeleteDirectory(string path) { throw new NotSupportedException(); } /// /// Deletes a file - not supported on read-only file systems. /// /// The path of the file to delete. public override void DeleteFile(string path) { throw new NotSupportedException(); } /// /// Moves a directory - not supported on read-only file systems. /// /// The directory to move. /// The target directory name. public override void MoveDirectory(string sourceDirectoryName, string destinationDirectoryName) { throw new NotSupportedException(); } /// /// Moves a file - not supported on read-only file systems. /// /// The file to move. /// The target file name. /// Whether to allow an existing file to be overwritten. public override void MoveFile(string sourceName, string destinationName, bool overwrite) { throw new NotSupportedException(); } /// /// Opens the specified file. /// /// The full path of the file to open. /// The file mode for the created stream. /// The new stream. public override SparseStream OpenFile(string path, FileMode mode) { return OpenFile(path, mode, FileAccess.Read); } /// /// Sets the attributes of a file or directory - not supported on read-only file systems. /// /// The file or directory to change. /// The new attributes of the file or directory. public override void SetAttributes(string path, FileAttributes newValue) { throw new NotSupportedException(); } /// /// Sets the creation time (in UTC) of a file or directory - not supported on read-only file systems. /// /// The path of the file or directory. /// The new time to set. public override void SetCreationTimeUtc(string path, DateTime newTime) { throw new NotSupportedException(); } /// /// Sets the last access time (in UTC) of a file or directory - not supported on read-only file systems. /// /// The path of the file or directory. /// The new time to set. public override void SetLastAccessTimeUtc(string path, DateTime newTime) { throw new NotSupportedException(); } /// /// Sets the last modification time (in UTC) of a file or directory - not supported on read-only file systems. /// /// The path of the file or directory. /// The new time to set. public override void SetLastWriteTimeUtc(string path, DateTime newTime) { throw new NotSupportedException(); } } }