diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index fb052c37..52ffaa1c 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs index 60ece4ee..3f2360b2 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs @@ -24,7 +24,7 @@ namespace SharpCompress.Archives.Rar public IArchive Archive => archive; - internal override IEnumerable Parts => this.parts; + internal override IEnumerable Parts => parts.Cast(); internal override FileHeader FileHeader => parts.First().FileHeader; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs index b0bc6da7..cd0b5eb0 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs @@ -10,10 +10,6 @@ using size_t = System.UInt64; using int64 = System.Int64; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SharpCompress.Compressors.Rar.UnpackV2017 { diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs index 3a0d63c5..53f0e713 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs @@ -334,7 +334,7 @@ void UnpWriteBuf() FragWindow.CopyData(Mem,0,BlockStart,BlockLength); else //x memcpy(Mem,Window+BlockStart,BlockLength); - Array.Copy(Window, BlockStart, Mem, 0, BlockLength); + Utility.Copy(Window, BlockStart, Mem, 0, BlockLength); } else { @@ -347,9 +347,9 @@ void UnpWriteBuf() else { //x memcpy(Mem,Window+BlockStart,FirstPartLength); - Array.Copy(Window, BlockStart, Mem, 0, FirstPartLength); + Utility.Copy(Window, BlockStart, Mem, 0, FirstPartLength); //x memcpy(Mem+FirstPartLength,Window,BlockEnd); - Array.Copy(Window, 0, Mem, FirstPartLength,BlockEnd); + Utility.Copy(Window, 0, Mem, FirstPartLength,BlockEnd); } } diff --git a/src/SharpCompress/Lazy.cs b/src/SharpCompress/Lazy.cs new file mode 100644 index 00000000..893e3bb1 --- /dev/null +++ b/src/SharpCompress/Lazy.cs @@ -0,0 +1,29 @@ +using System; + +namespace SharpCompress +{ + public class Lazy + { + private readonly Func _lazyFunc; + private bool _evaluated; + private T _value; + + public Lazy(Func lazyFunc) + { + _lazyFunc = lazyFunc; + } + + public T Value + { + get + { + if (!_evaluated) + { + _value = _lazyFunc(); + _evaluated = true; + } + return _value; + } + } + } +} \ No newline at end of file diff --git a/src/SharpCompress/Readers/Rar/RarReader.cs b/src/SharpCompress/Readers/Rar/RarReader.cs index 05fe0daa..23a4005e 100644 --- a/src/SharpCompress/Readers/Rar/RarReader.cs +++ b/src/SharpCompress/Readers/Rar/RarReader.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using SharpCompress.Common; diff --git a/src/SharpCompress/SharpCompress.csproj b/src/SharpCompress/SharpCompress.csproj index a20a92a9..5c1d0815 100644 --- a/src/SharpCompress/SharpCompress.csproj +++ b/src/SharpCompress/SharpCompress.csproj @@ -6,7 +6,7 @@ 0.20.0 0.20.0 Adam Hathcock - netstandard2.0 + net45;net35;netstandard1.0;netstandard1.3;netstandard2.0 true true SharpCompress diff --git a/src/SharpCompress/Utility.cs b/src/SharpCompress/Utility.cs index bca28a9d..e97d093d 100644 --- a/src/SharpCompress/Utility.cs +++ b/src/SharpCompress/Utility.cs @@ -184,6 +184,18 @@ namespace SharpCompress action(item); } } + + public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length) + { + if (sourceIndex > Int32.MaxValue || sourceIndex < Int32.MinValue) + throw new ArgumentOutOfRangeException(); + if (destinationIndex > Int32.MaxValue || destinationIndex < Int32.MinValue) + throw new ArgumentOutOfRangeException(); + if (length > Int32.MaxValue || length < Int32.MinValue) + throw new ArgumentOutOfRangeException(); + + Array.Copy(sourceArray, (int)sourceIndex, destinationArray, (int)destinationIndex, (int)length); + } public static IEnumerable AsEnumerable(this T item) {