diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 530ec766..45abba29 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -18,6 +18,13 @@ jobs: - uses: actions/setup-dotnet@v3 with: dotnet-version: 7.0.x + - name: NuGet Caching + uses: actions/cache@v3 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('packages.lock.json', '*/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget- - run: dotnet run --project build/build.csproj - uses: actions/upload-artifact@v3 with: diff --git a/SharpCompress.sln b/SharpCompress.sln index 5b033547..71ec294e 100644 --- a/SharpCompress.sln +++ b/SharpCompress.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F18F1765-4A02-42FD-9BEF-F0E2FCBD9D17}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3C5BE746-03E5-4895-9988-0B57F162F86C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0F0901FF-E8D9-426A-B5A2-17C7F47C1529}" @@ -15,6 +13,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpCompress.Test", "tests EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "build", "build\build.csproj", "{D4D613CB-5E94-47FB-85BE-B8423D20C545}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{CDB42573-7D22-4490-BA12-1B7FB99CE7FB}" + ProjectSection(SolutionItems) = preProject + Directory.Build.props = Directory.Build.props + global.json = global.json + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/build/Program.cs b/build/Program.cs index 000051dd..a54e9b3e 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -7,8 +7,10 @@ using static Bullseye.Targets; using static SimpleExec.Command; const string Clean = "clean"; +const string Restore = "restore"; const string Build = "build"; const string Test = "test"; +const string Format = "format"; const string Publish = "publish"; Target( @@ -37,8 +39,19 @@ Target( } ); +Target( + Format, + () => + { + Run("dotnet", "tool restore", "./csharp"); + Run("dotnet", "csharpier --check .", "./csharp"); + } +); +Target(Restore, DependsOn(Format), () => Run("dotnet", "restore --locked-mode", "./csharp")); + Target( Build, + DependsOn(Restore), () => { Run("dotnet", "build src/SharpCompress/SharpCompress.csproj -c Release"); @@ -63,7 +76,10 @@ Target( foreach (var file in GetFiles("**/*.Test.csproj")) { - Run("dotnet", $"test {file} -c Release -f {framework}"); + Run( + "dotnet", + $"test {file} -c Release -f {framework} --no-restore --no-build --verbosity=normal" + ); } } ); diff --git a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs index baca8403..936a3a0d 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs @@ -6,32 +6,29 @@ namespace SharpCompress.Compressors.Xz.Filters; public abstract class BlockFilter : ReadOnlyStream { - [CLSCompliant(false)] - public enum FilterTypes : ulong + private enum FilterTypes : ulong { - DELTA = 0x03, - ARCH_x86_FILTER = 0x04, - ARCH_PowerPC_FILTER = 0x05, - ARCH_IA64_FILTER = 0x06, - ARCH_ARM_FILTER = 0x07, - ARCH_ARMTHUMB_FILTER = 0x08, - ARCH_SPARC_FILTER = 0x09, - LZMA2 = 0x21 + //Delta = 0x03, + ArchX86Filter = 0x04, + ArchPowerPcFilter = 0x05, + ArchIa64Filter = 0x06, + ArchArmFilter = 0x07, + ArchArmThumbFilter = 0x08, + ArchSparcFilter = 0x09, + Lzma2 = 0x21 } - private static readonly Dictionary> FilterMap = new Dictionary< - FilterTypes, - Func - > - { - { FilterTypes.ARCH_x86_FILTER, () => new X86Filter() }, - { FilterTypes.ARCH_PowerPC_FILTER, () => new PowerPCFilter() }, - { FilterTypes.ARCH_IA64_FILTER, () => new IA64Filter() }, - { FilterTypes.ARCH_ARM_FILTER, () => new ArmFilter() }, - { FilterTypes.ARCH_ARMTHUMB_FILTER, () => new ArmThumbFilter() }, - { FilterTypes.ARCH_SPARC_FILTER, () => new SparcFilter() }, - { FilterTypes.LZMA2, () => new Lzma2Filter() } - }; + private static readonly Dictionary> FILTER_MAP = + new() + { + { FilterTypes.ArchX86Filter, () => new X86Filter() }, + { FilterTypes.ArchPowerPcFilter, () => new PowerPCFilter() }, + { FilterTypes.ArchIa64Filter, () => new IA64Filter() }, + { FilterTypes.ArchArmFilter, () => new ArmFilter() }, + { FilterTypes.ArchArmThumbFilter, () => new ArmThumbFilter() }, + { FilterTypes.ArchSparcFilter, () => new SparcFilter() }, + { FilterTypes.Lzma2, () => new Lzma2Filter() } + }; public abstract bool AllowAsLast { get; } public abstract bool AllowAsNonLast { get; } @@ -43,12 +40,12 @@ public abstract class BlockFilter : ReadOnlyStream public static BlockFilter Read(BinaryReader reader) { var filterType = (FilterTypes)reader.ReadXZInteger(); - if (!FilterMap.ContainsKey(filterType)) + if (!FILTER_MAP.ContainsKey(filterType)) { throw new NotImplementedException($"Filter {filterType} has not yet been implemented"); } - var filter = FilterMap[filterType]()!; + var filter = FILTER_MAP[filterType](); var sizeOfProperties = reader.ReadXZInteger(); if (sizeOfProperties > int.MaxValue) diff --git a/src/SharpCompress/IO/SourceStream.cs b/src/SharpCompress/IO/SourceStream.cs index 2a721001..26ce0af1 100644 --- a/src/SharpCompress/IO/SourceStream.cs +++ b/src/SharpCompress/IO/SourceStream.cs @@ -9,10 +9,10 @@ namespace SharpCompress.IO; public class SourceStream : Stream { private long _prevSize; - private List _files; - private List _streams; - private Func _getFilePart; - private Func _getStreamPart; + private readonly List _files; + private readonly List _streams; + private readonly Func _getFilePart; + private readonly Func _getStreamPart; private int _stream; public SourceStream(FileInfo file, Func getPart, ReaderOptions options) @@ -39,10 +39,10 @@ public class SourceStream : Stream { _streams.Add(stream!); _getStreamPart = getStreamPart!; - _getFilePart = new Func(a => null!); - if (stream is FileStream) + _getFilePart = _ => null!; + if (stream is FileStream fileStream) { - _files.Add(new FileInfo(((FileStream)stream!).Name)); + _files.Add(new FileInfo(fileStream.Name)); } } else @@ -50,7 +50,7 @@ public class SourceStream : Stream _files.Add(file!); _streams.Add(_files[0].OpenRead()); _getFilePart = getFilePart!; - _getStreamPart = new Func(a => null!); + _getStreamPart = _ => null!; } _stream = 0; _prevSize = 0; @@ -98,9 +98,9 @@ public class SourceStream : Stream } //throw new Exception($"Stream part {idx} not available."); _streams.Add(s); - if (s is FileStream) + if (s is FileStream stream) { - _files.Add(new FileInfo(((FileStream)s).Name)); + _files.Add(new FileInfo(stream.Name)); } } } @@ -123,11 +123,11 @@ public class SourceStream : Stream public override bool CanWrite => false; - public override long Length => (!IsVolumes ? _streams.Sum(a => a.Length) : Current.Length); + public override long Length => !IsVolumes ? _streams.Sum(a => a.Length) : Current.Length; public override long Position { - get => _prevSize + Current.Position; //_prevSize is 0 for multivolume + get => _prevSize + Current.Position; //_prevSize is 0 for multi-volume set => Seek(value, SeekOrigin.Begin); } @@ -222,9 +222,12 @@ public class SourceStream : Stream { try { - stream?.Dispose(); + stream.Dispose(); + } + catch + { + // ignored } - catch { } } _streams.Clear(); _files.Clear();