From 5fdae1cf8257f48b77d6c8a78827cb2e93bfeaa1 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Sat, 5 May 2018 19:23:34 +0100 Subject: [PATCH] Make readonly and fix visibility --- .../Zip/Headers/Zip64DirectoryEndHeader.cs | 2 +- .../Common/Zip/WinzipAesEncryptionData.cs | 8 +- src/SharpCompress/Compressors/ADC/ADCBase.cs | 12 +- .../Compressors/LZMA/LzmaDecoder.cs | 146 +++++++++--------- .../Compressors/LZMA/LzmaEncoder.cs | 42 ++--- .../Compressors/Rar/IRarUnpack.cs | 2 +- .../Compressors/Rar/UnpackV1/Unpack50.cs | 18 +-- .../Compressors/Rar/UnpackV1/UnpackInline.cs | 2 +- .../Rar/UnpackV2017/BitInput.getbits_cpp.cs | 3 +- .../Rar/UnpackV2017/BitInput.getbits_hpp.cs | 2 +- .../FragmentedWindow.unpack50frag_cpp.cs | 5 +- .../Rar/UnpackV2017/Unpack.rawint_hpp.cs | 6 +- .../Rar/UnpackV2017/Unpack.unpack15_cpp.cs | 80 +++++----- .../Rar/UnpackV2017/Unpack.unpack20_cpp.cs | 21 +-- .../Rar/UnpackV2017/Unpack.unpack50_cpp.cs | 38 ++--- .../Rar/UnpackV2017/Unpack.unpack_cpp.cs | 11 +- .../UnpackV2017/Unpack.unpackinline_cpp.cs | 11 +- .../Compressors/Rar/UnpackV2017/unpack_hpp.cs | 124 ++++++++------- src/SharpCompress/Compressors/Xz/Crc32.cs | 6 +- .../Compressors/Xz/Filters/BlockFilter.cs | 2 +- .../Compressors/Xz/Filters/Lzma2Filter.cs | 2 +- src/SharpCompress/Compressors/Xz/XZBlock.cs | 2 +- src/SharpCompress/Compressors/Xz/XZIndex.cs | 2 +- src/SharpCompress/Compressors/Xz/XZStream.cs | 2 +- src/SharpCompress/Converters/DataConverter.cs | 8 +- src/SharpCompress/Crypto/RijndaelEngine.cs | 4 +- src/SharpCompress/Writers/Tar/TarWriter.cs | 2 +- tests/SharpCompress.Test/ArchiveTests.cs | 6 +- .../Xz/Filters/Lzma2Tests.cs | 2 +- tests/SharpCompress.Test/Zip/Zip64Tests.cs | 2 +- .../SharpCompress.Test/Zip/ZipArchiveTests.cs | 2 +- .../SharpCompress.Test/Zip/ZipReaderTests.cs | 2 +- 32 files changed, 272 insertions(+), 305 deletions(-) diff --git a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs index 2f97ad53..41a74ef2 100644 --- a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs @@ -24,7 +24,7 @@ namespace SharpCompress.Common.Zip.Headers DataSector = reader.ReadBytes((int)(SizeOfDirectoryEndRecord - SizeOfFixedHeaderDataExceptSignatureAndSizeFields)); } - const int SizeOfFixedHeaderDataExceptSignatureAndSizeFields = 44; + private const int SizeOfFixedHeaderDataExceptSignatureAndSizeFields = 44; public long SizeOfDirectoryEndRecord { get; private set; } diff --git a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs index 1966704c..0d85bafc 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs @@ -10,10 +10,10 @@ namespace SharpCompress.Common.Zip { private const int RFC2898_ITERATIONS = 1000; - private byte[] salt; - private WinzipAesKeySize keySize; - private byte[] passwordVerifyValue; - private string password; + private readonly byte[] salt; + private readonly WinzipAesKeySize keySize; + private readonly byte[] passwordVerifyValue; + private readonly string password; private byte[] generatedVerifyValue; diff --git a/src/SharpCompress/Compressors/ADC/ADCBase.cs b/src/SharpCompress/Compressors/ADC/ADCBase.cs index 59b42016..83250cee 100644 --- a/src/SharpCompress/Compressors/ADC/ADCBase.cs +++ b/src/SharpCompress/Compressors/ADC/ADCBase.cs @@ -33,11 +33,11 @@ namespace SharpCompress.Compressors.ADC /// public static class ADCBase { - const int Plain = 1; - const int TwoByte = 2; - const int ThreeByte = 3; + private const int Plain = 1; + private const int TwoByte = 2; + private const int ThreeByte = 3; - static int GetChunkType(byte byt) + private static int GetChunkType(byte byt) { if ((byt & 0x80) == 0x80) { @@ -50,7 +50,7 @@ namespace SharpCompress.Compressors.ADC return TwoByte; } - static int GetChunkSize(byte byt) + private static int GetChunkSize(byte byt) { switch (GetChunkType(byt)) { @@ -65,7 +65,7 @@ namespace SharpCompress.Compressors.ADC } } - static int GetOffset(byte[] chunk, int position) + private static int GetOffset(byte[] chunk, int position) { switch (GetChunkType(chunk[position])) { diff --git a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs index 063b9e3e..6351a06a 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs @@ -9,50 +9,50 @@ namespace SharpCompress.Compressors.LZMA { private class LenDecoder { - private BitDecoder m_Choice = new BitDecoder(); - private BitDecoder m_Choice2 = new BitDecoder(); - private readonly BitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax]; - private readonly BitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax]; - private BitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits); - private uint m_NumPosStates; + private BitDecoder _Choice = new BitDecoder(); + private BitDecoder _Choice2 = new BitDecoder(); + private readonly BitTreeDecoder[] _LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax]; + private readonly BitTreeDecoder[] _MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax]; + private BitTreeDecoder _HighCoder = new BitTreeDecoder(Base.kNumHighLenBits); + private uint _NumPosStates; public void Create(uint numPosStates) { - for (uint posState = m_NumPosStates; posState < numPosStates; posState++) + for (uint posState = _NumPosStates; posState < numPosStates; posState++) { - m_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits); - m_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits); + _LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits); + _MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits); } - m_NumPosStates = numPosStates; + _NumPosStates = numPosStates; } public void Init() { - m_Choice.Init(); - for (uint posState = 0; posState < m_NumPosStates; posState++) + _Choice.Init(); + for (uint posState = 0; posState < _NumPosStates; posState++) { - m_LowCoder[posState].Init(); - m_MidCoder[posState].Init(); + _LowCoder[posState].Init(); + _MidCoder[posState].Init(); } - m_Choice2.Init(); - m_HighCoder.Init(); + _Choice2.Init(); + _HighCoder.Init(); } public uint Decode(RangeCoder.Decoder rangeDecoder, uint posState) { if (m_Choice.Decode(rangeDecoder) == 0) { - return m_LowCoder[posState].Decode(rangeDecoder); + return _LowCoder[posState].Decode(rangeDecoder); } uint symbol = Base.kNumLowLenSymbols; if (m_Choice2.Decode(rangeDecoder) == 0) { - symbol += m_MidCoder[posState].Decode(rangeDecoder); + symbol += _MidCoder[posState].Decode(rangeDecoder); } else { symbol += Base.kNumMidLenSymbols; - symbol += m_HighCoder.Decode(rangeDecoder); + symbol += _HighCoder.Decode(rangeDecoder); } return symbol; } @@ -62,18 +62,18 @@ namespace SharpCompress.Compressors.LZMA { private struct Decoder2 { - private BitDecoder[] m_Decoders; + private BitDecoder[] _Decoders; public void Create() { - m_Decoders = new BitDecoder[0x300]; + _Decoders = new BitDecoder[0x300]; } public void Init() { for (int i = 0; i < 0x300; i++) { - m_Decoders[i].Init(); + _Decoders[i].Init(); } } @@ -82,7 +82,7 @@ namespace SharpCompress.Compressors.LZMA uint symbol = 1; do { - symbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder); + symbol = (symbol << 1) | _Decoders[symbol].Decode(rangeDecoder); } while (symbol < 0x100); return (byte)symbol; @@ -95,13 +95,13 @@ namespace SharpCompress.Compressors.LZMA { uint matchBit = (uint)(matchByte >> 7) & 1; matchByte <<= 1; - uint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder); + uint bit = _Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder); symbol = (symbol << 1) | bit; if (matchBit != bit) { while (symbol < 0x100) { - symbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder); + symbol = (symbol << 1) | _Decoders[symbol].Decode(rangeDecoder); } break; } @@ -111,86 +111,86 @@ namespace SharpCompress.Compressors.LZMA } } - private Decoder2[] m_Coders; - private int m_NumPrevBits; - private int m_NumPosBits; - private uint m_PosMask; + private Decoder2[] _Coders; + private int _NumPrevBits; + private int _NumPosBits; + private uint _PosMask; public void Create(int numPosBits, int numPrevBits) { - if (m_Coders != null && m_NumPrevBits == numPrevBits && - m_NumPosBits == numPosBits) + if (m_Coders != null && _NumPrevBits == numPrevBits && + _NumPosBits == numPosBits) { return; } - m_NumPosBits = numPosBits; - m_PosMask = ((uint)1 << numPosBits) - 1; - m_NumPrevBits = numPrevBits; - uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits); - m_Coders = new Decoder2[numStates]; + _NumPosBits = numPosBits; + _PosMask = ((uint)1 << numPosBits) - 1; + _NumPrevBits = numPrevBits; + uint numStates = (uint)1 << (m_NumPrevBits + _NumPosBits); + _Coders = new Decoder2[numStates]; for (uint i = 0; i < numStates; i++) { - m_Coders[i].Create(); + _Coders[i].Create(); } } public void Init() { - uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits); + uint numStates = (uint)1 << (m_NumPrevBits + _NumPosBits); for (uint i = 0; i < numStates; i++) { - m_Coders[i].Init(); + _Coders[i].Init(); } } private uint GetState(uint pos, byte prevByte) { - return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); + return ((pos & _PosMask) << _NumPrevBits) + (uint)(prevByte >> (8 - _NumPrevBits)); } public byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte) { - return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); + return _Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); } public byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte) { - return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); + return _Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); } } - private OutWindow m_OutWindow; + private OutWindow _OutWindow; - private readonly BitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax]; - private readonly BitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates]; - private readonly BitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates]; - private readonly BitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates]; - private readonly BitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates]; - private readonly BitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax]; + private readonly BitDecoder[] _IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax]; + private readonly BitDecoder[] _IsRepDecoders = new BitDecoder[Base.kNumStates]; + private readonly BitDecoder[] _IsRepG0Decoders = new BitDecoder[Base.kNumStates]; + private readonly BitDecoder[] _IsRepG1Decoders = new BitDecoder[Base.kNumStates]; + private readonly BitDecoder[] _IsRepG2Decoders = new BitDecoder[Base.kNumStates]; + private readonly BitDecoder[] _IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax]; - private readonly BitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates]; - private readonly BitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex]; + private readonly BitTreeDecoder[] _PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates]; + private readonly BitDecoder[] _PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex]; - private BitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits); + private BitTreeDecoder _PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits); - private readonly LenDecoder m_LenDecoder = new LenDecoder(); - private readonly LenDecoder m_RepLenDecoder = new LenDecoder(); + private readonly LenDecoder _LenDecoder = new LenDecoder(); + private readonly LenDecoder _RepLenDecoder = new LenDecoder(); - private readonly LiteralDecoder m_LiteralDecoder = new LiteralDecoder(); + private readonly LiteralDecoder _LiteralDecoder = new LiteralDecoder(); - private int m_DictionarySize; + private int _DictionarySize; - private uint m_PosStateMask; + private uint _PosStateMask; private Base.State state = new Base.State(); private uint rep0, rep1, rep2, rep3; public Decoder() { - m_DictionarySize = -1; + _DictionarySize = -1; for (int i = 0; i < Base.kNumLenToPosStates; i++) { - m_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits); + _PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits); } } @@ -200,9 +200,9 @@ namespace SharpCompress.Compressors.LZMA { throw new InvalidParamException(); } - m_OutWindow = new OutWindow(); + _OutWindow = new OutWindow(); int blockSize = Math.Max(m_DictionarySize, (1 << 12)); - m_OutWindow.Create(blockSize); + _OutWindow.Create(blockSize); } private void SetLiteralProperties(int lp, int lc) @@ -215,7 +215,7 @@ namespace SharpCompress.Compressors.LZMA { throw new InvalidParamException(); } - m_LiteralDecoder.Create(lp, lc); + _LiteralDecoder.Create(lp, lc); } private void SetPosBitsProperties(int pb) @@ -225,9 +225,9 @@ namespace SharpCompress.Compressors.LZMA throw new InvalidParamException(); } uint numPosStates = (uint)1 << pb; - m_LenDecoder.Create(numPosStates); - m_RepLenDecoder.Create(numPosStates); - m_PosStateMask = numPosStates - 1; + _LenDecoder.Create(numPosStates); + _RepLenDecoder.Create(numPosStates); + _PosStateMask = numPosStates - 1; } private void Init() @@ -235,19 +235,19 @@ namespace SharpCompress.Compressors.LZMA uint i; for (i = 0; i < Base.kNumStates; i++) { - for (uint j = 0; j <= m_PosStateMask; j++) + for (uint j = 0; j <= _PosStateMask; j++) { uint index = (i << Base.kNumPosStatesBitsMax) + j; - m_IsMatchDecoders[index].Init(); - m_IsRep0LongDecoders[index].Init(); + _IsMatchDecoders[index].Init(); + _IsRep0LongDecoders[index].Init(); } - m_IsRepDecoders[i].Init(); - m_IsRepG0Decoders[i].Init(); - m_IsRepG1Decoders[i].Init(); - m_IsRepG2Decoders[i].Init(); + _IsRepDecoders[i].Init(); + _IsRepG0Decoders[i].Init(); + _IsRepG1Decoders[i].Init(); + _IsRepG2Decoders[i].Init(); } - m_LiteralDecoder.Init(); + _LiteralDecoder.Init(); for (i = 0; i < Base.kNumLenToPosStates; i++) { m_PosSlotDecoder[i].Init(); diff --git a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs index 6f5b0145..a4e76b72 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs @@ -80,18 +80,18 @@ namespace SharpCompress.Compressors.LZMA { public struct Encoder2 { - private BitEncoder[] m_Encoders; + private BitEncoder[] _Encoders; public void Create() { - m_Encoders = new BitEncoder[0x300]; + _Encoders = new BitEncoder[0x300]; } public void Init() { for (int i = 0; i < 0x300; i++) { - m_Encoders[i].Init(); + _Encoders[i].Init(); } } @@ -101,7 +101,7 @@ namespace SharpCompress.Compressors.LZMA for (int i = 7; i >= 0; i--) { uint bit = (uint)((symbol >> i) & 1); - m_Encoders[context].Encode(rangeEncoder, bit); + _Encoders[context].Encode(rangeEncoder, bit); context = (context << 1) | bit; } } @@ -120,7 +120,7 @@ namespace SharpCompress.Compressors.LZMA state += ((1 + matchBit) << 8); same = (matchBit == bit); } - m_Encoders[state].Encode(rangeEncoder, bit); + _Encoders[state].Encode(rangeEncoder, bit); context = (context << 1) | bit; } } @@ -136,7 +136,7 @@ namespace SharpCompress.Compressors.LZMA { uint matchBit = (uint)(matchByte >> i) & 1; uint bit = (uint)(symbol >> i) & 1; - price += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit); + price += _Encoders[((1 + matchBit) << 8) + context].GetPrice(bit); context = (context << 1) | bit; if (matchBit != bit) { @@ -148,47 +148,47 @@ namespace SharpCompress.Compressors.LZMA for (; i >= 0; i--) { uint bit = (uint)(symbol >> i) & 1; - price += m_Encoders[context].GetPrice(bit); + price += _Encoders[context].GetPrice(bit); context = (context << 1) | bit; } return price; } } - private Encoder2[] m_Coders; - private int m_NumPrevBits; - private int m_NumPosBits; - private uint m_PosMask; + private Encoder2[] _Coders; + private int _NumPrevBits; + private int _NumPosBits; + private uint _PosMask; public void Create(int numPosBits, int numPrevBits) { - if (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits) + if (m_Coders != null && _NumPrevBits == numPrevBits && _NumPosBits == numPosBits) { return; } - m_NumPosBits = numPosBits; - m_PosMask = ((uint)1 << numPosBits) - 1; - m_NumPrevBits = numPrevBits; - uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits); - m_Coders = new Encoder2[numStates]; + _NumPosBits = numPosBits; + _PosMask = ((uint)1 << numPosBits) - 1; + _NumPrevBits = numPrevBits; + uint numStates = (uint)1 << (m_NumPrevBits + _NumPosBits); + _Coders = new Encoder2[numStates]; for (uint i = 0; i < numStates; i++) { - m_Coders[i].Create(); + _Coders[i].Create(); } } public void Init() { - uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits); + uint numStates = (uint)1 << (m_NumPrevBits + _NumPosBits); for (uint i = 0; i < numStates; i++) { - m_Coders[i].Init(); + _Coders[i].Init(); } } public Encoder2 GetSubCoder(UInt32 pos, Byte prevByte) { - return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; + return _Coders[((pos & _PosMask) << _NumPrevBits) + (uint)(prevByte >> (8 - _NumPrevBits))]; } } diff --git a/src/SharpCompress/Compressors/Rar/IRarUnpack.cs b/src/SharpCompress/Compressors/Rar/IRarUnpack.cs index ecd70a47..0cc86a78 100644 --- a/src/SharpCompress/Compressors/Rar/IRarUnpack.cs +++ b/src/SharpCompress/Compressors/Rar/IRarUnpack.cs @@ -3,7 +3,7 @@ using SharpCompress.Common.Rar.Headers; namespace SharpCompress.Compressors.Rar { - interface IRarUnpack + internal interface IRarUnpack { void DoUnpack(FileHeader fileHeader, Stream readStream, Stream writeStream); void DoUnpack(); diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs index 01d3604f..ec3fbdc1 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs @@ -298,8 +298,7 @@ public bool TablePresent; UnpWriteBuf(); } - - uint ReadFilterData() + private uint ReadFilterData() { uint ByteCount=(Inp.fgetbits()>>14)+1; Inp.AddBits(2); @@ -314,8 +313,7 @@ public bool TablePresent; return Data; } - - bool ReadFilter(UnpackFilter Filter) + private bool ReadFilter(UnpackFilter Filter) { if (!Inp.ExternalBuffer && Inp.InAddr>ReadTop-16) if (!UnpReadBuf()) @@ -340,8 +338,7 @@ public bool TablePresent; return true; } - - bool AddFilter(UnpackFilter Filter) + private bool AddFilter(UnpackFilter Filter) { if (Filters.Count>=MAX_UNPACK_FILTERS) { @@ -360,8 +357,7 @@ public bool TablePresent; return true; } - - bool UnpReadBuf() + private bool UnpReadBuf() { int DataSize=ReadTop-Inp.InAddr; // Data left to process. if (DataSize<0) @@ -675,15 +671,13 @@ public bool TablePresent; // WrittenFileSize+=Size; // } - - void UnpInitData50(bool Solid) + private void UnpInitData50(bool Solid) { if (!Solid) TablesRead5=false; } - - bool ReadBlockHeader() + private bool ReadBlockHeader() { Header.HeaderSize=0; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs index 35b65eb7..1bb2893d 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs @@ -3,7 +3,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 { internal partial class Unpack { - uint SlotToLength(uint Slot) + private uint SlotToLength(uint Slot) { //uint LBits,Length=2; int LBits; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_cpp.cs index f702fb48..ff7b70d7 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_cpp.cs @@ -55,8 +55,7 @@ uint fgetbits() return getbits(); } - -void SetExternalBuffer(byte []Buf) + private void SetExternalBuffer(byte []Buf) { //if (InBuf!=NULL && !ExternalBuffer) // delete[] InBuf; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_hpp.cs index 0eb0b64a..4f16592e 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_hpp.cs @@ -59,7 +59,7 @@ internal partial class BitInput // Check if buffer has enough space for IncPtr bytes. Returns 'true' // if buffer will be overflown. - bool Overflow(uint IncPtr) + private bool Overflow(uint IncPtr) { return InAddr+IncPtr>=MAX_SIZE; } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs index cd0b5eb0..e3614217 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs @@ -13,7 +13,7 @@ using System; namespace SharpCompress.Compressors.Rar.UnpackV2017 { - partial class FragmentedWindow + internal partial class FragmentedWindow { public FragmentedWindow() @@ -28,8 +28,7 @@ public FragmentedWindow() // Reset(); //} - -void Reset() + private void Reset() { for (uint I=0;I>(xsize-(n)))) //#define rotrs(x,n,xsize) (((x)>>(n)) | ((x)<<(xsize-(n)))) @@ -29,7 +29,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 // return D[0]+(D[1]<<8); //} -uint32 RawGet4(byte[] D, int offset) + private uint32 RawGet4(byte[] D, int offset) { return (uint)(D[offset]+(D[offset+1]<<8)+(D[offset+2]<<16)+(D[offset+3]<<24)); } @@ -52,7 +52,7 @@ uint32 RawGet4(byte[] D, int offset) // D[1]=(byte)(Field>>8); //} -void RawPut4(uint32 Field,byte[] D, int offset) + private void RawPut4(uint32 Field,byte[] D, int offset) { D[offset]=(byte)(Field); D[offset+1]=(byte)(Field>>8); diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs index d76ee10c..8eeef6fe 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs @@ -4,47 +4,53 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { internal partial class Unpack { + private const int STARTL1 =2; -const int STARTL1 =2; -static uint[] DecL1={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00, + private static readonly uint[] DecL1={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00, 0xee00,0xf000,0xf200,0xf200,0xffff}; -static uint[] PosL1={0,0,0,2,3,5,7,11,16,20,24,32,32}; -const int STARTL2 =3; -static uint[] DecL2={0xa000,0xc000,0xd000,0xe000,0xea00,0xee00, + private static readonly uint[] PosL1={0,0,0,2,3,5,7,11,16,20,24,32,32}; + + private const int STARTL2 =3; + + private static readonly uint[] DecL2={0xa000,0xc000,0xd000,0xe000,0xea00,0xee00, 0xf000,0xf200,0xf240,0xffff}; -static uint[] PosL2={0,0,0,0,5,7,9,13,18,22,26,34,36}; -const int STARTHF0 =4; -static uint[] DecHf0={0x8000,0xc000,0xe000,0xf200,0xf200,0xf200, + private static readonly uint[] PosL2={0,0,0,0,5,7,9,13,18,22,26,34,36}; + + private const int STARTHF0 =4; + + private static readonly uint[] DecHf0={0x8000,0xc000,0xe000,0xf200,0xf200,0xf200, 0xf200,0xf200,0xffff}; -static uint[] PosHf0={0,0,0,0,0,8,16,24,33,33,33,33,33}; + private static readonly uint[] PosHf0={0,0,0,0,0,8,16,24,33,33,33,33,33}; -const int STARTHF1 =5; -static uint[] DecHf1={0x2000,0xc000,0xe000,0xf000,0xf200,0xf200, + private const int STARTHF1 =5; + + private static readonly uint[] DecHf1={0x2000,0xc000,0xe000,0xf000,0xf200,0xf200, 0xf7e0,0xffff}; -static uint[] PosHf1={0,0,0,0,0,0,4,44,60,76,80,80,127}; + private static readonly uint[] PosHf1={0,0,0,0,0,0,4,44,60,76,80,80,127}; -const int STARTHF2 =5; -static uint[] DecHf2={0x1000,0x2400,0x8000,0xc000,0xfa00,0xffff, + private const int STARTHF2 =5; + + private static readonly uint[] DecHf2={0x1000,0x2400,0x8000,0xc000,0xfa00,0xffff, 0xffff,0xffff}; -static uint[] PosHf2={0,0,0,0,0,0,2,7,53,117,233,0,0}; + private static readonly uint[] PosHf2={0,0,0,0,0,0,2,7,53,117,233,0,0}; -const int STARTHF3 =6; -static uint[] DecHf3={0x800,0x2400,0xee00,0xfe80,0xffff,0xffff, + private const int STARTHF3 =6; + + private static readonly uint[] DecHf3={0x800,0x2400,0xee00,0xfe80,0xffff,0xffff, 0xffff}; -static uint[] PosHf3={0,0,0,0,0,0,0,2,16,218,251,0,0}; + private static readonly uint[] PosHf3={0,0,0,0,0,0,0,2,16,218,251,0,0}; -const int STARTHF4 =8; -static uint[] DecHf4={0xff00,0xffff,0xffff,0xffff,0xffff,0xffff}; -static uint[] PosHf4={0,0,0,0,0,0,0,0,0,255,0,0,0}; + private const int STARTHF4 =8; + private static readonly uint[] DecHf4={0xff00,0xffff,0xffff,0xffff,0xffff,0xffff}; + private static readonly uint[] PosHf4={0,0,0,0,0,0,0,0,0,255,0,0,0}; - -void Unpack15(bool Solid) + private void Unpack15(bool Solid) { UnpInitData(Solid); UnpInitData15(Solid); @@ -119,9 +125,9 @@ void Unpack15(bool Solid) //#define GetShortLen1(pos) ((pos)==1 ? Buf60+3:ShortLen1[pos]) -uint GetShortLen1(uint pos) { return ((pos)==1 ? (uint)(this.Buf60+3):ShortLen1[pos]); } + private uint GetShortLen1(uint pos) { return ((pos)==1 ? (uint)(this.Buf60+3):ShortLen1[pos]); } //#define GetShortLen2(pos) ((pos)==3 ? Buf60+3:ShortLen2[pos]) -uint GetShortLen2(uint pos) { return ((pos)==3 ? (uint)(this.Buf60+3):ShortLen2[pos]); } + private uint GetShortLen2(uint pos) { return ((pos)==3 ? (uint)(this.Buf60+3):ShortLen2[pos]); } internal static class Unpack15Local { public static readonly uint[] ShortLen1={1,3,4,4,5,6,7,8,8,4,4,5,6,6,4,0}; @@ -132,7 +138,7 @@ internal static class Unpack15Local { 0xfc,0xc0,0x80,0x90,0x98,0x9c,0xb0}; } -void ShortLZ() + private void ShortLZ() { uint Length,SaveLength; uint LastDistance; @@ -235,8 +241,7 @@ void ShortLZ() CopyString15(Distance,Length); } - -void LongLZ() + private void LongLZ() { uint Length; uint Distance; @@ -327,8 +332,7 @@ void LongLZ() CopyString15(Distance,Length); } - -void HuffDecode() + private void HuffDecode() { uint CurByte,NewBytePlace; uint Length; @@ -405,8 +409,7 @@ void HuffDecode() ChSet[NewBytePlace]=(ushort)CurByte; } - -void GetFlagsBuf() + private void GetFlagsBuf() { uint Flags,NewFlagsPlace; uint FlagsPlace=DecodeNum(Inp.fgetbits(),STARTHF2,DecHf2,PosHf2); @@ -433,7 +436,7 @@ void GetFlagsBuf() ChSetC[NewFlagsPlace]=(ushort)Flags; } -void UnpInitData15(bool Solid) + private void UnpInitData15(bool Solid) { if (!Solid) { @@ -450,7 +453,7 @@ void UnpInitData15(bool Solid) ReadTop=0; } -void InitHuff() + private void InitHuff() { for (uint I=0;I<256;I++) { @@ -464,8 +467,7 @@ void InitHuff() CorrHuff(ChSetB,NToPlB); } - -void CorrHuff(ushort[] CharSet,byte[] NumToPlace) + private void CorrHuff(ushort[] CharSet,byte[] NumToPlace) { int I,J; for (I=7;I>=0;I--) @@ -476,8 +478,7 @@ void CorrHuff(ushort[] CharSet,byte[] NumToPlace) NumToPlace[I]=(byte)((7-I)*32); } - -void CopyString15(uint Distance,uint Length) + private void CopyString15(uint Distance,uint Length) { DestUnpSize-=Length; while (Length-- != 0) @@ -487,8 +488,7 @@ void CopyString15(uint Distance,uint Length) } } - -uint DecodeNum(uint Num,uint StartPos,uint[] DecTab,uint[] PosTab) + private uint DecodeNum(uint Num,uint StartPos,uint[] DecTab,uint[] PosTab) { int I; for (Num&=0xfff0,I=0;DecTab[I]<=Num;I++) diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs index 57ecdc02..72d1b529 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs @@ -17,8 +17,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { internal partial class Unpack { - -void CopyString20(uint Length,uint Distance) + private void CopyString20(uint Length,uint Distance) { LastDist=OldDist[OldDistPtr++ & 3]=Distance; LastLength=Length; @@ -35,7 +34,8 @@ internal static class Unpack20Local { public static readonly byte[] SDDecode={0,4,8,16,32,64,128,192}; public static readonly byte[] SDBits= {2,2,3, 4, 5, 6, 6, 6}; } -void Unpack20(bool Solid) + + private void Unpack20(bool Solid) { uint Bits; @@ -165,8 +165,7 @@ void Unpack20(bool Solid) UnpWriteBuf20(); } - -void UnpWriteBuf20() + private void UnpWriteBuf20() { if (UnpPtr!=WrPtr) UnpSomeRead=true; @@ -181,8 +180,7 @@ void UnpWriteBuf20() WrPtr=UnpPtr; } - -bool ReadTables20() + private bool ReadTables20() { byte[] BitLength = new byte[BC20]; byte[] Table = new byte[MC20*4]; @@ -273,8 +271,7 @@ bool ReadTables20() return true; } - -void ReadLastTables() + private void ReadLastTables() { if (ReadTop>=Inp.InAddr+5) if (UnpAudioBlock) @@ -287,8 +284,7 @@ void ReadLastTables() ReadTables20(); } - -void UnpInitData20(bool Solid) + private void UnpInitData20(bool Solid) { if (!Solid) { @@ -306,8 +302,7 @@ void UnpInitData20(bool Solid) } } - -byte DecodeAudio(int Delta) + private byte DecodeAudio(int Delta) { AudioVariables V=AudV[UnpCurChannel]; V.ByteCount++; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs index 53f0e713..d35aa3e4 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs @@ -17,7 +17,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { internal partial class Unpack { -void Unpack5(bool Solid) + private void Unpack5(bool Solid) { FileExtracted=true; @@ -173,8 +173,7 @@ void Unpack5(bool Solid) UnpWriteBuf(); } - -uint ReadFilterData(BitInput Inp) + private uint ReadFilterData(BitInput Inp) { uint ByteCount=(Inp.fgetbits()>>14)+1; Inp.addbits(2); @@ -188,8 +187,7 @@ uint ReadFilterData(BitInput Inp) return Data; } - -bool ReadFilter(BitInput Inp,UnpackFilter Filter) + private bool ReadFilter(BitInput Inp,UnpackFilter Filter) { if (!Inp.ExternalBuffer && Inp.InAddr>ReadTop-16) if (!UnpReadBuf()) @@ -212,8 +210,7 @@ bool ReadFilter(BitInput Inp,UnpackFilter Filter) return true; } - -bool AddFilter(UnpackFilter Filter) + private bool AddFilter(UnpackFilter Filter) { if (Filters.Count>=MAX_UNPACK_FILTERS) { @@ -232,8 +229,7 @@ bool AddFilter(UnpackFilter Filter) return true; } - -bool UnpReadBuf() + private bool UnpReadBuf() { int DataSize=ReadTop-Inp.InAddr; // Data left to process. if (DataSize<0) @@ -271,8 +267,7 @@ bool UnpReadBuf() return ReadCode!=-1; } - -void UnpWriteBuf() + private void UnpWriteBuf() { size_t WrittenBorder=WrPtr; size_t FullWriteSize=(UnpPtr-WrittenBorder)&MaxWinMask; @@ -425,8 +420,7 @@ void UnpWriteBuf() WriteBorder=WrPtr; } - -byte[] ApplyFilter(byte[] __d,uint DataSize,UnpackFilter Flt) + private byte[] ApplyFilter(byte[] __d,uint DataSize,UnpackFilter Flt) { int Data = 0; byte[] SrcData=__d; @@ -513,8 +507,7 @@ byte[] ApplyFilter(byte[] __d,uint DataSize,UnpackFilter Flt) return null; } - -void UnpWriteArea(size_t StartPtr,size_t EndPtr) + private void UnpWriteArea(size_t StartPtr,size_t EndPtr) { if (EndPtr!=StartPtr) UnpSomeRead=true; @@ -544,8 +537,7 @@ void UnpWriteArea(size_t StartPtr,size_t EndPtr) UnpWriteData(Window,StartPtr,EndPtr-StartPtr); } - -void UnpWriteData(byte[] Data, size_t offset, size_t Size) + private void UnpWriteData(byte[] Data, size_t offset, size_t Size) { if (WrittenFileSize>=DestUnpSize) return; @@ -557,15 +549,13 @@ void UnpWriteData(byte[] Data, size_t offset, size_t Size) WrittenFileSize+=Size; } - -void UnpInitData50(bool Solid) + private void UnpInitData50(bool Solid) { if (!Solid) TablesRead5=false; } - -bool ReadBlockHeader(BitInput Inp,ref UnpackBlockHeader Header) + private bool ReadBlockHeader(BitInput Inp,ref UnpackBlockHeader Header) { Header.HeaderSize=0; @@ -608,8 +598,7 @@ bool ReadBlockHeader(BitInput Inp,ref UnpackBlockHeader Header) return true; } - -bool ReadTables(BitInput Inp,ref UnpackBlockHeader Header, ref UnpackBlockTables Tables) + private bool ReadTables(BitInput Inp,ref UnpackBlockHeader Header, ref UnpackBlockTables Tables) { if (!Header.TablePresent) return true; @@ -713,8 +702,7 @@ bool ReadTables(BitInput Inp,ref UnpackBlockHeader Header, ref UnpackBlockTables return true; } - -void InitFilters() + private void InitFilters() { //Filters.SoftReset(); Filters.Clear(); diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs index 44abffa3..21d3cd91 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs @@ -64,8 +64,7 @@ public Unpack(/* ComprDataIO *DataIO */) //#endif //} - -void Init(size_t WinSize,bool Solid) + private void Init(size_t WinSize,bool Solid) { // If 32-bit RAR unpacks an archive with 4 GB dictionary, the window size // will be 0 because of size_t overflow. Let's issue the memory error. @@ -145,8 +144,7 @@ void Init(size_t WinSize,bool Solid) MaxWinMask=MaxWinSize-1; } - -void DoUnpack(uint Method,bool Solid) + private void DoUnpack(uint Method,bool Solid) { // Methods <50 will crash in Fragmented mode when accessing NULL Window. // They cannot be called in such mode now, but we check it below anyway @@ -194,8 +192,7 @@ void DoUnpack(uint Method,bool Solid) } } - -void UnpInitData(bool Solid) + private void UnpInitData(bool Solid) { if (!Solid) { @@ -233,7 +230,7 @@ void UnpInitData(bool Solid) // LengthTable contains the length in bits for every element of alphabet. // Dec is the structure to decode Huffman code/ // Size is size of length table and DecodeNum field in Dec structure, -void MakeDecodeTables(byte[] LengthTable, int offset, DecodeTable Dec,uint Size) + private void MakeDecodeTables(byte[] LengthTable, int offset, DecodeTable Dec,uint Size) { // Size of alphabet and DecodePos array. Dec.MaxNum=Size; diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs index cd2fa8f0..db705807 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs @@ -15,8 +15,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { internal partial class Unpack { - -void InsertOldDist(uint Distance) + private void InsertOldDist(uint Distance) { OldDist[3]=OldDist[2]; OldDist[2]=OldDist[1]; @@ -28,7 +27,7 @@ void InsertOldDist(uint Distance) //#define FAST_MEMCPY //#endif -void CopyString(uint Length,uint Distance) + private void CopyString(uint Length,uint Distance) { size_t SrcPtr=UnpPtr-Distance; @@ -104,8 +103,7 @@ void CopyString(uint Length,uint Distance) } } - -uint DecodeNumber(BitInput Inp,DecodeTable Dec) + private uint DecodeNumber(BitInput Inp,DecodeTable Dec) { // Left aligned 15 bit length raw bit field. uint BitField=Inp.getbits() & 0xfffe; @@ -149,8 +147,7 @@ uint DecodeNumber(BitInput Inp,DecodeTable Dec) return Dec.DecodeNum[Pos]; } - -uint SlotToLength(BitInput Inp,uint Slot) + private uint SlotToLength(BitInput Inp,uint Slot) { uint LBits,Length=2; if (Slot<8) diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs index 06520ab5..b5175d24 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs @@ -51,7 +51,7 @@ public const int UNPACK_MAX_WRITE =0x400000; } // Decode compressed bit fields to alphabet numbers. -sealed class DecodeTable + internal sealed class DecodeTable { // Real size of DecodeNum table. public uint MaxNum; @@ -92,8 +92,7 @@ sealed class DecodeTable public readonly ushort[] DecodeNum = new ushort[LARGEST_TABLE_SIZE]; }; - -struct UnpackBlockHeader + internal struct UnpackBlockHeader { public int BlockSize; public int BlockBitSize; @@ -103,8 +102,7 @@ struct UnpackBlockHeader public bool TablePresent; }; - -struct UnpackBlockTables + internal struct UnpackBlockTables { public DecodeTable LD; // Decode literals. public DecodeTable DD; // Decode distances. @@ -173,7 +171,7 @@ struct UnpackThreadData //struct UnpackFilter -class UnpackFilter + internal class UnpackFilter { public byte Type; public uint BlockStart; @@ -186,7 +184,7 @@ class UnpackFilter //struct UnpackFilter30 -class UnpackFilter30 + internal class UnpackFilter30 { public uint BlockStart; public uint BlockLength; @@ -201,8 +199,7 @@ class UnpackFilter30 #endif*/ }; - -class AudioVariables // For RAR 2.0 archives only. + internal class AudioVariables // For RAR 2.0 archives only. { public int K1,K2,K3,K4,K5; public int D1,D2,D3,D4; @@ -215,13 +212,13 @@ class AudioVariables // For RAR 2.0 archives only. // We can use the fragmented dictionary in case heap does not have the single // large enough memory block. It is slower than normal dictionary. -partial class FragmentedWindow + internal partial class FragmentedWindow { - const int MAX_MEM_BLOCKS=32; + private const int MAX_MEM_BLOCKS=32; //void Reset(); - readonly byte[][] Mem = new byte[MAX_MEM_BLOCKS][]; - readonly size_t[] MemSize = new size_t[MAX_MEM_BLOCKS]; + private readonly byte[][] Mem = new byte[MAX_MEM_BLOCKS][]; + private readonly size_t[] MemSize = new size_t[MAX_MEM_BLOCKS]; //FragmentedWindow(); //~FragmentedWindow(); @@ -261,7 +258,7 @@ internal partial class Unpack //ComprDataIO *UnpIO; //BitInput Inp; - BitInput Inp { get { return this; } } // hopefully this gets inlined + private BitInput Inp { get { return this; } } // hopefully this gets inlined #if RarV2017_RAR_SMP void InitMT(); @@ -274,48 +271,47 @@ internal partial class Unpack byte *ReadBufMT; #endif - byte[] FilterSrcMemory = new byte[0]; - byte[] FilterDstMemory = new byte[0]; + private byte[] FilterSrcMemory = new byte[0]; + private byte[] FilterDstMemory = new byte[0]; // Filters code, one entry per filter. - readonly List Filters = new List(); + private readonly List Filters = new List(); - readonly uint[] OldDist = new uint[4]; - uint OldDistPtr; - uint LastLength; + private readonly uint[] OldDist = new uint[4]; + private uint OldDistPtr; + private uint LastLength; // LastDist is necessary only for RAR2 and older with circular OldDist // array. In RAR3 last distance is always stored in OldDist[0]. - uint LastDist; + private uint LastDist; - size_t UnpPtr,WrPtr; + private size_t UnpPtr,WrPtr; // Top border of read packed data. - int ReadTop; + private int ReadTop; // Border to call UnpReadBuf. We use it instead of (ReadTop-C) // for optimization reasons. Ensures that we have C bytes in buffer // unless we are at the end of file. - int ReadBorder; + private int ReadBorder; - UnpackBlockHeader BlockHeader; - UnpackBlockTables BlockTables; + private UnpackBlockHeader BlockHeader; + private UnpackBlockTables BlockTables; - size_t WriteBorder; + private size_t WriteBorder; - byte[] Window; + private byte[] Window; - readonly FragmentedWindow FragWindow = new FragmentedWindow(); - bool Fragmented; + private readonly FragmentedWindow FragWindow = new FragmentedWindow(); + private bool Fragmented; - - int64 DestUnpSize; + private int64 DestUnpSize; //bool Suspended; - bool UnpAllBuf; - bool UnpSomeRead; - int64 WrittenFileSize; - bool FileExtracted; + private bool UnpAllBuf; + private bool UnpSomeRead; + private int64 WrittenFileSize; + private bool FileExtracted; /***************************** Unpack v 1.5 *********************************/ @@ -330,29 +326,31 @@ internal partial class Unpack //void CopyString15(uint Distance,uint Length); //uint DecodeNum(uint Num,uint StartPos,uint *DecTab,uint *PosTab); - readonly ushort[] ChSet = new ushort[256],ChSetA = new ushort[256],ChSetB = new ushort[256],ChSetC = new ushort[256]; - readonly byte[] NToPl = new byte[256],NToPlB = new byte[256],NToPlC = new byte[256]; - uint FlagBuf,AvrPlc,AvrPlcB,AvrLn1,AvrLn2,AvrLn3; - int Buf60,NumHuf,StMode,LCount,FlagsCnt; - uint Nhfb,Nlzb,MaxDist3; + 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; /***************************** Unpack v 1.5 *********************************/ /***************************** Unpack v 2.0 *********************************/ //void Unpack20(bool Solid); - DecodeTable[] MD = new DecodeTable[4]; // Decode multimedia data, up to 4 channels. + private DecodeTable[] MD = new DecodeTable[4]; // Decode multimedia data, up to 4 channels. - readonly byte[] UnpOldTable20 = new byte[MC20*4]; - bool UnpAudioBlock; - uint UnpChannels,UnpCurChannel; - int UnpChannelDelta; + private readonly byte[] UnpOldTable20 = new byte[MC20*4]; + private bool UnpAudioBlock; + private uint UnpChannels,UnpCurChannel; + + private int UnpChannelDelta; //void CopyString20(uint Length,uint Distance); //bool ReadTables20(); //void UnpWriteBuf20(); //void UnpInitData20(int Solid); //void ReadLastTables(); //byte DecodeAudio(int Delta); - AudioVariables[] AudV = new AudioVariables[4]; + private AudioVariables[] AudV = new AudioVariables[4]; /***************************** Unpack v 2.0 *********************************/ /***************************** Unpack v 3.0 *********************************/ @@ -372,22 +370,22 @@ internal partial class Unpack //void UnpWriteBuf30(); //void ExecuteCode(VM_PreparedProgram *Prg); - int PrevLowDist,LowDistRepCount; + private int PrevLowDist,LowDistRepCount; /*#if !RarV2017_RAR5ONLY ModelPPM PPM; #endif*/ - int PPMEscChar; + private int PPMEscChar; - readonly byte [] UnpOldTable = new byte[HUFF_TABLE_SIZE30]; - int UnpBlockType; + private readonly byte [] UnpOldTable = new byte[HUFF_TABLE_SIZE30]; + private int UnpBlockType; // If we already read decoding tables for Unpack v2,v3,v5. // We should not use a single variable for all algorithm versions, // 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. - bool TablesRead2,TablesRead3,TablesRead5; + private bool TablesRead2,TablesRead3,TablesRead5; // Virtual machine to execute filters code. /*#if !RarV2017_RAR5ONLY @@ -396,29 +394,29 @@ internal partial class Unpack // Buffer to read VM filters code. We moved it here from AddVMCode // function to reduce time spent in BitInput constructor. - readonly BitInput VMCodeInp = new BitInput(true); + private readonly BitInput VMCodeInp = new BitInput(true); // Filters code, one entry per filter. - readonly List Filters30 = new List(); + private readonly List Filters30 = new List(); // Filters stack, several entrances of same filter are possible. - readonly List PrgStack = new List(); + private readonly List PrgStack = new List(); // Lengths of preceding data blocks, one length of one last block // for every filter. Used to reduce the size required to write // the data block length if lengths are repeating. - readonly List OldFilterLengths = new List(); + private readonly List OldFilterLengths = new List(); - int LastFilter; + private int LastFilter; /***************************** Unpack v 3.0 *********************************/ //Unpack(ComprDataIO *DataIO); //~Unpack(); //void Init(size_t WinSize,bool Solid); //void DoUnpack(uint Method,bool Solid); - bool IsFileExtracted() {return(FileExtracted);} - void SetDestSize(int64 DestSize) {DestUnpSize=DestSize;FileExtracted=false;} - void SetSuspended(bool Suspended) {this.Suspended=Suspended;} + private bool IsFileExtracted() {return(FileExtracted);} + private void SetDestSize(int64 DestSize) {DestUnpSize=DestSize;FileExtracted=false;} + private void SetSuspended(bool Suspended) {this.Suspended=Suspended;} #if RarV2017_RAR_SMP // More than 8 threads are unlikely to provide a noticeable gain @@ -428,10 +426,10 @@ internal partial class Unpack void UnpackDecode(UnpackThreadData &D); #endif - size_t MaxWinSize; - size_t MaxWinMask; + private size_t MaxWinSize; + private size_t MaxWinMask; - uint GetChar() + private uint GetChar() { if (Inp.InAddr>BitInput.MAX_SIZE-30) UnpReadBuf(); diff --git a/src/SharpCompress/Compressors/Xz/Crc32.cs b/src/SharpCompress/Compressors/Xz/Crc32.cs index cb65fec9..72c37ba1 100644 --- a/src/SharpCompress/Compressors/Xz/Crc32.cs +++ b/src/SharpCompress/Compressors/Xz/Crc32.cs @@ -8,7 +8,7 @@ namespace SharpCompress.Compressors.Xz public const UInt32 DefaultPolynomial = 0xedb88320u; public const UInt32 DefaultSeed = 0xffffffffu; - static UInt32[] defaultTable; + private static UInt32[] defaultTable; public static UInt32 Compute(byte[] buffer) { @@ -25,7 +25,7 @@ namespace SharpCompress.Compressors.Xz return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length); } - static UInt32[] InitializeTable(UInt32 polynomial) + private static UInt32[] InitializeTable(UInt32 polynomial) { if (polynomial == DefaultPolynomial && defaultTable != null) return defaultTable; @@ -48,7 +48,7 @@ namespace SharpCompress.Compressors.Xz return createTable; } - static UInt32 CalculateHash(UInt32[] table, UInt32 seed, IList buffer, int start, int size) + private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, IList buffer, int start, int size) { var crc = seed; for (var i = start; i < size - start; i++) diff --git a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs index e260a9cd..0f793dff 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs @@ -18,7 +18,7 @@ namespace SharpCompress.Compressors.Xz.Filters LZMA2 = 0x21, } - static Dictionary FilterMap = new Dictionary() + private static readonly Dictionary FilterMap = new Dictionary() { {FilterTypes.LZMA2, typeof(Lzma2Filter) } }; diff --git a/src/SharpCompress/Compressors/Xz/Filters/Lzma2Filter.cs b/src/SharpCompress/Compressors/Xz/Filters/Lzma2Filter.cs index 7d0020e8..970fafd3 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/Lzma2Filter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/Lzma2Filter.cs @@ -9,7 +9,7 @@ namespace SharpCompress.Compressors.Xz.Filters public override bool AllowAsNonLast => false; public override bool ChangesDataSize => true; - byte _dictionarySize; + private byte _dictionarySize; public uint DictionarySize { get diff --git a/src/SharpCompress/Compressors/Xz/XZBlock.cs b/src/SharpCompress/Compressors/Xz/XZBlock.cs index 0848618b..96ecef17 100644 --- a/src/SharpCompress/Compressors/Xz/XZBlock.cs +++ b/src/SharpCompress/Compressors/Xz/XZBlock.cs @@ -13,7 +13,7 @@ namespace SharpCompress.Compressors.Xz public Stack Filters { get; private set; } = new Stack(); public bool HeaderIsLoaded { get; private set; } private CheckType _checkType; - private int _checkSize; + private readonly int _checkSize; private bool _streamConnected; private int _numFilters; private byte _blockHeaderSizeByte; diff --git a/src/SharpCompress/Compressors/Xz/XZIndex.cs b/src/SharpCompress/Compressors/Xz/XZIndex.cs index f1a66776..736f978a 100644 --- a/src/SharpCompress/Compressors/Xz/XZIndex.cs +++ b/src/SharpCompress/Compressors/Xz/XZIndex.cs @@ -15,7 +15,7 @@ namespace SharpCompress.Compressors.Xz public ulong NumberOfRecords { get; private set; } public List Records { get; } = new List(); - private bool _indexMarkerAlreadyVerified; + private readonly bool _indexMarkerAlreadyVerified; public XZIndex(BinaryReader reader, bool indexMarkerAlreadyVerified) { diff --git a/src/SharpCompress/Compressors/Xz/XZStream.cs b/src/SharpCompress/Compressors/Xz/XZStream.cs index d1de55a1..df755c26 100644 --- a/src/SharpCompress/Compressors/Xz/XZStream.cs +++ b/src/SharpCompress/Compressors/Xz/XZStream.cs @@ -40,7 +40,7 @@ namespace SharpCompress.Compressors.Xz public bool HeaderIsRead { get; private set; } private XZBlock _currentBlock; - bool _endOfStream; + private bool _endOfStream; public XZStream(Stream stream) : base(stream) { diff --git a/src/SharpCompress/Converters/DataConverter.cs b/src/SharpCompress/Converters/DataConverter.cs index 2ea5c5c9..6be04586 100644 --- a/src/SharpCompress/Converters/DataConverter.cs +++ b/src/SharpCompress/Converters/DataConverter.cs @@ -47,12 +47,12 @@ namespace SharpCompress.Converters public #endif - unsafe abstract class DataConverter + internal unsafe abstract class DataConverter { // Disables the warning: CLS compliance checking will not be performed on // `XXXX' because it is not visible from outside this assembly #pragma warning disable 3019 - static readonly DataConverter SwapConv = new SwapConverter(); + private static readonly DataConverter SwapConv = new SwapConverter(); public static readonly bool IsLittleEndian = BitConverter.IsLittleEndian; @@ -164,7 +164,7 @@ namespace SharpCompress.Converters } } - class CopyConverter : DataConverter + private class CopyConverter : DataConverter { public override double GetDouble(byte[] data, int index) { @@ -462,7 +462,7 @@ namespace SharpCompress.Converters } } - class SwapConverter : DataConverter + private class SwapConverter : DataConverter { public override double GetDouble(byte[] data, int index) { diff --git a/src/SharpCompress/Crypto/RijndaelEngine.cs b/src/SharpCompress/Crypto/RijndaelEngine.cs index 6fa73b4b..f90be37f 100644 --- a/src/SharpCompress/Crypto/RijndaelEngine.cs +++ b/src/SharpCompress/Crypto/RijndaelEngine.cs @@ -128,7 +128,7 @@ namespace Org.BouncyCastle.Crypto.Engines 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 }; - static readonly byte[][] shifts0 = + private static readonly byte[][] shifts0 = { new byte[] {0, 8, 16, 24}, new byte[] {0, 8, 16, 24}, @@ -137,7 +137,7 @@ namespace Org.BouncyCastle.Crypto.Engines new byte[] {0, 8, 24, 32} }; - static readonly byte[][] shifts1 = + private static readonly byte[][] shifts1 = { new byte[] {0, 24, 16, 8}, new byte[] {0, 32, 24, 16}, diff --git a/src/SharpCompress/Writers/Tar/TarWriter.cs b/src/SharpCompress/Writers/Tar/TarWriter.cs index f6f06c56..61e98ffd 100644 --- a/src/SharpCompress/Writers/Tar/TarWriter.cs +++ b/src/SharpCompress/Writers/Tar/TarWriter.cs @@ -12,7 +12,7 @@ namespace SharpCompress.Writers.Tar { public class TarWriter : AbstractWriter { - private bool finalizeArchiveOnClose; + private readonly bool finalizeArchiveOnClose; public TarWriter(Stream destination, TarWriterOptions options) : base(ArchiveType.Tar, options) diff --git a/tests/SharpCompress.Test/ArchiveTests.cs b/tests/SharpCompress.Test/ArchiveTests.cs index a5413891..beea1870 100644 --- a/tests/SharpCompress.Test/ArchiveTests.cs +++ b/tests/SharpCompress.Test/ArchiveTests.cs @@ -134,7 +134,7 @@ namespace SharpCompress.Test } } - void archive_CompressedBytesRead(object sender, CompressedBytesReadEventArgs e) + private void archive_CompressedBytesRead(object sender, CompressedBytesReadEventArgs e) { Console.WriteLine("Read Compressed File Part Bytes: {0} Percentage: {1}%", e.CurrentFilePartCompressedBytesRead, CreatePercentage(e.CurrentFilePartCompressedBytesRead, partTotal)); @@ -145,13 +145,13 @@ namespace SharpCompress.Test e.CompressedBytesRead, percentage); } - void archive_FilePartExtractionBegin(object sender, FilePartExtractionBeginEventArgs e) + private void archive_FilePartExtractionBegin(object sender, FilePartExtractionBeginEventArgs e) { partTotal = e.Size; Console.WriteLine("Initializing File Part Extraction: " + e.Name); } - void archive_EntryExtractionBegin(object sender, ArchiveExtractionEventArgs e) + private void archive_EntryExtractionBegin(object sender, ArchiveExtractionEventArgs e) { entryTotal = e.Item.Size; Console.WriteLine("Initializing File Entry Extraction: " + e.Item.Key); diff --git a/tests/SharpCompress.Test/Xz/Filters/Lzma2Tests.cs b/tests/SharpCompress.Test/Xz/Filters/Lzma2Tests.cs index b42c8788..c9594c1b 100644 --- a/tests/SharpCompress.Test/Xz/Filters/Lzma2Tests.cs +++ b/tests/SharpCompress.Test/Xz/Filters/Lzma2Tests.cs @@ -7,7 +7,7 @@ namespace SharpCompress.Test.Xz.Filters { public class Lzma2Tests : XZTestsBase { - Lzma2Filter filter; + private readonly Lzma2Filter filter; public Lzma2Tests() { diff --git a/tests/SharpCompress.Test/Zip/Zip64Tests.cs b/tests/SharpCompress.Test/Zip/Zip64Tests.cs index ffa2859b..d1e105a6 100644 --- a/tests/SharpCompress.Test/Zip/Zip64Tests.cs +++ b/tests/SharpCompress.Test/Zip/Zip64Tests.cs @@ -19,7 +19,7 @@ namespace SharpCompress.Test.Zip } // 4GiB + 1 - const long FOUR_GB_LIMIT = ((long)uint.MaxValue) + 1; + private const long FOUR_GB_LIMIT = ((long)uint.MaxValue) + 1; [Trait("format", "zip64")] public void Zip64_Single_Large_File() diff --git a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs index da17ccbf..20c76dfc 100644 --- a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs @@ -458,7 +458,7 @@ namespace SharpCompress.Test.Zip }); } - class NonSeekableMemoryStream : MemoryStream + private class NonSeekableMemoryStream : MemoryStream { public override bool CanSeek => false; } diff --git a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs index c1f7f701..e30c0eed 100644 --- a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs @@ -274,7 +274,7 @@ namespace SharpCompress.Test.Zip VerifyFiles(); } - class NonSeekableMemoryStream : MemoryStream + private class NonSeekableMemoryStream : MemoryStream { public override bool CanSeek => false; }