diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index 699073cb..fb052c37 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -12,7 +13,8 @@ namespace SharpCompress.Archives.Rar { public class RarArchive : AbstractArchive { - internal IRarUnpack Unpack { get; } + internal Lazy UnpackV2017 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV2017.Unpack()); + internal Lazy UnpackV1 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV1.Unpack()); #if !NO_FILE @@ -24,11 +26,6 @@ namespace SharpCompress.Archives.Rar internal RarArchive(FileInfo fileInfo, ReaderOptions options) : base(ArchiveType.Rar, fileInfo, options) { -#if !RarV2017_USELEGACY - Unpack = new SharpCompress.Compressors.Rar.UnpackV2017.Unpack(); -#else - Unpack = new SharpCompress.Compressors.Rar.UnpackV1.Unpack(); -#endif } protected override IEnumerable LoadVolumes(FileInfo file) @@ -45,11 +42,6 @@ namespace SharpCompress.Archives.Rar internal RarArchive(IEnumerable streams, ReaderOptions options) : base(ArchiveType.Rar, streams, options) { -#if !RarV2017_USELEGACY - Unpack = new SharpCompress.Compressors.Rar.UnpackV2017.Unpack(); -#else - Unpack = new SharpCompress.Compressors.Rar.UnpackV1.Unpack(); -#endif } protected override IEnumerable LoadEntries(IEnumerable volumes) diff --git a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs index 064dcf7a..60ece4ee 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs @@ -51,7 +51,7 @@ namespace SharpCompress.Archives.Rar get { CheckIncomplete(); - return parts.Aggregate(0L, (total, fp) => { return total + fp.FileHeader.CompressedSize; }); + return parts.Aggregate(0L, (total, fp) => total + fp.FileHeader.CompressedSize); } } @@ -61,7 +61,13 @@ namespace SharpCompress.Archives.Rar { throw new InvalidOperationException("Use ExtractAllEntries to extract SOLID archives."); } - return new RarStream(archive.Unpack, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast(), archive)); + + if (IsRarV3) + { + return new RarStream(archive.UnpackV1.Value, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast(), archive)); + } + + return new RarStream(archive.UnpackV2017.Value, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast(), archive)); } public bool IsComplete diff --git a/src/SharpCompress/Common/Rar/Headers/MarkHeader.cs b/src/SharpCompress/Common/Rar/Headers/MarkHeader.cs index 4e972913..c7b94149 100644 --- a/src/SharpCompress/Common/Rar/Headers/MarkHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/MarkHeader.cs @@ -67,10 +67,6 @@ namespace SharpCompress.Common.Rar.Headers { return new MarkHeader(false); // Rar4 } - else - { - continue; - } } else if (b == 0x45) { @@ -80,19 +76,11 @@ namespace SharpCompress.Common.Rar.Headers if (b != 0x5e) continue; throw new InvalidFormatException("Rar format version pre-4 is unsupported."); } - else - { - continue; - } } else { b = GetByte(stream); start++; - continue; } - - // unreachable - throw new InvalidOperationException(); } } catch (Exception e) diff --git a/src/SharpCompress/Common/Rar/RarEntry.cs b/src/SharpCompress/Common/Rar/RarEntry.cs index cec1eb44..85be0bb3 100644 --- a/src/SharpCompress/Common/Rar/RarEntry.cs +++ b/src/SharpCompress/Common/Rar/RarEntry.cs @@ -7,6 +7,11 @@ namespace SharpCompress.Common.Rar { internal abstract FileHeader FileHeader { get; } + /// + /// As the V2017 port isn't complete, add this check to use the legacy Rar code. + /// + internal bool IsRarV3 => FileHeader.CompressionAlgorithm == 29 || FileHeader.CompressionAlgorithm == 36; + /// /// The File's 32 bit CRC Hash /// diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs index e5ca5b1e..35b65eb7 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace SharpCompress.Compressors.Rar.UnpackV1 { internal partial class Unpack diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack30_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack30_cpp.cs index 8ec81763..7e77c7d4 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack30_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack30_cpp.cs @@ -13,7 +13,7 @@ using System; using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; using static SharpCompress.Compressors.Rar.UnpackV2017.UnpackGlobal; //using static SharpCompress.Compressors.Rar.UnpackV2017.Unpack.Unpack30Local; - +/* namespace SharpCompress.Compressors.Rar.UnpackV2017 { internal partial class Unpack @@ -797,3 +797,4 @@ void InitFilters30(bool Solid) } } +*/ \ No newline at end of file diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs index 0fa14295..44abffa3 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs @@ -167,7 +167,7 @@ void DoUnpack(uint Method,bool Solid) #if !RarV2017_RAR5ONLY case 29: // rar 3.x compression if (!Fragmented) - Unpack29(Solid); + throw new NotImplementedException(); break; #endif case 50: // RAR 5.0 compression algorithm. @@ -225,7 +225,7 @@ void UnpInitData(bool Solid) #if !RarV2017_SFX_MODULE UnpInitData20(Solid); #endif - UnpInitData30(Solid); + //UnpInitData30(Solid); UnpInitData50(Solid); } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs index afea642c..06520ab5 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs @@ -196,9 +196,9 @@ class UnpackFilter30 // in PrgStack array. Not defined for filters in Filters array. public uint ParentFilter; -#if !RarV2017_RAR5ONLY +/*#if !RarV2017_RAR5ONLY public VM_PreparedProgram Prg; -#endif +#endif*/ }; @@ -374,9 +374,9 @@ internal partial class Unpack int PrevLowDist,LowDistRepCount; -#if !RarV2017_RAR5ONLY +/*#if !RarV2017_RAR5ONLY ModelPPM PPM; -#endif +#endif*/ int PPMEscChar; readonly byte [] UnpOldTable = new byte[HUFF_TABLE_SIZE30]; @@ -390,9 +390,9 @@ internal partial class Unpack bool TablesRead2,TablesRead3,TablesRead5; // Virtual machine to execute filters code. -#if !RarV2017_RAR5ONLY +/*#if !RarV2017_RAR5ONLY RarVM VM; -#endif +#endif*/ // Buffer to read VM filters code. We moved it here from AddVMCode // function to reduce time spent in BitInput constructor. diff --git a/src/SharpCompress/Readers/Rar/RarReader.cs b/src/SharpCompress/Readers/Rar/RarReader.cs index 71fe260c..05fe0daa 100644 --- a/src/SharpCompress/Readers/Rar/RarReader.cs +++ b/src/SharpCompress/Readers/Rar/RarReader.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using SharpCompress.Common; @@ -13,16 +14,12 @@ namespace SharpCompress.Readers.Rar public abstract class RarReader : AbstractReader { private RarVolume volume; - private readonly IRarUnpack pack; + internal Lazy UnpackV2017 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV2017.Unpack()); + internal Lazy UnpackV1 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV1.Unpack()); internal RarReader(ReaderOptions options) : base(options, ArchiveType.Rar) { -#if !RarV2017_USELEGACY - this.pack = new SharpCompress.Compressors.Rar.UnpackV2017.Unpack(); -#else - this.pack = new SharpCompress.Compressors.Rar.UnpackV1.Unpack(); -#endif } internal abstract void ValidateArchive(RarVolume archive); @@ -68,9 +65,14 @@ namespace SharpCompress.Readers.Rar return Entry.Parts; } - protected override EntryStream GetEntryStream() { + protected override EntryStream GetEntryStream() + { var stream = new MultiVolumeReadOnlyStream(CreateFilePartEnumerableForCurrentEntry().Cast(), this); - return CreateEntryStream(new RarCrcStream(pack, Entry.FileHeader, stream)); + if (Entry.IsRarV3) + { + return CreateEntryStream(new RarCrcStream(UnpackV1.Value, Entry.FileHeader, stream)); + } + return CreateEntryStream(new RarCrcStream(UnpackV2017.Value, Entry.FileHeader, stream)); } } } diff --git a/src/SharpCompress/SharpCompress.csproj b/src/SharpCompress/SharpCompress.csproj index 5c1d0815..a20a92a9 100644 --- a/src/SharpCompress/SharpCompress.csproj +++ b/src/SharpCompress/SharpCompress.csproj @@ -6,7 +6,7 @@ 0.20.0 0.20.0 Adam Hathcock - net45;net35;netstandard1.0;netstandard1.3;netstandard2.0 + netstandard2.0 true true SharpCompress diff --git a/src/SharpCompress/Utility.cs b/src/SharpCompress/Utility.cs index 320a59c6..bca28a9d 100644 --- a/src/SharpCompress/Utility.cs +++ b/src/SharpCompress/Utility.cs @@ -427,10 +427,5 @@ namespace SharpCompress } return true; } - - public static void CopyTo(this byte[] array, byte[] destination, int index) - { - Array.Copy(array, 0, destination, index, array.Length); - } } } \ No newline at end of file