internal DiskImageFile(FileLocator locator, string path, FileAccess access) { FileShare share = access == FileAccess.Read ? FileShare.Read : FileShare.None; _fileStream = locator.Open(path, FileMode.Open, access, share); _ownsStream = Ownership.Dispose; _fileLocator = locator.GetRelativeLocator(locator.GetDirectoryFromPath(path)); _fileName = locator.GetFileFromPath(path); Initialize(); }
/// <summary> /// Initializes a new instance of the DiskImageFile class. /// </summary> /// <param name="fileLocator">An object to open the file and any extents.</param> /// <param name="file">The file name.</param> /// <param name="access">The type of access desired.</param> internal DiskImageFile(FileLocator fileLocator, string file, FileAccess access) { _access = access; FileAccess fileAccess = FileAccess.Read; FileShare fileShare = FileShare.Read; if (_access != FileAccess.Read) { fileAccess = FileAccess.ReadWrite; fileShare = FileShare.None; } Stream fileStream = null; try { fileStream = fileLocator.Open(file, FileMode.Open, fileAccess, fileShare); LoadDescriptor(fileStream); // For monolithic disks, keep hold of the stream - we won't try to use the file name // from the embedded descriptor because the file may have been renamed, making the // descriptor out of date. if (_descriptor.CreateType == DiskCreateType.StreamOptimized || _descriptor.CreateType == DiskCreateType.MonolithicSparse) { _monolithicStream = fileStream; _ownsMonolithicStream = Ownership.Dispose; fileStream = null; } } finally { if (fileStream != null) { fileStream.Dispose(); } } _fileLocator = fileLocator.GetRelativeLocator(fileLocator.GetDirectoryFromPath(file)); }
internal DiskImageFile(FileLocator locator, string path, FileAccess access) { FileShare share = access == FileAccess.Read ? FileShare.Read : FileShare.None; _fileStream = locator.Open(path, FileMode.Open, access, share); _ownsStream = Ownership.Dispose; try { _fileLocator = locator.GetRelativeLocator(locator.GetDirectoryFromPath(path)); _fileName = locator.GetFileFromPath(path); ReadFooter(true); ReadHeaders(); } catch { _fileStream.Dispose(); throw; } }
/// <summary> /// Initializes a new instance of the DiskImageFile class. /// </summary> /// <param name="fileLocator">An object to open the file and any extents</param> /// <param name="file">The file name</param> /// <param name="access">The type of access desired</param> internal DiskImageFile(FileLocator fileLocator, string file, FileAccess access) { _access = access; FileAccess fileAccess = FileAccess.Read; FileShare fileShare = FileShare.Read; if (_access != FileAccess.Read) { fileAccess = FileAccess.ReadWrite; fileShare = FileShare.None; } Stream fileStream = null; try { fileStream = fileLocator.Open(file, FileMode.Open, fileAccess, fileShare); LoadDescriptor(fileStream); // For monolithic disks, keep hold of the stream - we won't try to use the file name // from the embedded descriptor because the file may have been renamed, making the // descriptor out of date. if (_descriptor.CreateType == DiskCreateType.StreamOptimized || _descriptor.CreateType == DiskCreateType.MonolithicSparse) { _monolithicStream = fileStream; _ownsMonolithicStream = Ownership.Dispose; fileStream = null; } } finally { if (fileStream != null) { fileStream.Dispose(); } } _fileLocator = fileLocator.GetRelativeLocator(fileLocator.GetDirectoryFromPath(file)); }
internal DiskImageFile(FileLocator locator, string path, Stream stream, Ownership ownsStream) : this(stream, ownsStream) { _fileLocator = locator.GetRelativeLocator(locator.GetDirectoryFromPath(path)); _fileName = locator.GetFileFromPath(path); }