From 7da10795a12f007ef847078af94b59a300f79c44 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 20 Dec 2022 15:14:22 +0000 Subject: [PATCH] csharpier --- .editorconfig | 2 +- src/SharpCompress/Algorithms/Adler32.cs | 10 +- src/SharpCompress/Archives/AbstractArchive.cs | 5 +- .../Archives/AbstractWritableArchive.cs | 4 +- src/SharpCompress/Archives/ArchiveFactory.cs | 2 +- .../Archives/GZip/GZipArchive.cs | 18 +- .../Archives/IMultiArchiveFactory.cs | 5 +- .../Archives/IWritableArchiveExtensions.cs | 4 +- src/SharpCompress/Archives/Rar/RarArchive.cs | 9 +- .../Archives/Rar/SeekableFilePart.cs | 3 +- .../Archives/Rar/StreamRarArchiveVolume.cs | 8 +- .../Archives/SevenZip/SevenZipArchive.cs | 7 +- src/SharpCompress/Archives/Tar/TarArchive.cs | 9 +- .../Archives/Tar/TarArchiveEntry.cs | 7 +- src/SharpCompress/Archives/Zip/ZipArchive.cs | 66 +- src/SharpCompress/Common/GZip/GZipFilePart.cs | 3 +- src/SharpCompress/Common/GZip/GZipVolume.cs | 3 +- .../Common/MultiVolumeExtractionException.cs | 4 +- .../Common/PasswordProtectedException.cs | 3 +- .../Common/Rar/Headers/ArchiveCryptHeader.cs | 5 +- .../Common/Rar/Headers/FileHeader.cs | 112 +- .../Common/Rar/Headers/FileNameDecoder.cs | 6 +- .../Common/Rar/Headers/RarHeaderFactory.cs | 83 +- src/SharpCompress/Common/Rar/RarVolume.cs | 58 +- .../Common/SevenZip/ArchiveReader.cs | 47 +- .../Common/SevenZip/SevenZipFilePart.cs | 10 +- .../Common/Tar/Headers/TarHeader.cs | 10 +- .../Common/Tar/TarHeaderFactory.cs | 20 +- .../Zip/Headers/DirectoryEntryHeader.cs | 4 +- .../Common/Zip/Headers/LocalEntryHeader.cs | 4 +- .../Headers/LocalEntryHeaderExtraFactory.cs | 15 +- .../Common/Zip/Headers/ZipFileEntry.cs | 8 +- .../Common/Zip/StreamingZipHeaderFactory.cs | 6 +- src/SharpCompress/Common/Zip/ZipFilePart.cs | 16 +- .../Common/Zip/ZipHeaderFactory.cs | 7 +- .../Compressors/ADC/ADCStream.cs | 7 +- .../Compressors/BZip2/BZip2Stream.cs | 6 +- .../Compressors/BZip2/CBZip2InputStream.cs | 13 +- .../Compressors/BZip2/CBZip2OutputStream.cs | 46 +- .../Compressors/Deflate/DeflateManager.cs | 41 +- .../Compressors/Deflate/InfTree.cs | 8 +- .../Compressors/Deflate/Inflate.cs | 21 +- src/SharpCompress/Compressors/Deflate/Tree.cs | 4 +- src/SharpCompress/Compressors/Deflate/Zlib.cs | 7 +- .../Compressors/Deflate64/DeflateInput.cs | 2 +- .../Compressors/Deflate64/InflaterManaged.cs | 3 +- .../Compressors/Filters/BranchExecFilter.cs | 12 +- .../Compressors/LZMA/DecoderStream.cs | 11 +- src/SharpCompress/Compressors/LZMA/ICoder.cs | 8 +- .../Compressors/LZMA/LZipStream.cs | 3 +- .../Compressors/LZMA/LzmaDecoder.cs | 22 +- .../Compressors/LZMA/LzmaEncoder.cs | 73 +- .../Compressors/LZMA/LzmaStream.cs | 4 +- .../LZMA/RangeCoder/RangeCoderBit.cs | 3 +- .../LZMA/RangeCoder/RangeCoderBitTree.cs | 4 +- .../Compressors/PPMd/H/ModelPPM.cs | 25 +- .../Compressors/PPMd/H/PPMContext.cs | 23 +- .../Compressors/PPMd/H/RarMemBlock.cs | 3 +- src/SharpCompress/Compressors/PPMd/H/State.cs | 18 +- .../Compressors/PPMd/H/SubAllocator.cs | 6 +- .../Compressors/PPMd/I1/Allocator.cs | 9 +- .../Compressors/PPMd/I1/Coder.cs | 6 +- .../Compressors/PPMd/I1/Model.cs | 19 +- .../Compressors/PPMd/I1/Pointer.cs | 16 +- .../Compressors/PPMd/I1/PpmContext.cs | 2 +- .../Compressors/Rar/UnpackV1/Unpack.cs | 24 +- .../Compressors/Rar/UnpackV1/Unpack15.cs | 40 +- .../Compressors/Rar/UnpackV1/Unpack20.cs | 7 +- .../Compressors/Rar/UnpackV1/Unpack50.cs | 12 +- .../Compressors/Rar/UnpackV1/UnpackUtility.cs | 13 +- .../Rar/UnpackV2017/Unpack.unpack15_cpp.cs | 14 +- .../Rar/UnpackV2017/Unpack.unpack20_cpp.cs | 2 +- .../Rar/UnpackV2017/Unpack.unpack50_cpp.cs | 111 +- .../Rar/UnpackV2017/Unpack.unpack_cpp.cs | 4 +- src/SharpCompress/Compressors/Rar/VM/RarVM.cs | 1214 ++++++++--------- .../Compressors/Xz/Filters/BlockFilter.cs | 4 +- src/SharpCompress/Compressors/Xz/XZStream.cs | 4 +- src/SharpCompress/Crypto/Crc32Stream.cs | 3 +- .../Crypto/DataLengthException.cs | 3 +- src/SharpCompress/Factories/GZipFactory.cs | 4 +- src/SharpCompress/IO/ListeningStream.cs | 10 +- src/SharpCompress/IO/ReadOnlySubStream.cs | 3 +- src/SharpCompress/IO/SourceStream.cs | 3 +- src/SharpCompress/Readers/AbstractReader.cs | 8 +- .../Readers/Rar/NonSeekableStreamFilePart.cs | 3 +- src/SharpCompress/Readers/Rar/RarReader.cs | 4 +- src/SharpCompress/Readers/ReaderFactory.cs | 5 +- src/SharpCompress/Readers/Zip/ZipReader.cs | 17 +- src/SharpCompress/Utility.cs | 3 +- src/SharpCompress/Writers/Tar/TarWriter.cs | 27 +- src/SharpCompress/Writers/WriterFactory.cs | 6 +- src/SharpCompress/Writers/Zip/ZipWriter.cs | 27 +- tests/SharpCompress.Test/ADCTest.cs | 34 +- tests/SharpCompress.Test/ArchiveTests.cs | 21 +- .../GZip/GZipArchiveTests.cs | 4 +- .../GZip/GZipReaderTests.cs | 4 +- tests/SharpCompress.Test/Mocks/TestStream.cs | 4 +- .../SharpCompress.Test/Rar/RarArchiveTests.cs | 16 +- .../Rar/RarHeaderFactoryTest.cs | 13 +- .../SharpCompress.Test/Rar/RarReaderTests.cs | 23 +- tests/SharpCompress.Test/ReaderTests.cs | 11 +- .../SevenZip/SevenZipArchiveTests.cs | 5 +- .../Streams/ZlibBaseStreamTests.cs | 14 +- .../SharpCompress.Test/Tar/TarWriterTests.cs | 7 +- tests/SharpCompress.Test/WriterTests.cs | 10 +- tests/SharpCompress.Test/Zip/Zip64Tests.cs | 12 +- .../SharpCompress.Test/Zip/ZipReaderTests.cs | 35 +- .../SharpCompress.Test/Zip/ZipWriterTests.cs | 7 +- 108 files changed, 1112 insertions(+), 1691 deletions(-) diff --git a/.editorconfig b/.editorconfig index be296daf..1903a97c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -351,7 +351,7 @@ dotnet_diagnostic.IDE0066.severity = suggestion # switch expression dotnet_diagnostic.IDE0072.severity = suggestion # Populate switch - forces population of all cases even when default specified dotnet_diagnostic.IDE0078.severity = suggestion # use pattern matching dotnet_diagnostic.IDE0090.severity = suggestion # new can be simplified -dotnet_diagnostic.IDE0130.severity = suggestion # namespace folder structure +dotnet_diagnostic.IDE0130.severity = error # namespace folder structure dotnet_diagnostic.IDE0160.severity = silent # Use block namespaces ARE NOT required dotnet_diagnostic.IDE0161.severity = error # Please use file namespaces dotnet_diagnostic.IDE0200.severity = suggestion # lambda not needed diff --git a/src/SharpCompress/Algorithms/Adler32.cs b/src/SharpCompress/Algorithms/Adler32.cs index e32893ac..1f094c13 100644 --- a/src/SharpCompress/Algorithms/Adler32.cs +++ b/src/SharpCompress/Algorithms/Adler32.cs @@ -236,17 +236,11 @@ internal static class Adler32 // From https://github.com/SixLabors/ImageSharp/bl // Horizontally add the bytes for s1, multiply-adds the // bytes by [ 32, 31, 30, ... ] for s2. - v_s1 = Sse2.Add( - v_s1, - Sse2.SumAbsoluteDifferences(bytes1, zero).AsUInt32() - ); + v_s1 = Sse2.Add(v_s1, Sse2.SumAbsoluteDifferences(bytes1, zero).AsUInt32()); Vector128 mad1 = Ssse3.MultiplyAddAdjacent(bytes1, tap1); v_s2 = Sse2.Add(v_s2, Sse2.MultiplyAddAdjacent(mad1, ones).AsUInt32()); - v_s1 = Sse2.Add( - v_s1, - Sse2.SumAbsoluteDifferences(bytes2, zero).AsUInt32() - ); + v_s1 = Sse2.Add(v_s1, Sse2.SumAbsoluteDifferences(bytes2, zero).AsUInt32()); Vector128 mad2 = Ssse3.MultiplyAddAdjacent(bytes2, tap2); v_s2 = Sse2.Add(v_s2, Sse2.MultiplyAddAdjacent(mad2, ones).AsUInt32()); diff --git a/src/SharpCompress/Archives/AbstractArchive.cs b/src/SharpCompress/Archives/AbstractArchive.cs index d747189e..630cf3c5 100644 --- a/src/SharpCompress/Archives/AbstractArchive.cs +++ b/src/SharpCompress/Archives/AbstractArchive.cs @@ -49,10 +49,7 @@ public abstract class AbstractArchive : IArchive, IArchiveExtra void IArchiveExtractionListener.FireEntryExtractionBegin(IArchiveEntry entry) { - EntryExtractionBegin?.Invoke( - this, - new ArchiveExtractionEventArgs(entry) - ); + EntryExtractionBegin?.Invoke(this, new ArchiveExtractionEventArgs(entry)); } void IArchiveExtractionListener.FireEntryExtractionEnd(IArchiveEntry entry) diff --git a/src/SharpCompress/Archives/AbstractWritableArchive.cs b/src/SharpCompress/Archives/AbstractWritableArchive.cs index 146c8338..f3f98be8 100644 --- a/src/SharpCompress/Archives/AbstractWritableArchive.cs +++ b/src/SharpCompress/Archives/AbstractWritableArchive.cs @@ -146,9 +146,7 @@ public abstract class AbstractWritableArchive public void SaveTo(Stream stream, WriterOptions options) { //reset streams of new entries - newEntries - .Cast() - .ForEach(x => x.Stream.Seek(0, SeekOrigin.Begin)); + newEntries.Cast().ForEach(x => x.Stream.Seek(0, SeekOrigin.Begin)); SaveTo(stream, options, OldEntries, newEntries); } diff --git a/src/SharpCompress/Archives/ArchiveFactory.cs b/src/SharpCompress/Archives/ArchiveFactory.cs index a246bad9..6b489fa1 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.cs @@ -27,7 +27,7 @@ public static class ArchiveFactory { var factory = Factory.Factories .OfType() -.FirstOrDefault(item => item.KnownArchiveType == type); + .FirstOrDefault(item => item.KnownArchiveType == type); if (factory != null) { diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.cs b/src/SharpCompress/Archives/GZip/GZipArchive.cs index 4100f2f2..43a43c00 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchive.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchive.cs @@ -68,10 +68,7 @@ public class GZipArchive : AbstractWritableArchive /// /// /// - public static GZipArchive Open( - IEnumerable streams, - ReaderOptions? readerOptions = null - ) + public static GZipArchive Open(IEnumerable streams, ReaderOptions? readerOptions = null) { streams.CheckNotNull(nameof(streams)); var strms = streams.ToArray(); @@ -176,14 +173,7 @@ public class GZipArchive : AbstractWritableArchive { throw new InvalidOperationException("Only one entry is allowed in a GZip Archive"); } - return new GZipWritableArchiveEntry( - this, - source, - filePath, - size, - modified, - closeStream - ); + return new GZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream); } protected override void SaveTo( @@ -205,9 +195,7 @@ public class GZipArchive : AbstractWritableArchive } } - protected override IEnumerable LoadEntries( - IEnumerable volumes - ) + protected override IEnumerable LoadEntries(IEnumerable volumes) { var stream = volumes.Single().Stream; yield return new GZipArchiveEntry( diff --git a/src/SharpCompress/Archives/IMultiArchiveFactory.cs b/src/SharpCompress/Archives/IMultiArchiveFactory.cs index be2eefb8..c26b649f 100644 --- a/src/SharpCompress/Archives/IMultiArchiveFactory.cs +++ b/src/SharpCompress/Archives/IMultiArchiveFactory.cs @@ -32,8 +32,5 @@ public interface IMultiArchiveFactory : IFactory /// /// /// reading options. - IArchive Open( - IReadOnlyList fileInfos, - ReaderOptions? readerOptions = null - ); + IArchive Open(IReadOnlyList fileInfos, ReaderOptions? readerOptions = null); } diff --git a/src/SharpCompress/Archives/IWritableArchiveExtensions.cs b/src/SharpCompress/Archives/IWritableArchiveExtensions.cs index e534b306..794aea1f 100644 --- a/src/SharpCompress/Archives/IWritableArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IWritableArchiveExtensions.cs @@ -54,9 +54,7 @@ public static class IWritableArchiveExtensions { using (writableArchive.PauseEntryRebuilding()) { - foreach ( - var path in Directory.EnumerateFiles(filePath, searchPattern, searchOption) - ) + foreach (var path in Directory.EnumerateFiles(filePath, searchPattern, searchOption)) { var fileInfo = new FileInfo(path); writableArchive.AddEntry( diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index dad32f3c..c9d8a6a8 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -107,9 +107,7 @@ public class RarArchive : AbstractArchive public static RarArchive Open(Stream stream, ReaderOptions? options = null) { stream.CheckNotNull(nameof(stream)); - return new RarArchive( - new SourceStream(stream, i => null, options ?? new ReaderOptions()) - ); + return new RarArchive(new SourceStream(stream, i => null, options ?? new ReaderOptions())); } /// @@ -138,10 +136,7 @@ public class RarArchive : AbstractArchive /// /// /// - public static RarArchive Open( - IEnumerable streams, - ReaderOptions? readerOptions = null - ) + public static RarArchive Open(IEnumerable streams, ReaderOptions? readerOptions = null) { streams.CheckNotNull(nameof(streams)); var strms = streams.ToArray(); diff --git a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs index 9f27b674..e7247eae 100644 --- a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs +++ b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs @@ -31,6 +31,5 @@ internal class SeekableFilePart : RarFilePart return stream; } - internal override string FilePartName => - "Unknown Stream - File Entry: " + FileHeader.FileName; + internal override string FilePartName => "Unknown Stream - File Entry: " + FileHeader.FileName; } diff --git a/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs b/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs index 6d388746..236c64e2 100644 --- a/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs +++ b/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs @@ -19,12 +19,6 @@ internal class StreamRarArchiveVolume : RarVolume internal override RarFilePart CreateFilePart(MarkHeader markHeader, FileHeader fileHeader) { - return new SeekableFilePart( - markHeader, - fileHeader, - Index, - Stream, - ReaderOptions.Password - ); + return new SeekableFilePart(markHeader, fileHeader, Index, Stream, ReaderOptions.Password); } } diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index 870de6b2..c49bd550 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -145,9 +145,7 @@ public class SevenZipArchive : AbstractArchive !x.IsDirectory).GroupBy(x => x.FilePart.Folder) - ) + foreach (var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder)) { var isSolid = false; foreach (var entry in group) @@ -202,8 +200,7 @@ public class SevenZipArchive : AbstractArchive !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() - > 1; + return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1; } } diff --git a/src/SharpCompress/Archives/Tar/TarArchive.cs b/src/SharpCompress/Archives/Tar/TarArchive.cs index 2870555c..cb808761 100644 --- a/src/SharpCompress/Archives/Tar/TarArchive.cs +++ b/src/SharpCompress/Archives/Tar/TarArchive.cs @@ -69,10 +69,7 @@ public class TarArchive : AbstractWritableArchive /// /// /// - public static TarArchive Open( - IEnumerable streams, - ReaderOptions? readerOptions = null - ) + public static TarArchive Open(IEnumerable streams, ReaderOptions? readerOptions = null) { streams.CheckNotNull(nameof(streams)); var strms = streams.ToArray(); @@ -182,9 +179,7 @@ public class TarArchive : AbstractWritableArchive memoryStream.Position = 0; var bytes = memoryStream.ToArray(); - header.Name = ReaderOptions.ArchiveEncoding - .Decode(bytes) - .TrimNulls(); + header.Name = ReaderOptions.ArchiveEncoding.Decode(bytes).TrimNulls(); } stream.Position = oldStreamPos; diff --git a/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs b/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs index d2ac353f..eee8ed7a 100644 --- a/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs @@ -7,11 +7,8 @@ namespace SharpCompress.Archives.Tar; public class TarArchiveEntry : TarEntry, IArchiveEntry { - internal TarArchiveEntry( - TarArchive archive, - TarFilePart part, - CompressionType compressionType - ) : base(part, compressionType) + internal TarArchiveEntry(TarArchive archive, TarFilePart part, CompressionType compressionType) + : base(part, compressionType) { Archive = archive; } diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs index 11b8cd0a..ba3ccdb9 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs @@ -94,10 +94,7 @@ public class ZipArchive : AbstractWritableArchive /// /// /// - public static ZipArchive Open( - IEnumerable streams, - ReaderOptions? readerOptions = null - ) + public static ZipArchive Open(IEnumerable streams, ReaderOptions? readerOptions = null) { streams.CheckNotNull(nameof(streams)); var strms = streams.ToArray(); @@ -140,10 +137,7 @@ public class ZipArchive : AbstractWritableArchive public static bool IsZipFile(Stream stream, string? password = null) { - var headerFactory = new StreamingZipHeaderFactory( - password, - new ArchiveEncoding() - ); + var headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding()); try { var header = headerFactory @@ -167,10 +161,7 @@ public class ZipArchive : AbstractWritableArchive public static bool IsZipMulti(Stream stream, string? password = null) { - var headerFactory = new StreamingZipHeaderFactory( - password, - new ArchiveEncoding() - ); + var headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding()); try { var header = headerFactory @@ -180,10 +171,7 @@ public class ZipArchive : AbstractWritableArchive { if (stream.CanSeek) //could be multipart. Test for central directory - might not be z64 safe { - var z = new SeekableZipHeaderFactory( - password, - new ArchiveEncoding() - ); + var z = new SeekableZipHeaderFactory(password, new ArchiveEncoding()); var x = z.ReadSeekableHeader(stream).FirstOrDefault(); return x?.ZipHeaderType == ZipHeaderType.DirectoryEntry; } @@ -246,32 +234,32 @@ public class ZipArchive : AbstractWritableArchive { case ZipHeaderType.DirectoryEntry: - { - var deh = (DirectoryEntryHeader)h; - Stream s; - if ( - deh.RelativeOffsetOfEntryHeader + deh.CompressedSize - > vols[deh.DiskNumberStart].Stream.Length - ) { - var v = vols.Skip(deh.DiskNumberStart).ToArray(); - s = new SourceStream( - v[0].Stream, - i => i < v.Length ? v[i].Stream : null, - new ReaderOptions() { LeaveStreamOpen = true } + var deh = (DirectoryEntryHeader)h; + Stream s; + if ( + deh.RelativeOffsetOfEntryHeader + deh.CompressedSize + > vols[deh.DiskNumberStart].Stream.Length + ) + { + var v = vols.Skip(deh.DiskNumberStart).ToArray(); + s = new SourceStream( + v[0].Stream, + i => i < v.Length ? v[i].Stream : null, + new ReaderOptions() { LeaveStreamOpen = true } + ); + } + else + { + s = vols[deh.DiskNumberStart].Stream; + } + + yield return new ZipArchiveEntry( + this, + new SeekableZipFilePart(headerFactory, deh, s) ); } - else - { - s = vols[deh.DiskNumberStart].Stream; - } - - yield return new ZipArchiveEntry( - this, - new SeekableZipFilePart(headerFactory, deh, s) - ); - } - break; + break; case ZipHeaderType.DirectoryEnd: { var bytes = ((DirectoryEndHeader)h).Comment ?? Array.Empty(); diff --git a/src/SharpCompress/Common/GZip/GZipFilePart.cs b/src/SharpCompress/Common/GZip/GZipFilePart.cs index e5e969f1..04cfc355 100644 --- a/src/SharpCompress/Common/GZip/GZipFilePart.cs +++ b/src/SharpCompress/Common/GZip/GZipFilePart.cs @@ -13,8 +13,7 @@ internal sealed class GZipFilePart : FilePart private string? _name; private readonly Stream _stream; - internal GZipFilePart(Stream stream, ArchiveEncoding archiveEncoding) - : base(archiveEncoding) + internal GZipFilePart(Stream stream, ArchiveEncoding archiveEncoding) : base(archiveEncoding) { _stream = stream; ReadAndValidateGzipHeader(); diff --git a/src/SharpCompress/Common/GZip/GZipVolume.cs b/src/SharpCompress/Common/GZip/GZipVolume.cs index cc2ec364..e13abd8c 100644 --- a/src/SharpCompress/Common/GZip/GZipVolume.cs +++ b/src/SharpCompress/Common/GZip/GZipVolume.cs @@ -8,8 +8,7 @@ public class GZipVolume : Volume public GZipVolume(Stream stream, ReaderOptions options, int index = 0) : base(stream, options, index) { } - public GZipVolume(FileInfo fileInfo, ReaderOptions options) - : base(fileInfo.OpenRead(), options) + public GZipVolume(FileInfo fileInfo, ReaderOptions options) : base(fileInfo.OpenRead(), options) { options.LeaveStreamOpen = false; } diff --git a/src/SharpCompress/Common/MultiVolumeExtractionException.cs b/src/SharpCompress/Common/MultiVolumeExtractionException.cs index 7e6f14e3..ee2f95ad 100644 --- a/src/SharpCompress/Common/MultiVolumeExtractionException.cs +++ b/src/SharpCompress/Common/MultiVolumeExtractionException.cs @@ -6,6 +6,6 @@ public class MultiVolumeExtractionException : ExtractionException { public MultiVolumeExtractionException(string message) : base(message) { } - public MultiVolumeExtractionException(string message, Exception inner) - : base(message, inner) { } + public MultiVolumeExtractionException(string message, Exception inner) : base(message, inner) + { } } diff --git a/src/SharpCompress/Common/PasswordProtectedException.cs b/src/SharpCompress/Common/PasswordProtectedException.cs index ab5317c2..7b559625 100644 --- a/src/SharpCompress/Common/PasswordProtectedException.cs +++ b/src/SharpCompress/Common/PasswordProtectedException.cs @@ -6,6 +6,5 @@ public class PasswordProtectedException : ExtractionException { public PasswordProtectedException(string message) : base(message) { } - public PasswordProtectedException(string message, Exception inner) : base(message, inner) - { } + public PasswordProtectedException(string message, Exception inner) : base(message, inner) { } } diff --git a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs index 64edb8c4..619e8fc9 100644 --- a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs @@ -30,10 +30,7 @@ internal class ArchiveCryptHeader : RarHeader return; } var encryptionFlags = reader.ReadRarVIntUInt32(); - _usePswCheck = FlagUtility.HasFlag( - encryptionFlags, - EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK - ); + _usePswCheck = FlagUtility.HasFlag(encryptionFlags, EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK); _lg2Count = reader.ReadRarVIntByte(1); //UsePswCheck = HasHeaderFlag(EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK); diff --git a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs index 66a8a78b..d0f7450b 100644 --- a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs @@ -116,13 +116,13 @@ internal class FileHeader : RarHeader //TODO case 1: // file encryption - { - isEncryptedRar5 = true; + { + isEncryptedRar5 = true; - //var version = reader.ReadRarVIntByte(); - //if (version != 0) throw new InvalidFormatException("unknown encryption algorithm " + version); - } - break; + //var version = reader.ReadRarVIntByte(); + //if (version != 0) throw new InvalidFormatException("unknown encryption algorithm " + version); + } + break; // case 2: // file hash // { // @@ -130,23 +130,23 @@ internal class FileHeader : RarHeader // break; case 3: // file time - { - var flags = reader.ReadRarVIntUInt16(); - var isWindowsTime = (flags & 1) == 0; - if ((flags & 0x2) == 0x2) { - FileLastModifiedTime = ReadExtendedTimeV5(reader, isWindowsTime); + var flags = reader.ReadRarVIntUInt16(); + var isWindowsTime = (flags & 1) == 0; + if ((flags & 0x2) == 0x2) + { + FileLastModifiedTime = ReadExtendedTimeV5(reader, isWindowsTime); + } + if ((flags & 0x4) == 0x4) + { + FileCreatedTime = ReadExtendedTimeV5(reader, isWindowsTime); + } + if ((flags & 0x8) == 0x8) + { + FileLastAccessedTime = ReadExtendedTimeV5(reader, isWindowsTime); + } } - if ((flags & 0x4) == 0x4) - { - FileCreatedTime = ReadExtendedTimeV5(reader, isWindowsTime); - } - if ((flags & 0x8) == 0x8) - { - FileLastAccessedTime = ReadExtendedTimeV5(reader, isWindowsTime); - } - } - break; + break; //TODO // case 4: // file version // { @@ -262,54 +262,54 @@ internal class FileHeader : RarHeader { case HeaderCodeV.RAR4_FILE_HEADER: - { - if (HasFlag(FileFlagsV4.UNICODE)) { - var length = 0; - while (length < fileNameBytes.Length && fileNameBytes[length] != 0) + if (HasFlag(FileFlagsV4.UNICODE)) { - length++; - } - if (length != nameSize) - { - length++; - FileName = FileNameDecoder.Decode(fileNameBytes, length); + var length = 0; + while (length < fileNameBytes.Length && fileNameBytes[length] != 0) + { + length++; + } + if (length != nameSize) + { + length++; + FileName = FileNameDecoder.Decode(fileNameBytes, length); + } + else + { + FileName = ArchiveEncoding.Decode(fileNameBytes); + } } else { FileName = ArchiveEncoding.Decode(fileNameBytes); } + FileName = ConvertPathV4(FileName); } - else - { - FileName = ArchiveEncoding.Decode(fileNameBytes); - } - FileName = ConvertPathV4(FileName); - } - break; + break; case HeaderCodeV.RAR4_NEW_SUB_HEADER: - { - var datasize = HeaderSize - newLhdSize - nameSize; - if (HasFlag(FileFlagsV4.SALT)) { - datasize -= saltSize; - } - if (datasize > 0) - { - SubData = reader.ReadBytes(datasize); - } + var datasize = HeaderSize - newLhdSize - nameSize; + if (HasFlag(FileFlagsV4.SALT)) + { + datasize -= saltSize; + } + if (datasize > 0) + { + SubData = reader.ReadBytes(datasize); + } - if (NewSubHeaderType.SUBHEAD_TYPE_RR.Equals(fileNameBytes)) - { - RecoverySectors = - SubData[8] - + (SubData[9] << 8) - + (SubData[10] << 16) - + (SubData[11] << 24); + if (NewSubHeaderType.SUBHEAD_TYPE_RR.Equals(fileNameBytes)) + { + RecoverySectors = + SubData[8] + + (SubData[9] << 8) + + (SubData[10] << 16) + + (SubData[11] << 24); + } } - } - break; + break; } if (HasFlag(FileFlagsV4.SALT)) diff --git a/src/SharpCompress/Common/Rar/Headers/FileNameDecoder.cs b/src/SharpCompress/Common/Rar/Headers/FileNameDecoder.cs index c6b85001..d6447b49 100644 --- a/src/SharpCompress/Common/Rar/Headers/FileNameDecoder.cs +++ b/src/SharpCompress/Common/Rar/Headers/FileNameDecoder.cs @@ -66,11 +66,7 @@ internal static class FileNameDecoder } else { - for ( - length += 2; - length > 0 && decPos < name.Length; - length--, decPos++ - ) + for (length += 2; length > 0 && decPos < name.Length; length--, decPos++) { buf.Append((char)(GetChar(name, decPos))); } diff --git a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs index 37a59d2d..d371166d 100644 --- a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs +++ b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs @@ -21,11 +21,7 @@ public class RarHeaderFactory public IEnumerable ReadHeaders(Stream stream) { - var markHeader = MarkHeader.Read( - stream, - Options.LeaveStreamOpen, - Options.LookForHeader - ); + var markHeader = MarkHeader.Read(stream, Options.LeaveStreamOpen, Options.LookForHeader); _isRar5 = markHeader.IsRar5; yield return markHeader; @@ -87,16 +83,16 @@ public class RarHeaderFactory { case StreamingMode.Seekable: - { - reader.BaseStream.Position += ph.DataSize; - } - break; + { + reader.BaseStream.Position += ph.DataSize; + } + break; case StreamingMode.Streaming: - { - reader.BaseStream.Skip(ph.DataSize); - } - break; + { + reader.BaseStream.Skip(ph.DataSize); + } + break; default: { throw new InvalidFormatException("Invalid StreamingMode"); @@ -128,32 +124,29 @@ public class RarHeaderFactory { case StreamingMode.Seekable: - { - fh.DataStartPosition = reader.BaseStream.Position; - reader.BaseStream.Position += fh.CompressedSize; - } - break; + { + fh.DataStartPosition = reader.BaseStream.Position; + reader.BaseStream.Position += fh.CompressedSize; + } + break; case StreamingMode.Streaming: - { - var ms = new ReadOnlySubStream( - reader.BaseStream, - fh.CompressedSize - ); - if (fh.R4Salt is null) { - fh.PackedStream = ms; + var ms = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize); + if (fh.R4Salt is null) + { + fh.PackedStream = ms; + } + else + { + fh.PackedStream = new RarCryptoWrapper( + ms, + Options.Password!, + fh.R4Salt + ); + } } - else - { - fh.PackedStream = new RarCryptoWrapper( - ms, - Options.Password!, - fh.R4Salt - ); - } - } - break; + break; default: { throw new InvalidFormatException("Invalid StreamingMode"); @@ -185,18 +178,18 @@ public class RarHeaderFactory { case StreamingMode.Seekable: - { - fh.DataStartPosition = reader.BaseStream.Position; - reader.BaseStream.Position += fh.CompressedSize; - } - break; + { + fh.DataStartPosition = reader.BaseStream.Position; + reader.BaseStream.Position += fh.CompressedSize; + } + break; case StreamingMode.Streaming: - { - //skip the data because it's useless? - reader.BaseStream.Skip(fh.CompressedSize); - } - break; + { + //skip the data because it's useless? + reader.BaseStream.Skip(fh.CompressedSize); + } + break; default: { throw new InvalidFormatException("Invalid StreamingMode"); diff --git a/src/SharpCompress/Common/Rar/RarVolume.cs b/src/SharpCompress/Common/Rar/RarVolume.cs index eac09e33..49c04698 100644 --- a/src/SharpCompress/Common/Rar/RarVolume.cs +++ b/src/SharpCompress/Common/Rar/RarVolume.cs @@ -42,45 +42,45 @@ public abstract class RarVolume : Volume { case HeaderType.Mark: - { - lastMarkHeader = (MarkHeader)header; - } - break; + { + lastMarkHeader = (MarkHeader)header; + } + break; case HeaderType.Archive: - { - ArchiveHeader = (ArchiveHeader)header; - } - break; + { + ArchiveHeader = (ArchiveHeader)header; + } + break; case HeaderType.File: - { - var fh = (FileHeader)header; - if (_maxCompressionAlgorithm < fh.CompressionAlgorithm) { - _maxCompressionAlgorithm = fh.CompressionAlgorithm; - } + var fh = (FileHeader)header; + if (_maxCompressionAlgorithm < fh.CompressionAlgorithm) + { + _maxCompressionAlgorithm = fh.CompressionAlgorithm; + } - yield return CreateFilePart(lastMarkHeader!, fh); - } - break; + yield return CreateFilePart(lastMarkHeader!, fh); + } + break; case HeaderType.Service: - { - var fh = (FileHeader)header; - if (fh.FileName == "CMT") { - var part = CreateFilePart(lastMarkHeader!, fh); - var buffer = new byte[fh.CompressedSize]; - part.GetCompressedStream().Read(buffer, 0, buffer.Length); - Comment = System.Text.Encoding.UTF8.GetString( - buffer, - 0, - buffer.Length - 1 - ); + var fh = (FileHeader)header; + if (fh.FileName == "CMT") + { + var part = CreateFilePart(lastMarkHeader!, fh); + var buffer = new byte[fh.CompressedSize]; + part.GetCompressedStream().Read(buffer, 0, buffer.Length); + Comment = System.Text.Encoding.UTF8.GetString( + buffer, + 0, + buffer.Length - 1 + ); + } } - } - break; + break; } } } diff --git a/src/SharpCompress/Common/SevenZip/ArchiveReader.cs b/src/SharpCompress/Common/SevenZip/ArchiveReader.cs index 908fb453..543b5323 100644 --- a/src/SharpCompress/Common/SevenZip/ArchiveReader.cs +++ b/src/SharpCompress/Common/SevenZip/ArchiveReader.cs @@ -154,11 +154,7 @@ internal class ArchiveReader return ReadBitVector(length); } - private void ReadNumberVector( - List dataVector, - int numFiles, - Action action - ) + private void ReadNumberVector(List dataVector, int numFiles, Action action) { var defined = ReadOptionalBitVector(numFiles); @@ -877,9 +873,7 @@ internal class ArchiveReader outStream.ReadExact(data, 0, data.Length); if (outStream.ReadByte() >= 0) { - throw new InvalidOperationException( - "Decoded stream is longer than expected." - ); + throw new InvalidOperationException("Decoded stream is longer than expected."); } dataVector.Add(data); @@ -1030,7 +1024,7 @@ internal class ArchiveReader ReadAttributeVector( dataVector, numFiles, - delegate (int i, uint? attr) + delegate(int i, uint? attr) { // Some third party implementations established an unofficial extension // of the 7z archive format by placing posix file attributes in the high @@ -1124,17 +1118,12 @@ internal class ArchiveReader ReadNumberVector( dataVector, numFiles, - delegate (int i, long? startPos) + delegate(int i, long? startPos) { db._files[i].StartPos = startPos; #if DEBUG Log.Write( - " " - + ( - startPos.HasValue - ? startPos.Value.ToString() - : "n/a" - ) + " " + (startPos.HasValue ? startPos.Value.ToString() : "n/a") ); #endif } @@ -1150,13 +1139,11 @@ internal class ArchiveReader ReadDateTimeVector( dataVector, numFiles, - delegate (int i, DateTime? time) + delegate(int i, DateTime? time) { db._files[i].CTime = time; #if DEBUG - Log.Write( - " " + (time.HasValue ? time.Value.ToString() : "n/a") - ); + Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a")); #endif } ); @@ -1171,13 +1158,11 @@ internal class ArchiveReader ReadDateTimeVector( dataVector, numFiles, - delegate (int i, DateTime? time) + delegate(int i, DateTime? time) { db._files[i].ATime = time; #if DEBUG - Log.Write( - " " + (time.HasValue ? time.Value.ToString() : "n/a") - ); + Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a")); #endif } ); @@ -1192,13 +1177,11 @@ internal class ArchiveReader ReadDateTimeVector( dataVector, numFiles, - delegate (int i, DateTime? time) + delegate(int i, DateTime? time) { db._files[i].MTime = time; #if DEBUG - Log.Write( - " " + (time.HasValue ? time.Value.ToString() : "n/a") - ); + Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a")); #endif } ); @@ -1276,7 +1259,7 @@ internal class ArchiveReader // TODO: Check Signature! _header = new byte[0x20]; - for (var offset = 0; offset < 0x20;) + for (var offset = 0; offset < 0x20; ) { var delta = stream.Read(_header, offset, 0x20 - offset); if (delta == 0) @@ -1625,11 +1608,7 @@ internal class ArchiveReader var efi = extractFolderInfoVector.Last(); var startIndex = db._folderStartFileIndex[folderIndex]; - for ( - var index = efi._extractStatuses.Count; - index <= fileIndex - startIndex; - index++ - ) + for (var index = efi._extractStatuses.Count; index <= fileIndex - startIndex; index++) { efi._extractStatuses.Add(index == fileIndex - startIndex); } diff --git a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs index 234d4a1d..92e375aa 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs @@ -45,15 +45,9 @@ internal class SevenZipFilePart : FilePart { return null!; } - var folderStream = _database.GetFolderStream( - _stream, - Folder!, - _database.PasswordProvider - ); + var folderStream = _database.GetFolderStream(_stream, Folder!, _database.PasswordProvider); - var firstFileIndex = _database._folderStartFileIndex[ - _database._folders.IndexOf(Folder!) - ]; + var firstFileIndex = _database._folderStartFileIndex[_database._folders.IndexOf(Folder!)]; var skipCount = Index - firstFileIndex; long skipSize = 0; for (var i = 0; i < skipCount; i++) diff --git a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs index 78c2e0d9..5ae1b806 100644 --- a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs +++ b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs @@ -9,15 +9,7 @@ namespace SharpCompress.Common.Tar.Headers; internal sealed class TarHeader { - internal static readonly DateTime EPOCH = new DateTime( - 1970, - 1, - 1, - 0, - 0, - 0, - DateTimeKind.Utc - ); + internal static readonly DateTime EPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); public TarHeader(ArchiveEncoding archiveEncoding) { diff --git a/src/SharpCompress/Common/Tar/TarHeaderFactory.cs b/src/SharpCompress/Common/Tar/TarHeaderFactory.cs index 0edb7463..85eec5b4 100644 --- a/src/SharpCompress/Common/Tar/TarHeaderFactory.cs +++ b/src/SharpCompress/Common/Tar/TarHeaderFactory.cs @@ -29,19 +29,19 @@ internal static class TarHeaderFactory { case StreamingMode.Seekable: - { - header.DataStartPosition = reader.BaseStream.Position; + { + header.DataStartPosition = reader.BaseStream.Position; - //skip to nearest 512 - reader.BaseStream.Position += PadTo512(header.Size); - } - break; + //skip to nearest 512 + reader.BaseStream.Position += PadTo512(header.Size); + } + break; case StreamingMode.Streaming: - { - header.PackedStream = new TarReadOnlySubStream(stream, header.Size); - } - break; + { + header.PackedStream = new TarReadOnlySubStream(stream, header.Size); + } + break; default: { throw new InvalidFormatException("Invalid StreamingMode"); diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs index dc566482..fc2cb262 100644 --- a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs @@ -60,9 +60,7 @@ internal class DirectoryEntryHeader : ZipFileEntry Name = ((ExtraUnicodePathExtraField)unicodePathExtra).UnicodeName; } - var zip64ExtraData = Extra - .OfType() - .FirstOrDefault(); + var zip64ExtraData = Extra.OfType().FirstOrDefault(); if (zip64ExtraData != null) { zip64ExtraData.Process( diff --git a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs index 3cd8ce46..93cc55ac 100644 --- a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs @@ -50,9 +50,7 @@ internal class LocalEntryHeader : ZipFileEntry Name = ((ExtraUnicodePathExtraField)unicodePathExtra).UnicodeName; } - var zip64ExtraData = Extra - .OfType() - .FirstOrDefault(); + var zip64ExtraData = Extra.OfType().FirstOrDefault(); if (zip64ExtraData != null) { zip64ExtraData.Process(UncompressedSize, CompressedSize, 0, 0); diff --git a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs index 4920ca36..b230e9cc 100644 --- a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs +++ b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs @@ -61,11 +61,8 @@ internal sealed class ExtraUnicodePathExtraField : ExtraData internal sealed class Zip64ExtendedInformationExtraField : ExtraData { - public Zip64ExtendedInformationExtraField( - ExtraDataType type, - ushort length, - byte[] dataBytes - ) : base(type, length, dataBytes) { } + public Zip64ExtendedInformationExtraField(ExtraDataType type, ushort length, byte[] dataBytes) + : base(type, length, dataBytes) { } // From the spec, values are only in the extradata if the standard // value is set to 0xFFFFFFFF (or 0xFFFF for the Disk Start Number). @@ -105,9 +102,7 @@ internal sealed class Zip64ExtendedInformationExtraField : ExtraData if (compressedFileSize == uint.MaxValue) { - CompressedSize = BinaryPrimitives.ReadInt64LittleEndian( - DataBytes.AsSpan(currentIndex) - ); + CompressedSize = BinaryPrimitives.ReadInt64LittleEndian(DataBytes.AsSpan(currentIndex)); currentIndex += 8; } @@ -121,9 +116,7 @@ internal sealed class Zip64ExtendedInformationExtraField : ExtraData if (diskNumber == ushort.MaxValue) { - VolumeNumber = BinaryPrimitives.ReadUInt32LittleEndian( - DataBytes.AsSpan(currentIndex) - ); + VolumeNumber = BinaryPrimitives.ReadUInt32LittleEndian(DataBytes.AsSpan(currentIndex)); } } diff --git a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs index 7ac43a07..79347014 100644 --- a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs +++ b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs @@ -59,8 +59,7 @@ internal abstract class ZipFileEntry : ZipHeader var buffer = new byte[12]; archiveStream.ReadFully(buffer); - var encryptionData = - PkwareTraditionalEncryptionData.ForRead(Password!, this, buffer); + var encryptionData = PkwareTraditionalEncryptionData.ForRead(Password!, this, buffer); return encryptionData; } @@ -75,10 +74,9 @@ internal abstract class ZipFileEntry : ZipHeader protected void LoadExtra(byte[] extra) { - for (var i = 0; i < extra.Length - 4;) + for (var i = 0; i < extra.Length - 4; ) { - var type = (ExtraDataType) - BinaryPrimitives.ReadUInt16LittleEndian(extra.AsSpan(i)); + var type = (ExtraDataType)BinaryPrimitives.ReadUInt16LittleEndian(extra.AsSpan(i)); if (!Enum.IsDefined(typeof(ExtraDataType), type)) { type = ExtraDataType.NotImplementedExtraData; diff --git a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs index 485ad901..3e5cd808 100644 --- a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs @@ -30,10 +30,8 @@ internal class StreamingZipHeaderFactory : ZipHeaderFactory if ( _lastEntryHeader != null && ( - FlagUtility.HasFlag( - _lastEntryHeader.Flags, - HeaderFlags.UsePostDataDescriptor - ) || _lastEntryHeader.IsZip64 + FlagUtility.HasFlag(_lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor) + || _lastEntryHeader.IsZip64 ) ) { diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs index 54c64d16..4a8dbc2a 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs @@ -105,9 +105,7 @@ internal abstract class ZipFilePart : FilePart } case ZipCompressionMethod.WinzipAes: { - var data = Header.Extra.SingleOrDefault( - x => x.Type == ExtraDataType.WinZipAes - ); + var data = Header.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); if (data is null) { throw new InvalidFormatException("No Winzip AES extra data found."); @@ -116,9 +114,7 @@ internal abstract class ZipFilePart : FilePart { throw new InvalidFormatException("Winzip data length is not 7."); } - var compressedMethod = BinaryPrimitives.ReadUInt16LittleEndian( - data.DataBytes - ); + var compressedMethod = BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes); if (compressedMethod != 0x01 && compressedMethod != 0x02) { @@ -127,9 +123,7 @@ internal abstract class ZipFilePart : FilePart ); } - var vendorId = BinaryPrimitives.ReadUInt16LittleEndian( - data.DataBytes.AsSpan(2) - ); + var vendorId = BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(2)); if (vendorId != 0x4541) { throw new InvalidFormatException( @@ -144,9 +138,7 @@ internal abstract class ZipFilePart : FilePart } default: { - throw new NotSupportedException( - "CompressionMethod: " + Header.CompressionMethod - ); + throw new NotSupportedException("CompressionMethod: " + Header.CompressionMethod); } } } diff --git a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs index e7737cec..8a58e220 100644 --- a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs @@ -55,12 +55,7 @@ internal class ZipHeaderFactory } case POST_DATA_DESCRIPTOR: { - if ( - FlagUtility.HasFlag( - _lastEntryHeader!.Flags, - HeaderFlags.UsePostDataDescriptor - ) - ) + if (FlagUtility.HasFlag(_lastEntryHeader!.Flags, HeaderFlags.UsePostDataDescriptor)) { _lastEntryHeader.Crc = reader.ReadUInt32(); _lastEntryHeader.CompressedSize = zip64 diff --git a/src/SharpCompress/Compressors/ADC/ADCStream.cs b/src/SharpCompress/Compressors/ADC/ADCStream.cs index 9d57d1d7..313583db 100644 --- a/src/SharpCompress/Compressors/ADC/ADCStream.cs +++ b/src/SharpCompress/Compressors/ADC/ADCStream.cs @@ -1,4 +1,4 @@ -// +// // ADC.cs // // Author: @@ -66,10 +66,7 @@ public sealed class ADCStream : Stream /// /// Stream that contains the compressed data /// Must be set to because compression is not implemented - public ADCStream( - Stream stream, - CompressionMode compressionMode = CompressionMode.Decompress - ) + public ADCStream(Stream stream, CompressionMode compressionMode = CompressionMode.Decompress) { if (compressionMode == CompressionMode.Compress) { diff --git a/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs b/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs index 1c7aaeb4..852adc1e 100644 --- a/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs +++ b/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs @@ -14,11 +14,7 @@ public sealed class BZip2Stream : Stream /// The stream to read from /// Compression Mode /// Decompress Concatenated - public BZip2Stream( - Stream stream, - CompressionMode compressionMode, - bool decompressConcatenated - ) + public BZip2Stream(Stream stream, CompressionMode compressionMode, bool decompressConcatenated) { Mode = compressionMode; if (Mode == CompressionMode.Compress) diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs index 5f58b363..f53f48dc 100644 --- a/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs +++ b/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs @@ -342,8 +342,7 @@ internal class CBZip2InputStream : Stream CrcError(); } - computedCombinedCRC = - (computedCombinedCRC << 1) | (int)(((uint)computedCombinedCRC) >> 31); + computedCombinedCRC = (computedCombinedCRC << 1) | (int)(((uint)computedCombinedCRC) >> 31); computedCombinedCRC ^= computedBlockCRC; } @@ -631,15 +630,7 @@ internal class CBZip2InputStream : Stream minLen = len[t][i]; } } - HbCreateDecodeTables( - limit[t], - basev[t], - perm[t], - len[t], - minLen, - maxLen, - alphaSize - ); + HbCreateDecodeTables(limit[t], basev[t], perm[t], len[t], minLen, maxLen, alphaSize); minLens[t] = minLen; } } diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs index d2bf3448..2e79312e 100644 --- a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs +++ b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs @@ -1275,15 +1275,15 @@ internal sealed class CBZip2OutputStream : Stream unLo = ltLo = lo; unHi = gtHi = hi; + while (true) + { while (true) { - while (true) + if (unLo > unHi) { - if (unLo > unHi) - { - break; - } - n = block[zptr[unLo] + d + 1] - med; + break; + } + n = block[zptr[unLo] + d + 1] - med; if (n == 0) { var temp = 0; @@ -1311,30 +1311,30 @@ internal sealed class CBZip2OutputStream : Stream if (n == 0) { var temp = 0; - temp = zptr[unHi]; - zptr[unHi] = zptr[gtHi]; - zptr[gtHi] = temp; - gtHi--; - unHi--; - continue; - } - ; - if (n < 0) - { - break; - } + temp = zptr[unHi]; + zptr[unHi] = zptr[gtHi]; + zptr[gtHi] = temp; + gtHi--; unHi--; + continue; } - if (unLo > unHi) + ; + if (n < 0) { break; } - var tempx = zptr[unLo]; - zptr[unLo] = zptr[unHi]; - zptr[unHi] = tempx; - unLo++; unHi--; } + if (unLo > unHi) + { + break; + } + var tempx = zptr[unLo]; + zptr[unLo] = zptr[unHi]; + zptr[unHi] = tempx; + unLo++; + unHi--; + } if (gtHi < ltLo) { diff --git a/src/SharpCompress/Compressors/Deflate/DeflateManager.cs b/src/SharpCompress/Compressors/Deflate/DeflateManager.cs index f424b1a0..a7dff8b5 100644 --- a/src/SharpCompress/Compressors/Deflate/DeflateManager.cs +++ b/src/SharpCompress/Compressors/Deflate/DeflateManager.cs @@ -1150,19 +1150,12 @@ internal sealed partial class DeflateManager else if (static_lenb == opt_lenb) { send_bits((STATIC_TREES << 1) + (eof ? 1 : 0), 3); - send_compressed_block( - StaticTree.lengthAndLiteralsTreeCodes, - StaticTree.distTreeCodes - ); + send_compressed_block(StaticTree.lengthAndLiteralsTreeCodes, StaticTree.distTreeCodes); } else { send_bits((DYN_TREES << 1) + (eof ? 1 : 0), 3); - send_all_trees( - treeLiterals.max_code + 1, - treeDistances.max_code + 1, - max_blindex + 1 - ); + send_all_trees(treeLiterals.max_code + 1, treeDistances.max_code + 1, max_blindex + 1); send_compressed_block(dyn_ltree, dyn_dtree); } @@ -1352,10 +1345,8 @@ internal sealed partial class DeflateManager strstart++; ins_h = - ( - (ins_h << hash_shift) - ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff) - ) & hash_mask; + ((ins_h << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) + & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h]; hash_head = (head[ins_h] & 0xffff); @@ -1373,8 +1364,7 @@ internal sealed partial class DeflateManager match_length = 0; ins_h = window[strstart] & 0xff; - ins_h = - (((ins_h) << hash_shift) ^ (window[strstart + 1] & 0xff)) & hash_mask; + ins_h = (((ins_h) << hash_shift) ^ (window[strstart + 1] & 0xff)) & hash_mask; // If lookahead < MIN_MATCH, ins_h is garbage, but it does not // matter since it will be recomputed at next deflate call. @@ -1595,8 +1585,7 @@ internal sealed partial class DeflateManager int match; // matched string int len; // length of current match var best_len = prev_length; // best match length so far - var limit = - strstart > (w_size - MIN_LOOKAHEAD) ? strstart - (w_size - MIN_LOOKAHEAD) : 0; + var limit = strstart > (w_size - MIN_LOOKAHEAD) ? strstart - (w_size - MIN_LOOKAHEAD) : 0; var niceLength = config.NiceLength; @@ -1651,8 +1640,7 @@ internal sealed partial class DeflateManager // We check for insufficient lookahead only every 8th comparison; // the 256th check will be made at strstart+258. - do - { } while ( + do { } while ( window[++scan] == window[++match] && window[++scan] == window[++match] && window[++scan] == window[++match] @@ -1678,9 +1666,7 @@ internal sealed partial class DeflateManager scan_end1 = window[scan + best_len - 1]; scan_end = window[scan + best_len]; } - } while ( - (cur_match = (prev[cur_match & wmask] & 0xffff)) > limit && --chain_length != 0 - ); + } while ((cur_match = (prev[cur_match & wmask] & 0xffff)) > limit && --chain_length != 0); if (best_len <= lookahead) { @@ -1890,8 +1876,7 @@ internal sealed partial class DeflateManager for (var n = 0; n <= length - MIN_MATCH; n++) { - ins_h = - (((ins_h) << hash_shift) ^ (window[(n) + (MIN_MATCH - 1)] & 0xff)) & hash_mask; + ins_h = (((ins_h) << hash_shift) ^ (window[(n) + (MIN_MATCH - 1)] & 0xff)) & hash_mask; prev[n & w_mask] = head[ins_h]; head[ins_h] = (short)n; } @@ -1917,9 +1902,7 @@ internal sealed partial class DeflateManager } if (_codec.AvailableBytesOut == 0) { - _codec.Message = _ErrorMessage[ - ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_BUF_ERROR) - ]; + _codec.Message = _ErrorMessage[ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_BUF_ERROR)]; throw new ZlibException("OutputBuffer is full (AvailableBytesOut == 0)"); //return ZlibConstants.Z_BUF_ERROR; @@ -2006,9 +1989,7 @@ internal sealed partial class DeflateManager // User must not provide more input after the first FINISH: if (status == FINISH_STATE && _codec.AvailableBytesIn != 0) { - _codec.Message = _ErrorMessage[ - ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_BUF_ERROR) - ]; + _codec.Message = _ErrorMessage[ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_BUF_ERROR)]; throw new ZlibException("status == FINISH_STATE && _codec.AvailableBytesIn != 0"); } diff --git a/src/SharpCompress/Compressors/Deflate/InfTree.cs b/src/SharpCompress/Compressors/Deflate/InfTree.cs index 89f02d7a..74f4069d 100644 --- a/src/SharpCompress/Compressors/Deflate/InfTree.cs +++ b/src/SharpCompress/Compressors/Deflate/InfTree.cs @@ -2187,13 +2187,7 @@ internal sealed class InfTree return Z_OK; } - internal static int inflate_trees_fixed( - int[] bl, - int[] bd, - int[][] tl, - int[][] td, - ZlibCodec z - ) + internal static int inflate_trees_fixed(int[] bl, int[] bd, int[][] tl, int[][] td, ZlibCodec z) { bl[0] = fixed_bl; bd[0] = fixed_bd; diff --git a/src/SharpCompress/Compressors/Deflate/Inflate.cs b/src/SharpCompress/Compressors/Deflate/Inflate.cs index 91bea79e..abeebb32 100644 --- a/src/SharpCompress/Compressors/Deflate/Inflate.cs +++ b/src/SharpCompress/Compressors/Deflate/Inflate.cs @@ -562,10 +562,7 @@ internal sealed class InflateBlocks i = index; t = table; - if ( - i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) - || (c == 16 && i < 1) - ) + if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) { blens = null; mode = InflateBlockMode.BAD; @@ -781,10 +778,7 @@ internal sealed class InflateBlocks // update check information if (checkfn != null) { - _codec._adler32 = check = Adler32.Calculate( - check, - window.AsSpan(readAt, nBytes) - ); + _codec._adler32 = check = Adler32.Calculate(check, window.AsSpan(readAt, nBytes)); } // copy as far as end of window @@ -983,8 +977,7 @@ internal sealed class InflateCodes { // Handling missing trailing bit(s) var tmp_tindex = - (tree_index + (b & InternalInflateConstants.InflateMask[k])) - * 3; + (tree_index + (b & InternalInflateConstants.InflateMask[k])) * 3; if (k >= tree[tmp_tindex + 1]) { break; @@ -1098,8 +1091,7 @@ internal sealed class InflateCodes { // Handling missing trailing bit(s) var tmp_tindex = - (tree_index + (b & InternalInflateConstants.InflateMask[k])) - * 3; + (tree_index + (b & InternalInflateConstants.InflateMask[k])) * 3; if (k >= tree[tmp_tindex + 1]) { break; @@ -1209,10 +1201,7 @@ internal sealed class InflateCodes if (q == blocks.end && blocks.readAt != 0) { q = 0; - m = - q < blocks.readAt - ? blocks.readAt - q - 1 - : blocks.end - q; + m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) diff --git a/src/SharpCompress/Compressors/Deflate/Tree.cs b/src/SharpCompress/Compressors/Deflate/Tree.cs index 7056e7a0..25f8ada3 100644 --- a/src/SharpCompress/Compressors/Deflate/Tree.cs +++ b/src/SharpCompress/Compressors/Deflate/Tree.cs @@ -960,9 +960,7 @@ internal sealed partial class DeflateManager /// internal static int DistanceCode(int dist) { - return (dist < 256) - ? _dist_code[dist] - : _dist_code[256 + SharedUtils.URShift(dist, 7)]; + return (dist < 256) ? _dist_code[dist] : _dist_code[256 + SharedUtils.URShift(dist, 7)]; } // Compute the optimal bit lengths for a tree and update the total bit length diff --git a/src/SharpCompress/Compressors/Deflate/Zlib.cs b/src/SharpCompress/Compressors/Deflate/Zlib.cs index 0c5865fb..00336548 100644 --- a/src/SharpCompress/Compressors/Deflate/Zlib.cs +++ b/src/SharpCompress/Compressors/Deflate/Zlib.cs @@ -234,12 +234,7 @@ internal class SharedUtils /// count depending on the data available in the source TextReader. Returns -1 /// if the end of the stream is reached. /// - public static int ReadInput( - TextReader sourceTextReader, - byte[] target, - int start, - int count - ) + public static int ReadInput(TextReader sourceTextReader, byte[] target, int start, int count) { // Returns 0 bytes if not enough space in target if (target.Length == 0) diff --git a/src/SharpCompress/Compressors/Deflate64/DeflateInput.cs b/src/SharpCompress/Compressors/Deflate64/DeflateInput.cs index f539e3bb..b4e8fc82 100644 --- a/src/SharpCompress/Compressors/Deflate64/DeflateInput.cs +++ b/src/SharpCompress/Compressors/Deflate64/DeflateInput.cs @@ -34,7 +34,7 @@ internal sealed class DeflateInput } internal /*readonly */ -readonly struct InputState + readonly struct InputState { internal readonly int _count; internal readonly int _startIndex; diff --git a/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs b/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs index a4890899..7b11812e 100644 --- a/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs +++ b/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs @@ -468,8 +468,7 @@ internal sealed class InflaterManaged _blockLengthBuffer[_state - InflaterState.UncompressedByte1] = (byte)bits; if (_state == InflaterState.UncompressedByte4) { - _blockLength = - _blockLengthBuffer[0] + (_blockLengthBuffer[1] * 256); + _blockLength = _blockLengthBuffer[0] + (_blockLengthBuffer[1] * 256); var blockLengthComplement = _blockLengthBuffer[2] + (_blockLengthBuffer[3] * 256); diff --git a/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs b/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs index 8dffc4d5..83260180 100644 --- a/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs +++ b/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs @@ -64,11 +64,7 @@ public sealed class BranchExecFilter mask >>= (int)d; if ( mask != 0 - && ( - mask > 4 - || mask == 3 - || (((((data[(mask >> 1) + 1])) + 1) & 0xFE) == 0) - ) + && (mask > 4 || mask == 3 || (((((data[(mask >> 1) + 1])) + 1) & 0xFE) == 0)) ) { mask = (mask >> 1) | 4; @@ -253,10 +249,8 @@ public sealed class BranchExecFilter var iterator = (i + (m * 5) - 8); if ( ((data[iterator + 3] >> (int)m) & 15) == 5 - && ( - ((data[iterator - 1] | ((uint)data[iterator] << 8)) >> (int)m) - & 0x70 - ) == 0 + && (((data[iterator - 1] | ((uint)data[iterator] << 8)) >> (int)m) & 0x70) + == 0 ) { var raw = BitConverter.ToUInt32(data, (int)iterator); diff --git a/src/SharpCompress/Compressors/LZMA/DecoderStream.cs b/src/SharpCompress/Compressors/LZMA/DecoderStream.cs index 11c62528..2b2e20b4 100644 --- a/src/SharpCompress/Compressors/LZMA/DecoderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/DecoderStream.cs @@ -145,10 +145,7 @@ internal static class DecoderStreamHelper ); } - var otherCoderIndex = FindCoderIndexForOutStreamIndex( - folderInfo, - pairedOutIndex - ); + var otherCoderIndex = FindCoderIndexForOutStreamIndex(folderInfo, pairedOutIndex); inStreams[i] = CreateDecoderStream( packStreams, packSizes, @@ -215,7 +212,11 @@ internal static class DecoderStreamHelper var outStreams = new Stream[folderInfo._unpackSizes.Count]; - FindPrimaryOutStreamIndex(folderInfo, out var primaryCoderIndex, out var primaryOutStreamIndex); + FindPrimaryOutStreamIndex( + folderInfo, + out var primaryCoderIndex, + out var primaryOutStreamIndex + ); return CreateDecoderStream( inStreams, packSizes, diff --git a/src/SharpCompress/Compressors/LZMA/ICoder.cs b/src/SharpCompress/Compressors/LZMA/ICoder.cs index c0fd198b..569568f5 100644 --- a/src/SharpCompress/Compressors/LZMA/ICoder.cs +++ b/src/SharpCompress/Compressors/LZMA/ICoder.cs @@ -53,13 +53,7 @@ internal interface ICoder /// /// callback progress reference. /// - void Code( - Stream inStream, - Stream outStream, - long inSize, - long outSize, - ICodeProgress progress - ); + void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress); } /* diff --git a/src/SharpCompress/Compressors/LZMA/LZipStream.cs b/src/SharpCompress/Compressors/LZMA/LZipStream.cs index 5d799619..d55f8d7e 100644 --- a/src/SharpCompress/Compressors/LZMA/LZipStream.cs +++ b/src/SharpCompress/Compressors/LZMA/LZipStream.cs @@ -124,8 +124,7 @@ public sealed class LZipStream : Stream public override int ReadByte() => _stream.ReadByte(); - public override long Seek(long offset, SeekOrigin origin) => - throw new NotSupportedException(); + public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); public override void SetLength(long value) => throw new NotImplementedException(); diff --git a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs index 8889dd68..e22fbaf3 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs @@ -13,12 +13,8 @@ public class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream { private BitDecoder _choice = new BitDecoder(); private BitDecoder _choice2 = new BitDecoder(); - private readonly BitTreeDecoder[] _lowCoder = new BitTreeDecoder[ - Base.K_NUM_POS_STATES_MAX - ]; - private readonly BitTreeDecoder[] _midCoder = new BitTreeDecoder[ - Base.K_NUM_POS_STATES_MAX - ]; + private readonly BitTreeDecoder[] _lowCoder = new BitTreeDecoder[Base.K_NUM_POS_STATES_MAX]; + private readonly BitTreeDecoder[] _midCoder = new BitTreeDecoder[Base.K_NUM_POS_STATES_MAX]; private BitTreeDecoder _highCoder = new BitTreeDecoder(Base.K_NUM_HIGH_LEN_BITS); private uint _numPosStates; @@ -163,10 +159,7 @@ public class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream byte matchByte ) { - return _coders[GetState(pos, prevByte)].DecodeWithMatchByte( - rangeDecoder, - matchByte - ); + return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); } } @@ -413,9 +406,7 @@ public class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream _rep1 = _rep0; len = Base.K_MATCH_MIN_LEN + _lenDecoder.Decode(rangeDecoder, posState); _state.UpdateMatch(); - var posSlot = _posSlotDecoder[Base.GetLenToPosState(len)].Decode( - rangeDecoder - ); + var posSlot = _posSlotDecoder[Base.GetLenToPosState(len)].Decode(rangeDecoder); if (posSlot >= Base.K_START_POS_MODEL_INDEX) { var numDirectBits = (int)((posSlot >> 1) - 1); @@ -432,9 +423,8 @@ public class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream else { _rep0 += ( - rangeDecoder.DecodeDirectBits( - numDirectBits - Base.K_NUM_ALIGN_BITS - ) << Base.K_NUM_ALIGN_BITS + rangeDecoder.DecodeDirectBits(numDirectBits - Base.K_NUM_ALIGN_BITS) + << Base.K_NUM_ALIGN_BITS ); _rep0 += _posAlignDecoder.ReverseDecode(rangeDecoder); } diff --git a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs index be1e8a08..1495ec2c 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs @@ -108,11 +108,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties } } - public void EncodeMatched( - RangeCoder.Encoder rangeEncoder, - byte matchByte, - byte symbol - ) + public void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) { uint context = 1; var same = true; @@ -278,8 +274,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties { return; } - prices[st + i] = - b0 + _midCoder[posState].GetPrice(i - Base.K_NUM_LOW_LEN_SYMBOLS); + prices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.K_NUM_LOW_LEN_SYMBOLS); } for (; i < numSymbols; i++) { @@ -569,9 +564,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties private uint GetRepLen1Price(Base.State state, uint posState) { return _isRepG0[state._index].GetPrice0() - + _isRep0Long[ - (state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState - ].GetPrice0(); + + _isRep0Long[(state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice0(); } private uint GetPureRepPrice(uint repIndex, Base.State state, uint posState) @@ -786,8 +779,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties var price = repMatchPrice + GetPureRepPrice(i, _state, posState); do { - var curAndLenPrice = - price + _repMatchLenEncoder.GetPrice(repLen - 2, posState); + var curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState); var optimum = _optimum[repLen]; if (curAndLenPrice < optimum._price) { @@ -812,8 +804,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties for (; ; len++) { var distance = _matchDistances[offs + 1]; - var curAndLenPrice = - normalMatchPrice + GetPosLenPrice(distance, len, posState); + var curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState); var optimum = _optimum[len]; if (curAndLenPrice < optimum._price) { @@ -964,9 +955,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties var curAnd1Price = curPrice - + _isMatch[ - (state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState - ].GetPrice0() + + _isMatch[(state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice0() + _literalEncoder .GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)) .GetPrice(!state.IsCharState(), matchByte, currentByte); @@ -984,9 +973,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties matchPrice = curPrice - + _isMatch[ - (state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState - ].GetPrice1(); + + _isMatch[(state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice1(); repMatchPrice = matchPrice + _isRep[state._index].GetPrice1(); if ( @@ -1057,11 +1044,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties for (uint repIndex = 0; repIndex < Base.K_NUM_REP_DISTANCES; repIndex++) { - var lenTest = _matchFinder.GetMatchLen( - 0 - 1, - _reps[repIndex], - numAvailableBytes - ); + var lenTest = _matchFinder.GetMatchLen(0 - 1, _reps[repIndex], numAvailableBytes); if (lenTest < 2) { continue; @@ -1095,11 +1078,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties if (lenTest < numAvailableBytesFull) { var t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes); - var lenTest2 = _matchFinder.GetMatchLen( - (int)lenTest, - _reps[repIndex], - t - ); + var lenTest2 = _matchFinder.GetMatchLen((int)lenTest, _reps[repIndex], t); if (lenTest2 >= 2) { var state2 = state; @@ -1130,8 +1109,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties + _isMatch[ (state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + posStateNext ].GetPrice1(); - var nextRepMatchPrice = - nextMatchPrice + _isRep[state2._index].GetPrice1(); + var nextRepMatchPrice = nextMatchPrice + _isRep[state2._index].GetPrice1(); // for(; lenTest2 >= 2; lenTest2--) { @@ -1141,8 +1119,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties _optimum[++lenEnd]._price = K_IFINITY_PRICE; } var curAndLenPrice = - nextRepMatchPrice - + GetRepPrice(0, lenTest2, state2, posStateNext); + nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext); var optimum = _optimum[cur + offset]; if (curAndLenPrice < optimum._price) { @@ -1205,15 +1182,8 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties { if (lenTest < numAvailableBytesFull) { - var t = Math.Min( - numAvailableBytesFull - 1 - lenTest, - _numFastBytes - ); - var lenTest2 = _matchFinder.GetMatchLen( - (int)lenTest, - curBack, - t - ); + var t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes); + var lenTest2 = _matchFinder.GetMatchLen((int)lenTest, curBack, t); if (lenTest2 >= 2) { var state2 = state; @@ -1410,10 +1380,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties { _isMatch[complexState].Encode(_rangeEncoder, 0); var curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset)); - var subCoder = _literalEncoder.GetSubCoder( - (uint)_nowPos64, - _previousByte - ); + var subCoder = _literalEncoder.GetSubCoder((uint)_nowPos64, _previousByte); if (!_state.IsCharState()) { var matchByte = _matchFinder.GetIndexByte( @@ -1729,11 +1696,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties ); } - for ( - uint lenToPosState = 0; - lenToPosState < Base.K_NUM_LEN_TO_POS_STATES; - lenToPosState++ - ) + for (uint lenToPosState = 0; lenToPosState < Base.K_NUM_LEN_TO_POS_STATES; lenToPosState++) { uint posSlot; var encoder = _posSlotEncoder[lenToPosState]; @@ -1858,11 +1821,7 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties } _dictionarySize = (uint)dictionarySize; int dicLogSize; - for ( - dicLogSize = 0; - dicLogSize < (uint)kDicLogSizeMaxCompress; - dicLogSize++ - ) + for (dicLogSize = 0; dicLogSize < (uint)kDicLogSizeMaxCompress; dicLogSize++) { if (dictionarySize <= ((uint)(1) << dicLogSize)) { diff --git a/src/SharpCompress/Compressors/LZMA/LzmaStream.cs b/src/SharpCompress/Compressors/LZMA/LzmaStream.cs index 108381e5..aa7a42c9 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaStream.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaStream.cs @@ -194,9 +194,7 @@ public class LzmaStream : Stream { _inputPosition += _outWindow.CopyStream(_inputStream, toProcess); } - else if ( - _decoder.Code(_dictionarySize, _outWindow, _rangeDecoder) && _outputSize < 0 - ) + else if (_decoder.Code(_dictionarySize, _outWindow, _rangeDecoder) && _outputSize < 0) { _availableBytes = _outWindow.AvailableBytes; } diff --git a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBit.cs b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBit.cs index 15827a54..2123f204 100644 --- a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBit.cs +++ b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBit.cs @@ -135,8 +135,7 @@ internal struct BitDecoder _prob -= (_prob) >> K_NUM_MOVE_BITS; if (rangeDecoder._range < Decoder.K_TOP_VALUE) { - rangeDecoder._code = - (rangeDecoder._code << 8) | (byte)rangeDecoder._stream.ReadByte(); + rangeDecoder._code = (rangeDecoder._code << 8) | (byte)rangeDecoder._stream.ReadByte(); rangeDecoder._range <<= 8; rangeDecoder._total++; } diff --git a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBitTree.cs b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBitTree.cs index cef8872c..b6a66e82 100644 --- a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBitTree.cs +++ b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBitTree.cs @@ -22,7 +22,7 @@ internal readonly struct BitTreeEncoder public void Encode(Encoder rangeEncoder, uint symbol) { uint m = 1; - for (var bitIndex = _numBitLevels; bitIndex > 0;) + for (var bitIndex = _numBitLevels; bitIndex > 0; ) { bitIndex--; var bit = (symbol >> bitIndex) & 1; @@ -47,7 +47,7 @@ internal readonly struct BitTreeEncoder { uint price = 0; uint m = 1; - for (var bitIndex = _numBitLevels; bitIndex > 0;) + for (var bitIndex = _numBitLevels; bitIndex > 0; ) { bitIndex--; var bit = (symbol >> bitIndex) & 1; diff --git a/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs b/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs index 1eb8ae3d..1675acf7 100644 --- a/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs +++ b/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs @@ -367,10 +367,7 @@ internal class ModelPpm { _orderFall++; _minContext.Address = _minContext.GetSuffix(); // =MinContext->Suffix; - if ( - _minContext.Address <= SubAlloc.PText - || _minContext.Address > SubAlloc.HeapEnd - ) + if (_minContext.Address <= SubAlloc.PText || _minContext.Address > SubAlloc.HeapEnd) { return (-1); } @@ -683,11 +680,10 @@ internal class ModelPpm // .getSummFreq() <= 8 * ns1) ? 1 : 0)); var sum = ((2 * ns1 < ns) ? 1 : 0) - + (2 - * ( - ((4 * ns1 <= ns) ? 1 : 0) - & ((pc.FreqData.SummFreq <= 8 * ns1) ? 1 : 0) - )); + + ( + 2 + * (((4 * ns1 <= ns) ? 1 : 0) & ((pc.FreqData.SummFreq <= 8 * ns1) ? 1 : 0)) + ); pc.FreqData.IncrementSummFreq(sum); } else @@ -719,11 +715,7 @@ internal class ModelPpm } else { - cf = - 4 - + (cf >= 9 * sf ? 1 : 0) - + (cf >= 12 * sf ? 1 : 0) - + (cf >= 15 * sf ? 1 : 0); + cf = 4 + (cf >= 9 * sf ? 1 : 0) + (cf >= 12 * sf ? 1 : 0) + (cf >= 15 * sf ? 1 : 0); pc.FreqData.IncrementSummFreq(cf); } p.Address = pc.FreqData.GetStats() + (ns1 * State.SIZE); @@ -926,10 +918,7 @@ internal class ModelPpm { _orderFall++; _minContext.Address = _minContext.GetSuffix(); - if ( - _minContext.Address <= SubAlloc.PText - || _minContext.Address > SubAlloc.HeapEnd - ) + if (_minContext.Address <= SubAlloc.PText || _minContext.Address > SubAlloc.HeapEnd) { return -1; } diff --git a/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs b/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs index 52768984..b27da093 100644 --- a/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs +++ b/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs @@ -24,8 +24,7 @@ internal class PpmContext : Pointer { if (Memory != null) { - _numStats = - BinaryPrimitives.ReadInt16LittleEndian(Memory.AsSpan(Address)) & 0xffff; + _numStats = BinaryPrimitives.ReadInt16LittleEndian(Memory.AsSpan(Address)) & 0xffff; } return _numStats; } @@ -61,25 +60,7 @@ internal class PpmContext : Pointer private int _suffix; // pointer ppmcontext //UPGRADE_NOTE: Final was removed from the declaration of 'ExpEscape'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" - public static readonly int[] EXP_ESCAPE = - { - 25, - 14, - 9, - 7, - 5, - 5, - 4, - 4, - 4, - 3, - 3, - 3, - 2, - 2, - 2, - 2 - }; + public static readonly int[] EXP_ESCAPE = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 }; // Temp fields //UPGRADE_NOTE: Final was removed from the declaration of 'tempState1 '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" diff --git a/src/SharpCompress/Compressors/PPMd/H/RarMemBlock.cs b/src/SharpCompress/Compressors/PPMd/H/RarMemBlock.cs index f3f7b147..cdf8cef8 100644 --- a/src/SharpCompress/Compressors/PPMd/H/RarMemBlock.cs +++ b/src/SharpCompress/Compressors/PPMd/H/RarMemBlock.cs @@ -21,8 +21,7 @@ internal class RarMemBlock : Pointer { if (Memory != null) { - _stamp = - BinaryPrimitives.ReadInt16LittleEndian(Memory.AsSpan(Address)) & 0xffff; + _stamp = BinaryPrimitives.ReadInt16LittleEndian(Memory.AsSpan(Address)) & 0xffff; } return _stamp; } diff --git a/src/SharpCompress/Compressors/PPMd/H/State.cs b/src/SharpCompress/Compressors/PPMd/H/State.cs index 3aa9b20f..186476c3 100644 --- a/src/SharpCompress/Compressors/PPMd/H/State.cs +++ b/src/SharpCompress/Compressors/PPMd/H/State.cs @@ -71,17 +71,17 @@ internal sealed class State : Pointer return this; } - internal static void PpmdSwap(State ptr1, State ptr2) + internal static void PpmdSwap(State ptr1, State ptr2) + { + byte[] mem1 = ptr1.Memory, + mem2 = ptr2.Memory; + for (int i = 0, pos1 = ptr1.Address, pos2 = ptr2.Address; i < SIZE; i++, pos1++, pos2++) { - byte[] mem1 = ptr1.Memory, - mem2 = ptr2.Memory; - for (int i = 0, pos1 = ptr1.Address, pos2 = ptr2.Address; i < SIZE; i++, pos1++, pos2++) - { - var temp = mem1[pos1]; - mem1[pos1] = mem2[pos2]; - mem2[pos2] = temp; - } + var temp = mem1[pos1]; + mem1[pos1] = mem2[pos2]; + mem2[pos2] = temp; } + } public override string ToString() { diff --git a/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs b/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs index a3757715..43aaeca2 100644 --- a/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs +++ b/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs @@ -247,11 +247,7 @@ internal class SubAllocator p.Address = s0.GetNext(); while (p.Address != s0.Address) { - for ( - p.Remove(), sz = p.GetNu(); - sz > 128; - sz -= 128, p.Address = MbPtr(p.Address, 128) - ) + for (p.Remove(), sz = p.GetNu(); sz > 128; sz -= 128, p.Address = MbPtr(p.Address, 128)) { InsertNode(p.Address, N_INDEXES - 1); } diff --git a/src/SharpCompress/Compressors/PPMd/I1/Allocator.cs b/src/SharpCompress/Compressors/PPMd/I1/Allocator.cs index 6f66e310..ac270a3d 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/Allocator.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/Allocator.cs @@ -338,11 +338,7 @@ internal class Allocator for (uint index = 0; index < INDEX_COUNT; index++) { - for ( - memoryNode = _memoryNodes[index]; - counts[index] != 0; - memoryNode = memoryNode.Next - ) + for (memoryNode = _memoryNodes[index]; counts[index] != 0; memoryNode = memoryNode.Next) { while (memoryNode.Next.Stamp == 0) { @@ -435,8 +431,7 @@ internal class Allocator if (memoryNode0.UnitCount != 0) { while ( - (memoryNode2 = memoryNode0 + memoryNode0.UnitCount).Stamp - == uint.MaxValue + (memoryNode2 = memoryNode0 + memoryNode0.UnitCount).Stamp == uint.MaxValue ) { memoryNode0.UnitCount += memoryNode2.UnitCount; diff --git a/src/SharpCompress/Compressors/PPMd/I1/Coder.cs b/src/SharpCompress/Compressors/PPMd/I1/Coder.cs index c1644521..75a4e65b 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/Coder.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/Coder.cs @@ -35,8 +35,7 @@ internal class Coder { while ( (_low ^ (_low + _range)) < RANGE_TOP - || _range < RANGE_BOTTOM - && ((_range = (uint)-_low & (RANGE_BOTTOM - 1)) != 0 || true) + || _range < RANGE_BOTTOM && ((_range = (uint)-_low & (RANGE_BOTTOM - 1)) != 0 || true) ) { stream.WriteByte((byte)(_low >> 24)); @@ -81,8 +80,7 @@ internal class Coder { while ( (_low ^ (_low + _range)) < RANGE_TOP - || _range < RANGE_BOTTOM - && ((_range = (uint)-_low & (RANGE_BOTTOM - 1)) != 0 || true) + || _range < RANGE_BOTTOM && ((_range = (uint)-_low & (RANGE_BOTTOM - 1)) != 0 || true) ) { _code = (_code << 8) | (byte)stream.ReadByte(); diff --git a/src/SharpCompress/Compressors/PPMd/I1/Model.cs b/src/SharpCompress/Compressors/PPMd/I1/Model.cs index aebfcae8..f630aced 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/Model.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/Model.cs @@ -853,11 +853,7 @@ internal partial class Model } else { - Refresh( - (uint)((currentContext.NumberStatistics + 3) >> 1), - false, - currentContext - ); + Refresh((uint)((currentContext.NumberStatistics + 3) >> 1), false, currentContext); } } @@ -870,24 +866,17 @@ internal partial class Model ); } else if ( - (currentContext.SummaryFrequency += 4) - > 128 + (4 * currentContext.NumberStatistics) + (currentContext.SummaryFrequency += 4) > 128 + (4 * currentContext.NumberStatistics) ) { - Refresh( - (uint)((currentContext.NumberStatistics + 2) >> 1), - true, - currentContext - ); + Refresh((uint)((currentContext.NumberStatistics + 2) >> 1), true, currentContext); } } if (_method > ModelRestorationMethod.Freeze) { _maximumContext = foundStateSuccessor; - _allocator._glueCount += (uint)( - ((_allocator._memoryNodes[1].Stamp & 1) == 0) ? 1 : 0 - ); + _allocator._glueCount += (uint)(((_allocator._memoryNodes[1].Stamp & 1) == 0) ? 1 : 0); } else if (_method == ModelRestorationMethod.Freeze) { diff --git a/src/SharpCompress/Compressors/PPMd/I1/Pointer.cs b/src/SharpCompress/Compressors/PPMd/I1/Pointer.cs index 791a556d..48fa7fff 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/Pointer.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/Pointer.cs @@ -46,9 +46,7 @@ internal struct Pointer #if DEBUG if (_address == 0) { - throw new InvalidOperationException( - "The pointer being indexed is a null pointer." - ); + throw new InvalidOperationException("The pointer being indexed is a null pointer."); } #endif return _memory[_address + offset]; @@ -58,9 +56,7 @@ internal struct Pointer #if DEBUG if (_address == 0) { - throw new InvalidOperationException( - "The pointer being indexed is a null pointer." - ); + throw new InvalidOperationException("The pointer being indexed is a null pointer."); } #endif _memory[_address + offset] = value; @@ -143,9 +139,7 @@ internal struct Pointer #if DEBUG if (pointer._address == 0) { - throw new InvalidOperationException( - "The pointer being incremented is a null pointer." - ); + throw new InvalidOperationException("The pointer being incremented is a null pointer."); } #endif pointer._address++; @@ -198,9 +192,7 @@ internal struct Pointer #if DEBUG if (pointer._address == 0) { - throw new InvalidOperationException( - "The pointer being decremented is a null pointer." - ); + throw new InvalidOperationException("The pointer being decremented is a null pointer."); } #endif pointer._address--; diff --git a/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs b/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs index 3e122032..9df07688 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs @@ -402,7 +402,7 @@ internal partial class Model _coder._lowCount = lowCount; lowCount += state.Frequency; _coder._highCount = lowCount; - for (var p1 = state; --index != 0;) + for (var p1 = state; --index != 0; ) { do { diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs index 08ba47f2..08f0ddeb 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs @@ -555,11 +555,7 @@ internal sealed partial class Unpack : BitInput, IRarUnpack } // memcpy(&ParentPrg->GlobalData[VM_FIXEDGLOBALSIZE],&Prg->GlobalData[VM_FIXEDGLOBALSIZE],Prg->GlobalData.Size()-VM_FIXEDGLOBALSIZE); - for ( - var i = 0; - i < Prg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; - i++ - ) + for (var i = 0; i < Prg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; i++) { ParentPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = Prg.GlobalData[ RarVM.VM_FIXEDGLOBALSIZE + i @@ -621,8 +617,9 @@ internal sealed partial class Unpack : BitInput, IRarUnpack i++ ) { - NextPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = - pPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i]; + NextPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = pPrg.GlobalData[ + RarVM.VM_FIXEDGLOBALSIZE + i + ]; } } @@ -643,8 +640,9 @@ internal sealed partial class Unpack : BitInput, IRarUnpack i++ ) { - pPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = - NextPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i]; + pPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = NextPrg.GlobalData[ + RarVM.VM_FIXEDGLOBALSIZE + i + ]; } } else @@ -758,11 +756,7 @@ internal sealed partial class Unpack : BitInput, IRarUnpack var destPtr = unpPtr - distance; // System.out.println(unpPtr+":"+distance); - if ( - destPtr >= 0 - && destPtr < PackDef.MAXWINSIZE - 260 - && unpPtr < PackDef.MAXWINSIZE - 260 - ) + if (destPtr >= 0 && destPtr < PackDef.MAXWINSIZE - 260 && unpPtr < PackDef.MAXWINSIZE - 260) { window[unpPtr++] = window[destPtr++]; @@ -931,7 +925,7 @@ internal sealed partial class Unpack : BitInput, IRarUnpack var TableSize = PackDef.HUFF_TABLE_SIZE; - for (var i = 0; i < TableSize;) + for (var i = 0; i < TableSize; ) { if (inAddr > readTop - 5) { diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack15.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack15.cs index c0257809..bac545db 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack15.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack15.cs @@ -181,25 +181,7 @@ internal partial class Unpack private static readonly int[] PosHf4 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0 }; - private static readonly int[] ShortLen1 = - { - 1, - 3, - 4, - 4, - 5, - 6, - 7, - 8, - 8, - 4, - 4, - 5, - 6, - 6, - 4, - 0 - }; + private static readonly int[] ShortLen1 = { 1, 3, 4, 4, 5, 6, 7, 8, 8, 4, 4, 5, 6, 6, 4, 0 }; private static readonly int[] ShortXor1 = { @@ -220,25 +202,7 @@ internal partial class Unpack 0xb0 }; - private static readonly int[] ShortLen2 = - { - 2, - 3, - 3, - 3, - 4, - 4, - 5, - 6, - 6, - 4, - 4, - 5, - 6, - 6, - 4, - 0 - }; + private static readonly int[] ShortLen2 = { 2, 3, 3, 3, 4, 4, 5, 6, 6, 4, 4, 5, 6, 6, 4, 0 }; private static readonly int[] ShortXor2 = { diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs index 1b882545..15b980da 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs @@ -492,12 +492,7 @@ internal partial class Unpack { UnpackUtility.makeDecodeTables(Table, 0, LD, PackDef.NC20); UnpackUtility.makeDecodeTables(Table, PackDef.NC20, DD, PackDef.DC20); - UnpackUtility.makeDecodeTables( - Table, - PackDef.NC20 + PackDef.DC20, - RD, - PackDef.RC20 - ); + UnpackUtility.makeDecodeTables(Table, PackDef.NC20 + PackDef.DC20, RD, PackDef.RC20); } // memcpy(UnpOldTable20,Table,sizeof(UnpOldTable20)); diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs index 553e1896..52757e12 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs @@ -430,8 +430,7 @@ internal partial class Unpack // If distance to filter start is that large that due to circular dictionary // mode now it points to old not written yet data, then we set 'NextWindow' // flag and process this filter only after processing that older data. - Filter.NextWindow = - WrPtr != UnpPtr && ((WrPtr - UnpPtr) & MaxWinMask) <= Filter.BlockStart; + Filter.NextWindow = WrPtr != UnpPtr && ((WrPtr - UnpPtr) & MaxWinMask) <= Filter.BlockStart; Filter.uBlockStart = (uint)((Filter.BlockStart + UnpPtr) & MaxWinMask); Filters.Add(Filter); @@ -490,10 +489,7 @@ internal partial class Unpack { // We may need to quit from main extraction loop and read new block header // and trees earlier than data in input buffer ends. - ReadBorder = Math.Min( - ReadBorder, - BlockHeader.BlockStart + BlockHeader.BlockSize - 1 - ); + ReadBorder = Math.Min(ReadBorder, BlockHeader.BlockStart + BlockHeader.BlockSize - 1); } return ReadCode != -1; } @@ -821,9 +817,7 @@ internal partial class Unpack } Header.BlockSize = BlockSize; - var CheckSum = (byte)( - 0x5a ^ BlockFlags ^ BlockSize ^ (BlockSize >> 8) ^ (BlockSize >> 16) - ); + var CheckSum = (byte)(0x5a ^ BlockFlags ^ BlockSize ^ (BlockSize >> 8) ^ (BlockSize >> 16)); if (CheckSum != SavedCheckSum) { return false; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs index 1db60c89..563ca47b 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs @@ -184,12 +184,7 @@ internal static class UnpackUtility return (dec.DecodeNum[N]); } - internal static void makeDecodeTables( - byte[] lenTab, - int offset, - Decode.Decode dec, - int size - ) + internal static void makeDecodeTables(byte[] lenTab, int offset, Decode.Decode dec, int size) { Span lenCount = stackalloc int[16]; Span tmpPos = stackalloc int[16]; @@ -204,11 +199,7 @@ internal static class UnpackUtility lenCount[lenTab[offset + i] & 0xF]++; } lenCount[0] = 0; - for ( - tmpPos[0] = 0, dec.DecodePos[0] = 0, dec.DecodeLen[0] = 0, N = 0, i = 1; - i < 16; - i++ - ) + for (tmpPos[0] = 0, dec.DecodePos[0] = 0, dec.DecodeLen[0] = 0, N = 0, i = 1; i < 16; i++) { N = 2 * (N + lenCount[i]); M = N << (15 - i); diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs index 80c2d03c..4be34b90 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs @@ -321,10 +321,7 @@ internal partial class Unpack { for (Length = 0; ; Length++) { - if ( - ((BitField ^ ShortXor1[Length]) & (~(0xff >> (int)GetShortLen1(Length)))) - == 0 - ) + if (((BitField ^ ShortXor1[Length]) & (~(0xff >> (int)GetShortLen1(Length)))) == 0) { break; } @@ -336,10 +333,7 @@ internal partial class Unpack { for (Length = 0; ; Length++) { - if ( - ((BitField ^ ShortXor2[Length]) & (~(0xff >> (int)GetShortLen2(Length)))) - == 0 - ) + if (((BitField ^ ShortXor2[Length]) & (~(0xff >> (int)GetShortLen2(Length)))) == 0) { break; } @@ -734,8 +728,6 @@ internal partial class Unpack } Inp.faddbits(StartPos); - return ( - ((Num - (I != 0 ? DecTab[I - 1] : 0)) >> (int)(16 - StartPos)) + PosTab[StartPos] - ); + return (((Num - (I != 0 ? DecTab[I - 1] : 0)) >> (int)(16 - StartPos)) + PosTab[StartPos]); } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs index d43a4ff2..b92af290 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs @@ -414,7 +414,7 @@ internal partial class Unpack Inp.addbits(4); } MakeDecodeTables(BitLength, 0, BlockTables.BD, BC20); - for (uint I = 0; I < TableSize;) + for (uint I = 0; I < TableSize; ) { if (Inp.InAddr > ReadTop - 5) { diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs index 08f58601..5f7bf613 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs @@ -77,10 +77,7 @@ internal partial class Unpack } } - if ( - ((WriteBorder - UnpPtr) & MaxWinMask) < MAX_LZ_MATCH + 3 - && WriteBorder != UnpPtr - ) + if (((WriteBorder - UnpPtr) & MaxWinMask) < MAX_LZ_MATCH + 3 && WriteBorder != UnpPtr) { UnpWriteBuf(); if (WrittenFileSize > DestUnpSize) @@ -284,8 +281,7 @@ internal partial class Unpack // If distance to filter start is that large that due to circular dictionary // mode now it points to old not written yet data, then we set 'NextWindow' // flag and process this filter only after processing that older data. - Filter.NextWindow = - WrPtr != UnpPtr && ((WrPtr - UnpPtr) & MaxWinMask) <= Filter.BlockStart; + Filter.NextWindow = WrPtr != UnpPtr && ((WrPtr - UnpPtr) & MaxWinMask) <= Filter.BlockStart; Filter.BlockStart = (Filter.BlockStart + UnpPtr) & MaxWinMask; Filters.Add(Filter); @@ -340,10 +336,7 @@ internal partial class Unpack { // We may need to quit from main extraction loop and read new block header // and trees earlier than data in input buffer ends. - ReadBorder = Math.Min( - ReadBorder, - BlockHeader.BlockStart + BlockHeader.BlockSize - 1 - ); + ReadBorder = Math.Min(ReadBorder, BlockHeader.BlockStart + BlockHeader.BlockSize - 1); } return ReadCode != -1; } @@ -539,66 +532,66 @@ internal partial class Unpack case FILTER_E8: case FILTER_E8E9: - { - var FileOffset = (uint)WrittenFileSize; - - const uint FileSize = 0x1000000; - var CmpByte2 = Flt.Type == FILTER_E8E9 ? (byte)0xe9 : (byte)0xe8; - // DataSize is unsigned, so we use "CurPos+4" and not "DataSize-4" - // to avoid overflow for DataSize<4. - for (uint CurPos = 0; CurPos + 4 < DataSize;) { - //x byte CurByte=*(Data++); - var CurByte = __d[Data++]; - CurPos++; - if (CurByte == 0xe8 || CurByte == CmpByte2) + var FileOffset = (uint)WrittenFileSize; + + const uint FileSize = 0x1000000; + var CmpByte2 = Flt.Type == FILTER_E8E9 ? (byte)0xe9 : (byte)0xe8; + // DataSize is unsigned, so we use "CurPos+4" and not "DataSize-4" + // to avoid overflow for DataSize<4. + for (uint CurPos = 0; CurPos + 4 < DataSize; ) { - var Offset = (CurPos + FileOffset) % FileSize; - var Addr = RawGet4(__d, Data); - - // We check 0x80000000 bit instead of '< 0' comparison - // not assuming int32 presence or uint size and endianness. - if ((Addr & 0x80000000) != 0) // Addr<0 + //x byte CurByte=*(Data++); + var CurByte = __d[Data++]; + CurPos++; + if (CurByte == 0xe8 || CurByte == CmpByte2) { - if (((Addr + Offset) & 0x80000000) == 0) // Addr+Offset>=0 + var Offset = (CurPos + FileOffset) % FileSize; + var Addr = RawGet4(__d, Data); + + // We check 0x80000000 bit instead of '< 0' comparison + // not assuming int32 presence or uint size and endianness. + if ((Addr & 0x80000000) != 0) // Addr<0 { - RawPut4(Addr + FileSize, __d, Data); + if (((Addr + Offset) & 0x80000000) == 0) // Addr+Offset>=0 + { + RawPut4(Addr + FileSize, __d, Data); + } + } + else if (((Addr - FileSize) & 0x80000000) != 0) // Addr> 8); - __d[D + 2] = (byte)(Offset >> 16); + var D = Data + CurPos; + if (__d[D + 3] == 0xeb) // BL command with '1110' (Always) condition. + { + var Offset = + __d[D] + + ((uint)(__d[D + 1]) * 0x100) + + ((uint)(__d[D + 2]) * 0x10000); + Offset -= (FileOffset + CurPos) / 4; + __d[D] = (byte)Offset; + __d[D + 1] = (byte)(Offset >> 8); + __d[D + 2] = (byte)(Offset >> 16); + } } } - } - return SrcData; + return SrcData; case FILTER_DELTA: { // Unlike RAR3, we do not need to reject excessive channel @@ -727,9 +720,7 @@ internal partial class Unpack } Header.BlockSize = BlockSize; - var CheckSum = (byte)( - 0x5a ^ BlockFlags ^ BlockSize ^ (BlockSize >> 8) ^ (BlockSize >> 16) - ); + var CheckSum = (byte)(0x5a ^ BlockFlags ^ BlockSize ^ (BlockSize >> 8) ^ (BlockSize >> 16)); if (CheckSum != SavedCheckSum) { return false; @@ -796,7 +787,7 @@ internal partial class Unpack var Table = new byte[HUFF_TABLE_SIZE]; const uint TableSize = HUFF_TABLE_SIZE; - for (uint I = 0; I < TableSize;) + for (uint I = 0; I < TableSize; ) { if (!Inp.ExternalBuffer && Inp.InAddr > ReadTop - 5) { diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs index 69b35200..f9a74440 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs @@ -372,9 +372,7 @@ internal sealed partial class Unpack : BitInput // Find the upper limit for current bit field and adjust the bit length // accordingly if necessary. - while ( - CurBitLength < Dec.DecodeLen.Length && BitField >= Dec.DecodeLen[CurBitLength] - ) + while (CurBitLength < Dec.DecodeLen.Length && BitField >= Dec.DecodeLen[CurBitLength]) { CurBitLength++; } diff --git a/src/SharpCompress/Compressors/Rar/VM/RarVM.cs b/src/SharpCompress/Compressors/Rar/VM/RarVM.cs index 612f56ff..07d406cb 100644 --- a/src/SharpCompress/Compressors/Rar/VM/RarVM.cs +++ b/src/SharpCompress/Compressors/Rar/VM/RarVM.cs @@ -143,8 +143,7 @@ internal sealed class RarVM : BitInput Mem[VM_GLOBALMEMADDR + i] = prg.GlobalData[i]; } } - var staticSize = - Math.Min(prg.StaticData.Count, VM_GLOBALMEMSIZE - globalSize) & 0xffFFffFF; + var staticSize = Math.Min(prg.StaticData.Count, VM_GLOBALMEMSIZE - globalSize) & 0xffFFffFF; if (staticSize != 0) { for (var i = 0; i < staticSize; i++) @@ -157,8 +156,7 @@ internal sealed class RarVM : BitInput flags = 0; //UPGRADE_NOTE: There is an untranslated Statement. Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'" - var preparedCode = - prg.AltCommands.Count != 0 ? prg.AltCommands : prg.Commands; + var preparedCode = prg.AltCommands.Count != 0 ? prg.AltCommands : prg.Commands; if (!ExecuteCode(preparedCode, prg.CommandCount)) { @@ -239,104 +237,100 @@ internal sealed class RarVM : BitInput case VMCommands.VM_CMP: - { - var value1 = (VMFlags)GetValue(cmd.IsByteMode, Mem, op1); - var result = value1 - GetValue(cmd.IsByteMode, Mem, op2); + { + var value1 = (VMFlags)GetValue(cmd.IsByteMode, Mem, op1); + var result = value1 - GetValue(cmd.IsByteMode, Mem, op2); - if (result == 0) - { - flags = VMFlags.VM_FZ; + if (result == 0) + { + flags = VMFlags.VM_FZ; + } + else + { + flags = (VMFlags)( + (result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS) + ); + } } - else - { - flags = (VMFlags)( - (result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS) - ); - } - } - break; + break; case VMCommands.VM_CMPB: - { - var value1 = (VMFlags)GetValue(true, Mem, op1); - var result = value1 - GetValue(true, Mem, op2); - if (result == 0) { - flags = VMFlags.VM_FZ; + var value1 = (VMFlags)GetValue(true, Mem, op1); + var result = value1 - GetValue(true, Mem, op2); + if (result == 0) + { + flags = VMFlags.VM_FZ; + } + else + { + flags = (VMFlags)( + (result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS) + ); + } } - else - { - flags = (VMFlags)( - (result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS) - ); - } - } - break; + break; case VMCommands.VM_CMPD: - { - var value1 = (VMFlags)GetValue(false, Mem, op1); - var result = value1 - GetValue(false, Mem, op2); - if (result == 0) { - flags = VMFlags.VM_FZ; + var value1 = (VMFlags)GetValue(false, Mem, op1); + var result = value1 - GetValue(false, Mem, op2); + if (result == 0) + { + flags = VMFlags.VM_FZ; + } + else + { + flags = (VMFlags)( + (result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS) + ); + } } - else - { - flags = (VMFlags)( - (result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS) - ); - } - } - break; + break; case VMCommands.VM_ADD: - { - var value1 = GetValue(cmd.IsByteMode, Mem, op1); - var result = (int)( - ((value1 + (long)GetValue(cmd.IsByteMode, Mem, op2))) - & unchecked((int)0xffffffff) - ); - if (cmd.IsByteMode) { - result &= 0xff; - flags = (VMFlags)( - (result < value1) - ? 1 - : 0 - | ( - result == 0 - ? (int)VMFlags.VM_FZ - : ( - ((result & 0x80) != 0) - ? (int)VMFlags.VM_FS - : 0 - ) - ) + var value1 = GetValue(cmd.IsByteMode, Mem, op1); + var result = (int)( + ((value1 + (long)GetValue(cmd.IsByteMode, Mem, op2))) + & unchecked((int)0xffffffff) ); + if (cmd.IsByteMode) + { + result &= 0xff; + flags = (VMFlags)( + (result < value1) + ? 1 + : 0 + | ( + result == 0 + ? (int)VMFlags.VM_FZ + : (((result & 0x80) != 0) ? (int)VMFlags.VM_FS : 0) + ) + ); - // Flags=(Result value1) ? 1 : 0 | (result & (int)VMFlags.VM_FS)) - ); - SetValue(cmd.IsByteMode, Mem, op1, result); // (Cmd->ByteMode,Op1,Result); - } - break; + { + var value1 = GetValue(cmd.IsByteMode, Mem, op1); + var result = (int)( + value1 + & (0xffFFffFF - GetValue(cmd.IsByteMode, Mem, op2)) + & unchecked((int)0xFFffFFff) + ); + flags = (VMFlags)( + (result == 0) + ? (int)VMFlags.VM_FZ + : ((result > value1) ? 1 : 0 | (result & (int)VMFlags.VM_FS)) + ); + SetValue(cmd.IsByteMode, Mem, op1, result); // (Cmd->ByteMode,Op1,Result); + } + break; case VMCommands.VM_SUBB: SetValue( @@ -426,29 +420,22 @@ internal sealed class RarVM : BitInput case VMCommands.VM_INC: - { - var result = (int)( - GetValue(cmd.IsByteMode, Mem, op1) & (0xFFffFFffL + 1L) - ); - if (cmd.IsByteMode) { - result &= 0xff; - } + var result = (int)(GetValue(cmd.IsByteMode, Mem, op1) & (0xFFffFFffL + 1L)); + if (cmd.IsByteMode) + { + result &= 0xff; + } - SetValue(cmd.IsByteMode, Mem, op1, result); - flags = (VMFlags)( - result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS - ); - } - break; + SetValue(cmd.IsByteMode, Mem, op1, result); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); + } + break; case VMCommands.VM_INCB: - SetValue( - true, - Mem, - op1, - (int)(GetValue(true, Mem, op1) & (0xFFffFFffL + 1L)) - ); + SetValue(true, Mem, op1, (int)(GetValue(true, Mem, op1) & (0xFFffFFffL + 1L))); break; case VMCommands.VM_INCD: @@ -462,26 +449,21 @@ internal sealed class RarVM : BitInput case VMCommands.VM_DEC: - { - var result = (int)(GetValue(cmd.IsByteMode, Mem, op1) & (0xFFffFFff - 1)); - SetValue(cmd.IsByteMode, Mem, op1, result); - flags = (VMFlags)( - result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS - ); - } - break; + { + var result = (int)(GetValue(cmd.IsByteMode, Mem, op1) & (0xFFffFFff - 1)); + SetValue(cmd.IsByteMode, Mem, op1, result); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); + } + break; case VMCommands.VM_DECB: SetValue(true, Mem, op1, (int)(GetValue(true, Mem, op1) & (0xFFffFFff - 1))); break; case VMCommands.VM_DECD: - SetValue( - false, - Mem, - op1, - (int)(GetValue(false, Mem, op1) & (0xFFffFFff - 1)) - ); + SetValue(false, Mem, op1, (int)(GetValue(false, Mem, op1) & (0xFFffFFff - 1))); break; case VMCommands.VM_JMP: @@ -490,54 +472,50 @@ internal sealed class RarVM : BitInput case VMCommands.VM_XOR: - { - var result = - GetValue(cmd.IsByteMode, Mem, op1) - ^ GetValue(cmd.IsByteMode, Mem, op2); - flags = (VMFlags)( - result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + { + var result = + GetValue(cmd.IsByteMode, Mem, op1) ^ GetValue(cmd.IsByteMode, Mem, op2); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); + SetValue(cmd.IsByteMode, Mem, op1, result); + } + break; case VMCommands.VM_AND: - { - var result = - GetValue(cmd.IsByteMode, Mem, op1) - & GetValue(cmd.IsByteMode, Mem, op2); - flags = (VMFlags)( - result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + { + var result = + GetValue(cmd.IsByteMode, Mem, op1) & GetValue(cmd.IsByteMode, Mem, op2); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); + SetValue(cmd.IsByteMode, Mem, op1, result); + } + break; case VMCommands.VM_OR: - { - var result = - GetValue(cmd.IsByteMode, Mem, op1) - | GetValue(cmd.IsByteMode, Mem, op2); - flags = (VMFlags)( - result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + { + var result = + GetValue(cmd.IsByteMode, Mem, op1) | GetValue(cmd.IsByteMode, Mem, op2); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); + SetValue(cmd.IsByteMode, Mem, op1, result); + } + break; case VMCommands.VM_TEST: - { - var result = - GetValue(cmd.IsByteMode, Mem, op1) - & GetValue(cmd.IsByteMode, Mem, op2); - flags = (VMFlags)( - result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS - ); - } - break; + { + var result = + GetValue(cmd.IsByteMode, Mem, op1) & GetValue(cmd.IsByteMode, Mem, op2); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); + } + break; case VMCommands.VM_JS: if ((flags & VMFlags.VM_FS) != 0) @@ -609,62 +587,62 @@ internal sealed class RarVM : BitInput case VMCommands.VM_SHL: - { - var value1 = GetValue(cmd.IsByteMode, Mem, op1); - var value2 = GetValue(cmd.IsByteMode, Mem, op2); - var result = value1 << value2; - flags = (VMFlags)( - (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) - | ( - ((value1 << (value2 - 1)) & unchecked((int)0x80000000)) != 0 - ? (int)VMFlags.VM_FC - : 0 - ) - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + { + var value1 = GetValue(cmd.IsByteMode, Mem, op1); + var value2 = GetValue(cmd.IsByteMode, Mem, op2); + var result = value1 << value2; + flags = (VMFlags)( + (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) + | ( + ((value1 << (value2 - 1)) & unchecked((int)0x80000000)) != 0 + ? (int)VMFlags.VM_FC + : 0 + ) + ); + SetValue(cmd.IsByteMode, Mem, op1, result); + } + break; case VMCommands.VM_SHR: - { - var value1 = GetValue(cmd.IsByteMode, Mem, op1); - var value2 = GetValue(cmd.IsByteMode, Mem, op2); - var result = Utility.URShift(value1, value2); - flags = (VMFlags)( - (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) - | ((Utility.URShift(value1, (value2 - 1))) & (int)VMFlags.VM_FC) - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + { + var value1 = GetValue(cmd.IsByteMode, Mem, op1); + var value2 = GetValue(cmd.IsByteMode, Mem, op2); + var result = Utility.URShift(value1, value2); + flags = (VMFlags)( + (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) + | ((Utility.URShift(value1, (value2 - 1))) & (int)VMFlags.VM_FC) + ); + SetValue(cmd.IsByteMode, Mem, op1, result); + } + break; case VMCommands.VM_SAR: - { - var value1 = GetValue(cmd.IsByteMode, Mem, op1); - var value2 = GetValue(cmd.IsByteMode, Mem, op2); - var result = value1 >> value2; - flags = (VMFlags)( - (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) - | ((value1 >> (value2 - 1)) & (int)VMFlags.VM_FC) - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + { + var value1 = GetValue(cmd.IsByteMode, Mem, op1); + var value2 = GetValue(cmd.IsByteMode, Mem, op2); + var result = value1 >> value2; + flags = (VMFlags)( + (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) + | ((value1 >> (value2 - 1)) & (int)VMFlags.VM_FC) + ); + SetValue(cmd.IsByteMode, Mem, op1, result); + } + break; case VMCommands.VM_NEG: - { - var result = -GetValue(cmd.IsByteMode, Mem, op1); - flags = (VMFlags)( - result == 0 - ? (int)VMFlags.VM_FZ - : (int)VMFlags.VM_FC | (result & (int)VMFlags.VM_FS) - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + { + var result = -GetValue(cmd.IsByteMode, Mem, op1); + flags = (VMFlags)( + result == 0 + ? (int)VMFlags.VM_FZ + : (int)VMFlags.VM_FC | (result & (int)VMFlags.VM_FS) + ); + SetValue(cmd.IsByteMode, Mem, op1, result); + } + break; case VMCommands.VM_NEGB: SetValue(true, Mem, op1, -GetValue(true, Mem, op1)); @@ -676,24 +654,24 @@ internal sealed class RarVM : BitInput case VMCommands.VM_PUSHA: - { - for (int i = 0, SP = R[7] - 4; i < regCount; i++, SP -= 4) { - SetValue(false, Mem, SP & VM_MEMMASK, R[i]); + for (int i = 0, SP = R[7] - 4; i < regCount; i++, SP -= 4) + { + SetValue(false, Mem, SP & VM_MEMMASK, R[i]); + } + R[7] -= regCount * 4; } - R[7] -= regCount * 4; - } - break; + break; case VMCommands.VM_POPA: - { - for (int i = 0, SP = R[7]; i < regCount; i++, SP += 4) { - R[7 - i] = GetValue(false, Mem, SP & VM_MEMMASK); + for (int i = 0, SP = R[7]; i < regCount; i++, SP += 4) + { + R[7 - i] = GetValue(false, Mem, SP & VM_MEMMASK); + } } - } - break; + break; case VMCommands.VM_PUSHF: R[7] -= 4; @@ -715,97 +693,97 @@ internal sealed class RarVM : BitInput case VMCommands.VM_XCHG: - { - var value1 = GetValue(cmd.IsByteMode, Mem, op1); - SetValue(cmd.IsByteMode, Mem, op1, GetValue(cmd.IsByteMode, Mem, op2)); - SetValue(cmd.IsByteMode, Mem, op2, value1); - } - break; + { + var value1 = GetValue(cmd.IsByteMode, Mem, op1); + SetValue(cmd.IsByteMode, Mem, op1, GetValue(cmd.IsByteMode, Mem, op2)); + SetValue(cmd.IsByteMode, Mem, op2, value1); + } + break; case VMCommands.VM_MUL: - { - var result = (int)( - ( - GetValue(cmd.IsByteMode, Mem, op1) - & (0xFFffFFff * GetValue(cmd.IsByteMode, Mem, op2)) - & unchecked((int)0xFFffFFff) - ) & unchecked((int)0xFFffFFff) - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + { + var result = (int)( + ( + GetValue(cmd.IsByteMode, Mem, op1) + & (0xFFffFFff * GetValue(cmd.IsByteMode, Mem, op2)) + & unchecked((int)0xFFffFFff) + ) & unchecked((int)0xFFffFFff) + ); + SetValue(cmd.IsByteMode, Mem, op1, result); + } + break; case VMCommands.VM_DIV: - { - var divider = GetValue(cmd.IsByteMode, Mem, op2); - if (divider != 0) { - var result = GetValue(cmd.IsByteMode, Mem, op1) / divider; - SetValue(cmd.IsByteMode, Mem, op1, result); + var divider = GetValue(cmd.IsByteMode, Mem, op2); + if (divider != 0) + { + var result = GetValue(cmd.IsByteMode, Mem, op1) / divider; + SetValue(cmd.IsByteMode, Mem, op1, result); + } } - } - break; + break; case VMCommands.VM_ADC: - { - var value1 = GetValue(cmd.IsByteMode, Mem, op1); - var FC = (int)(flags & VMFlags.VM_FC); - var result = (int)( - value1 - & (0xFFffFFff + GetValue(cmd.IsByteMode, Mem, op2)) - & (0xFFffFFff + FC) - & unchecked((int)0xFFffFFff) - ); - if (cmd.IsByteMode) { - result &= 0xff; - } + var value1 = GetValue(cmd.IsByteMode, Mem, op1); + var FC = (int)(flags & VMFlags.VM_FC); + var result = (int)( + value1 + & (0xFFffFFff + GetValue(cmd.IsByteMode, Mem, op2)) + & (0xFFffFFff + FC) + & unchecked((int)0xFFffFFff) + ); + if (cmd.IsByteMode) + { + result &= 0xff; + } - flags = (VMFlags)( - (result < value1 || result == value1 && FC != 0) - ? 1 - : 0 - | ( - result == 0 - ? (int)VMFlags.VM_FZ - : (result & (int)VMFlags.VM_FS) - ) - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + flags = (VMFlags)( + (result < value1 || result == value1 && FC != 0) + ? 1 + : 0 + | ( + result == 0 + ? (int)VMFlags.VM_FZ + : (result & (int)VMFlags.VM_FS) + ) + ); + SetValue(cmd.IsByteMode, Mem, op1, result); + } + break; case VMCommands.VM_SBB: - { - var value1 = GetValue(cmd.IsByteMode, Mem, op1); - var FC = (int)(flags & VMFlags.VM_FC); - var result = (int)( - value1 - & (0xFFffFFff - GetValue(cmd.IsByteMode, Mem, op2)) - & (0xFFffFFff - FC) - & unchecked((int)0xFFffFFff) - ); - if (cmd.IsByteMode) { - result &= 0xff; + var value1 = GetValue(cmd.IsByteMode, Mem, op1); + var FC = (int)(flags & VMFlags.VM_FC); + var result = (int)( + value1 + & (0xFFffFFff - GetValue(cmd.IsByteMode, Mem, op2)) + & (0xFFffFFff - FC) + & unchecked((int)0xFFffFFff) + ); + if (cmd.IsByteMode) + { + result &= 0xff; + } + flags = (VMFlags)( + (result > value1 || result == value1 && FC != 0) + ? 1 + : 0 + | ( + result == 0 + ? (int)VMFlags.VM_FZ + : (result & (int)VMFlags.VM_FS) + ) + ); + SetValue(cmd.IsByteMode, Mem, op1, result); } - flags = (VMFlags)( - (result > value1 || result == value1 && FC != 0) - ? 1 - : 0 - | ( - result == 0 - ? (int)VMFlags.VM_FZ - : (result & (int)VMFlags.VM_FS) - ) - ); - SetValue(cmd.IsByteMode, Mem, op1, result); - } - break; + break; case VMCommands.VM_RET: if (R[7] >= VM_MEMSIZE) @@ -898,9 +876,7 @@ internal sealed class RarVM : BitInput curCmd.OpCode = (VMCommands)((data >> 10) - 24); AddBits(6); } - if ( - (VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] & VMCmdFlags.VMCF_BYTEMODE) != 0 - ) + if ((VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] & VMCmdFlags.VMCF_BYTEMODE) != 0) { curCmd.IsByteMode = (GetBits() >> 15) == 1; AddBits(1); @@ -912,9 +888,7 @@ internal sealed class RarVM : BitInput curCmd.Op1.Type = VMOpType.VM_OPNONE; curCmd.Op2.Type = VMOpType.VM_OPNONE; - var opNum = ( - VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] & VMCmdFlags.VMCF_OPMASK - ); + var opNum = (VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] & VMCmdFlags.VMCF_OPMASK); // TODO >>> CurCmd->Op1.Addr=CurCmd->Op2.Addr=NULL; << 0) @@ -1082,11 +1056,7 @@ internal sealed class RarVM : BitInput if ( ( flags - & ( - VMCmdFlags.VMCF_JUMP - | VMCmdFlags.VMCF_PROC - | VMCmdFlags.VMCF_USEFLAGS - ) + & (VMCmdFlags.VMCF_JUMP | VMCmdFlags.VMCF_PROC | VMCmdFlags.VMCF_USEFLAGS) ) != 0 ) { @@ -1195,368 +1165,368 @@ internal sealed class RarVM : BitInput case VMStandardFilters.VMSF_E8: case VMStandardFilters.VMSF_E8E9: - { - var dataSize = R[4]; - long fileOffset = R[6] & unchecked((int)0xFFffFFff); + { + var dataSize = R[4]; + long fileOffset = R[6] & unchecked((int)0xFFffFFff); - if (dataSize >= VM_GLOBALMEMADDR) - { - break; - } - var fileSize = 0x1000000; - var cmpByte2 = (byte)( - (filterType == VMStandardFilters.VMSF_E8E9) ? 0xe9 : 0xe8 - ); - for (var curPos = 0; curPos < dataSize - 4;) - { - var curByte = Mem[curPos++]; - if (curByte == 0xe8 || curByte == cmpByte2) + if (dataSize >= VM_GLOBALMEMADDR) { - // #ifdef PRESENT_INT32 - // sint32 Offset=CurPos+FileOffset; - // sint32 Addr=GET_VALUE(false,Data); - // if (Addr<0) - // { - // if (Addr+Offset>=0) - // SET_VALUE(false,Data,Addr+FileSize); - // } - // else - // if (Addr= VM_GLOBALMEMADDR) - { - break; - } - var curPos = 0; - - //UPGRADE_NOTE: Final was removed from the declaration of 'Masks '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" - byte[] Masks = { 4, 4, 6, 6, 0, 0, 7, 7, 4, 4, 0, 0, 4, 4, 0, 0 }; - fileOffset = Utility.URShift(fileOffset, 4); - - while (curPos < dataSize - 21) - { - var Byte = (Mem[curPos] & 0x1f) - 0x10; - if (Byte >= 0) + var fileSize = 0x1000000; + var cmpByte2 = (byte)( + (filterType == VMStandardFilters.VMSF_E8E9) ? 0xe9 : 0xe8 + ); + for (var curPos = 0; curPos < dataSize - 4; ) { - var cmdMask = Masks[Byte]; - if (cmdMask != 0) + var curByte = Mem[curPos++]; + if (curByte == 0xe8 || curByte == cmpByte2) { - for (var i = 0; i <= 2; i++) + // #ifdef PRESENT_INT32 + // sint32 Offset=CurPos+FileOffset; + // sint32 Addr=GET_VALUE(false,Data); + // if (Addr<0) + // { + // if (Addr+Offset>=0) + // SET_VALUE(false,Data,Addr+FileSize); + // } + // else + // if (Addr= VM_GLOBALMEMADDR / 2) - { - break; - } - - // bytes from same channels are grouped to continual data blocks, - // so we need to place them back to their interleaving positions - - for (var curChannel = 0; curChannel < channels; curChannel++) - { - byte PrevByte = 0; - for ( - var destPos = dataSize + curChannel; - destPos < border; - destPos += channels - ) - { - Mem[destPos] = (PrevByte = (byte)(PrevByte - Mem[srcPos++])); - } - } - } - break; - - case VMStandardFilters.VMSF_RGB: - - { - // byte *SrcData=Mem,*DestData=SrcData+DataSize; - int dataSize = R[4], - width = R[0] - 3, - posR = R[1]; - var channels = 3; - var srcPos = 0; - var destDataPos = dataSize; - SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize); - if (dataSize >= VM_GLOBALMEMADDR / 2 || posR < 0) - { - break; - } - for (var curChannel = 0; curChannel < channels; curChannel++) - { - long prevByte = 0; - - for (var i = curChannel; i < dataSize; i += channels) - { - long predicted; - var upperPos = i - width; - if (upperPos >= 3) - { - var upperDataPos = destDataPos + upperPos; - var upperByte = Mem[upperDataPos] & 0xff; - var upperLeftByte = Mem[upperDataPos - 3] & 0xff; - predicted = prevByte + upperByte - upperLeftByte; - var pa = Math.Abs((int)(predicted - prevByte)); - var pb = Math.Abs((int)(predicted - upperByte)); - var pc = Math.Abs((int)(predicted - upperLeftByte)); - if (pa <= pb && pa <= pc) - { - predicted = prevByte; - } else { - if (pb <= pc) + if (((Addr - fileSize) & unchecked((int)0x80000000)) != 0) { - predicted = upperByte; + SetValue(false, Mem, curPos, (int)(Addr - offset)); + } + } + + // #endif + curPos += 4; + } + } + } + break; + + case VMStandardFilters.VMSF_ITANIUM: + + { + var dataSize = R[4]; + long fileOffset = R[6] & unchecked((int)0xFFffFFff); + + if (dataSize >= VM_GLOBALMEMADDR) + { + break; + } + var curPos = 0; + + //UPGRADE_NOTE: Final was removed from the declaration of 'Masks '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" + byte[] Masks = { 4, 4, 6, 6, 0, 0, 7, 7, 4, 4, 0, 0, 4, 4, 0, 0 }; + fileOffset = Utility.URShift(fileOffset, 4); + + while (curPos < dataSize - 21) + { + var Byte = (Mem[curPos] & 0x1f) - 0x10; + if (Byte >= 0) + { + var cmdMask = Masks[Byte]; + if (cmdMask != 0) + { + for (var i = 0; i <= 2; i++) + { + if ((cmdMask & (1 << i)) != 0) + { + var startPos = (i * 41) + 5; + var opType = filterItanium_GetBits( + curPos, + startPos + 37, + 4 + ); + if (opType == 5) + { + var offset = filterItanium_GetBits( + curPos, + startPos + 13, + 20 + ); + filterItanium_SetBits( + curPos, + (int)(offset - fileOffset) & 0xfffff, + startPos + 13, + 20 + ); + } + } + } + } + } + curPos += 16; + fileOffset++; + } + } + break; + + case VMStandardFilters.VMSF_DELTA: + + { + var dataSize = R[4] & unchecked((int)0xFFffFFff); + var channels = R[0] & unchecked((int)0xFFffFFff); + var srcPos = 0; + var border = (dataSize * 2) & unchecked((int)0xFFffFFff); + SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize); + if (dataSize >= VM_GLOBALMEMADDR / 2) + { + break; + } + + // bytes from same channels are grouped to continual data blocks, + // so we need to place them back to their interleaving positions + + for (var curChannel = 0; curChannel < channels; curChannel++) + { + byte PrevByte = 0; + for ( + var destPos = dataSize + curChannel; + destPos < border; + destPos += channels + ) + { + Mem[destPos] = (PrevByte = (byte)(PrevByte - Mem[srcPos++])); + } + } + } + break; + + case VMStandardFilters.VMSF_RGB: + + { + // byte *SrcData=Mem,*DestData=SrcData+DataSize; + int dataSize = R[4], + width = R[0] - 3, + posR = R[1]; + var channels = 3; + var srcPos = 0; + var destDataPos = dataSize; + SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize); + if (dataSize >= VM_GLOBALMEMADDR / 2 || posR < 0) + { + break; + } + for (var curChannel = 0; curChannel < channels; curChannel++) + { + long prevByte = 0; + + for (var i = curChannel; i < dataSize; i += channels) + { + long predicted; + var upperPos = i - width; + if (upperPos >= 3) + { + var upperDataPos = destDataPos + upperPos; + var upperByte = Mem[upperDataPos] & 0xff; + var upperLeftByte = Mem[upperDataPos - 3] & 0xff; + predicted = prevByte + upperByte - upperLeftByte; + var pa = Math.Abs((int)(predicted - prevByte)); + var pb = Math.Abs((int)(predicted - upperByte)); + var pc = Math.Abs((int)(predicted - upperLeftByte)); + if (pa <= pb && pa <= pc) + { + predicted = prevByte; } else { - predicted = upperLeftByte; + if (pb <= pc) + { + predicted = upperByte; + } + else + { + predicted = upperLeftByte; + } } } - } - else - { - predicted = prevByte; - } + else + { + predicted = prevByte; + } - prevByte = ((predicted - Mem[srcPos++]) & 0xff) & 0xff; - Mem[destDataPos + i] = (byte)(prevByte & 0xff); + prevByte = ((predicted - Mem[srcPos++]) & 0xff) & 0xff; + Mem[destDataPos + i] = (byte)(prevByte & 0xff); + } + } + for (int i = posR, border = dataSize - 2; i < border; i += 3) + { + var G = Mem[destDataPos + i + 1]; + Mem[destDataPos + i] = (byte)(Mem[destDataPos + i] + G); + Mem[destDataPos + i + 2] = (byte)(Mem[destDataPos + i + 2] + G); } } - for (int i = posR, border = dataSize - 2; i < border; i += 3) - { - var G = Mem[destDataPos + i + 1]; - Mem[destDataPos + i] = (byte)(Mem[destDataPos + i] + G); - Mem[destDataPos + i + 2] = (byte)(Mem[destDataPos + i + 2] + G); - } - } - break; + break; case VMStandardFilters.VMSF_AUDIO: - { - int dataSize = R[4], - channels = R[0]; - var srcPos = 0; - var destDataPos = dataSize; - - //byte *SrcData=Mem,*DestData=SrcData+DataSize; - SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize); - if (dataSize >= VM_GLOBALMEMADDR / 2) { - break; - } - for (var curChannel = 0; curChannel < channels; curChannel++) - { - long prevByte = 0; - long prevDelta = 0; - var Dif = new long[7]; - int D1 = 0, - D2 = 0, - D3; - int K1 = 0, - K2 = 0, - K3 = 0; + int dataSize = R[4], + channels = R[0]; + var srcPos = 0; + var destDataPos = dataSize; - for ( - int i = curChannel, byteCount = 0; - i < dataSize; - i += channels, byteCount++ - ) + //byte *SrcData=Mem,*DestData=SrcData+DataSize; + SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize); + if (dataSize >= VM_GLOBALMEMADDR / 2) { - D3 = D2; - D2 = (int)(prevDelta - D1); - D1 = (int)prevDelta; + break; + } + for (var curChannel = 0; curChannel < channels; curChannel++) + { + long prevByte = 0; + long prevDelta = 0; + var Dif = new long[7]; + int D1 = 0, + D2 = 0, + D3; + int K1 = 0, + K2 = 0, + K3 = 0; - var predicted = (8 * prevByte) + (K1 * D1) + (K2 * D2) + (K3 * D3); - predicted = Utility.URShift(predicted, 3) & 0xff; - - long curByte = Mem[srcPos++]; - - predicted -= curByte; - Mem[destDataPos + i] = (byte)predicted; - prevDelta = (byte)(predicted - prevByte); - - //fix java byte - if (prevDelta >= 128) + for ( + int i = curChannel, byteCount = 0; + i < dataSize; + i += channels, byteCount++ + ) { - prevDelta = 0 - (256 - prevDelta); - } - prevByte = predicted; + D3 = D2; + D2 = (int)(prevDelta - D1); + D1 = (int)prevDelta; - //fix java byte - if (curByte >= 128) - { - curByte = 0 - (256 - curByte); - } - var D = ((int)curByte) << 3; + var predicted = (8 * prevByte) + (K1 * D1) + (K2 * D2) + (K3 * D3); + predicted = Utility.URShift(predicted, 3) & 0xff; - Dif[0] += Math.Abs(D); - Dif[1] += Math.Abs(D - D1); - Dif[2] += Math.Abs(D + D1); - Dif[3] += Math.Abs(D - D2); - Dif[4] += Math.Abs(D + D2); - Dif[5] += Math.Abs(D - D3); - Dif[6] += Math.Abs(D + D3); + long curByte = Mem[srcPos++]; - if ((byteCount & 0x1f) == 0) - { - long minDif = Dif[0], - numMinDif = 0; - Dif[0] = 0; - for (var j = 1; j < Dif.Length; j++) + predicted -= curByte; + Mem[destDataPos + i] = (byte)predicted; + prevDelta = (byte)(predicted - prevByte); + + //fix java byte + if (prevDelta >= 128) { - if (Dif[j] < minDif) - { - minDif = Dif[j]; - numMinDif = j; - } - Dif[j] = 0; + prevDelta = 0 - (256 - prevDelta); } - switch ((int)numMinDif) + prevByte = predicted; + + //fix java byte + if (curByte >= 128) { - case 1: - if (K1 >= -16) - { - K1--; - } - break; + curByte = 0 - (256 - curByte); + } + var D = ((int)curByte) << 3; - case 2: - if (K1 < 16) - { - K1++; - } - break; + Dif[0] += Math.Abs(D); + Dif[1] += Math.Abs(D - D1); + Dif[2] += Math.Abs(D + D1); + Dif[3] += Math.Abs(D - D2); + Dif[4] += Math.Abs(D + D2); + Dif[5] += Math.Abs(D - D3); + Dif[6] += Math.Abs(D + D3); - case 3: - if (K2 >= -16) + if ((byteCount & 0x1f) == 0) + { + long minDif = Dif[0], + numMinDif = 0; + Dif[0] = 0; + for (var j = 1; j < Dif.Length; j++) + { + if (Dif[j] < minDif) { - K2--; + minDif = Dif[j]; + numMinDif = j; } - break; + Dif[j] = 0; + } + switch ((int)numMinDif) + { + case 1: + if (K1 >= -16) + { + K1--; + } + break; - case 4: - if (K2 < 16) - { - K2++; - } - break; + case 2: + if (K1 < 16) + { + K1++; + } + break; - case 5: - if (K3 >= -16) - { - K3--; - } - break; + case 3: + if (K2 >= -16) + { + K2--; + } + break; - case 6: - if (K3 < 16) - { - K3++; - } - break; + case 4: + if (K2 < 16) + { + K2++; + } + break; + + case 5: + if (K3 >= -16) + { + K3--; + } + break; + + case 6: + if (K3 < 16) + { + K3++; + } + break; + } } } } } - } - break; + break; case VMStandardFilters.VMSF_UPCASE: - { - int dataSize = R[4], - srcPos = 0, - destPos = dataSize; - if (dataSize >= VM_GLOBALMEMADDR / 2) { - break; - } - while (srcPos < dataSize) - { - var curByte = Mem[srcPos++]; - if (curByte == 2 && (curByte = Mem[srcPos++]) != 2) + int dataSize = R[4], + srcPos = 0, + destPos = dataSize; + if (dataSize >= VM_GLOBALMEMADDR / 2) { - curByte = (byte)(curByte - 32); + break; } - Mem[destPos++] = curByte; + while (srcPos < dataSize) + { + var curByte = Mem[srcPos++]; + if (curByte == 2 && (curByte = Mem[srcPos++]) != 2) + { + curByte = (byte)(curByte - 32); + } + Mem[destPos++] = curByte; + } + SetValue(false, Mem, VM_GLOBALMEMADDR + 0x1c, destPos - dataSize); + SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize); } - SetValue(false, Mem, VM_GLOBALMEMADDR + 0x1c, destPos - dataSize); - SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize); - } - break; + break; } } diff --git a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs index f141f4f2..ecfe7ae0 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs @@ -45,9 +45,7 @@ public abstract class BlockFilter : ReadOnlyStream var filterType = (FilterTypes)reader.ReadXZInteger(); if (!FilterMap.ContainsKey(filterType)) { - throw new NotImplementedException( - $"Filter {filterType} has not yet been implemented" - ); + throw new NotImplementedException($"Filter {filterType} has not yet been implemented"); } var filter = (BlockFilter)Activator.CreateInstance(FilterMap[filterType])!; diff --git a/src/SharpCompress/Compressors/Xz/XZStream.cs b/src/SharpCompress/Compressors/Xz/XZStream.cs index f1157182..b95b5081 100644 --- a/src/SharpCompress/Compressors/Xz/XZStream.cs +++ b/src/SharpCompress/Compressors/Xz/XZStream.cs @@ -33,9 +33,7 @@ public sealed class XZStream : XZReadOnlyStream case CheckType.SHA256: throw new NotImplementedException(); default: - throw new NotSupportedException( - "Check Type unknown to this version of decoder." - ); + throw new NotSupportedException("Check Type unknown to this version of decoder."); } } diff --git a/src/SharpCompress/Crypto/Crc32Stream.cs b/src/SharpCompress/Crypto/Crc32Stream.cs index 827b1fad..66d9f3c5 100644 --- a/src/SharpCompress/Crypto/Crc32Stream.cs +++ b/src/SharpCompress/Crypto/Crc32Stream.cs @@ -37,8 +37,7 @@ public sealed class Crc32Stream : Stream public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException(); - public override long Seek(long offset, SeekOrigin origin) => - throw new NotSupportedException(); + public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); public override void SetLength(long value) => throw new NotSupportedException(); diff --git a/src/SharpCompress/Crypto/DataLengthException.cs b/src/SharpCompress/Crypto/DataLengthException.cs index f751adf5..bc6cd183 100644 --- a/src/SharpCompress/Crypto/DataLengthException.cs +++ b/src/SharpCompress/Crypto/DataLengthException.cs @@ -18,6 +18,5 @@ public class DataLengthException : CryptoException public DataLengthException(string message) : base(message) { } - public DataLengthException(string message, Exception exception) : base(message, exception) - { } + public DataLengthException(string message, Exception exception) : base(message, exception) { } } diff --git a/src/SharpCompress/Factories/GZipFactory.cs b/src/SharpCompress/Factories/GZipFactory.cs index e504e577..1c90a88f 100644 --- a/src/SharpCompress/Factories/GZipFactory.cs +++ b/src/SharpCompress/Factories/GZipFactory.cs @@ -126,9 +126,7 @@ public class GZipFactory { if (writerOptions.CompressionType != CompressionType.GZip) { - throw new InvalidFormatException( - "GZip archives only support GZip compression type." - ); + throw new InvalidFormatException("GZip archives only support GZip compression type."); } return new GZipWriter(stream, new GZipWriterOptions(writerOptions)); } diff --git a/src/SharpCompress/IO/ListeningStream.cs b/src/SharpCompress/IO/ListeningStream.cs index 0cccdc6b..4aeb5347 100644 --- a/src/SharpCompress/IO/ListeningStream.cs +++ b/src/SharpCompress/IO/ListeningStream.cs @@ -48,10 +48,7 @@ internal class ListeningStream : Stream { var read = Stream.Read(buffer, offset, count); currentEntryTotalReadBytes += read; - listener.FireCompressedBytesRead( - currentEntryTotalReadBytes, - currentEntryTotalReadBytes - ); + listener.FireCompressedBytesRead(currentEntryTotalReadBytes, currentEntryTotalReadBytes); return read; } @@ -64,10 +61,7 @@ internal class ListeningStream : Stream } ++currentEntryTotalReadBytes; - listener.FireCompressedBytesRead( - currentEntryTotalReadBytes, - currentEntryTotalReadBytes - ); + listener.FireCompressedBytesRead(currentEntryTotalReadBytes, currentEntryTotalReadBytes); return value; } diff --git a/src/SharpCompress/IO/ReadOnlySubStream.cs b/src/SharpCompress/IO/ReadOnlySubStream.cs index acdb6e4a..ce8709d2 100644 --- a/src/SharpCompress/IO/ReadOnlySubStream.cs +++ b/src/SharpCompress/IO/ReadOnlySubStream.cs @@ -5,8 +5,7 @@ namespace SharpCompress.IO; internal class ReadOnlySubStream : NonDisposingStream { - public ReadOnlySubStream(Stream stream, long bytesToRead) : this(stream, null, bytesToRead) - { } + public ReadOnlySubStream(Stream stream, long bytesToRead) : this(stream, null, bytesToRead) { } public ReadOnlySubStream(Stream stream, long? origin, long bytesToRead) : base(stream, throwOnDispose: false) diff --git a/src/SharpCompress/IO/SourceStream.cs b/src/SharpCompress/IO/SourceStream.cs index 5f722b65..d02770c4 100644 --- a/src/SharpCompress/IO/SourceStream.cs +++ b/src/SharpCompress/IO/SourceStream.cs @@ -58,8 +58,7 @@ public class SourceStream : Stream public void LoadAllParts() { - for (var i = 1; SetStream(i); i++) - { } + for (var i = 1; SetStream(i); i++) { } SetStream(0); } diff --git a/src/SharpCompress/Readers/AbstractReader.cs b/src/SharpCompress/Readers/AbstractReader.cs index 5c383cb2..10cebc12 100644 --- a/src/SharpCompress/Readers/AbstractReader.cs +++ b/src/SharpCompress/Readers/AbstractReader.cs @@ -157,9 +157,7 @@ public abstract class AbstractReader : IReader, IReaderExtracti { if (wroteCurrentEntry) { - throw new ArgumentException( - "WriteEntryTo or OpenEntryStream can only be called once." - ); + throw new ArgumentException("WriteEntryTo or OpenEntryStream can only be called once."); } if (writableStream is null) @@ -188,9 +186,7 @@ public abstract class AbstractReader : IReader, IReaderExtracti { if (wroteCurrentEntry) { - throw new ArgumentException( - "WriteEntryTo or OpenEntryStream can only be called once." - ); + throw new ArgumentException("WriteEntryTo or OpenEntryStream can only be called once."); } var stream = GetEntryStream(); wroteCurrentEntry = true; diff --git a/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs b/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs index 99db4583..344ca994 100644 --- a/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs +++ b/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs @@ -14,6 +14,5 @@ internal class NonSeekableStreamFilePart : RarFilePart return FileHeader.PackedStream; } - internal override string FilePartName => - "Unknown Stream - File Entry: " + FileHeader.FileName; + internal override string FilePartName => "Unknown Stream - File Entry: " + FileHeader.FileName; } diff --git a/src/SharpCompress/Readers/Rar/RarReader.cs b/src/SharpCompress/Readers/Rar/RarReader.cs index b665ddf9..6eb49b2d 100644 --- a/src/SharpCompress/Readers/Rar/RarReader.cs +++ b/src/SharpCompress/Readers/Rar/RarReader.cs @@ -71,9 +71,7 @@ public abstract class RarReader : AbstractReader ); if (Entry.IsRarV3) { - return CreateEntryStream( - new RarCrcStream(UnpackV1.Value, Entry.FileHeader, stream) - ); + return CreateEntryStream(new RarCrcStream(UnpackV1.Value, Entry.FileHeader, stream)); } return CreateEntryStream(new RarCrcStream(UnpackV2017.Value, Entry.FileHeader, stream)); } diff --git a/src/SharpCompress/Readers/ReaderFactory.cs b/src/SharpCompress/Readers/ReaderFactory.cs index 3fcb2dcd..a079c235 100644 --- a/src/SharpCompress/Readers/ReaderFactory.cs +++ b/src/SharpCompress/Readers/ReaderFactory.cs @@ -23,10 +23,7 @@ public static class ReaderFactory foreach (var factory in Factories.Factory.Factories.OfType()) { - if ( - factory.TryOpenReader(rewindableStream, options, out var reader) - && reader != null - ) + if (factory.TryOpenReader(rewindableStream, options, out var reader) && reader != null) { return reader; } diff --git a/src/SharpCompress/Readers/Zip/ZipReader.cs b/src/SharpCompress/Readers/Zip/ZipReader.cs index 2f0e34bb..616e8057 100644 --- a/src/SharpCompress/Readers/Zip/ZipReader.cs +++ b/src/SharpCompress/Readers/Zip/ZipReader.cs @@ -13,10 +13,7 @@ public class ZipReader : AbstractReader private ZipReader(Stream stream, ReaderOptions options) : base(options, ArchiveType.Zip) { Volume = new ZipVolume(stream, options); - _headerFactory = new StreamingZipHeaderFactory( - options.Password, - options.ArchiveEncoding - ); + _headerFactory = new StreamingZipHeaderFactory(options.Password, options.ArchiveEncoding); } public override ZipVolume Volume { get; } @@ -47,12 +44,12 @@ public class ZipReader : AbstractReader { case ZipHeaderType.LocalEntry: - { - yield return new ZipEntry( - new StreamingZipFilePart((LocalEntryHeader)h, stream) - ); - } - break; + { + yield return new ZipEntry( + new StreamingZipFilePart((LocalEntryHeader)h, stream) + ); + } + break; case ZipHeaderType.DirectoryEnd: { yield break; diff --git a/src/SharpCompress/Utility.cs b/src/SharpCompress/Utility.cs index a40da612..99b5d8e9 100644 --- a/src/SharpCompress/Utility.cs +++ b/src/SharpCompress/Utility.cs @@ -166,8 +166,7 @@ public static class Utility var buffer = GetTransferByteArray(); try { - do - { } while (source.Read(buffer, 0, buffer.Length) == buffer.Length); + do { } while (source.Read(buffer, 0, buffer.Length) == buffer.Length); } finally { diff --git a/src/SharpCompress/Writers/Tar/TarWriter.cs b/src/SharpCompress/Writers/Tar/TarWriter.cs index 223e6303..8151c3f3 100644 --- a/src/SharpCompress/Writers/Tar/TarWriter.cs +++ b/src/SharpCompress/Writers/Tar/TarWriter.cs @@ -14,8 +14,7 @@ public class TarWriter : AbstractWriter { private readonly bool finalizeArchiveOnClose; - public TarWriter(Stream destination, TarWriterOptions options) - : base(ArchiveType.Tar, options) + public TarWriter(Stream destination, TarWriterOptions options) : base(ArchiveType.Tar, options) { finalizeArchiveOnClose = options.FinalizeArchiveOnClose; @@ -33,22 +32,22 @@ public class TarWriter : AbstractWriter break; case CompressionType.BZip2: - { - destination = new BZip2Stream(destination, CompressionMode.Compress, false); - } - break; + { + destination = new BZip2Stream(destination, CompressionMode.Compress, false); + } + break; case CompressionType.GZip: - { - destination = new GZipStream(destination, CompressionMode.Compress); - } - break; + { + destination = new GZipStream(destination, CompressionMode.Compress); + } + break; case CompressionType.LZip: - { - destination = new LZipStream(destination, CompressionMode.Compress); - } - break; + { + destination = new LZipStream(destination, CompressionMode.Compress); + } + break; default: { throw new InvalidFormatException( diff --git a/src/SharpCompress/Writers/WriterFactory.cs b/src/SharpCompress/Writers/WriterFactory.cs index fc4f1319..fcbf2d68 100644 --- a/src/SharpCompress/Writers/WriterFactory.cs +++ b/src/SharpCompress/Writers/WriterFactory.cs @@ -8,11 +8,7 @@ namespace SharpCompress.Writers; public static class WriterFactory { - public static IWriter Open( - Stream stream, - ArchiveType archiveType, - WriterOptions writerOptions - ) + public static IWriter Open(Stream stream, ArchiveType archiveType, WriterOptions writerOptions) { var factory = Factories.Factory.Factories .OfType() diff --git a/src/SharpCompress/Writers/Zip/ZipWriter.cs b/src/SharpCompress/Writers/Zip/ZipWriter.cs index afc34800..b5d8a300 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriter.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriter.cs @@ -19,8 +19,7 @@ public class ZipWriter : AbstractWriter { private readonly CompressionType compressionType; private readonly CompressionLevel compressionLevel; - private readonly List entries = - new List(); + private readonly List entries = new List(); private readonly string zipComment; private long streamPosition; private PpmdProperties? ppmdProps; @@ -90,9 +89,7 @@ public class ZipWriter : AbstractWriter return ZipCompressionMethod.PPMd; } default: - throw new InvalidFormatException( - "Invalid compression method: " + compressionType - ); + throw new InvalidFormatException("Invalid compression method: " + compressionType); } } @@ -105,11 +102,7 @@ public class ZipWriter : AbstractWriter ); } - public void Write( - string entryPath, - Stream source, - ZipWriterEntryOptions zipWriterEntryOptions - ) + public void Write(string entryPath, Stream source, ZipWriterEntryOptions zipWriterEntryOptions) { using var output = WriteToStream(entryPath, zipWriterEntryOptions); source.TransferTo(output); @@ -245,9 +238,7 @@ public class ZipWriter : AbstractWriter if (extralength != 0) { OutputStream.Write(new byte[extralength], 0, extralength); // reserve space for zip64 data - entry.Zip64HeaderOffset = (ushort)( - 6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length - ); + entry.Zip64HeaderOffset = (ushort)(6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length); } return 6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length + extralength; @@ -392,11 +383,7 @@ public class ZipWriter : AbstractWriter } case ZipCompressionMethod.Deflate: { - return new DeflateStream( - counting, - CompressionMode.Compress, - compressionLevel - ); + return new DeflateStream(counting, CompressionMode.Compress, compressionLevel); } case ZipCompressionMethod.BZip2: { @@ -424,9 +411,7 @@ public class ZipWriter : AbstractWriter } default: { - throw new NotSupportedException( - "CompressionMethod: " + zipCompressionMethod - ); + throw new NotSupportedException("CompressionMethod: " + zipCompressionMethod); } } } diff --git a/tests/SharpCompress.Test/ADCTest.cs b/tests/SharpCompress.Test/ADCTest.cs index ae131ceb..11bb2fb0 100644 --- a/tests/SharpCompress.Test/ADCTest.cs +++ b/tests/SharpCompress.Test/ADCTest.cs @@ -1,4 +1,4 @@ -// +// // ADC.cs // // Author: @@ -37,15 +37,11 @@ public class ADCTest : TestBase [Fact] public void TestBuffer() { - using var decFs = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin") - ); + using var decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin")); var decompressed = new byte[decFs.Length]; decFs.Read(decompressed, 0, decompressed.Length); - using var cmpFs = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin") - ); + using var cmpFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin")); var compressed = new byte[cmpFs.Length]; cmpFs.Read(compressed, 0, compressed.Length); @@ -57,15 +53,11 @@ public class ADCTest : TestBase [Fact] public void TestBaseStream() { - using var decFs = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin") - ); + using var decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin")); var decompressed = new byte[decFs.Length]; decFs.Read(decompressed, 0, decompressed.Length); - using var cmpFs = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin") - ); + using var cmpFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin")); ADCBase.Decompress(cmpFs, out var test); @@ -75,15 +67,11 @@ public class ADCTest : TestBase [Fact] public void TestADCStreamWholeChunk() { - using var decFs = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin") - ); + using var decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin")); var decompressed = new byte[decFs.Length]; decFs.Read(decompressed, 0, decompressed.Length); - using var cmpFs = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin") - ); + using var cmpFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin")); using var decStream = new ADCStream(cmpFs, CompressionMode.Decompress); var test = new byte[262144]; @@ -95,15 +83,11 @@ public class ADCTest : TestBase [Fact] public void TestADCStream() { - using var decFs = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin") - ); + using var decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin")); var decompressed = new byte[decFs.Length]; decFs.Read(decompressed, 0, decompressed.Length); - using var cmpFs = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin") - ); + using var cmpFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin")); using var decStream = new ADCStream(cmpFs, CompressionMode.Decompress); using var decMs = new MemoryStream(); var test = new byte[512]; diff --git a/tests/SharpCompress.Test/ArchiveTests.cs b/tests/SharpCompress.Test/ArchiveTests.cs index 8b9a4c2d..e12ac339 100644 --- a/tests/SharpCompress.Test/ArchiveTests.cs +++ b/tests/SharpCompress.Test/ArchiveTests.cs @@ -53,17 +53,11 @@ public class ArchiveTests : ReaderTests stream.ThrowOnDispose = false; return; } - foreach ( - var entry in archive.Entries.Where(entry => !entry.IsDirectory) - ) + foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { entry.WriteToDirectory( SCRATCH_FILES_PATH, - new ExtractionOptions - { - ExtractFullPath = true, - Overwrite = true - } + new ExtractionOptions { ExtractFullPath = true, Overwrite = true } ); } stream.ThrowOnDispose = false; @@ -96,10 +90,7 @@ public class ArchiveTests : ReaderTests ); } - protected void ArchiveStreamRead( - ReaderOptions? readerOptions, - IEnumerable testArchives - ) + protected void ArchiveStreamRead(ReaderOptions? readerOptions, IEnumerable testArchives) { foreach (var path in testArchives) { @@ -231,9 +222,9 @@ public class ArchiveTests : ReaderTests { var src = testArchives.ToArray(); using var archive = ArchiveFactory.Open( - testArchives.Select(f => new FileInfo(f)), - readerOptions - ); + testArchives.Select(f => new FileInfo(f)), + readerOptions + ); try { var idx = 0; diff --git a/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs b/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs index 51ffd019..46270985 100644 --- a/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs +++ b/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs @@ -64,9 +64,7 @@ public class GZipArchiveTests : ArchiveTests var jpg = Path.Combine(ORIGINAL_FILES_PATH, "jpg", "test.jpg"); using Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz")); using var archive = GZipArchive.Open(stream); - Assert.Throws( - () => archive.AddEntry("jpg\\test.jpg", jpg) - ); + Assert.Throws(() => archive.AddEntry("jpg\\test.jpg", jpg)); archive.SaveTo(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz")); } diff --git a/tests/SharpCompress.Test/GZip/GZipReaderTests.cs b/tests/SharpCompress.Test/GZip/GZipReaderTests.cs index ed65c2a7..6890d4c6 100644 --- a/tests/SharpCompress.Test/GZip/GZipReaderTests.cs +++ b/tests/SharpCompress.Test/GZip/GZipReaderTests.cs @@ -23,9 +23,7 @@ public class GZipReaderTests : ReaderTests { //read only as GZip itme using Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz")); - using var reader = Readers.GZip.GZipReader.Open( - new RewindableStream(stream) - ); + using var reader = Readers.GZip.GZipReader.Open(new RewindableStream(stream)); while (reader.MoveToNextEntry()) // Crash here { Assert.NotEqual(0, reader.Entry.Size); diff --git a/tests/SharpCompress.Test/Mocks/TestStream.cs b/tests/SharpCompress.Test/Mocks/TestStream.cs index 3af53901..bd49ebc3 100644 --- a/tests/SharpCompress.Test/Mocks/TestStream.cs +++ b/tests/SharpCompress.Test/Mocks/TestStream.cs @@ -6,8 +6,8 @@ public class TestStream : Stream { private readonly Stream stream; - public TestStream(Stream stream) - : this(stream, stream.CanRead, stream.CanWrite, stream.CanSeek) { } + public TestStream(Stream stream) : this(stream, stream.CanRead, stream.CanWrite, stream.CanSeek) + { } public bool IsDisposed { get; private set; } diff --git a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs index af184c77..686eb708 100644 --- a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs +++ b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs @@ -168,12 +168,7 @@ public class RarArchiveTests : ArchiveTests public void Rar_Jpg_ArchiveStreamRead() { using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg")); - using ( - var archive = RarArchive.Open( - stream, - new ReaderOptions() { LookForHeader = true } - ) - ) + using (var archive = RarArchive.Open(stream, new ReaderOptions() { LookForHeader = true })) { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { @@ -219,7 +214,10 @@ public class RarArchiveTests : ArchiveTests public void QuickTest() { var textItems = new List(); - using var reader = new RarFactory().OpenReader(new FileInfo("/Users/adam/Downloads/Kuuki_Aether_chinesevcv_1.0.rar").OpenRead(), null); + using var reader = new RarFactory().OpenReader( + new FileInfo("/Users/adam/Downloads/Kuuki_Aether_chinesevcv_1.0.rar").OpenRead(), + null + ); textItems.Clear(); while (reader.MoveToNextEntry()) { @@ -344,8 +342,8 @@ public class RarArchiveTests : ArchiveTests private void DoRar_Multi_ArchiveStreamRead(string[] archives, bool isSolid) { using var archive = RarArchive.Open( - archives.Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)).Select(File.OpenRead) - ); + archives.Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)).Select(File.OpenRead) + ); Assert.Equal(archive.IsSolid, isSolid); foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { diff --git a/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs b/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs index 7e4f013a..2bf90768 100644 --- a/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs +++ b/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs @@ -48,16 +48,13 @@ public class RarHeaderFactoryTest : TestBase private void ReadEncryptedFlag(string testArchive, bool isEncrypted) { using var stream = new FileStream( - Path.Combine(TEST_ARCHIVES_PATH, testArchive), - FileMode.Open, - FileAccess.Read - ); + Path.Combine(TEST_ARCHIVES_PATH, testArchive), + FileMode.Open, + FileAccess.Read + ); foreach (var header in rarHeaderFactory.ReadHeaders(stream)) { - if ( - header.HeaderType == HeaderType.Archive - || header.HeaderType == HeaderType.Crypt - ) + if (header.HeaderType == HeaderType.Archive || header.HeaderType == HeaderType.Crypt) { Assert.Equal(isEncrypted, rarHeaderFactory.IsEncrypted); break; diff --git a/tests/SharpCompress.Test/Rar/RarReaderTests.cs b/tests/SharpCompress.Test/Rar/RarReaderTests.cs index 15266d6c..5e98eee0 100644 --- a/tests/SharpCompress.Test/Rar/RarReaderTests.cs +++ b/tests/SharpCompress.Test/Rar/RarReaderTests.cs @@ -282,15 +282,10 @@ public class RarReaderTests : ReaderTests public void Rar_Reader_Audio_program() { using ( - var stream = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "Rar.Audio_program.rar") - ) + var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.Audio_program.rar")) ) using ( - var reader = ReaderFactory.Open( - stream, - new ReaderOptions() { LookForHeader = true } - ) + var reader = ReaderFactory.Open(stream, new ReaderOptions() { LookForHeader = true }) ) { while (reader.MoveToNextEntry()) @@ -312,9 +307,7 @@ public class RarReaderTests : ReaderTests public void Rar_Jpg_Reader() { using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg"))) - using ( - var reader = RarReader.Open(stream, new ReaderOptions() { LookForHeader = true }) - ) + using (var reader = RarReader.Open(stream, new ReaderOptions() { LookForHeader = true })) { while (reader.MoveToNextEntry()) { @@ -355,10 +348,7 @@ public class RarReaderTests : ReaderTests private void DoRar_Solid_Skip_Reader(string filename) { using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, filename)); - using var reader = ReaderFactory.Open( - stream, - new ReaderOptions() { LookForHeader = true } - ); + using var reader = ReaderFactory.Open(stream, new ReaderOptions() { LookForHeader = true }); while (reader.MoveToNextEntry()) { if (reader.Entry.Key.Contains("jpg")) @@ -387,10 +377,7 @@ public class RarReaderTests : ReaderTests private void DoRar_Reader_Skip(string filename) { using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, filename)); - using var reader = ReaderFactory.Open( - stream, - new ReaderOptions() { LookForHeader = true } - ); + using var reader = ReaderFactory.Open(stream, new ReaderOptions() { LookForHeader = true }); while (reader.MoveToNextEntry()) { if (reader.Entry.Key.Contains("jpg")) diff --git a/tests/SharpCompress.Test/ReaderTests.cs b/tests/SharpCompress.Test/ReaderTests.cs index eb0de103..be1dbe07 100644 --- a/tests/SharpCompress.Test/ReaderTests.cs +++ b/tests/SharpCompress.Test/ReaderTests.cs @@ -35,18 +35,15 @@ public abstract class ReaderTests : TestBase { using var file = File.OpenRead(testArchive); using var protectedStream = NonDisposingStream.Create( - new ForwardOnlyStream(file), - throwOnDispose: true - ); + new ForwardOnlyStream(file), + throwOnDispose: true + ); using var testStream = new TestStream(protectedStream); using (var reader = ReaderFactory.Open(testStream, options)) { UseReader(reader, expectedCompression); protectedStream.ThrowOnDispose = false; - Assert.False( - testStream.IsDisposed, - "{nameof(testStream)} prematurely closed" - ); + Assert.False(testStream.IsDisposed, "{nameof(testStream)} prematurely closed"); } // Boolean XOR -- If the stream should be left open (true), then the stream should not be diposed (false) diff --git a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs index c988d1c2..23b99a1a 100644 --- a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs +++ b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs @@ -34,10 +34,7 @@ public class SevenZipArchiveTests : ArchiveTests [Fact] public void SevenZipArchive_LZMAAES_StreamRead() { - ArchiveStreamRead( - "7Zip.LZMA.Aes.7z", - new ReaderOptions() { Password = "testpassword" } - ); + ArchiveStreamRead("7Zip.LZMA.Aes.7z", new ReaderOptions() { Password = "testpassword" }); } [Fact] diff --git a/tests/SharpCompress.Test/Streams/ZlibBaseStreamTests.cs b/tests/SharpCompress.Test/Streams/ZlibBaseStreamTests.cs index 44f6843c..56f934d6 100644 --- a/tests/SharpCompress.Test/Streams/ZlibBaseStreamTests.cs +++ b/tests/SharpCompress.Test/Streams/ZlibBaseStreamTests.cs @@ -80,10 +80,10 @@ public class ZLibBaseStreamTests private void Compress(Stream input, Stream output, int compressionLevel) { using var zlibStream = new ZlibStream( - NonDisposingStream.Create(output), - CompressionMode.Compress, - (CompressionLevel)compressionLevel - ); + NonDisposingStream.Create(output), + CompressionMode.Compress, + (CompressionLevel)compressionLevel + ); zlibStream.FlushMode = FlushType.Sync; input.CopyTo(zlibStream); } @@ -91,9 +91,9 @@ public class ZLibBaseStreamTests private void Decompress(Stream input, Stream output) { using var zlibStream = new ZlibStream( - NonDisposingStream.Create(input), - CompressionMode.Decompress - ); + NonDisposingStream.Create(input), + CompressionMode.Decompress + ); zlibStream.CopyTo(output); } diff --git a/tests/SharpCompress.Test/Tar/TarWriterTests.cs b/tests/SharpCompress.Test/Tar/TarWriterTests.cs index 197e7ba3..98ed2e19 100644 --- a/tests/SharpCompress.Test/Tar/TarWriterTests.cs +++ b/tests/SharpCompress.Test/Tar/TarWriterTests.cs @@ -50,12 +50,7 @@ public class TarWriterTests : WriterTests public void Tar_Rar_Write() { Assert.Throws( - () => - Write( - CompressionType.Rar, - "Zip.ppmd.noEmptyDirs.zip", - "Zip.ppmd.noEmptyDirs.zip" - ) + () => Write(CompressionType.Rar, "Zip.ppmd.noEmptyDirs.zip", "Zip.ppmd.noEmptyDirs.zip") ); } diff --git a/tests/SharpCompress.Test/WriterTests.cs b/tests/SharpCompress.Test/WriterTests.cs index 7134ea9e..db2c4911 100644 --- a/tests/SharpCompress.Test/WriterTests.cs +++ b/tests/SharpCompress.Test/WriterTests.cs @@ -25,10 +25,7 @@ public class WriterTests : TestBase { using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive))) { - var writerOptions = new WriterOptions(compressionType) - { - LeaveStreamOpen = true, - }; + var writerOptions = new WriterOptions(compressionType) { LeaveStreamOpen = true, }; writerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default; @@ -46,10 +43,7 @@ public class WriterTests : TestBase readerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default; - using var reader = ReaderFactory.Open( - NonDisposingStream.Create(stream), - readerOptions - ); + using var reader = ReaderFactory.Open(NonDisposingStream.Create(stream), readerOptions); reader.WriteAllToDirectory( SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true } diff --git a/tests/SharpCompress.Test/Zip/Zip64Tests.cs b/tests/SharpCompress.Test/Zip/Zip64Tests.cs index d19913e1..039411a7 100644 --- a/tests/SharpCompress.Test/Zip/Zip64Tests.cs +++ b/tests/SharpCompress.Test/Zip/Zip64Tests.cs @@ -108,14 +108,7 @@ public class Zip64Tests : WriterTests if (!File.Exists(filename)) { - CreateZipArchive( - filename, - files, - filesize, - write_chunk_size, - set_zip64, - forward_only - ); + CreateZipArchive(filename, files, filesize, write_chunk_size, set_zip64, forward_only); } var resForward = ReadForwardOnly(filename); @@ -195,8 +188,7 @@ public class Zip64Tests : WriterTests { while (rd.MoveToNextEntry()) { - using (rd.OpenEntryStream()) - { } + using (rd.OpenEntryStream()) { } count++; if (prev != null) diff --git a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs index dab65cc0..62f2e751 100644 --- a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs @@ -77,8 +77,8 @@ public class ZipReaderTests : ReaderTests public void Zip_Deflate_Streamed_Skip() { using Stream stream = new ForwardOnlyStream( - File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")) - ); + File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")) + ); using var reader = ReaderFactory.Open(stream); var x = 0; while (reader.MoveToNextEntry()) @@ -149,9 +149,7 @@ public class ZipReaderTests : ReaderTests public void Zip_BZip2_PkwareEncryption_Read() { using ( - Stream stream = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip") - ) + Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip")) ) using (var reader = ZipReader.Open(stream, new ReaderOptions() { Password = "test" })) { @@ -174,8 +172,8 @@ public class ZipReaderTests : ReaderTests public void Zip_Reader_Disposal_Test() { using var stream = new TestStream( - File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")) - ); + File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")) + ); using (var reader = ReaderFactory.Open(stream)) { while (reader.MoveToNextEntry()) @@ -196,8 +194,8 @@ public class ZipReaderTests : ReaderTests public void Zip_Reader_Disposal_Test2() { using var stream = new TestStream( - File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")) - ); + File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")) + ); var reader = ReaderFactory.Open(stream); while (reader.MoveToNextEntry()) { @@ -222,9 +220,7 @@ public class ZipReaderTests : ReaderTests Path.Combine(TEST_ARCHIVES_PATH, "Zip.lzma.WinzipAES.zip") ) ) - using ( - var reader = ZipReader.Open(stream, new ReaderOptions() { Password = "test" }) - ) + using (var reader = ZipReader.Open(stream, new ReaderOptions() { Password = "test" })) { while (reader.MoveToNextEntry()) { @@ -302,13 +298,7 @@ public class ZipReaderTests : ReaderTests using var memory = new MemoryStream(); Stream stream = new TestStream(memory, read: true, write: true, seek: false); - using ( - var zipWriter = WriterFactory.Open( - stream, - ArchiveType.Zip, - CompressionType.Deflate - ) - ) + using (var zipWriter = WriterFactory.Open(stream, ArchiveType.Zip, CompressionType.Deflate)) { zipWriter.Write(expected[0].Item1, new MemoryStream(expected[0].Item2)); zipWriter.Write(expected[1].Item1, new MemoryStream(expected[1].Item2)); @@ -354,8 +344,8 @@ public class ZipReaderTests : ReaderTests }; using Stream stream = File.OpenRead( - Path.Combine(TEST_ARCHIVES_PATH, "Zip.none.issue86.zip") - ); + Path.Combine(TEST_ARCHIVES_PATH, "Zip.none.issue86.zip") + ); using var reader = ZipReader.Open(stream); foreach (var key in keys) { @@ -407,8 +397,7 @@ public class ZipReaderTests : ReaderTests var zipPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.uncompressed.zip"); using var stream = File.Open(zipPath, FileMode.Open, FileAccess.Read); using var reader = ReaderFactory.Open(stream); - while (reader.MoveToNextEntry()) - { } + while (reader.MoveToNextEntry()) { } } [Fact] diff --git a/tests/SharpCompress.Test/Zip/ZipWriterTests.cs b/tests/SharpCompress.Test/Zip/ZipWriterTests.cs index c073a8a2..b95efb81 100644 --- a/tests/SharpCompress.Test/Zip/ZipWriterTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipWriterTests.cs @@ -68,12 +68,7 @@ public class ZipWriterTests : WriterTests public void Zip_Rar_Write() { Assert.Throws( - () => - Write( - CompressionType.Rar, - "Zip.ppmd.noEmptyDirs.zip", - "Zip.ppmd.noEmptyDirs.zip" - ) + () => Write(CompressionType.Rar, "Zip.ppmd.noEmptyDirs.zip", "Zip.ppmd.noEmptyDirs.zip") ); } }