// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. namespace WixToolset.Dtf.Compression.Cab { using System; using System.IO; using System.Runtime.Serialization; /// /// Object representing a compressed file within a cabinet package; provides operations for getting /// the file properties and extracting the file. /// [Serializable] public class CabFileInfo : ArchiveFileInfo { private int cabFolder; /// /// Creates a new CabinetFileInfo object representing a file within a cabinet in a specified path. /// /// An object representing the cabinet containing the file. /// The path to the file within the cabinet. Usually, this is a simple file /// name, but if the cabinet contains a directory structure this may include the directory. public CabFileInfo(CabInfo cabinetInfo, string filePath) : base(cabinetInfo, filePath) { if (cabinetInfo == null) { throw new ArgumentNullException("cabinetInfo"); } this.cabFolder = -1; } /// /// Creates a new CabinetFileInfo object with all parameters specified, /// used internally when reading the metadata out of a cab. /// /// The internal path and name of the file in the cab. /// The folder number containing the file. /// The cabinet number where the file starts. /// The stored attributes of the file. /// The stored last write time of the file. /// The uncompressed size of the file. internal CabFileInfo( string filePath, int cabFolder, int cabNumber, FileAttributes attributes, DateTime lastWriteTime, long length) : base(filePath, cabNumber, attributes, lastWriteTime, length) { this.cabFolder = cabFolder; } /// /// Initializes a new instance of the CabinetFileInfo class with serialized data. /// /// The SerializationInfo that holds the serialized object data about the exception being thrown. /// The StreamingContext that contains contextual information about the source or destination. protected CabFileInfo(SerializationInfo info, StreamingContext context) : base(info, context) { this.cabFolder = info.GetInt32("cabFolder"); } /// /// Sets the SerializationInfo with information about the archive. /// /// The SerializationInfo that holds the serialized object data. /// The StreamingContext that contains contextual information /// about the source or destination. public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("cabFolder", this.cabFolder); } /// /// Gets or sets the cabinet that contains this file. /// /// /// The CabinetInfo instance that retrieved this file information -- this /// may be null if the CabinetFileInfo object was returned directly from a /// stream. /// public CabInfo Cabinet { get { return (CabInfo) this.Archive; } } /// /// Gets the full path of the cabinet that contains this file. /// /// The full path of the cabinet that contains this file. public string CabinetName { get { return this.ArchiveName; } } /// /// Gets the number of the folder containing this file. /// /// The number of the cabinet folder containing this file. /// A single folder or the first folder of a cabinet /// (or chain of cabinets) is numbered 0. public int CabinetFolderNumber { get { if (this.cabFolder < 0) { this.Refresh(); } return this.cabFolder; } } /// /// Refreshes the information in this object with new data retrieved /// from an archive. /// /// Fresh instance for the same file just /// read from the archive. /// /// This implementation refreshes the . /// protected override void Refresh(ArchiveFileInfo newFileInfo) { base.Refresh(newFileInfo); this.cabFolder = ((CabFileInfo) newFileInfo).cabFolder; } } }