using System; using System.IO; namespace Wabbajack.VirtualFileSystem.SevenZipExtractor { public class Entry { private readonly IInArchive archive; private readonly uint index; internal Entry(IInArchive archive, uint index) { this.archive = archive; this.index = index; } /// /// Name of the file with its relative path within the archive /// public string FileName { get; internal set; } /// /// True if entry is a folder, false if it is a file /// public bool IsFolder { get; internal set; } /// /// Original entry size /// public ulong Size { get; internal set; } /// /// Entry size in a archived state /// public ulong PackedSize { get; internal set; } /// /// Date and time of the file (entry) creation /// public DateTime CreationTime { get; internal set; } /// /// Date and time of the last change of the file (entry) /// public DateTime LastWriteTime { get; internal set; } /// /// Date and time of the last access of the file (entry) /// public DateTime LastAccessTime { get; internal set; } /// /// CRC hash of the entry /// public UInt32 CRC { get; internal set; } /// /// Attributes of the entry /// public UInt32 Attributes { get; internal set; } /// /// True if entry is encrypted, otherwise false /// public bool IsEncrypted { get; internal set; } /// /// Comment of the entry /// public string Comment { get; internal set; } /// /// Compression method of the entry /// public string Method { get; internal set; } /// /// Host operating system of the entry /// public string HostOS { get; internal set; } /// /// True if there are parts of this file in previous split archive parts /// public bool IsSplitBefore { get; set; } /// /// True if there are parts of this file in next split archive parts /// public bool IsSplitAfter { get; set; } public void Extract(string fileName, bool preserveTimestamp = true) { if (this.IsFolder) { Directory.CreateDirectory(fileName); return; } string directoryName = Path.GetDirectoryName(fileName); if (!string.IsNullOrWhiteSpace(directoryName)) { Directory.CreateDirectory(directoryName); } using (FileStream fileStream = File.Create(fileName)) { this.Extract(fileStream); } if (preserveTimestamp) { File.SetLastWriteTime(fileName, this.LastWriteTime); } } public void Extract(Stream stream) { this.archive.Extract(new[] { this.index }, 1, 0, new ArchiveStreamCallback(this.index, stream)); } } }