/// <summary> /// Initializes a new instance of the <see cref="GorgonFileSystemDirectory"/> class. /// </summary> /// <param name="fileSystem">The file system that owns this directory.</param> /// <param name="name">The name of the directory.</param> /// <param name="parent">Parent directory.</param> internal GorgonFileSystemDirectory(GorgonFileSystem fileSystem, string name, GorgonFileSystemDirectory parent) : base(name.RemoveIllegalPathChars()) { Directories = new GorgonFileSystemDirectoryCollection(); FileSystem = fileSystem; Files = new GorgonFileSystemFileEntryCollection(this); Parent = parent; }
/// <summary> /// Function to enumerate the files and directories for a mount point. /// </summary> /// <param name="physicalMountPoint">Mount point being enumerated.</param> /// <param name="mountPoint">Directory to hold the sub directories and files.</param> /// <param name="physicalDirectories">A list of directories in the physical file system (formatted to the virtual file system).</param> /// <param name="physicalFiles">A list of files in the physical file system (formatted to the virtual file system).</param> protected internal virtual void Enumerate(string physicalMountPoint, GorgonFileSystemDirectory mountPoint, out string[] physicalDirectories, out PhysicalFileInfo[] physicalFiles) { var directoryInfo = new DirectoryInfo(physicalMountPoint); DirectoryInfo[] directories = directoryInfo.GetDirectories("*", SearchOption.AllDirectories) .Where( item => (item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden && (item.Attributes & FileAttributes.System) != FileAttributes.System) .ToArray(); FileInfo[] files = directoryInfo.GetFiles("*", SearchOption.AllDirectories) .Where( item => (item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden && (item.Attributes & FileAttributes.System) != FileAttributes.System) .ToArray(); physicalDirectories = new string[directories.Length]; physicalFiles = new PhysicalFileInfo[files.Length]; for (int i = 0; i < directories.Length; i++) { DirectoryInfo directory = directories[i]; physicalDirectories[i] = MapToVirtualPath(directory.FullName.FormatDirectory(Path.DirectorySeparatorChar), physicalMountPoint, mountPoint.FullPath); } for (int i = 0; i < files.Length; i++) { FileInfo file = files[i]; string newPath = MapToVirtualPath(file.DirectoryName.FormatDirectory(Path.DirectorySeparatorChar) + file.Name, physicalMountPoint, mountPoint.FullPath); physicalFiles[i] = new PhysicalFileInfo(file.FullName, file.Name, file.CreationTime, 0, file.Length, newPath); } }
/// <summary> /// Initializes a new instance of the <see cref="GorgonFileSystemFileEntry"/> class. /// </summary> /// <param name="provider">The file system provider that owns this file.</param> /// <param name="directory">The directory that holds this file.</param> /// <param name="fileName">The file name of the file.</param> /// <param name="mountPoint">The mount point that holds the file.</param> /// <param name="physicalPath">Path to the file on the physical file system.</param> /// <param name="fileSize">Size of the file in bytes.</param> /// <param name="offset">Offset of the file within a packed file.</param> /// <param name="createDate">Create date for the file.</param> internal GorgonFileSystemFileEntry(GorgonFileSystemProvider provider, GorgonFileSystemDirectory directory, string fileName, string mountPoint, string physicalPath, long fileSize, long offset, DateTime createDate) : base(fileName.RemoveIllegalFilenameChars()) { Provider = provider; Directory = directory; Extension = Path.GetExtension(Name); BaseFileName = Path.GetFileNameWithoutExtension(fileName); if (string.IsNullOrEmpty(physicalPath)) { PhysicalFileSystemPath = Name; MountPoint = mountPoint; } else { MountPoint = mountPoint; PhysicalFileSystemPath = physicalPath; } Offset = offset; Size = fileSize; CreateDate = createDate; }
/// <summary> /// Initializes a new instance of the <see cref="GorgonFileSystemFileEntryCollection"/> class. /// </summary> /// <param name="parent">The parent directory that owns this collection.</param> internal GorgonFileSystemFileEntryCollection(GorgonFileSystemDirectory parent) : base(false) { _parent = parent; }