From 7080c2abd0d5d01070f695fc4d828f34cc777551 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 15 Nov 2023 11:05:30 +0000 Subject: [PATCH 1/3] Update csharpier and fix formatting --- .config/dotnet-tools.json | 2 +- src/SharpCompress/Archives/ArchiveFactory.cs | 3 ++- src/SharpCompress/Archives/Rar/RarArchive.cs | 6 ++--- .../Archives/SevenZip/SevenZipArchive.cs | 12 ++++++---- .../Common/Rar/Headers/FileHeader.cs | 9 ++++--- src/SharpCompress/Common/Rar/RarVolume.cs | 10 ++++---- .../Common/ReaderCancelledException.cs | 1 - .../Common/Tar/TarReadOnlySubStream.cs | 4 ++-- .../Common/Zip/ZipHeaderFactory.cs | 6 ++--- .../Compressors/Deflate/DeflateManager.cs | 5 ++-- .../Compressors/Deflate/Inflate.cs | 1 - .../Compressors/Deflate/ZlibBaseStream.cs | 2 +- .../Compressors/Deflate64/Deflate64Stream.cs | 2 +- .../Compressors/PPMd/I1/Model.cs | 3 ++- .../Compressors/Rar/UnpackV1/Unpack.cs | 7 +++--- .../Compressors/Rar/UnpackV1/UnpackUtility.cs | 1 - .../FragmentedWindow.unpack50frag_cpp.cs | 2 +- .../Compressors/Rar/UnpackV2017/Unpack.cs | 8 +++---- .../Rar/UnpackV2017/Unpack.rawint_hpp.cs | 5 ++-- .../Rar/UnpackV2017/Unpack.unpack20_cpp.cs | 7 +++--- .../Rar/UnpackV2017/Unpack.unpack50_cpp.cs | 9 ++++--- .../Rar/UnpackV2017/Unpack.unpack_cpp.cs | 9 ++++--- .../UnpackV2017/Unpack.unpackinline_cpp.cs | 3 ++- src/SharpCompress/Factories/GZipFactory.cs | 1 - src/SharpCompress/Factories/TarFactory.cs | 1 - src/SharpCompress/Factories/ZipFactory.cs | 1 - src/SharpCompress/Readers/Tar/TarReader.cs | 2 +- src/SharpCompress/Writers/IWriterFactory.cs | 1 - src/SharpCompress/Writers/WriterFactory.cs | 5 ++-- tests/SharpCompress.Test/ArchiveTests.cs | 8 +++---- .../SharpCompress.Test/Tar/TarArchiveTests.cs | 14 +++++------ .../SharpCompress.Test/Tar/TarReaderTests.cs | 23 +++++++++++------- tests/SharpCompress.Test/TestBase.cs | 8 +++---- .../Xz/Filters/Lzma2Tests.cs | 2 +- tests/SharpCompress.Test/Xz/XZHeaderTests.cs | 2 +- tests/SharpCompress.Test/Xz/XZIndexTests.cs | 4 ++-- tests/SharpCompress.Test/Xz/XZStreamTests.cs | 4 ++-- .../SharpCompress.Test/Zip/ZipArchiveTests.cs | 24 +++++++++---------- .../SharpCompress.Test/Zip/ZipWriterTests.cs | 1 - 39 files changed, 111 insertions(+), 107 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index ef84a272..3cf567c5 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "csharpier": { - "version": "0.25.0", + "version": "0.26.1", "commands": [ "dotnet-csharpier" ] diff --git a/src/SharpCompress/Archives/ArchiveFactory.cs b/src/SharpCompress/Archives/ArchiveFactory.cs index cd0952f1..2e859599 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.cs @@ -25,7 +25,8 @@ public static class ArchiveFactory public static IWritableArchive Create(ArchiveType type) { - var factory = Factory.Factories + var factory = Factory + .Factories .OfType() .FirstOrDefault(item => item.KnownArchiveType == type); diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index 29d733f6..e9c580fe 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -40,9 +40,9 @@ public class RarArchive : AbstractArchive streams[1].Position = 0; SrcStream.Position = 0; - return srcStream.Streams.Select( - a => new StreamRarArchiveVolume(a, ReaderOptions, idx++) - ); + return srcStream + .Streams + .Select(a => new StreamRarArchiveVolume(a, ReaderOptions, idx++)); } else //split mode or single file { diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index 7577b43d..99fe962d 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -236,11 +236,13 @@ public class SevenZipArchive : AbstractArchive x.Type == ExtraDataType.WinZipAes - ); + var data = entryHeader + .Extra + .SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); if (data != null) { var keySize = (WinzipAesKeySize)data.DataBytes[4]; diff --git a/src/SharpCompress/Compressors/Deflate/DeflateManager.cs b/src/SharpCompress/Compressors/Deflate/DeflateManager.cs index 27ad4018..06cf0005 100644 --- a/src/SharpCompress/Compressors/Deflate/DeflateManager.cs +++ b/src/SharpCompress/Compressors/Deflate/DeflateManager.cs @@ -69,7 +69,6 @@ // ----------------------------------------------------------------------- using System; - using SharpCompress.Algorithms; namespace SharpCompress.Compressors.Deflate; @@ -1959,7 +1958,9 @@ internal sealed partial class DeflateManager // returning Z_STREAM_END instead of Z_BUFF_ERROR. } else if ( - _codec.AvailableBytesIn == 0 && (int)flush <= old_flush && flush != FlushType.Finish + _codec.AvailableBytesIn == 0 + && (int)flush <= old_flush + && flush != FlushType.Finish ) { // workitem 8557 diff --git a/src/SharpCompress/Compressors/Deflate/Inflate.cs b/src/SharpCompress/Compressors/Deflate/Inflate.cs index ebea2805..37227b3d 100644 --- a/src/SharpCompress/Compressors/Deflate/Inflate.cs +++ b/src/SharpCompress/Compressors/Deflate/Inflate.cs @@ -64,7 +64,6 @@ // ----------------------------------------------------------------------- using System; - using SharpCompress.Algorithms; namespace SharpCompress.Compressors.Deflate; diff --git a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs index 19a3c60a..8248e900 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs @@ -30,8 +30,8 @@ using System; using System.Buffers.Binary; using System.Collections.Generic; using System.IO; -using SharpCompress.Common.Tar.Headers; using System.Text; +using SharpCompress.Common.Tar.Headers; namespace SharpCompress.Compressors.Deflate; diff --git a/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs b/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs index 149f7c92..3eda232c 100644 --- a/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs +++ b/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs @@ -4,11 +4,11 @@ #nullable disable -using SharpCompress.Common.Zip; using System; using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; +using SharpCompress.Common.Zip; namespace SharpCompress.Compressors.Deflate64; diff --git a/src/SharpCompress/Compressors/PPMd/I1/Model.cs b/src/SharpCompress/Compressors/PPMd/I1/Model.cs index 786cb0e7..9a1d090f 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/Model.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/Model.cs @@ -866,7 +866,8 @@ 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); diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs index 2ca62d6b..728d0f85 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs @@ -1269,9 +1269,10 @@ internal sealed partial class Unpack : BitInput, IRarUnpack if (CurSize < DataSize + RarVM.VM_FIXEDGLOBALSIZE) { // StackFilter->Prg.GlobalData.Add(DataSize+VM_FIXEDGLOBALSIZE-CurSize); - StackFilter.Program.GlobalData.SetSize( - DataSize + RarVM.VM_FIXEDGLOBALSIZE - CurSize - ); + StackFilter + .Program + .GlobalData + .SetSize(DataSize + RarVM.VM_FIXEDGLOBALSIZE - CurSize); } var offset = RarVM.VM_FIXEDGLOBALSIZE; globalData = StackFilter.Program.GlobalData; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs index 09f5ee8f..b501337b 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs @@ -1,5 +1,4 @@ using System; - using SharpCompress.Compressors.Rar.VM; namespace SharpCompress.Compressors.Rar.UnpackV1; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs index bfa69829..a9a6f280 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs @@ -1,5 +1,6 @@ #nullable disable +using System; #if !Rar2017_64bit using size_t = System.UInt32; #else @@ -7,7 +8,6 @@ using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; #endif -using System; namespace SharpCompress.Compressors.Rar.UnpackV2017; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs index 53db46d2..450b4694 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs @@ -1,13 +1,13 @@ -#if !Rar2017_64bit +using System; +using System.IO; +using SharpCompress.Common.Rar.Headers; +#if !Rar2017_64bit using size_t = System.UInt32; #else using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; #endif -using System; -using System.IO; -using SharpCompress.Common.Rar.Headers; namespace SharpCompress.Compressors.Rar.UnpackV2017; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs index 03614dde..333c7ae7 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs @@ -1,10 +1,11 @@ -#if !Rar2017_64bit +using uint32 = System.UInt32; +#if !Rar2017_64bit #else using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; #endif -using uint32 = System.UInt32; + namespace SharpCompress.Compressors.Rar.UnpackV2017; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs index b92af290..a7863588 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs @@ -1,12 +1,13 @@ +using System; +using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; +using static SharpCompress.Compressors.Rar.UnpackV2017.Unpack.Unpack20Local; #if !Rar2017_64bit #else using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; #endif -using System; -using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; -using static SharpCompress.Compressors.Rar.UnpackV2017.Unpack.Unpack20Local; + namespace SharpCompress.Compressors.Rar.UnpackV2017; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs index f85921bd..82294e27 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs @@ -1,5 +1,9 @@ #nullable disable +using System; +using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; +using static SharpCompress.Compressors.Rar.UnpackV2017.UnpackGlobal; +using int64 = System.Int64; #if !Rar2017_64bit using size_t = System.UInt32; #else @@ -7,11 +11,6 @@ using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; #endif -using int64 = System.Int64; - -using System; -using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; -using static SharpCompress.Compressors.Rar.UnpackV2017.UnpackGlobal; namespace SharpCompress.Compressors.Rar.UnpackV2017; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs index f9a74440..b8d1c78a 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs @@ -1,5 +1,9 @@ #nullable disable +using System; +using SharpCompress.Common; +using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; +using static SharpCompress.Compressors.Rar.UnpackV2017.UnpackGlobal; #if !Rar2017_64bit using size_t = System.UInt32; #else @@ -8,11 +12,6 @@ using nuint = System.UInt64; using size_t = System.UInt64; #endif -using System; -using SharpCompress.Common; -using static SharpCompress.Compressors.Rar.UnpackV2017.UnpackGlobal; -using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; - namespace SharpCompress.Compressors.Rar.UnpackV2017; internal sealed partial class Unpack : BitInput diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs index 584d0b51..1d53ae5b 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs @@ -1,10 +1,11 @@ +using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; #if !Rar2017_64bit #else using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; #endif -using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; + namespace SharpCompress.Compressors.Rar.UnpackV2017; diff --git a/src/SharpCompress/Factories/GZipFactory.cs b/src/SharpCompress/Factories/GZipFactory.cs index 5e522f5b..be1b4931 100644 --- a/src/SharpCompress/Factories/GZipFactory.cs +++ b/src/SharpCompress/Factories/GZipFactory.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; - using SharpCompress.Archives; using SharpCompress.Archives.GZip; using SharpCompress.Archives.Tar; diff --git a/src/SharpCompress/Factories/TarFactory.cs b/src/SharpCompress/Factories/TarFactory.cs index 61965b86..54c24c02 100644 --- a/src/SharpCompress/Factories/TarFactory.cs +++ b/src/SharpCompress/Factories/TarFactory.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.IO; - using SharpCompress.Archives; using SharpCompress.Archives.Tar; using SharpCompress.Common; diff --git a/src/SharpCompress/Factories/ZipFactory.cs b/src/SharpCompress/Factories/ZipFactory.cs index dca697dc..780d2a9c 100644 --- a/src/SharpCompress/Factories/ZipFactory.cs +++ b/src/SharpCompress/Factories/ZipFactory.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.IO; - using SharpCompress.Archives; using SharpCompress.Archives.Zip; using SharpCompress.Common; diff --git a/src/SharpCompress/Readers/Tar/TarReader.cs b/src/SharpCompress/Readers/Tar/TarReader.cs index c9802e46..34f337a6 100644 --- a/src/SharpCompress/Readers/Tar/TarReader.cs +++ b/src/SharpCompress/Readers/Tar/TarReader.cs @@ -8,9 +8,9 @@ using SharpCompress.Common.Tar; using SharpCompress.Compressors; using SharpCompress.Compressors.BZip2; using SharpCompress.Compressors.Deflate; -using SharpCompress.IO; using SharpCompress.Compressors.LZMA; using SharpCompress.Compressors.Xz; +using SharpCompress.IO; namespace SharpCompress.Readers.Tar; diff --git a/src/SharpCompress/Writers/IWriterFactory.cs b/src/SharpCompress/Writers/IWriterFactory.cs index 8e7bc701..094a5553 100644 --- a/src/SharpCompress/Writers/IWriterFactory.cs +++ b/src/SharpCompress/Writers/IWriterFactory.cs @@ -1,5 +1,4 @@ using System.IO; - using SharpCompress.Factories; namespace SharpCompress.Writers; diff --git a/src/SharpCompress/Writers/WriterFactory.cs b/src/SharpCompress/Writers/WriterFactory.cs index fcbf2d68..1f14f6bb 100644 --- a/src/SharpCompress/Writers/WriterFactory.cs +++ b/src/SharpCompress/Writers/WriterFactory.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Linq; - using SharpCompress.Common; namespace SharpCompress.Writers; @@ -10,7 +9,9 @@ public static class WriterFactory { public static IWriter Open(Stream stream, ArchiveType archiveType, WriterOptions writerOptions) { - var factory = Factories.Factory.Factories + var factory = Factories + .Factory + .Factories .OfType() .FirstOrDefault(item => item.KnownArchiveType == archiveType); diff --git a/tests/SharpCompress.Test/ArchiveTests.cs b/tests/SharpCompress.Test/ArchiveTests.cs index 08377a0e..33bd0ba7 100644 --- a/tests/SharpCompress.Test/ArchiveTests.cs +++ b/tests/SharpCompress.Test/ArchiveTests.cs @@ -298,10 +298,10 @@ public class ArchiveTests : ReaderTests memory.Position = 0; for (int y = 0; y < 9; y++) - for (int x = 0; x < 256; x++) - { - Assert.Equal(x, memory.ReadByte()); - } + for (int x = 0; x < 256; x++) + { + Assert.Equal(x, memory.ReadByte()); + } Assert.Equal((int)-1, memory.ReadByte()); } diff --git a/tests/SharpCompress.Test/Tar/TarArchiveTests.cs b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs index dddb32a6..711b14c1 100644 --- a/tests/SharpCompress.Test/Tar/TarArchiveTests.cs +++ b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs @@ -1,15 +1,15 @@ using System; using System.IO; using System.Linq; +using System.Text; using SharpCompress.Archives; using SharpCompress.Archives.Tar; using SharpCompress.Common; -using SharpCompress.Writers; -using Xunit; -using System.Text; using SharpCompress.Readers; -using SharpCompress.Writers.Tar; using SharpCompress.Readers.Tar; +using SharpCompress.Writers; +using SharpCompress.Writers.Tar; +using Xunit; namespace SharpCompress.Test.Tar; @@ -198,9 +198,9 @@ public class TarArchiveTests : ArchiveTests using (var archive = TarArchive.Open(unmodified)) { - var entry = archive.Entries.Single( - x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) - ); + var entry = archive + .Entries + .Single(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)); archive.RemoveEntry(entry); archive.SaveTo(scratchPath, CompressionType.None); } diff --git a/tests/SharpCompress.Test/Tar/TarReaderTests.cs b/tests/SharpCompress.Test/Tar/TarReaderTests.cs index 76629363..218eb43f 100644 --- a/tests/SharpCompress.Test/Tar/TarReaderTests.cs +++ b/tests/SharpCompress.Test/Tar/TarReaderTests.cs @@ -206,9 +206,11 @@ public class TarReaderTests : ReaderTests [Fact] public void Tar_GZip_With_Symlink_Entries() { - var isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform( - System.Runtime.InteropServices.OSPlatform.Windows - ); + var isWindows = System + .Runtime + .InteropServices + .RuntimeInformation + .IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows); using ( Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "TarWithSymlink.tar.gz")) ) @@ -251,12 +253,15 @@ public class TarReaderTests : ReaderTests { // need to convert the link to an absolute path for comparison var target = reader.Entry.LinkTarget; - var realTarget = System.IO.Path.GetFullPath( - System.IO.Path.Combine( - $"{System.IO.Path.GetDirectoryName(path)}", - target - ) - ); + var realTarget = System + .IO + .Path + .GetFullPath( + System + .IO + .Path + .Combine($"{System.IO.Path.GetDirectoryName(path)}", target) + ); Assert.Equal(realTarget, link.GetContents().ToString()); } diff --git a/tests/SharpCompress.Test/TestBase.cs b/tests/SharpCompress.Test/TestBase.cs index 3ad1fe79..b4966c31 100644 --- a/tests/SharpCompress.Test/TestBase.cs +++ b/tests/SharpCompress.Test/TestBase.cs @@ -20,10 +20,10 @@ public class TestBase : IDisposable public TestBase() { - var index = AppDomain.CurrentDomain.BaseDirectory.IndexOf( - "SharpCompress.Test", - StringComparison.OrdinalIgnoreCase - ); + var index = AppDomain + .CurrentDomain + .BaseDirectory + .IndexOf("SharpCompress.Test", StringComparison.OrdinalIgnoreCase); var path = AppDomain.CurrentDomain.BaseDirectory.Substring(0, index); SOLUTION_BASE_PATH = Path.GetDirectoryName(path) ?? throw new ArgumentNullException(); diff --git a/tests/SharpCompress.Test/Xz/Filters/Lzma2Tests.cs b/tests/SharpCompress.Test/Xz/Filters/Lzma2Tests.cs index 83eed21c..ff5dd467 100644 --- a/tests/SharpCompress.Test/Xz/Filters/Lzma2Tests.cs +++ b/tests/SharpCompress.Test/Xz/Filters/Lzma2Tests.cs @@ -1,7 +1,7 @@ using System; -using Xunit; using System.IO; using SharpCompress.Compressors.Xz.Filters; +using Xunit; namespace SharpCompress.Test.Xz.Filters; diff --git a/tests/SharpCompress.Test/Xz/XZHeaderTests.cs b/tests/SharpCompress.Test/Xz/XZHeaderTests.cs index 3fa9dc86..e187b47a 100644 --- a/tests/SharpCompress.Test/Xz/XZHeaderTests.cs +++ b/tests/SharpCompress.Test/Xz/XZHeaderTests.cs @@ -1,5 +1,5 @@ -using SharpCompress.Compressors.Xz; using System.IO; +using SharpCompress.Compressors.Xz; using Xunit; namespace SharpCompress.Test.Xz; diff --git a/tests/SharpCompress.Test/Xz/XZIndexTests.cs b/tests/SharpCompress.Test/Xz/XZIndexTests.cs index 9c9d15bf..ccbf81b7 100644 --- a/tests/SharpCompress.Test/Xz/XZIndexTests.cs +++ b/tests/SharpCompress.Test/Xz/XZIndexTests.cs @@ -1,5 +1,5 @@ -using SharpCompress.Compressors.Xz; -using System.IO; +using System.IO; +using SharpCompress.Compressors.Xz; using Xunit; namespace SharpCompress.Test.Xz; diff --git a/tests/SharpCompress.Test/Xz/XZStreamTests.cs b/tests/SharpCompress.Test/Xz/XZStreamTests.cs index 1f50fb40..1b5a9343 100644 --- a/tests/SharpCompress.Test/Xz/XZStreamTests.cs +++ b/tests/SharpCompress.Test/Xz/XZStreamTests.cs @@ -1,5 +1,5 @@ -using SharpCompress.Compressors.Xz; -using System.IO; +using System.IO; +using SharpCompress.Compressors.Xz; using Xunit; namespace SharpCompress.Test.Xz; diff --git a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs index fde87dc6..080ae318 100644 --- a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs @@ -184,9 +184,9 @@ public class ZipArchiveTests : ArchiveTests using (var archive = ZipArchive.Open(unmodified)) { - var entry = archive.Entries.Single( - x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) - ); + var entry = archive + .Entries + .Single(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)); archive.RemoveEntry(entry); WriterOptions writerOptions = new ZipWriterOptions(CompressionType.Deflate); @@ -252,9 +252,9 @@ public class ZipArchiveTests : ArchiveTests ) ); Assert.Null( - ((IArchive)vfs).Entries.FirstOrDefault( - v => v.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) - ) + ((IArchive)vfs) + .Entries + .FirstOrDefault(v => v.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)) ); } } @@ -391,14 +391,14 @@ public class ZipArchiveTests : ArchiveTests { archive.AddAllFromDirectory(SCRATCH_FILES_PATH); archive.RemoveEntry( - archive.Entries.Single( - x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) - ) + archive + .Entries + .Single(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)) ); Assert.Null( - archive.Entries.FirstOrDefault( - x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) - ) + archive + .Entries + .FirstOrDefault(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)) ); } Directory.Delete(SCRATCH_FILES_PATH, true); diff --git a/tests/SharpCompress.Test/Zip/ZipWriterTests.cs b/tests/SharpCompress.Test/Zip/ZipWriterTests.cs index 530397bd..55435b4a 100644 --- a/tests/SharpCompress.Test/Zip/ZipWriterTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipWriterTests.cs @@ -1,5 +1,4 @@ using System.Text; - using SharpCompress.Common; using Xunit; From d28a278d632b1442ebdf17ee2c4e22be03f27f43 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 15 Nov 2023 11:10:05 +0000 Subject: [PATCH 2/3] Comment out flag to allow formatting --- .../Rar/UnpackV2017/Unpack.unpack_cpp.cs | 42 +++---- .../Compressors/Rar/UnpackV2017/unpack_hpp.cs | 115 +++++++++++------- 2 files changed, 89 insertions(+), 68 deletions(-) diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs index b8d1c78a..38c21c9f 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs @@ -29,12 +29,12 @@ internal sealed partial class Unpack : BitInput Suspended = false; UnpAllBuf = false; UnpSomeRead = false; -#if RarV2017_RAR_SMP - MaxUserThreads = 1; - UnpThreadPool = CreateThreadPool(); - ReadBufMT = null; - UnpThreadData = null; -#endif + /*#if RarV2017_RAR_SMP + MaxUserThreads = 1; + UnpThreadPool = CreateThreadPool(); + ReadBufMT = null; + UnpThreadData = null; + #endif*/ MaxWinSize = 0; MaxWinMask = 0; @@ -198,21 +198,21 @@ internal sealed partial class Unpack : BitInput break; #endif case 50: // RAR 5.0 compression algorithm. -#if RarV2017_RAR_SMP - if (MaxUserThreads > 1) - { - // We do not use the multithreaded unpack routine to repack RAR archives - // in 'suspended' mode, because unlike the single threaded code it can - // write more than one dictionary for same loop pass. So we would need - // larger buffers of unknown size. Also we do not support multithreading - // in fragmented window mode. - if (!Fragmented) - { - Unpack5MT(Solid); - break; - } - } -#endif + /*#if RarV2017_RAR_SMP + if (MaxUserThreads > 1) + { + // We do not use the multithreaded unpack routine to repack RAR archives + // in 'suspended' mode, because unlike the single threaded code it can + // write more than one dictionary for same loop pass. So we would need + // larger buffers of unknown size. Also we do not support multithreading + // in fragmented window mode. + if (!Fragmented) + { + Unpack5MT(Solid); + break; + } + } + #endif*/ Unpack5(Solid); break; #if !Rar2017_NOSTRICT diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs index 18cd9697..4f77fc07 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs @@ -1,3 +1,8 @@ +using System; +using System.Collections.Generic; +using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; +using static SharpCompress.Compressors.Rar.UnpackV2017.UnpackGlobal; +using int64 = System.Int64; #if !Rar2017_64bit using size_t = System.UInt32; #else @@ -5,12 +10,6 @@ using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; #endif -using int64 = System.Int64; - -using System.Collections.Generic; -using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; -using static SharpCompress.Compressors.Rar.UnpackV2017.UnpackGlobal; -using System; // TODO: REMOVE THIS... WIP #pragma warning disable 169 @@ -20,8 +19,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017; internal static class UnpackGlobal { - - // Maximum allowed number of compressed bits processed in quick mode. public const int MAX_QUICK_DECODE_BITS = 10; @@ -97,11 +94,11 @@ internal struct UnpackBlockHeader internal struct UnpackBlockTables { - public DecodeTable LD; // Decode literals. - public DecodeTable DD; // Decode distances. + public DecodeTable LD; // Decode literals. + public DecodeTable DD; // Decode distances. public DecodeTable LDD; // Decode lower bits of distances. - public DecodeTable RD; // Decode repeating distances. - public DecodeTable BD; // Decode bit lengths in Huffman table. + public DecodeTable RD; // Decode repeating distances. + public DecodeTable BD; // Decode bit lengths in Huffman table. public void Init() { @@ -113,8 +110,7 @@ internal struct UnpackBlockTables } }; - -#if RarV2017_RAR_SMP +/*#if RarV2017_RAR_SMP enum UNP_DEC_TYPE { UNPDT_LITERAL,UNPDT_MATCH,UNPDT_FULLREP,UNPDT_REP,UNPDT_FILTER }; @@ -161,7 +157,7 @@ if (Decoded!=NULL) free(Decoded); } }; -#endif +#endif*/ //struct UnpackFilter @@ -171,12 +167,12 @@ internal class UnpackFilter public uint BlockStart; public uint BlockLength; public byte Channels; + // uint Width; // byte PosR; public bool NextWindow; }; - //struct UnpackFilter30 internal class UnpackFilter30 { @@ -195,15 +191,21 @@ internal class UnpackFilter30 internal class AudioVariables // For RAR 2.0 archives only. { - public int K1, K2, K3, K4, K5; - public int D1, D2, D3, D4; + public int K1, + K2, + K3, + K4, + K5; + public int D1, + D2, + D3, + D4; public int LastDelta; public readonly uint[] Dif = new uint[11]; public uint ByteCount; public int LastChar; }; - // We can use the fragmented dictionary in case heap does not have the single // large enough memory block. It is slower than normal dictionary. internal partial class FragmentedWindow @@ -223,10 +225,8 @@ internal partial class FragmentedWindow //size_t GetBlockSize(size_t StartPos,size_t RequiredSize); }; - internal partial class Unpack { - //void Unpack5(bool Solid); //void Unpack5MT(bool Solid); //bool UnpReadBuf(); @@ -254,16 +254,16 @@ internal partial class Unpack //BitInput Inp; private BitInput Inp => this; // hopefully this gets inlined -#if RarV2017_RAR_SMP -void InitMT(); -bool UnpackLargeBlock(UnpackThreadData &D); -bool ProcessDecoded(UnpackThreadData &D); - -ThreadPool *UnpThreadPool; -UnpackThreadData *UnpThreadData; -uint MaxUserThreads; -byte *ReadBufMT; -#endif + /*#if RarV2017_RAR_SMP + void InitMT(); + bool UnpackLargeBlock(UnpackThreadData &D); + bool ProcessDecoded(UnpackThreadData &D); + + ThreadPool *UnpThreadPool; + UnpackThreadData *UnpThreadData; + uint MaxUserThreads; + byte *ReadBufMT; + #endif*/ private byte[] FilterSrcMemory = Array.Empty(); private byte[] FilterDstMemory = Array.Empty(); @@ -279,7 +279,8 @@ byte *ReadBufMT; // array. In RAR3 last distance is always stored in OldDist[0]. private uint LastDist; - private size_t UnpPtr, WrPtr; + private size_t UnpPtr, + WrPtr; // Top border of read packed data. private int ReadTop; @@ -307,7 +308,6 @@ byte *ReadBufMT; private int64 WrittenFileSize; private bool FileExtracted; - /***************************** Unpack v 1.5 *********************************/ //void Unpack15(bool Solid); //void ShortLZ(); @@ -320,12 +320,29 @@ byte *ReadBufMT; //void CopyString15(uint Distance,uint Length); //uint DecodeNum(uint Num,uint StartPos,uint *DecTab,uint *PosTab); - private readonly ushort[] ChSet = new ushort[256], ChSetA = new ushort[256], ChSetB = new ushort[256], ChSetC = new ushort[256]; - private readonly byte[] NToPl = new byte[256], NToPlB = new byte[256], NToPlC = new byte[256]; - private uint FlagBuf, AvrPlc, AvrPlcB, AvrLn1, AvrLn2, AvrLn3; - private int Buf60, NumHuf, StMode, LCount, FlagsCnt; + private readonly ushort[] ChSet = new ushort[256], + ChSetA = new ushort[256], + ChSetB = new ushort[256], + ChSetC = new ushort[256]; + private readonly byte[] NToPl = new byte[256], + NToPlB = new byte[256], + NToPlC = new byte[256]; + private uint FlagBuf, + AvrPlc, + AvrPlcB, + AvrLn1, + AvrLn2, + AvrLn3; + private int Buf60, + NumHuf, + StMode, + LCount, + FlagsCnt; + + private uint Nhfb, + Nlzb, + MaxDist3; - private uint Nhfb, Nlzb, MaxDist3; /***************************** Unpack v 1.5 *********************************/ /***************************** Unpack v 2.0 *********************************/ @@ -335,9 +352,11 @@ byte *ReadBufMT; private readonly byte[] UnpOldTable20 = new byte[MC20 * 4]; private bool UnpAudioBlock; - private uint UnpChannels, UnpCurChannel; + private uint UnpChannels, + UnpCurChannel; private int UnpChannelDelta; + //void CopyString20(uint Length,uint Distance); //bool ReadTables20(); //void UnpWriteBuf20(); @@ -345,6 +364,7 @@ byte *ReadBufMT; //void ReadLastTables(); //byte DecodeAudio(int Delta); private AudioVariables[] AudV = new AudioVariables[4]; + /***************************** Unpack v 2.0 *********************************/ /***************************** Unpack v 3.0 *********************************/ @@ -363,7 +383,8 @@ byte *ReadBufMT; // because we can have a corrupt archive with one algorithm file // followed by another algorithm file with "solid" flag and we do not // want to reuse tables from one algorithm in another. - private bool TablesRead2, TablesRead5; + private bool TablesRead2, + TablesRead5; // Virtual machine to execute filters code. /*#if !RarV2017_RAR5ONLY @@ -385,13 +406,13 @@ byte *ReadBufMT; // the data block length if lengths are repeating. private readonly List OldFilterLengths = new List(); -#if RarV2017_RAR_SMP -// More than 8 threads are unlikely to provide a noticeable gain -// for unpacking, but would use the additional memory. -void SetThreads(uint Threads) {MaxUserThreads=Min(Threads,8);} - -void UnpackDecode(UnpackThreadData &D); -#endif + /*#if RarV2017_RAR_SMP + // More than 8 threads are unlikely to provide a noticeable gain + // for unpacking, but would use the additional memory. + void SetThreads(uint Threads) {MaxUserThreads=Min(Threads,8);} + + void UnpackDecode(UnpackThreadData &D); + #endif*/ private size_t MaxWinSize; private size_t MaxWinMask; From dc89c8858e31d242b1fa9254ed2f2f04f4420521 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 15 Nov 2023 11:14:39 +0000 Subject: [PATCH 3/3] comment out more C++ bits --- .../Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs | 5 +++-- .../Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs | 5 +++-- .../Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs index 333c7ae7..62fb3c9d 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs @@ -1,10 +1,11 @@ using uint32 = System.UInt32; -#if !Rar2017_64bit + +/*#if !Rar2017_64bit #else using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; -#endif +#endif*/ namespace SharpCompress.Compressors.Rar.UnpackV2017; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs index a7863588..397fd334 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs @@ -1,12 +1,13 @@ using System; using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; using static SharpCompress.Compressors.Rar.UnpackV2017.Unpack.Unpack20Local; -#if !Rar2017_64bit + +/*#if !Rar2017_64bit #else using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; -#endif +#endif*/ namespace SharpCompress.Compressors.Rar.UnpackV2017; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs index 1d53ae5b..b81d75c4 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs @@ -1,10 +1,11 @@ using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef; -#if !Rar2017_64bit + +/*#if !Rar2017_64bit #else using nint = System.Int64; using nuint = System.UInt64; using size_t = System.UInt64; -#endif +#endif*/ namespace SharpCompress.Compressors.Rar.UnpackV2017;