diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.cs b/src/SharpCompress/Archives/GZip/GZipArchive.cs index e24f6b78..845e05fb 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchive.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchive.cs @@ -89,7 +89,8 @@ namespace SharpCompress.Archives.GZip protected override IEnumerable LoadVolumes(SourceStream srcStream) { srcStream.LoadAllParts(); - return srcStream.Streams.Select(a => new GZipVolume(a, ReaderOptions)); + int idx = 0; + return srcStream.Streams.Select(a => new GZipVolume(a, ReaderOptions, idx++)); } public static bool IsGZipFile(string filePath) { diff --git a/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs b/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs index a3f57300..1afba647 100644 --- a/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs +++ b/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using SharpCompress.Common.Rar; @@ -13,8 +13,8 @@ namespace SharpCompress.Archives.Rar /// internal class FileInfoRarArchiveVolume : RarVolume { - internal FileInfoRarArchiveVolume(FileInfo fileInfo, ReaderOptions options) - : base(StreamingMode.Seekable, fileInfo.OpenRead(), FixOptions(options)) + internal FileInfoRarArchiveVolume(FileInfo fileInfo, ReaderOptions options, int index = 0) + : base(StreamingMode.Seekable, fileInfo.OpenRead(), FixOptions(options), index) { FileInfo = fileInfo; FileParts = GetVolumeFileParts().ToArray().ToReadOnly(); diff --git a/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs b/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs index 7b0943d5..b2134e6d 100644 --- a/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs +++ b/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using SharpCompress.Common.Rar.Headers; namespace SharpCompress.Archives.Rar @@ -6,7 +6,7 @@ namespace SharpCompress.Archives.Rar internal sealed class FileInfoRarFilePart : SeekableFilePart { internal FileInfoRarFilePart(FileInfoRarArchiveVolume volume, string? password, MarkHeader mh, FileHeader fh, FileInfo fi) - : base(mh, fh, volume.Stream, password) + : base(mh, fh, volume.Index, volume.Stream, password) { FileInfo = fi; } diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index a5d3cc4d..6d43a46b 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -37,16 +37,17 @@ namespace SharpCompress.Archives.Rar { base.SrcStream.LoadAllParts(); //request all streams Stream[] streams = base.SrcStream.Streams.ToArray(); + int idx = 0; if (streams.Length > 1 && IsRarFile(streams[1], ReaderOptions)) //test part 2 - true = multipart not split { base.SrcStream.IsVolumes = true; streams[1].Position = 0; base.SrcStream.Position = 0; - return srcStream.Streams.Select(a => new StreamRarArchiveVolume(a, ReaderOptions)); + return srcStream.Streams.Select(a => new StreamRarArchiveVolume(a, ReaderOptions, idx++)); } else //split mode or single file - return new StreamRarArchiveVolume(base.SrcStream, ReaderOptions).AsEnumerable(); + return new StreamRarArchiveVolume(base.SrcStream, ReaderOptions, idx++).AsEnumerable(); } protected override IReader CreateReaderForSolidExtraction() @@ -58,6 +59,9 @@ namespace SharpCompress.Archives.Rar public override bool IsSolid => Volumes.First().IsSolidArchive; + public virtual int MinVersion => Volumes.First().MinVersion; + public virtual int MaxVersion => Volumes.First().MaxVersion; + #region Creation /// /// Constructor with a FileInfo object to an existing file. diff --git a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs index 38c5ad4e..fb2ba0f8 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs @@ -86,4 +86,4 @@ namespace SharpCompress.Archives.Rar } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs index d8822a92..1e4758ad 100644 --- a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs +++ b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using SharpCompress.Common.Rar; using SharpCompress.Common.Rar.Headers; @@ -9,8 +9,8 @@ namespace SharpCompress.Archives.Rar private readonly Stream stream; private readonly string? password; - internal SeekableFilePart(MarkHeader mh, FileHeader fh, Stream stream, string? password) - : base(mh, fh) + internal SeekableFilePart(MarkHeader mh, FileHeader fh, int index, Stream stream, string? password) + : base(mh, fh, index) { this.stream = stream; this.password = password; @@ -28,4 +28,4 @@ namespace SharpCompress.Archives.Rar internal override string FilePartName => "Unknown Stream - File Entry: " + FileHeader.FileName; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs b/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs index 92602ae9..68def3f7 100644 --- a/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs +++ b/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using SharpCompress.Common.Rar; using SharpCompress.Common.Rar.Headers; @@ -9,8 +9,8 @@ namespace SharpCompress.Archives.Rar { internal class StreamRarArchiveVolume : RarVolume { - internal StreamRarArchiveVolume(Stream stream, ReaderOptions options) - : base(StreamingMode.Seekable, stream, options) + internal StreamRarArchiveVolume(Stream stream, ReaderOptions options, int index = 0) + : base(StreamingMode.Seekable, stream, options, index) { } @@ -21,7 +21,7 @@ namespace SharpCompress.Archives.Rar internal override RarFilePart CreateFilePart(MarkHeader markHeader, FileHeader fileHeader) { - return new SeekableFilePart(markHeader, fileHeader, Stream, ReaderOptions.Password); + return new SeekableFilePart(markHeader, fileHeader, this.Index, Stream, ReaderOptions.Password); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index eeae90b2..276f1399 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -85,7 +85,8 @@ namespace SharpCompress.Archives.SevenZip protected override IEnumerable LoadVolumes(SourceStream srcStream) { base.SrcStream.LoadAllParts(); //request all streams - return new SevenZipVolume(srcStream, ReaderOptions).AsEnumerable(); //simple single volume or split, multivolume not supported + int idx = 0; + return new SevenZipVolume(srcStream, ReaderOptions, idx++).AsEnumerable(); //simple single volume or split, multivolume not supported } public static bool IsSevenZipFile(string filePath) diff --git a/src/SharpCompress/Archives/Tar/TarArchive.cs b/src/SharpCompress/Archives/Tar/TarArchive.cs index 236fccba..51bdbc1f 100644 --- a/src/SharpCompress/Archives/Tar/TarArchive.cs +++ b/src/SharpCompress/Archives/Tar/TarArchive.cs @@ -107,7 +107,8 @@ namespace SharpCompress.Archives.Tar protected override IEnumerable LoadVolumes(SourceStream srcStream) { base.SrcStream.LoadAllParts(); //request all streams - return new TarVolume(srcStream, ReaderOptions).AsEnumerable(); //simple single volume or split, multivolume not supported + int idx = 0; + return new TarVolume(srcStream, ReaderOptions, idx++).AsEnumerable(); //simple single volume or split, multivolume not supported } /// diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs index 168d5838..97f83e02 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs @@ -168,6 +168,7 @@ namespace SharpCompress.Archives.Zip base.SrcStream.Position = 0; List streams = base.SrcStream.Streams.ToList(); + int idx = 0; if (streams.Count > 1) //test part 2 - true = multipart not split { streams[1].Position += 4; //skip the POST_DATA_DESCRIPTOR to prevent an exception @@ -182,12 +183,12 @@ namespace SharpCompress.Archives.Zip streams.Add(tmp); //streams[0].Position = 4; //skip the POST_DATA_DESCRIPTOR to prevent an exception - return streams.Select(a => new ZipVolume(a, ReaderOptions)); + return streams.Select(a => new ZipVolume(a, ReaderOptions, idx++)); } } //split mode or single file - return new ZipVolume(base.SrcStream, ReaderOptions).AsEnumerable(); + return new ZipVolume(base.SrcStream, ReaderOptions, idx++).AsEnumerable(); } internal ZipArchive() diff --git a/src/SharpCompress/Common/Entry.cs b/src/SharpCompress/Common/Entry.cs index 26a959bd..06afcabd 100644 --- a/src/SharpCompress/Common/Entry.cs +++ b/src/SharpCompress/Common/Entry.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.Linq; namespace SharpCompress.Common { @@ -70,6 +71,8 @@ namespace SharpCompress.Common /// public abstract bool IsSplitAfter { get; } + public int VolumeIndexFirst => this.Parts?.FirstOrDefault()?.Index ?? 0; + public int VolumeIndexLast => this.Parts?.LastOrDefault()?.Index ?? 0; /// public override string ToString() => Key; diff --git a/src/SharpCompress/Common/FilePart.cs b/src/SharpCompress/Common/FilePart.cs index 263838b5..fad184aa 100644 --- a/src/SharpCompress/Common/FilePart.cs +++ b/src/SharpCompress/Common/FilePart.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; namespace SharpCompress.Common { @@ -12,6 +12,7 @@ namespace SharpCompress.Common internal ArchiveEncoding ArchiveEncoding { get; } internal abstract string FilePartName { get; } + public int Index { get; set; } internal abstract Stream GetCompressedStream(); internal abstract Stream? GetRawStream(); diff --git a/src/SharpCompress/Common/GZip/GZipFilePart.cs b/src/SharpCompress/Common/GZip/GZipFilePart.cs index 6edacfe9..c6fd9849 100644 --- a/src/SharpCompress/Common/GZip/GZipFilePart.cs +++ b/src/SharpCompress/Common/GZip/GZipFilePart.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Buffers.Binary; using System.Collections.Generic; using System.IO; @@ -31,8 +31,8 @@ namespace SharpCompress.Common.GZip internal long EntryStartPosition { get; } internal DateTime? DateModified { get; private set; } - internal int? Crc { get; private set; } - internal int? UncompressedSize { get; private set; } + internal uint? Crc { get; private set; } + internal uint? UncompressedSize { get; private set; } internal override string FilePartName => _name!; @@ -52,8 +52,8 @@ namespace SharpCompress.Common.GZip Span trailer = stackalloc byte[8]; int n = _stream.Read(trailer); - Crc = BinaryPrimitives.ReadInt32LittleEndian(trailer); - UncompressedSize = BinaryPrimitives.ReadInt32LittleEndian(trailer.Slice(4)); + Crc = BinaryPrimitives.ReadUInt32LittleEndian(trailer); + UncompressedSize = BinaryPrimitives.ReadUInt32LittleEndian(trailer.Slice(4)); } private void ReadAndValidateGzipHeader() diff --git a/src/SharpCompress/Common/GZip/GZipVolume.cs b/src/SharpCompress/Common/GZip/GZipVolume.cs index 51c5e246..6d77029f 100644 --- a/src/SharpCompress/Common/GZip/GZipVolume.cs +++ b/src/SharpCompress/Common/GZip/GZipVolume.cs @@ -1,12 +1,12 @@ -using System.IO; +using System.IO; using SharpCompress.Readers; namespace SharpCompress.Common.GZip { public class GZipVolume : Volume { - public GZipVolume(Stream stream, ReaderOptions options) - : base(stream, options) + public GZipVolume(Stream stream, ReaderOptions options, int index = 0) + : base(stream, options, index) { } @@ -20,4 +20,4 @@ namespace SharpCompress.Common.GZip public override bool IsMultiVolume => true; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/IEntry.cs b/src/SharpCompress/Common/IEntry.cs index 8328ff29..63e8f9ca 100644 --- a/src/SharpCompress/Common/IEntry.cs +++ b/src/SharpCompress/Common/IEntry.cs @@ -1,4 +1,5 @@ -using System; +using System; +using System.Collections.Generic; namespace SharpCompress.Common { @@ -15,9 +16,11 @@ namespace SharpCompress.Common bool IsEncrypted { get; } bool IsSplitAfter { get; } bool IsSolid { get; } + int VolumeIndexFirst { get; } + int VolumeIndexLast { get; } DateTime? LastAccessedTime { get; } DateTime? LastModifiedTime { get; } long Size { get; } int? Attrib { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/IVolume.cs b/src/SharpCompress/Common/IVolume.cs index f19971fe..b29d6be9 100644 --- a/src/SharpCompress/Common/IVolume.cs +++ b/src/SharpCompress/Common/IVolume.cs @@ -1,8 +1,11 @@ -using System; +using System; namespace SharpCompress.Common { public interface IVolume : IDisposable { + int Index { get; } + + string FileName { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/RarFilePart.cs b/src/SharpCompress/Common/Rar/RarFilePart.cs index 6e16dff7..4075198e 100644 --- a/src/SharpCompress/Common/Rar/RarFilePart.cs +++ b/src/SharpCompress/Common/Rar/RarFilePart.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using SharpCompress.Common.Rar.Headers; namespace SharpCompress.Common.Rar @@ -8,11 +8,12 @@ namespace SharpCompress.Common.Rar /// internal abstract class RarFilePart : FilePart { - internal RarFilePart(MarkHeader mh, FileHeader fh) + internal RarFilePart(MarkHeader mh, FileHeader fh, int index) : base(fh.ArchiveEncoding) { MarkHeader = mh; FileHeader = fh; + Index = index; } internal MarkHeader MarkHeader { get; } @@ -24,4 +25,4 @@ namespace SharpCompress.Common.Rar return null; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/RarVolume.cs b/src/SharpCompress/Common/Rar/RarVolume.cs index 6a4628ac..0546e1f1 100644 --- a/src/SharpCompress/Common/Rar/RarVolume.cs +++ b/src/SharpCompress/Common/Rar/RarVolume.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -14,9 +14,10 @@ namespace SharpCompress.Common.Rar public abstract class RarVolume : Volume { private readonly RarHeaderFactory _headerFactory; + internal int _maxCompressionAlgorithm; - internal RarVolume(StreamingMode mode, Stream stream, ReaderOptions options) - : base(stream, options) + internal RarVolume(StreamingMode mode, Stream stream, ReaderOptions options, int index = 0) + : base(stream, options, index) { _headerFactory = new RarHeaderFactory(mode, options); } @@ -51,6 +52,8 @@ namespace SharpCompress.Common.Rar case HeaderType.File: { var fh = (FileHeader)header; + if (_maxCompressionAlgorithm < fh.CompressionAlgorithm) + _maxCompressionAlgorithm = fh.CompressionAlgorithm; yield return CreateFilePart(lastMarkHeader!, fh); } break; @@ -110,5 +113,37 @@ namespace SharpCompress.Common.Rar return ArchiveHeader.IsSolid; } } + + public int MinVersion + { + get + { + EnsureArchiveHeaderLoaded(); + if (_maxCompressionAlgorithm >= 50) + return 5; //5-6 + else if (_maxCompressionAlgorithm >= 29) + return 3; //3-4 + else if (_maxCompressionAlgorithm >= 20) + return 2; //2 + else + return 1; + } + } + + public int MaxVersion + { + get + { + EnsureArchiveHeaderLoaded(); + if (_maxCompressionAlgorithm >= 50) + return 6; //5-6 + else if (_maxCompressionAlgorithm >= 29) + return 4; //3-4 + else if (_maxCompressionAlgorithm >= 20) + return 2; //2 + else + return 1; + } + } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs index 5a80508b..4a5a8d43 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using SharpCompress.IO; @@ -26,7 +26,6 @@ namespace SharpCompress.Common.SevenZip internal CFileItem Header { get; } internal CFolder? Folder { get; } - internal int Index { get; } internal override string FilePartName => Header.Name; @@ -105,4 +104,4 @@ namespace SharpCompress.Common.SevenZip internal bool IsEncrypted => Folder!._coders.FindIndex(c => c._methodId._id == CMethodId.K_AES_ID) != -1; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/SevenZip/SevenZipVolume.cs b/src/SharpCompress/Common/SevenZip/SevenZipVolume.cs index 1609c817..79d6c9d0 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipVolume.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipVolume.cs @@ -1,13 +1,13 @@ -using System.IO; +using System.IO; using SharpCompress.Readers; namespace SharpCompress.Common.SevenZip { public class SevenZipVolume : Volume { - public SevenZipVolume(Stream stream, ReaderOptions readerFactoryOptions) - : base(stream, readerFactoryOptions) + public SevenZipVolume(Stream stream, ReaderOptions readerFactoryOptions, int index = 0) + : base(stream, readerFactoryOptions, index) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Tar/TarVolume.cs b/src/SharpCompress/Common/Tar/TarVolume.cs index 1ddae4d7..5b76c56f 100644 --- a/src/SharpCompress/Common/Tar/TarVolume.cs +++ b/src/SharpCompress/Common/Tar/TarVolume.cs @@ -1,13 +1,13 @@ -using System.IO; +using System.IO; using SharpCompress.Readers; namespace SharpCompress.Common.Tar { public class TarVolume : Volume { - public TarVolume(Stream stream, ReaderOptions readerOptions) - : base(stream, readerOptions) + public TarVolume(Stream stream, ReaderOptions readerOptions, int index = 0) + : base(stream, readerOptions, index) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Volume.cs b/src/SharpCompress/Common/Volume.cs index f1b93d02..8e1446b9 100644 --- a/src/SharpCompress/Common/Volume.cs +++ b/src/SharpCompress/Common/Volume.cs @@ -9,8 +9,9 @@ namespace SharpCompress.Common { private readonly Stream _actualStream; - internal Volume(Stream stream, ReaderOptions readerOptions) + internal Volume(Stream stream, ReaderOptions readerOptions, int index = 0) { + Index = index; ReaderOptions = readerOptions; if (readerOptions.LeaveStreamOpen) { @@ -29,6 +30,10 @@ namespace SharpCompress.Common /// public virtual bool IsFirstVolume => true; + public virtual int Index { get; internal set; } + + public string FileName { get { return (_actualStream as FileStream)?.Name!; } } + /// /// RarArchive is part of a multi-part archive. /// diff --git a/src/SharpCompress/Common/Zip/ZipVolume.cs b/src/SharpCompress/Common/Zip/ZipVolume.cs index aa485fa7..856a5836 100644 --- a/src/SharpCompress/Common/Zip/ZipVolume.cs +++ b/src/SharpCompress/Common/Zip/ZipVolume.cs @@ -1,15 +1,15 @@ -using System.IO; +using System.IO; using SharpCompress.Readers; namespace SharpCompress.Common.Zip { public class ZipVolume : Volume { - public ZipVolume(Stream stream, ReaderOptions readerOptions) - : base(stream, readerOptions) + public ZipVolume(Stream stream, ReaderOptions readerOptions, int index = 0) + : base(stream, readerOptions, index) { } public string? Comment { get; internal set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs b/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs index c5f62a44..76c9f201 100644 --- a/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs +++ b/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using SharpCompress.Common.Rar; using SharpCompress.Common.Rar.Headers; @@ -6,8 +6,8 @@ namespace SharpCompress.Readers.Rar { internal class NonSeekableStreamFilePart : RarFilePart { - internal NonSeekableStreamFilePart(MarkHeader mh, FileHeader fh) - : base(mh, fh) + internal NonSeekableStreamFilePart(MarkHeader mh, FileHeader fh, int index = 0) + : base(mh, fh, index) { } @@ -18,4 +18,4 @@ namespace SharpCompress.Readers.Rar internal override string FilePartName => "Unknown Stream - File Entry: " + FileHeader.FileName; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Readers/Rar/RarReaderVolume.cs b/src/SharpCompress/Readers/Rar/RarReaderVolume.cs index 98a8c5c0..fa3bbdf1 100644 --- a/src/SharpCompress/Readers/Rar/RarReaderVolume.cs +++ b/src/SharpCompress/Readers/Rar/RarReaderVolume.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using SharpCompress.Common.Rar; using SharpCompress.Common.Rar.Headers; @@ -8,14 +8,14 @@ namespace SharpCompress.Readers.Rar { public class RarReaderVolume : RarVolume { - internal RarReaderVolume(Stream stream, ReaderOptions options) - : base(StreamingMode.Streaming, stream, options) + internal RarReaderVolume(Stream stream, ReaderOptions options, int index = 0) + : base(StreamingMode.Streaming, stream, options, index) { } internal override RarFilePart CreateFilePart(MarkHeader markHeader, FileHeader fileHeader) { - return new NonSeekableStreamFilePart(markHeader, fileHeader); + return new NonSeekableStreamFilePart(markHeader, fileHeader, this.Index); } internal override IEnumerable ReadFileParts() @@ -23,4 +23,4 @@ namespace SharpCompress.Readers.Rar return GetVolumeFileParts(); } } -} \ No newline at end of file +} diff --git a/tests/SharpCompress.Test/ArchiveTests.cs b/tests/SharpCompress.Test/ArchiveTests.cs index bfd88569..5c103b78 100644 --- a/tests/SharpCompress.Test/ArchiveTests.cs +++ b/tests/SharpCompress.Test/ArchiveTests.cs @@ -173,6 +173,38 @@ namespace SharpCompress.Test VerifyFiles(); } + protected void ArchiveOpenEntryVolumeIndexTest(int[][] results, ReaderOptions readerOptions = null, params string[] testArchives) + { + ArchiveOpenEntryVolumeIndexTest(results, readerOptions, testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x))); + } + + + protected void ArchiveOpenEntryVolumeIndexTest(int[][] results, ReaderOptions readerOptions, IEnumerable testArchives) + { + string[] src = testArchives.ToArray(); + using (var archive = ArchiveFactory.Open(testArchives.Select(f => new FileInfo(f)), null)) + { + try + { + int idx = 0; + foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) + { + Assert.Equal(entry.VolumeIndexFirst, results[idx][0]); + Assert.Equal(entry.VolumeIndexLast, results[idx][1]); + Assert.Equal(src[entry.VolumeIndexFirst], archive.Volumes.First(a => a.Index == entry.VolumeIndexFirst).FileName); + Assert.Equal(src[entry.VolumeIndexLast], archive.Volumes.First(a => a.Index == entry.VolumeIndexLast).FileName); + + idx++; + } + } + catch (IndexOutOfRangeException) + { + throw; + } + } + } + + protected void ArchiveFileRead(string testArchive, ReaderOptions readerOptions = null) { diff --git a/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs b/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs index 5f4a7c22..15389a4f 100644 --- a/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs +++ b/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using SharpCompress.Archives; @@ -107,5 +107,21 @@ namespace SharpCompress.Test.GZip Assert.Equal(size, tarStream.Length); } } + + [Fact] + public void TestGzCrcWithMostSignificaltBitNotNegative() + { + using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz"))) + { + using (var archive = GZipArchive.Open(stream)) + { + //process all entries in solid archive until the one we want to test + foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) + { + Assert.InRange(entry.Crc, 0L, 0xFFFFFFFFL); + } + } + } + } } } diff --git a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs index d9d2443a..3580aba3 100644 --- a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs +++ b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs @@ -435,6 +435,42 @@ namespace SharpCompress.Test.Rar ArchiveFileRead("Rar2.rar"); } + [Fact] + public void Rar2_ArchiveVersionTest() + { + string testArchive = Path.Combine(TEST_ARCHIVES_PATH, "Rar2.rar"); + + using (var archive = RarArchive.Open(testArchive)) + { + Assert.Equal(2, archive.MinVersion); + Assert.Equal(2, archive.MaxVersion); + } + } + + [Fact] + public void Rar4_ArchiveVersionTest() + { + string testArchive = Path.Combine(TEST_ARCHIVES_PATH, "Rar4.multi.part01.rar"); + + using (var archive = RarArchive.Open(testArchive)) + { + Assert.Equal(3, archive.MinVersion); + Assert.Equal(4, archive.MaxVersion); + } + } + + [Fact] + public void Rar5_ArchiveVersionTest() + { + string testArchive = Path.Combine(TEST_ARCHIVES_PATH, "Rar5.solid.rar"); + + using (var archive = RarArchive.Open(testArchive)) + { + Assert.Equal(5, archive.MinVersion); + Assert.Equal(6, archive.MaxVersion); + } + } + [Fact] public void Rar4_Multi_ArchiveFileRead() { @@ -575,6 +611,25 @@ namespace SharpCompress.Test.Rar "Rar4.multi.part07.rar"); } + [Fact] + public void Rar4_Multi_ArchiveOpenEntryVolumeIndexTest() + { + ArchiveOpenEntryVolumeIndexTest( + new[] { + new[] { 0, 1 }, //exe - Rar4.multi.part01.rar to Rar4.multi.part02.rar + new[] { 1, 5 }, //jpg - Rar4.multi.part02.rar to Rar4.multi.part06.rar + new[] { 5, 6 } //txt - Rar4.multi.part06.rar to Rar4.multi.part07.rar + }, + null, + "Rar4.multi.part01.rar", + "Rar4.multi.part02.rar", + "Rar4.multi.part03.rar", + "Rar4.multi.part04.rar", + "Rar4.multi.part05.rar", + "Rar4.multi.part06.rar", + "Rar4.multi.part07.rar"); + } + [Fact] public void Rar_Multi_ArchiveFileRead() {