// // 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.Vfs { /// /// Base class for the public facade on a file system. /// /// /// The derived class can extend the functionality available from a file system /// beyond that defined by DiscFileSystem. /// public abstract class VfsFileSystemFacade : DiscFileSystem { private readonly DiscFileSystem _wrapped; /// /// Initializes a new instance of the VfsFileSystemFacade class. /// /// The actual file system instance. protected VfsFileSystemFacade(DiscFileSystem toWrap) { _wrapped = toWrap; } /// /// Indicates whether the file system is read-only or read-write. /// /// true if the file system is read-write. public override bool CanWrite { get { return _wrapped.CanWrite; } } /// /// Gets a friendly name for the file system. /// public override string FriendlyName { get { return _wrapped.FriendlyName; } } /// /// Gets a value indicating whether the file system is thread-safe. /// public override bool IsThreadSafe { get { return _wrapped.IsThreadSafe; } } /// /// Gets the file system options, which can be modified. /// public override DiscFileSystemOptions Options { get { return _wrapped.Options; } } /// /// Gets the root directory of the file system. /// public override DiscDirectoryInfo Root { get { return new DiscDirectoryInfo(this, string.Empty); } } /// /// Gets the volume label. /// public override string VolumeLabel { get { return _wrapped.VolumeLabel; } } /// /// Copies an existing file to a new file. /// /// The source file. /// The destination file. public override void CopyFile(string sourceFile, string destinationFile) { _wrapped.CopyFile(sourceFile, destinationFile); } /// /// Copies an existing file to a new file. /// /// The source file. /// The destination file. /// Overwrite any existing file. public override void CopyFile(string sourceFile, string destinationFile, bool overwrite) { _wrapped.CopyFile(sourceFile, destinationFile, overwrite); } /// /// Creates a directory. /// /// The path of the new directory. public override void CreateDirectory(string path) { _wrapped.CreateDirectory(path); } /// /// Deletes a directory. /// /// The path of the directory to delete. public override void DeleteDirectory(string path) { _wrapped.DeleteDirectory(path); } /// /// Deletes a directory, optionally with all descendants. /// /// The path of the directory to delete. /// Determines if the all descendants should be deleted. public override void DeleteDirectory(string path, bool recursive) { _wrapped.DeleteDirectory(path, recursive); } /// /// Deletes a file. /// /// The path of the file to delete. public override void DeleteFile(string path) { _wrapped.DeleteFile(path); } /// /// Indicates if a directory exists. /// /// The path to test. /// true if the directory exists. public override bool DirectoryExists(string path) { return _wrapped.DirectoryExists(path); } /// /// Indicates if a file exists. /// /// The path to test. /// true if the file exists. public override bool FileExists(string path) { return _wrapped.FileExists(path); } /// /// Indicates if a file or directory exists. /// /// The path to test. /// true if the file or directory exists. public override bool Exists(string path) { return _wrapped.Exists(path); } /// /// Gets the names of subdirectories in a specified directory. /// /// The path to search. /// Array of directories. public override string[] GetDirectories(string path) { return _wrapped.GetDirectories(path); } /// /// Gets the names of subdirectories in a specified directory matching a specified /// search pattern. /// /// The path to search. /// The search string to match against. /// Array of directories matching the search pattern. public override string[] GetDirectories(string path, string searchPattern) { return _wrapped.GetDirectories(path, searchPattern); } /// /// Gets the names of subdirectories in a specified directory matching a specified /// search pattern, using a value to determine whether to search subdirectories. /// /// The path to search. /// The search string to match against. /// Indicates whether to search subdirectories. /// Array of directories matching the search pattern. public override string[] GetDirectories(string path, string searchPattern, SearchOption searchOption) { return _wrapped.GetDirectories(path, searchPattern, searchOption); } /// /// Gets the names of files in a specified directory. /// /// The path to search. /// Array of files. public override string[] GetFiles(string path) { return _wrapped.GetFiles(path); } /// /// Gets the names of files in a specified directory. /// /// The path to search. /// The search string to match against. /// Array of files matching the search pattern. public override string[] GetFiles(string path, string searchPattern) { return _wrapped.GetFiles(path, searchPattern); } /// /// Gets the names of files in a specified directory matching a specified /// search pattern, using a value to determine whether to search subdirectories. /// /// The path to search. /// The search string to match against. /// Indicates whether to search subdirectories. /// Array of files matching the search pattern. public override string[] GetFiles(string path, string searchPattern, SearchOption searchOption) { return _wrapped.GetFiles(path, searchPattern, searchOption); } /// /// Gets the names of all files and subdirectories in a specified directory. /// /// The path to search. /// Array of files and subdirectories matching the search pattern. public override string[] GetFileSystemEntries(string path) { return _wrapped.GetFileSystemEntries(path); } /// /// Gets the names of files and subdirectories in a specified directory matching a specified /// search pattern. /// /// The path to search. /// The search string to match against. /// Array of files and subdirectories matching the search pattern. public override string[] GetFileSystemEntries(string path, string searchPattern) { return _wrapped.GetFileSystemEntries(path, searchPattern); } /// /// Moves a directory. /// /// The directory to move. /// The target directory name. public override void MoveDirectory(string sourceDirectoryName, string destinationDirectoryName) { _wrapped.MoveDirectory(sourceDirectoryName, destinationDirectoryName); } /// /// Moves a file. /// /// The file to move. /// The target file name. public override void MoveFile(string sourceName, string destinationName) { _wrapped.MoveFile(sourceName, destinationName); } /// /// Moves a file, allowing an existing file to be overwritten. /// /// The file to move. /// The target file name. /// Whether to permit a destination file to be overwritten. public override void MoveFile(string sourceName, string destinationName, bool overwrite) { _wrapped.MoveFile(sourceName, destinationName, overwrite); } /// /// 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 _wrapped.OpenFile(path, mode); } /// /// Opens the specified file. /// /// The full path of the file to open. /// The file mode for the created stream. /// The access permissions for the created stream. /// The new stream. public override SparseStream OpenFile(string path, FileMode mode, FileAccess access) { return _wrapped.OpenFile(path, mode, access); } /// /// Gets the attributes of a file or directory. /// /// The file or directory to inspect. /// The attributes of the file or directory. public override FileAttributes GetAttributes(string path) { return _wrapped.GetAttributes(path); } /// /// Sets the attributes of a file or directory. /// /// The file or directory to change. /// The new attributes of the file or directory. public override void SetAttributes(string path, FileAttributes newValue) { _wrapped.SetAttributes(path, newValue); } /// /// Gets the creation time (in local time) of a file or directory. /// /// The path of the file or directory. /// The creation time. public override DateTime GetCreationTime(string path) { return _wrapped.GetCreationTime(path); } /// /// Sets the creation time (in local time) of a file or directory. /// /// The path of the file or directory. /// The new time to set. public override void SetCreationTime(string path, DateTime newTime) { _wrapped.SetCreationTime(path, newTime); } /// /// Gets the creation time (in UTC) of a file or directory. /// /// The path of the file or directory. /// The creation time. public override DateTime GetCreationTimeUtc(string path) { return _wrapped.GetCreationTimeUtc(path); } /// /// Sets the creation time (in UTC) of a file or directory. /// /// The path of the file or directory. /// The new time to set. public override void SetCreationTimeUtc(string path, DateTime newTime) { _wrapped.SetCreationTimeUtc(path, newTime); } /// /// Gets the last access time (in local time) of a file or directory. /// /// The path of the file or directory. /// The last access time. public override DateTime GetLastAccessTime(string path) { return _wrapped.GetLastAccessTime(path); } /// /// Sets the last access time (in local time) of a file or directory. /// /// The path of the file or directory. /// The new time to set. public override void SetLastAccessTime(string path, DateTime newTime) { _wrapped.SetLastAccessTime(path, newTime); } /// /// Gets the last access time (in UTC) of a file or directory. /// /// The path of the file or directory. /// The last access time. public override DateTime GetLastAccessTimeUtc(string path) { return _wrapped.GetLastAccessTimeUtc(path); } /// /// Sets the last access time (in UTC) of a file or directory. /// /// The path of the file or directory. /// The new time to set. public override void SetLastAccessTimeUtc(string path, DateTime newTime) { _wrapped.SetLastAccessTimeUtc(path, newTime); } /// /// Gets the last modification time (in local time) of a file or directory. /// /// The path of the file or directory. /// The last write time. public override DateTime GetLastWriteTime(string path) { return _wrapped.GetLastWriteTime(path); } /// /// Sets the last modification time (in local time) of a file or directory. /// /// The path of the file or directory. /// The new time to set. public override void SetLastWriteTime(string path, DateTime newTime) { _wrapped.SetLastWriteTime(path, newTime); } /// /// Gets the last modification time (in UTC) of a file or directory. /// /// The path of the file or directory. /// The last write time. public override DateTime GetLastWriteTimeUtc(string path) { return _wrapped.GetLastWriteTimeUtc(path); } /// /// Sets the last modification time (in UTC) of a file or directory. /// /// The path of the file or directory. /// The new time to set. public override void SetLastWriteTimeUtc(string path, DateTime newTime) { _wrapped.SetLastWriteTimeUtc(path, newTime); } /// /// Gets the length of a file. /// /// The path to the file. /// The length in bytes. public override long GetFileLength(string path) { return _wrapped.GetFileLength(path); } /// /// Gets an object representing a possible file. /// /// The file path. /// The representing object. /// The file does not need to exist. public override DiscFileInfo GetFileInfo(string path) { return new DiscFileInfo(this, path); } /// /// Gets an object representing a possible directory. /// /// The directory path. /// The representing object. /// The directory does not need to exist. public override DiscDirectoryInfo GetDirectoryInfo(string path) { return new DiscDirectoryInfo(this, path); } /// /// Gets an object representing a possible file system object (file or directory). /// /// The file system path. /// The representing object. /// The file system object does not need to exist. public override DiscFileSystemInfo GetFileSystemInfo(string path) { return new DiscFileSystemInfo(this, path); } /// /// Size of the Filesystem in bytes /// public override long Size { get { return _wrapped.Size; } } /// /// Used space of the Filesystem in bytes /// public override long UsedSpace { get { return _wrapped.UsedSpace; } } /// /// Available space of the Filesystem in bytes /// public override long AvailableSpace { get { return _wrapped.AvailableSpace; } } /// /// Provides access to the actual file system implementation. /// /// The concrete type representing directory entries. /// The concrete type representing files. /// The concrete type representing directories. /// The concrete type holding global state. /// The actual file system instance. protected VfsFileSystem GetRealFileSystem () where TDirEntry : VfsDirEntry where TFile : IVfsFile where TDirectory : class, IVfsDirectory, TFile where TContext : VfsContext { return (VfsFileSystem)_wrapped; } /// /// Provides access to the actual file system implementation. /// /// The concrete type of the actual file system. /// The actual file system instance. protected T GetRealFileSystem() where T : DiscFileSystem { return (T)_wrapped; } } }