├── .vs └── Compress │ └── v15 │ ├── .suo │ └── sqlite3 │ └── storage.ide ├── Compress.Info ├── Compress.Info.csproj ├── FileChangeInfo.cs ├── Properties │ └── AssemblyInfo.cs ├── bin │ └── Debug │ │ ├── Compress.Info.dll │ │ └── Compress.Info.pdb └── obj │ └── Debug │ ├── Compress.Info.csproj.CoreCompileInputs.cache │ ├── Compress.Info.csproj.FileListAbsolute.txt │ ├── Compress.Info.csprojResolveAssemblyReference.cache │ ├── Compress.Info.dll │ ├── Compress.Info.pdb │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs ├── Compress.LZMA ├── 7zip │ ├── Common.meta │ ├── Common │ │ ├── CRC.cs │ │ ├── CRC.cs.meta │ │ ├── CommandLineParser.cs │ │ ├── CommandLineParser.cs.meta │ │ ├── InBuffer.cs │ │ ├── InBuffer.cs.meta │ │ ├── OutBuffer.cs │ │ └── OutBuffer.cs.meta │ ├── Compress.meta │ ├── Compress │ │ ├── LZ.meta │ │ ├── LZ │ │ │ ├── IMatchFinder.cs │ │ │ ├── IMatchFinder.cs.meta │ │ │ ├── LzBinTree.cs │ │ │ ├── LzBinTree.cs.meta │ │ │ ├── LzInWindow.cs │ │ │ ├── LzInWindow.cs.meta │ │ │ ├── LzOutWindow.cs │ │ │ └── LzOutWindow.cs.meta │ │ ├── LZMA.meta │ │ ├── LZMA │ │ │ ├── LzmaBase.cs │ │ │ ├── LzmaBase.cs.meta │ │ │ ├── LzmaDecoder.cs │ │ │ ├── LzmaDecoder.cs.meta │ │ │ ├── LzmaEncoder.cs │ │ │ └── LzmaEncoder.cs.meta │ │ ├── LzmaAlone.meta │ │ ├── LzmaAlone │ │ │ ├── LzmaAlone.cs │ │ │ ├── LzmaAlone.cs.meta │ │ │ ├── LzmaAlone.csproj │ │ │ ├── LzmaAlone.csproj.meta │ │ │ ├── LzmaAlone.sln │ │ │ ├── LzmaAlone.sln.meta │ │ │ ├── LzmaBench.cs │ │ │ ├── LzmaBench.cs.meta │ │ │ ├── Properties.meta │ │ │ └── Properties │ │ │ │ ├── AssemblyInfo.cs │ │ │ │ ├── AssemblyInfo.cs.meta │ │ │ │ ├── Resources.cs │ │ │ │ └── Resources.cs.meta │ │ ├── RangeCoder.meta │ │ └── RangeCoder │ │ │ ├── RangeCoder.cs │ │ │ ├── RangeCoder.cs.meta │ │ │ ├── RangeCoderBit.cs │ │ │ ├── RangeCoderBit.cs.meta │ │ │ ├── RangeCoderBitTree.cs │ │ │ └── RangeCoderBitTree.cs.meta │ ├── ICoder.cs │ └── ICoder.cs.meta ├── Compress.Info.dll ├── Compress.LZMA.csproj ├── LZMAFile.cs ├── Properties │ └── AssemblyInfo.cs ├── README.md ├── UnityEngine.dll ├── bin │ └── Debug │ │ ├── Compress.Info.dll │ │ ├── Compress.LZMA.dll │ │ ├── Compress.LZMA.pdb │ │ └── UnityEngine.dll └── obj │ └── Debug │ ├── Compress.LZMA.csproj.CoreCompileInputs.cache │ ├── Compress.LZMA.csproj.FileListAbsolute.txt │ ├── Compress.LZMA.csprojResolveAssemblyReference.cache │ ├── Compress.LZMA.dll │ ├── Compress.LZMA.pdb │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs ├── Compress.UPK ├── Compress.Info.dll ├── Compress.UPK.csproj ├── Properties │ └── AssemblyInfo.cs ├── UPKFolder.cs ├── UnityEngine.dll ├── bin │ └── Debug │ │ ├── Compress.Info.dll │ │ ├── Compress.UPK.dll │ │ ├── Compress.UPK.pdb │ │ └── UnityEngine.dll └── obj │ └── Debug │ ├── Compress.UPK.csproj.CoreCompileInputs.cache │ ├── Compress.UPK.csproj.FileListAbsolute.txt │ ├── Compress.UPK.csprojResolveAssemblyReference.cache │ ├── Compress.UPK.dll │ ├── Compress.UPK.pdb │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs ├── Compress.sln ├── Compress.v12.suo ├── ICSharpCode.SharpZipLib ├── AssemblyInfo.cs ├── BZip2 │ ├── BZip2.cs │ ├── BZip2Constants.cs │ ├── BZip2Exception.cs │ ├── BZip2InputStream.cs │ └── BZip2OutputStream.cs ├── Checksum │ ├── Adler32.cs │ ├── BZip2Crc.cs │ ├── Crc32.cs │ └── IChecksum.cs ├── Compress.Info.dll ├── Core │ ├── FileSystemScanner.cs │ ├── INameTransform.cs │ ├── IScanFilter.cs │ ├── NameFilter.cs │ ├── PathFilter.cs │ ├── StreamUtils.cs │ └── WindowsPathUtils.cs ├── Encryption │ ├── PkzipClassic.cs │ ├── ZipAESStream.cs │ └── ZipAESTransform.cs ├── GZip │ ├── GZip.cs │ ├── GZipConstants.cs │ ├── GZipException.cs │ ├── GZipFile.cs │ ├── GzipInputStream.cs │ └── GzipOutputStream.cs ├── GlobalAssemblyInfo.cs ├── ICSharpCode.SharpZipLib.csproj ├── Lzw │ ├── LzwConstants.cs │ ├── LzwException.cs │ └── LzwInputStream.cs ├── SharpZipBaseException.cs ├── Tar │ ├── InvalidHeaderException.cs │ ├── TarArchive.cs │ ├── TarBuffer.cs │ ├── TarEntry.cs │ ├── TarException.cs │ ├── TarHeader.cs │ ├── TarInputStream.cs │ └── TarOutputStream.cs ├── Zip │ ├── Compression │ │ ├── Deflater.cs │ │ ├── DeflaterConstants.cs │ │ ├── DeflaterEngine.cs │ │ ├── DeflaterHuffman.cs │ │ ├── DeflaterPending.cs │ │ ├── Inflater.cs │ │ ├── InflaterDynHeader.cs │ │ ├── InflaterHuffmanTree.cs │ │ ├── PendingBuffer.cs │ │ └── Streams │ │ │ ├── DeflaterOutputStream.cs │ │ │ ├── InflaterInputStream.cs │ │ │ ├── OutputWindow.cs │ │ │ └── StreamManipulator.cs │ ├── FastZip.cs │ ├── IEntryFactory.cs │ ├── WindowsNameTransform.cs │ ├── ZipConstants.cs │ ├── ZipEntry.cs │ ├── ZipEntryFactory.cs │ ├── ZipException.cs │ ├── ZipExtraData.cs │ ├── ZipFile.cs │ ├── ZipHelperStream.cs │ ├── ZipInputStream.cs │ ├── ZipNameTransform.cs │ └── ZipOutputStream.cs ├── bin │ └── Debug │ │ ├── Compress.Info.dll │ │ ├── ICSharpCode.SharpZipLib.dll │ │ ├── ICSharpCode.SharpZipLib.dll.CodeAnalysisLog.xml │ │ ├── ICSharpCode.SharpZipLib.dll.lastcodeanalysissucceeded │ │ ├── ICSharpCode.SharpZipLib.pdb │ │ ├── ICSharpCode.SharpZipLib.vshost.exe │ │ └── ICSharpCode.SharpZipLib.xml └── obj │ └── Debug │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── ICSharpCode.SharpZipLib.csproj.CoreCompileInputs.cache │ ├── ICSharpCode.SharpZipLib.csproj.FileListAbsolute.txt │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs └── README.md /.vs/Compress/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/.vs/Compress/v15/.suo -------------------------------------------------------------------------------- /.vs/Compress/v15/sqlite3/storage.ide: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/.vs/Compress/v15/sqlite3/storage.ide -------------------------------------------------------------------------------- /Compress.Info/Compress.Info.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5A0381AB-E0BC-443E-91D1-4F026A1051FB} 8 | Library 9 | Properties 10 | Compress.Info 11 | Compress.Info 12 | v3.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | -------------------------------------------------------------------------------- /Compress.Info/FileChangeInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace YZL.Compress.Info 4 | { 5 | public delegate void ProgressDelegate(Int64 fileSize, Int64 processSize); 6 | public class FileChangeInfo 7 | { 8 | public string inpath; 9 | public string outpath; 10 | public ProgressDelegate progressDelegate; 11 | }; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Compress.Info/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Compress.Info")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Compress.Info")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("3a3fd7f4-d915-466f-896e-702572830d70")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Compress.Info/bin/Debug/Compress.Info.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.Info/bin/Debug/Compress.Info.dll -------------------------------------------------------------------------------- /Compress.Info/bin/Debug/Compress.Info.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.Info/bin/Debug/Compress.Info.pdb -------------------------------------------------------------------------------- /Compress.Info/obj/Debug/Compress.Info.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | 283f9b5797e9d27d7112fe87152247b7f3f1eacb 2 | -------------------------------------------------------------------------------- /Compress.Info/obj/Debug/Compress.Info.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.Info\Compress.Info\bin\Debug\Compress.Info.dll 2 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.Info\Compress.Info\bin\Debug\Compress.Info.pdb 3 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.Info\Compress.Info\obj\Debug\Compress.Info.csprojResolveAssemblyReference.cache 4 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.Info\Compress.Info\obj\Debug\Compress.Info.dll 5 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.Info\Compress.Info\obj\Debug\Compress.Info.pdb 6 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.Info\bin\Debug\Compress.Info.dll 7 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.Info\bin\Debug\Compress.Info.pdb 8 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.Info\obj\Debug\Compress.Info.csprojResolveAssemblyReference.cache 9 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.Info\obj\Debug\Compress.Info.dll 10 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.Info\obj\Debug\Compress.Info.pdb 11 | -------------------------------------------------------------------------------- /Compress.Info/obj/Debug/Compress.Info.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.Info/obj/Debug/Compress.Info.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Compress.Info/obj/Debug/Compress.Info.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.Info/obj/Debug/Compress.Info.dll -------------------------------------------------------------------------------- /Compress.Info/obj/Debug/Compress.Info.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.Info/obj/Debug/Compress.Info.pdb -------------------------------------------------------------------------------- /Compress.Info/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.Info/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /Compress.Info/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.Info/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs -------------------------------------------------------------------------------- /Compress.Info/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.Info/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs -------------------------------------------------------------------------------- /Compress.Info/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.Info/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Common.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26ce4512b6047c64bbfd38096f8a4996 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Common/CRC.cs: -------------------------------------------------------------------------------- 1 | // Common/CRC.cs 2 | 3 | namespace SevenZip 4 | { 5 | class CRC 6 | { 7 | public static readonly uint[] Table; 8 | 9 | static CRC() 10 | { 11 | Table = new uint[256]; 12 | const uint kPoly = 0xEDB88320; 13 | for (uint i = 0; i < 256; i++) 14 | { 15 | uint r = i; 16 | for (int j = 0; j < 8; j++) 17 | if ((r & 1) != 0) 18 | r = (r >> 1) ^ kPoly; 19 | else 20 | r >>= 1; 21 | Table[i] = r; 22 | } 23 | } 24 | 25 | uint _value = 0xFFFFFFFF; 26 | 27 | public void Init() { _value = 0xFFFFFFFF; } 28 | 29 | public void UpdateByte(byte b) 30 | { 31 | _value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8); 32 | } 33 | 34 | public void Update(byte[] data, uint offset, uint size) 35 | { 36 | for (uint i = 0; i < size; i++) 37 | _value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8); 38 | } 39 | 40 | public uint GetDigest() { return _value ^ 0xFFFFFFFF; } 41 | 42 | static uint CalculateDigest(byte[] data, uint offset, uint size) 43 | { 44 | CRC crc = new CRC(); 45 | // crc.Init(); 46 | crc.Update(data, offset, size); 47 | return crc.GetDigest(); 48 | } 49 | 50 | static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size) 51 | { 52 | return (CalculateDigest(data, offset, size) == digest); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Common/CRC.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dfff8e13fc8d09e4c9676d6f32552a8d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Common/CommandLineParser.cs: -------------------------------------------------------------------------------- 1 | // CommandLineParser.cs 2 | 3 | using System; 4 | using System.Collections; 5 | 6 | namespace SevenZip.CommandLineParser 7 | { 8 | public enum SwitchType 9 | { 10 | Simple, 11 | PostMinus, 12 | LimitedPostString, 13 | UnLimitedPostString, 14 | PostChar 15 | } 16 | 17 | public class SwitchForm 18 | { 19 | public string IDString; 20 | public SwitchType Type; 21 | public bool Multi; 22 | public int MinLen; 23 | public int MaxLen; 24 | public string PostCharSet; 25 | 26 | public SwitchForm(string idString, SwitchType type, bool multi, 27 | int minLen, int maxLen, string postCharSet) 28 | { 29 | IDString = idString; 30 | Type = type; 31 | Multi = multi; 32 | MinLen = minLen; 33 | MaxLen = maxLen; 34 | PostCharSet = postCharSet; 35 | } 36 | public SwitchForm(string idString, SwitchType type, bool multi, int minLen): 37 | this(idString, type, multi, minLen, 0, "") 38 | { 39 | } 40 | public SwitchForm(string idString, SwitchType type, bool multi): 41 | this(idString, type, multi, 0) 42 | { 43 | } 44 | } 45 | 46 | public class SwitchResult 47 | { 48 | public bool ThereIs; 49 | public bool WithMinus; 50 | public ArrayList PostStrings = new ArrayList(); 51 | public int PostCharIndex; 52 | public SwitchResult() 53 | { 54 | ThereIs = false; 55 | } 56 | } 57 | 58 | public class Parser 59 | { 60 | public ArrayList NonSwitchStrings = new ArrayList(); 61 | SwitchResult[] _switches; 62 | 63 | public Parser(int numSwitches) 64 | { 65 | _switches = new SwitchResult[numSwitches]; 66 | for (int i = 0; i < numSwitches; i++) 67 | _switches[i] = new SwitchResult(); 68 | } 69 | 70 | bool ParseString(string srcString, SwitchForm[] switchForms) 71 | { 72 | int len = srcString.Length; 73 | if (len == 0) 74 | return false; 75 | int pos = 0; 76 | if (!IsItSwitchChar(srcString[pos])) 77 | return false; 78 | while (pos < len) 79 | { 80 | if (IsItSwitchChar(srcString[pos])) 81 | pos++; 82 | const int kNoLen = -1; 83 | int matchedSwitchIndex = 0; 84 | int maxLen = kNoLen; 85 | for (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++) 86 | { 87 | int switchLen = switchForms[switchIndex].IDString.Length; 88 | if (switchLen <= maxLen || pos + switchLen > len) 89 | continue; 90 | if (String.Compare(switchForms[switchIndex].IDString, 0, 91 | srcString, pos, switchLen, true) == 0) 92 | { 93 | matchedSwitchIndex = switchIndex; 94 | maxLen = switchLen; 95 | } 96 | } 97 | if (maxLen == kNoLen) 98 | throw new Exception("maxLen == kNoLen"); 99 | SwitchResult matchedSwitch = _switches[matchedSwitchIndex]; 100 | SwitchForm switchForm = switchForms[matchedSwitchIndex]; 101 | if ((!switchForm.Multi) && matchedSwitch.ThereIs) 102 | throw new Exception("switch must be single"); 103 | matchedSwitch.ThereIs = true; 104 | pos += maxLen; 105 | int tailSize = len - pos; 106 | SwitchType type = switchForm.Type; 107 | switch (type) 108 | { 109 | case SwitchType.PostMinus: 110 | { 111 | if (tailSize == 0) 112 | matchedSwitch.WithMinus = false; 113 | else 114 | { 115 | matchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus); 116 | if (matchedSwitch.WithMinus) 117 | pos++; 118 | } 119 | break; 120 | } 121 | case SwitchType.PostChar: 122 | { 123 | if (tailSize < switchForm.MinLen) 124 | throw new Exception("switch is not full"); 125 | string charSet = switchForm.PostCharSet; 126 | const int kEmptyCharValue = -1; 127 | if (tailSize == 0) 128 | matchedSwitch.PostCharIndex = kEmptyCharValue; 129 | else 130 | { 131 | int index = charSet.IndexOf(srcString[pos]); 132 | if (index < 0) 133 | matchedSwitch.PostCharIndex = kEmptyCharValue; 134 | else 135 | { 136 | matchedSwitch.PostCharIndex = index; 137 | pos++; 138 | } 139 | } 140 | break; 141 | } 142 | case SwitchType.LimitedPostString: 143 | case SwitchType.UnLimitedPostString: 144 | { 145 | int minLen = switchForm.MinLen; 146 | if (tailSize < minLen) 147 | throw new Exception("switch is not full"); 148 | if (type == SwitchType.UnLimitedPostString) 149 | { 150 | matchedSwitch.PostStrings.Add(srcString.Substring(pos)); 151 | return true; 152 | } 153 | String stringSwitch = srcString.Substring(pos, minLen); 154 | pos += minLen; 155 | for (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++) 156 | { 157 | char c = srcString[pos]; 158 | if (IsItSwitchChar(c)) 159 | break; 160 | stringSwitch += c; 161 | } 162 | matchedSwitch.PostStrings.Add(stringSwitch); 163 | break; 164 | } 165 | } 166 | } 167 | return true; 168 | 169 | } 170 | 171 | public void ParseStrings(SwitchForm[] switchForms, string[] commandStrings) 172 | { 173 | int numCommandStrings = commandStrings.Length; 174 | bool stopSwitch = false; 175 | for (int i = 0; i < numCommandStrings; i++) 176 | { 177 | string s = commandStrings[i]; 178 | if (stopSwitch) 179 | NonSwitchStrings.Add(s); 180 | else 181 | if (s == kStopSwitchParsing) 182 | stopSwitch = true; 183 | else 184 | if (!ParseString(s, switchForms)) 185 | NonSwitchStrings.Add(s); 186 | } 187 | } 188 | 189 | public SwitchResult this[int index] { get { return _switches[index]; } } 190 | 191 | public static int ParseCommand(CommandForm[] commandForms, string commandString, 192 | out string postString) 193 | { 194 | for (int i = 0; i < commandForms.Length; i++) 195 | { 196 | string id = commandForms[i].IDString; 197 | if (commandForms[i].PostStringMode) 198 | { 199 | if (commandString.IndexOf(id) == 0) 200 | { 201 | postString = commandString.Substring(id.Length); 202 | return i; 203 | } 204 | } 205 | else 206 | if (commandString == id) 207 | { 208 | postString = ""; 209 | return i; 210 | } 211 | } 212 | postString = ""; 213 | return -1; 214 | } 215 | 216 | static bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms, 217 | string commandString, ArrayList indices) 218 | { 219 | indices.Clear(); 220 | int numUsedChars = 0; 221 | for (int i = 0; i < numForms; i++) 222 | { 223 | CommandSubCharsSet charsSet = forms[i]; 224 | int currentIndex = -1; 225 | int len = charsSet.Chars.Length; 226 | for (int j = 0; j < len; j++) 227 | { 228 | char c = charsSet.Chars[j]; 229 | int newIndex = commandString.IndexOf(c); 230 | if (newIndex >= 0) 231 | { 232 | if (currentIndex >= 0) 233 | return false; 234 | if (commandString.IndexOf(c, newIndex + 1) >= 0) 235 | return false; 236 | currentIndex = j; 237 | numUsedChars++; 238 | } 239 | } 240 | if (currentIndex == -1 && !charsSet.EmptyAllowed) 241 | return false; 242 | indices.Add(currentIndex); 243 | } 244 | return (numUsedChars == commandString.Length); 245 | } 246 | const char kSwitchID1 = '-'; 247 | const char kSwitchID2 = '/'; 248 | 249 | const char kSwitchMinus = '-'; 250 | const string kStopSwitchParsing = "--"; 251 | 252 | static bool IsItSwitchChar(char c) 253 | { 254 | return (c == kSwitchID1 || c == kSwitchID2); 255 | } 256 | } 257 | 258 | public class CommandForm 259 | { 260 | public string IDString = ""; 261 | public bool PostStringMode = false; 262 | public CommandForm(string idString, bool postStringMode) 263 | { 264 | IDString = idString; 265 | PostStringMode = postStringMode; 266 | } 267 | } 268 | 269 | class CommandSubCharsSet 270 | { 271 | public string Chars = ""; 272 | public bool EmptyAllowed = false; 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Common/CommandLineParser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7096a5bf420158b4088b184a6455d6e5 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Common/InBuffer.cs: -------------------------------------------------------------------------------- 1 | // InBuffer.cs 2 | 3 | namespace SevenZip.Buffer 4 | { 5 | public class InBuffer 6 | { 7 | byte[] m_Buffer; 8 | uint m_Pos; 9 | uint m_Limit; 10 | uint m_BufferSize; 11 | System.IO.Stream m_Stream; 12 | bool m_StreamWasExhausted; 13 | ulong m_ProcessedSize; 14 | 15 | public InBuffer(uint bufferSize) 16 | { 17 | m_Buffer = new byte[bufferSize]; 18 | m_BufferSize = bufferSize; 19 | } 20 | 21 | public void Init(System.IO.Stream stream) 22 | { 23 | m_Stream = stream; 24 | m_ProcessedSize = 0; 25 | m_Limit = 0; 26 | m_Pos = 0; 27 | m_StreamWasExhausted = false; 28 | } 29 | 30 | public bool ReadBlock() 31 | { 32 | if (m_StreamWasExhausted) 33 | return false; 34 | m_ProcessedSize += m_Pos; 35 | int aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize); 36 | m_Pos = 0; 37 | m_Limit = (uint)aNumProcessedBytes; 38 | m_StreamWasExhausted = (aNumProcessedBytes == 0); 39 | return (!m_StreamWasExhausted); 40 | } 41 | 42 | 43 | public void ReleaseStream() 44 | { 45 | // m_Stream.Close(); 46 | m_Stream = null; 47 | } 48 | 49 | public bool ReadByte(byte b) // check it 50 | { 51 | if (m_Pos >= m_Limit) 52 | if (!ReadBlock()) 53 | return false; 54 | b = m_Buffer[m_Pos++]; 55 | return true; 56 | } 57 | 58 | public byte ReadByte() 59 | { 60 | // return (byte)m_Stream.ReadByte(); 61 | if (m_Pos >= m_Limit) 62 | if (!ReadBlock()) 63 | return 0xFF; 64 | return m_Buffer[m_Pos++]; 65 | } 66 | 67 | public ulong GetProcessedSize() 68 | { 69 | return m_ProcessedSize + m_Pos; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Common/InBuffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e19c8258ce137854e87519a5040eb0d3 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Common/OutBuffer.cs: -------------------------------------------------------------------------------- 1 | // OutBuffer.cs 2 | 3 | namespace SevenZip.Buffer 4 | { 5 | public class OutBuffer 6 | { 7 | byte[] m_Buffer; 8 | uint m_Pos; 9 | uint m_BufferSize; 10 | System.IO.Stream m_Stream; 11 | ulong m_ProcessedSize; 12 | 13 | public OutBuffer(uint bufferSize) 14 | { 15 | m_Buffer = new byte[bufferSize]; 16 | m_BufferSize = bufferSize; 17 | } 18 | 19 | public void SetStream(System.IO.Stream stream) { m_Stream = stream; } 20 | public void FlushStream() { m_Stream.Flush(); } 21 | public void CloseStream() { m_Stream.Close(); } 22 | public void ReleaseStream() { m_Stream = null; } 23 | 24 | public void Init() 25 | { 26 | m_ProcessedSize = 0; 27 | m_Pos = 0; 28 | } 29 | 30 | public void WriteByte(byte b) 31 | { 32 | m_Buffer[m_Pos++] = b; 33 | if (m_Pos >= m_BufferSize) 34 | FlushData(); 35 | } 36 | 37 | public void FlushData() 38 | { 39 | if (m_Pos == 0) 40 | return; 41 | m_Stream.Write(m_Buffer, 0, (int)m_Pos); 42 | m_Pos = 0; 43 | } 44 | 45 | public ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Common/OutBuffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e3ef707c2a420464ab5420a9bd23753a 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6be9696fd5201b84a89366f3d794d86b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZ.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fb2102ccd78f22447b5b5ec8b332b057 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZ/IMatchFinder.cs: -------------------------------------------------------------------------------- 1 | // IMatchFinder.cs 2 | 3 | using System; 4 | 5 | namespace SevenZip.Compression.LZ 6 | { 7 | interface IInWindowStream 8 | { 9 | void SetStream(System.IO.Stream inStream); 10 | void Init(); 11 | void ReleaseStream(); 12 | Byte GetIndexByte(Int32 index); 13 | UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit); 14 | UInt32 GetNumAvailableBytes(); 15 | } 16 | 17 | interface IMatchFinder : IInWindowStream 18 | { 19 | void Create(UInt32 historySize, UInt32 keepAddBufferBefore, 20 | UInt32 matchMaxLen, UInt32 keepAddBufferAfter); 21 | UInt32 GetMatches(UInt32[] distances); 22 | void Skip(UInt32 num); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZ/IMatchFinder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b5d00fd4649ac964f91176b8a93537bd 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZ/LzBinTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dc18f37d40681074ba19c94fc4a2eab2 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZ/LzInWindow.cs: -------------------------------------------------------------------------------- 1 | // LzInWindow.cs 2 | 3 | using System; 4 | 5 | namespace SevenZip.Compression.LZ 6 | { 7 | public class InWindow 8 | { 9 | public Byte[] _bufferBase = null; // pointer to buffer with data 10 | System.IO.Stream _stream; 11 | UInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done 12 | bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream 13 | 14 | UInt32 _pointerToLastSafePosition; 15 | 16 | public UInt32 _bufferOffset; 17 | 18 | public UInt32 _blockSize; // Size of Allocated memory block 19 | public UInt32 _pos; // offset (from _buffer) of curent byte 20 | UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos 21 | UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos 22 | public UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream 23 | 24 | public void MoveBlock() 25 | { 26 | UInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore; 27 | // we need one additional byte, since MovePos moves on 1 byte. 28 | if (offset > 0) 29 | offset--; 30 | 31 | UInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset; 32 | 33 | // check negative offset ???? 34 | for (UInt32 i = 0; i < numBytes; i++) 35 | _bufferBase[i] = _bufferBase[offset + i]; 36 | _bufferOffset -= offset; 37 | } 38 | 39 | public virtual void ReadBlock() 40 | { 41 | if (_streamEndWasReached) 42 | return; 43 | while (true) 44 | { 45 | int size = (int)((0 - _bufferOffset) + _blockSize - _streamPos); 46 | if (size == 0) 47 | return; 48 | int numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size); 49 | if (numReadBytes == 0) 50 | { 51 | _posLimit = _streamPos; 52 | UInt32 pointerToPostion = _bufferOffset + _posLimit; 53 | if (pointerToPostion > _pointerToLastSafePosition) 54 | _posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset); 55 | 56 | _streamEndWasReached = true; 57 | return; 58 | } 59 | _streamPos += (UInt32)numReadBytes; 60 | if (_streamPos >= _pos + _keepSizeAfter) 61 | _posLimit = _streamPos - _keepSizeAfter; 62 | } 63 | } 64 | 65 | void Free() { _bufferBase = null; } 66 | 67 | public void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv) 68 | { 69 | _keepSizeBefore = keepSizeBefore; 70 | _keepSizeAfter = keepSizeAfter; 71 | UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv; 72 | if (_bufferBase == null || _blockSize != blockSize) 73 | { 74 | Free(); 75 | _blockSize = blockSize; 76 | _bufferBase = new Byte[_blockSize]; 77 | } 78 | _pointerToLastSafePosition = _blockSize - keepSizeAfter; 79 | } 80 | 81 | public void SetStream(System.IO.Stream stream) { _stream = stream; } 82 | public void ReleaseStream() { _stream = null; } 83 | 84 | public void Init() 85 | { 86 | _bufferOffset = 0; 87 | _pos = 0; 88 | _streamPos = 0; 89 | _streamEndWasReached = false; 90 | ReadBlock(); 91 | } 92 | 93 | public void MovePos() 94 | { 95 | _pos++; 96 | if (_pos > _posLimit) 97 | { 98 | UInt32 pointerToPostion = _bufferOffset + _pos; 99 | if (pointerToPostion > _pointerToLastSafePosition) 100 | MoveBlock(); 101 | ReadBlock(); 102 | } 103 | } 104 | 105 | public Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; } 106 | 107 | // index + limit have not to exceed _keepSizeAfter; 108 | public UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) 109 | { 110 | if (_streamEndWasReached) 111 | if ((_pos + index) + limit > _streamPos) 112 | limit = _streamPos - (UInt32)(_pos + index); 113 | distance++; 114 | // Byte *pby = _buffer + (size_t)_pos + index; 115 | UInt32 pby = _bufferOffset + _pos + (UInt32)index; 116 | 117 | UInt32 i; 118 | for (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++); 119 | return i; 120 | } 121 | 122 | public UInt32 GetNumAvailableBytes() { return _streamPos - _pos; } 123 | 124 | public void ReduceOffsets(Int32 subValue) 125 | { 126 | _bufferOffset += (UInt32)subValue; 127 | _posLimit -= (UInt32)subValue; 128 | _pos -= (UInt32)subValue; 129 | _streamPos -= (UInt32)subValue; 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZ/LzInWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ed8bcd3b51e1d246b0adb172b43ef48 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZ/LzOutWindow.cs: -------------------------------------------------------------------------------- 1 | // LzOutWindow.cs 2 | 3 | namespace SevenZip.Compression.LZ 4 | { 5 | public class OutWindow 6 | { 7 | byte[] _buffer = null; 8 | uint _pos; 9 | uint _windowSize = 0; 10 | uint _streamPos; 11 | System.IO.Stream _stream; 12 | 13 | public uint TrainSize = 0; 14 | 15 | public void Create(uint windowSize) 16 | { 17 | if (_windowSize != windowSize) 18 | { 19 | // System.GC.Collect(); 20 | _buffer = new byte[windowSize]; 21 | } 22 | _windowSize = windowSize; 23 | _pos = 0; 24 | _streamPos = 0; 25 | } 26 | 27 | public void Init(System.IO.Stream stream, bool solid) 28 | { 29 | ReleaseStream(); 30 | _stream = stream; 31 | if (!solid) 32 | { 33 | _streamPos = 0; 34 | _pos = 0; 35 | TrainSize = 0; 36 | } 37 | } 38 | 39 | public bool Train(System.IO.Stream stream) 40 | { 41 | long len = stream.Length; 42 | uint size = (len < _windowSize) ? (uint)len : _windowSize; 43 | TrainSize = size; 44 | stream.Position = len - size; 45 | _streamPos = _pos = 0; 46 | while (size > 0) 47 | { 48 | uint curSize = _windowSize - _pos; 49 | if (size < curSize) 50 | curSize = size; 51 | int numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize); 52 | if (numReadBytes == 0) 53 | return false; 54 | size -= (uint)numReadBytes; 55 | _pos += (uint)numReadBytes; 56 | _streamPos += (uint)numReadBytes; 57 | if (_pos == _windowSize) 58 | _streamPos = _pos = 0; 59 | } 60 | return true; 61 | } 62 | 63 | public void ReleaseStream() 64 | { 65 | Flush(); 66 | _stream = null; 67 | } 68 | 69 | public void Flush() 70 | { 71 | uint size = _pos - _streamPos; 72 | if (size == 0) 73 | return; 74 | _stream.Write(_buffer, (int)_streamPos, (int)size); 75 | if (_pos >= _windowSize) 76 | _pos = 0; 77 | _streamPos = _pos; 78 | } 79 | 80 | public void CopyBlock(uint distance, uint len) 81 | { 82 | uint pos = _pos - distance - 1; 83 | if (pos >= _windowSize) 84 | pos += _windowSize; 85 | for (; len > 0; len--) 86 | { 87 | if (pos >= _windowSize) 88 | pos = 0; 89 | _buffer[_pos++] = _buffer[pos++]; 90 | if (_pos >= _windowSize) 91 | Flush(); 92 | } 93 | } 94 | 95 | public void PutByte(byte b) 96 | { 97 | _buffer[_pos++] = b; 98 | if (_pos >= _windowSize) 99 | Flush(); 100 | } 101 | 102 | public byte GetByte(uint distance) 103 | { 104 | uint pos = _pos - distance - 1; 105 | if (pos >= _windowSize) 106 | pos += _windowSize; 107 | return _buffer[pos]; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZ/LzOutWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0e599b94e55fa848b0ac44bfa7d19a4 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZMA.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d7d7b235464caf0449a65cd865b5e675 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZMA/LzmaBase.cs: -------------------------------------------------------------------------------- 1 | // LzmaBase.cs 2 | 3 | namespace SevenZip.Compression.LZMA 4 | { 5 | internal abstract class Base 6 | { 7 | public const uint kNumRepDistances = 4; 8 | public const uint kNumStates = 12; 9 | 10 | // static byte []kLiteralNextStates = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5}; 11 | // static byte []kMatchNextStates = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10}; 12 | // static byte []kRepNextStates = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11}; 13 | // static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11}; 14 | 15 | public struct State 16 | { 17 | public uint Index; 18 | public void Init() { Index = 0; } 19 | public void UpdateChar() 20 | { 21 | if (Index < 4) Index = 0; 22 | else if (Index < 10) Index -= 3; 23 | else Index -= 6; 24 | } 25 | public void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); } 26 | public void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); } 27 | public void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); } 28 | public bool IsCharState() { return Index < 7; } 29 | } 30 | 31 | public const int kNumPosSlotBits = 6; 32 | public const int kDicLogSizeMin = 0; 33 | // public const int kDicLogSizeMax = 30; 34 | // public const uint kDistTableSizeMax = kDicLogSizeMax * 2; 35 | 36 | public const int kNumLenToPosStatesBits = 2; // it's for speed optimization 37 | public const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits; 38 | 39 | public const uint kMatchMinLen = 2; 40 | 41 | public static uint GetLenToPosState(uint len) 42 | { 43 | len -= kMatchMinLen; 44 | if (len < kNumLenToPosStates) 45 | return len; 46 | return (uint)(kNumLenToPosStates - 1); 47 | } 48 | 49 | public const int kNumAlignBits = 4; 50 | public const uint kAlignTableSize = 1 << kNumAlignBits; 51 | public const uint kAlignMask = (kAlignTableSize - 1); 52 | 53 | public const uint kStartPosModelIndex = 4; 54 | public const uint kEndPosModelIndex = 14; 55 | public const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; 56 | 57 | public const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2); 58 | 59 | public const uint kNumLitPosStatesBitsEncodingMax = 4; 60 | public const uint kNumLitContextBitsMax = 8; 61 | 62 | public const int kNumPosStatesBitsMax = 4; 63 | public const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax); 64 | public const int kNumPosStatesBitsEncodingMax = 4; 65 | public const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax); 66 | 67 | public const int kNumLowLenBits = 3; 68 | public const int kNumMidLenBits = 3; 69 | public const int kNumHighLenBits = 8; 70 | public const uint kNumLowLenSymbols = 1 << kNumLowLenBits; 71 | public const uint kNumMidLenSymbols = 1 << kNumMidLenBits; 72 | public const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols + 73 | (1 << kNumHighLenBits); 74 | public const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZMA/LzmaBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea4e580c52a13b74ba6d59ce0bcb6e3d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZMA/LzmaDecoder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 718aaeb91af7dcc4cad47e5acd47830a 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LZMA/LzmaEncoder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c968a345de13f4b43855de69db3ae466 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9b4efa336db9e649a09e4f644441328 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/LzmaAlone.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4bb699ad509cd0b429bb341c30841b77 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/LzmaAlone.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Debug 4 | AnyCPU 5 | 8.0.50727 6 | 2.0 7 | {CE33DF18-F9C8-4D6F-9057-DBB4DB96E973} 8 | Exe 9 | LzmaAlone 10 | Lzma# 11 | 4 12 | 13 | 14 | true 15 | full 16 | false 17 | .\bin\Debug\ 18 | DEBUG;TRACE 19 | 20 | 21 | false 22 | true 23 | .\bin\Release\ 24 | TRACE 25 | AnyCPU 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | Common\CommandLineParser.cs 35 | 36 | 37 | Common\CRC.cs 38 | 39 | 40 | ICoder.cs 41 | 42 | 43 | LZ\IMatchFinder.cs 44 | 45 | 46 | LZ\LzBinTree.cs 47 | 48 | 49 | LZ\LzInWindow.cs 50 | 51 | 52 | LZ\LzOutWindow.cs 53 | 54 | 55 | LZMA\LzmaBase.cs 56 | 57 | 58 | LZMA\LzmaDecoder.cs 59 | 60 | 61 | LZMA\LzmaEncoder.cs 62 | 63 | 64 | RangeCoder\RangeCoder.cs 65 | 66 | 67 | RangeCoder\RangeCoderBit.cs 68 | 69 | 70 | RangeCoder\RangeCoderBitTree.cs 71 | 72 | 73 | Code 74 | 75 | 76 | Code 77 | 78 | 79 | 80 | True 81 | Settings.settings 82 | 83 | 84 | SettingsSingleFileGenerator 85 | Settings.cs 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/LzmaAlone.csproj.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a78ace98430a1643aaea4ddcf4f1a04 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/LzmaAlone.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual C# Express 2005 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LzmaAlone", "LzmaAlone.csproj", "{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/LzmaAlone.sln.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d579f9c134179fd42a471b3489f6bfdc 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/LzmaBench.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dcc8cff770285c14ebe8f11c075c677f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/Properties.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d15daa41381c04445be4aa1eeb38585b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region Using directives 2 | 3 | using System.Reflection; 4 | using System.Runtime.CompilerServices; 5 | 6 | #endregion 7 | 8 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c249a778ddbbf4d479fec4e2d3a46af3 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/Properties/Resources.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:2.0.40607.42 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace LzmaAlone.Properties 12 | { 13 | using System; 14 | using System.IO; 15 | using System.Resources; 16 | 17 | /// 18 | /// A strongly-typed resource class, for looking up localized strings, etc. 19 | /// 20 | // This class was auto-generated by the Strongly Typed Resource Builder 21 | // class via a tool like ResGen or Visual Studio.NET. 22 | // To add or remove a member, edit your .ResX file then rerun ResGen 23 | // with the /str option, or rebuild your VS project. 24 | class Resources 25 | { 26 | 27 | private static System.Resources.ResourceManager _resMgr; 28 | 29 | private static System.Globalization.CultureInfo _resCulture; 30 | 31 | /*FamANDAssem*/ 32 | internal Resources() 33 | { 34 | } 35 | 36 | /// 37 | /// Returns the cached ResourceManager instance used by this class. 38 | /// 39 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 40 | public static System.Resources.ResourceManager ResourceManager 41 | { 42 | get 43 | { 44 | if ((_resMgr == null)) 45 | { 46 | System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Resources", typeof(Resources).Assembly); 47 | _resMgr = temp; 48 | } 49 | return _resMgr; 50 | } 51 | } 52 | 53 | /// 54 | /// Overrides the current thread's CurrentUICulture property for all 55 | /// resource lookups using this strongly typed resource class. 56 | /// 57 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 58 | public static System.Globalization.CultureInfo Culture 59 | { 60 | get 61 | { 62 | return _resCulture; 63 | } 64 | set 65 | { 66 | _resCulture = value; 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/LzmaAlone/Properties/Resources.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 594aee51690949e43ad03feeafbca4d0 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/RangeCoder.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d59d6caa94905a940a8fb028451d2fa0 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/RangeCoder/RangeCoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SevenZip.Compression.RangeCoder 4 | { 5 | class Encoder 6 | { 7 | public const uint kTopValue = (1 << 24); 8 | 9 | System.IO.Stream Stream; 10 | 11 | public UInt64 Low; 12 | public uint Range; 13 | uint _cacheSize; 14 | byte _cache; 15 | 16 | long StartPosition; 17 | 18 | public void SetStream(System.IO.Stream stream) 19 | { 20 | Stream = stream; 21 | } 22 | 23 | public void ReleaseStream() 24 | { 25 | Stream = null; 26 | } 27 | 28 | public void Init() 29 | { 30 | StartPosition = Stream.Position; 31 | 32 | Low = 0; 33 | Range = 0xFFFFFFFF; 34 | _cacheSize = 1; 35 | _cache = 0; 36 | } 37 | 38 | public void FlushData() 39 | { 40 | for (int i = 0; i < 5; i++) 41 | ShiftLow(); 42 | } 43 | 44 | public void FlushStream() 45 | { 46 | Stream.Flush(); 47 | } 48 | 49 | public void CloseStream() 50 | { 51 | Stream.Close(); 52 | } 53 | 54 | public void Encode(uint start, uint size, uint total) 55 | { 56 | Low += start * (Range /= total); 57 | Range *= size; 58 | while (Range < kTopValue) 59 | { 60 | Range <<= 8; 61 | ShiftLow(); 62 | } 63 | } 64 | 65 | public void ShiftLow() 66 | { 67 | if ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1) 68 | { 69 | byte temp = _cache; 70 | do 71 | { 72 | Stream.WriteByte((byte)(temp + (Low >> 32))); 73 | temp = 0xFF; 74 | } 75 | while (--_cacheSize != 0); 76 | _cache = (byte)(((uint)Low) >> 24); 77 | } 78 | _cacheSize++; 79 | Low = ((uint)Low) << 8; 80 | } 81 | 82 | public void EncodeDirectBits(uint v, int numTotalBits) 83 | { 84 | for (int i = numTotalBits - 1; i >= 0; i--) 85 | { 86 | Range >>= 1; 87 | if (((v >> i) & 1) == 1) 88 | Low += Range; 89 | if (Range < kTopValue) 90 | { 91 | Range <<= 8; 92 | ShiftLow(); 93 | } 94 | } 95 | } 96 | 97 | public void EncodeBit(uint size0, int numTotalBits, uint symbol) 98 | { 99 | uint newBound = (Range >> numTotalBits) * size0; 100 | if (symbol == 0) 101 | Range = newBound; 102 | else 103 | { 104 | Low += newBound; 105 | Range -= newBound; 106 | } 107 | while (Range < kTopValue) 108 | { 109 | Range <<= 8; 110 | ShiftLow(); 111 | } 112 | } 113 | 114 | public long GetProcessedSizeAdd() 115 | { 116 | return _cacheSize + 117 | Stream.Position - StartPosition + 4; 118 | // (long)Stream.GetProcessedSize(); 119 | } 120 | } 121 | 122 | class Decoder 123 | { 124 | public const uint kTopValue = (1 << 24); 125 | public uint Range; 126 | public uint Code; 127 | // public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16); 128 | public System.IO.Stream Stream; 129 | 130 | public void Init(System.IO.Stream stream) 131 | { 132 | // Stream.Init(stream); 133 | Stream = stream; 134 | 135 | Code = 0; 136 | Range = 0xFFFFFFFF; 137 | for (int i = 0; i < 5; i++) 138 | Code = (Code << 8) | (byte)Stream.ReadByte(); 139 | } 140 | 141 | public void ReleaseStream() 142 | { 143 | // Stream.ReleaseStream(); 144 | Stream = null; 145 | } 146 | 147 | public void CloseStream() 148 | { 149 | Stream.Close(); 150 | } 151 | 152 | public void Normalize() 153 | { 154 | while (Range < kTopValue) 155 | { 156 | Code = (Code << 8) | (byte)Stream.ReadByte(); 157 | Range <<= 8; 158 | } 159 | } 160 | 161 | public void Normalize2() 162 | { 163 | if (Range < kTopValue) 164 | { 165 | Code = (Code << 8) | (byte)Stream.ReadByte(); 166 | Range <<= 8; 167 | } 168 | } 169 | 170 | public uint GetThreshold(uint total) 171 | { 172 | return Code / (Range /= total); 173 | } 174 | 175 | public void Decode(uint start, uint size, uint total) 176 | { 177 | Code -= start * Range; 178 | Range *= size; 179 | Normalize(); 180 | } 181 | 182 | public uint DecodeDirectBits(int numTotalBits) 183 | { 184 | uint range = Range; 185 | uint code = Code; 186 | uint result = 0; 187 | for (int i = numTotalBits; i > 0; i--) 188 | { 189 | range >>= 1; 190 | /* 191 | result <<= 1; 192 | if (code >= range) 193 | { 194 | code -= range; 195 | result |= 1; 196 | } 197 | */ 198 | uint t = (code - range) >> 31; 199 | code -= range & (t - 1); 200 | result = (result << 1) | (1 - t); 201 | 202 | if (range < kTopValue) 203 | { 204 | code = (code << 8) | (byte)Stream.ReadByte(); 205 | range <<= 8; 206 | } 207 | } 208 | Range = range; 209 | Code = code; 210 | return result; 211 | } 212 | 213 | public uint DecodeBit(uint size0, int numTotalBits) 214 | { 215 | uint newBound = (Range >> numTotalBits) * size0; 216 | uint symbol; 217 | if (Code < newBound) 218 | { 219 | symbol = 0; 220 | Range = newBound; 221 | } 222 | else 223 | { 224 | symbol = 1; 225 | Code -= newBound; 226 | Range -= newBound; 227 | } 228 | Normalize(); 229 | return symbol; 230 | } 231 | 232 | // ulong GetProcessedSize() {return Stream.GetProcessedSize(); } 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/RangeCoder/RangeCoder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 90993db9412f9634bb34fe2c88a77f9f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/RangeCoder/RangeCoderBit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SevenZip.Compression.RangeCoder 4 | { 5 | struct BitEncoder 6 | { 7 | public const int kNumBitModelTotalBits = 11; 8 | public const uint kBitModelTotal = (1 << kNumBitModelTotalBits); 9 | const int kNumMoveBits = 5; 10 | const int kNumMoveReducingBits = 2; 11 | public const int kNumBitPriceShiftBits = 6; 12 | 13 | uint Prob; 14 | 15 | public void Init() { Prob = kBitModelTotal >> 1; } 16 | 17 | public void UpdateModel(uint symbol) 18 | { 19 | if (symbol == 0) 20 | Prob += (kBitModelTotal - Prob) >> kNumMoveBits; 21 | else 22 | Prob -= (Prob) >> kNumMoveBits; 23 | } 24 | 25 | public void Encode(Encoder encoder, uint symbol) 26 | { 27 | // encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol); 28 | // UpdateModel(symbol); 29 | uint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob; 30 | if (symbol == 0) 31 | { 32 | encoder.Range = newBound; 33 | Prob += (kBitModelTotal - Prob) >> kNumMoveBits; 34 | } 35 | else 36 | { 37 | encoder.Low += newBound; 38 | encoder.Range -= newBound; 39 | Prob -= (Prob) >> kNumMoveBits; 40 | } 41 | if (encoder.Range < Encoder.kTopValue) 42 | { 43 | encoder.Range <<= 8; 44 | encoder.ShiftLow(); 45 | } 46 | } 47 | 48 | private static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits]; 49 | 50 | static BitEncoder() 51 | { 52 | const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits); 53 | for (int i = kNumBits - 1; i >= 0; i--) 54 | { 55 | UInt32 start = (UInt32)1 << (kNumBits - i - 1); 56 | UInt32 end = (UInt32)1 << (kNumBits - i); 57 | for (UInt32 j = start; j < end; j++) 58 | ProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) + 59 | (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1)); 60 | } 61 | } 62 | 63 | public uint GetPrice(uint symbol) 64 | { 65 | return ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits]; 66 | } 67 | public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; } 68 | public uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; } 69 | } 70 | 71 | struct BitDecoder 72 | { 73 | public const int kNumBitModelTotalBits = 11; 74 | public const uint kBitModelTotal = (1 << kNumBitModelTotalBits); 75 | const int kNumMoveBits = 5; 76 | 77 | uint Prob; 78 | 79 | public void UpdateModel(int numMoveBits, uint symbol) 80 | { 81 | if (symbol == 0) 82 | Prob += (kBitModelTotal - Prob) >> numMoveBits; 83 | else 84 | Prob -= (Prob) >> numMoveBits; 85 | } 86 | 87 | public void Init() { Prob = kBitModelTotal >> 1; } 88 | 89 | public uint Decode(RangeCoder.Decoder rangeDecoder) 90 | { 91 | uint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob; 92 | if (rangeDecoder.Code < newBound) 93 | { 94 | rangeDecoder.Range = newBound; 95 | Prob += (kBitModelTotal - Prob) >> kNumMoveBits; 96 | if (rangeDecoder.Range < Decoder.kTopValue) 97 | { 98 | rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte(); 99 | rangeDecoder.Range <<= 8; 100 | } 101 | return 0; 102 | } 103 | else 104 | { 105 | rangeDecoder.Range -= newBound; 106 | rangeDecoder.Code -= newBound; 107 | Prob -= (Prob) >> kNumMoveBits; 108 | if (rangeDecoder.Range < Decoder.kTopValue) 109 | { 110 | rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte(); 111 | rangeDecoder.Range <<= 8; 112 | } 113 | return 1; 114 | } 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/RangeCoder/RangeCoderBit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f5d4f5afe7186e4f8571cdfb3991cb0 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/RangeCoder/RangeCoderBitTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SevenZip.Compression.RangeCoder 4 | { 5 | struct BitTreeEncoder 6 | { 7 | BitEncoder[] Models; 8 | int NumBitLevels; 9 | 10 | public BitTreeEncoder(int numBitLevels) 11 | { 12 | NumBitLevels = numBitLevels; 13 | Models = new BitEncoder[1 << numBitLevels]; 14 | } 15 | 16 | public void Init() 17 | { 18 | for (uint i = 1; i < (1 << NumBitLevels); i++) 19 | Models[i].Init(); 20 | } 21 | 22 | public void Encode(Encoder rangeEncoder, UInt32 symbol) 23 | { 24 | UInt32 m = 1; 25 | for (int bitIndex = NumBitLevels; bitIndex > 0; ) 26 | { 27 | bitIndex--; 28 | UInt32 bit = (symbol >> bitIndex) & 1; 29 | Models[m].Encode(rangeEncoder, bit); 30 | m = (m << 1) | bit; 31 | } 32 | } 33 | 34 | public void ReverseEncode(Encoder rangeEncoder, UInt32 symbol) 35 | { 36 | UInt32 m = 1; 37 | for (UInt32 i = 0; i < NumBitLevels; i++) 38 | { 39 | UInt32 bit = symbol & 1; 40 | Models[m].Encode(rangeEncoder, bit); 41 | m = (m << 1) | bit; 42 | symbol >>= 1; 43 | } 44 | } 45 | 46 | public UInt32 GetPrice(UInt32 symbol) 47 | { 48 | UInt32 price = 0; 49 | UInt32 m = 1; 50 | for (int bitIndex = NumBitLevels; bitIndex > 0; ) 51 | { 52 | bitIndex--; 53 | UInt32 bit = (symbol >> bitIndex) & 1; 54 | price += Models[m].GetPrice(bit); 55 | m = (m << 1) + bit; 56 | } 57 | return price; 58 | } 59 | 60 | public UInt32 ReverseGetPrice(UInt32 symbol) 61 | { 62 | UInt32 price = 0; 63 | UInt32 m = 1; 64 | for (int i = NumBitLevels; i > 0; i--) 65 | { 66 | UInt32 bit = symbol & 1; 67 | symbol >>= 1; 68 | price += Models[m].GetPrice(bit); 69 | m = (m << 1) | bit; 70 | } 71 | return price; 72 | } 73 | 74 | public static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex, 75 | int NumBitLevels, UInt32 symbol) 76 | { 77 | UInt32 price = 0; 78 | UInt32 m = 1; 79 | for (int i = NumBitLevels; i > 0; i--) 80 | { 81 | UInt32 bit = symbol & 1; 82 | symbol >>= 1; 83 | price += Models[startIndex + m].GetPrice(bit); 84 | m = (m << 1) | bit; 85 | } 86 | return price; 87 | } 88 | 89 | public static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex, 90 | Encoder rangeEncoder, int NumBitLevels, UInt32 symbol) 91 | { 92 | UInt32 m = 1; 93 | for (int i = 0; i < NumBitLevels; i++) 94 | { 95 | UInt32 bit = symbol & 1; 96 | Models[startIndex + m].Encode(rangeEncoder, bit); 97 | m = (m << 1) | bit; 98 | symbol >>= 1; 99 | } 100 | } 101 | } 102 | 103 | struct BitTreeDecoder 104 | { 105 | BitDecoder[] Models; 106 | int NumBitLevels; 107 | 108 | public BitTreeDecoder(int numBitLevels) 109 | { 110 | NumBitLevels = numBitLevels; 111 | Models = new BitDecoder[1 << numBitLevels]; 112 | } 113 | 114 | public void Init() 115 | { 116 | for (uint i = 1; i < (1 << NumBitLevels); i++) 117 | Models[i].Init(); 118 | } 119 | 120 | public uint Decode(RangeCoder.Decoder rangeDecoder) 121 | { 122 | uint m = 1; 123 | for (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--) 124 | m = (m << 1) + Models[m].Decode(rangeDecoder); 125 | return m - ((uint)1 << NumBitLevels); 126 | } 127 | 128 | public uint ReverseDecode(RangeCoder.Decoder rangeDecoder) 129 | { 130 | uint m = 1; 131 | uint symbol = 0; 132 | for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) 133 | { 134 | uint bit = Models[m].Decode(rangeDecoder); 135 | m <<= 1; 136 | m += bit; 137 | symbol |= (bit << bitIndex); 138 | } 139 | return symbol; 140 | } 141 | 142 | public static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex, 143 | RangeCoder.Decoder rangeDecoder, int NumBitLevels) 144 | { 145 | uint m = 1; 146 | uint symbol = 0; 147 | for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) 148 | { 149 | uint bit = Models[startIndex + m].Decode(rangeDecoder); 150 | m <<= 1; 151 | m += bit; 152 | symbol |= (bit << bitIndex); 153 | } 154 | return symbol; 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/Compress/RangeCoder/RangeCoderBitTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26e66b347ed676340acaaf5aa4757ace 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/ICoder.cs: -------------------------------------------------------------------------------- 1 | // ICoder.h 2 | 3 | using System; 4 | 5 | namespace SevenZip 6 | { 7 | /// 8 | /// The exception that is thrown when an error in input stream occurs during decoding. 9 | /// 10 | class DataErrorException : ApplicationException 11 | { 12 | public DataErrorException(): base("Data Error") { } 13 | } 14 | 15 | /// 16 | /// The exception that is thrown when the value of an argument is outside the allowable range. 17 | /// 18 | class InvalidParamException : ApplicationException 19 | { 20 | public InvalidParamException(): base("Invalid Parameter") { } 21 | } 22 | 23 | public interface ICodeProgress 24 | { 25 | /// 26 | /// Callback progress. 27 | /// 28 | /// 29 | /// input size. -1 if unknown. 30 | /// 31 | /// 32 | /// output size. -1 if unknown. 33 | /// 34 | void SetProgress(Int64 inSize, Int64 outSize); 35 | 36 | void SetProgressPercent(Int64 fileSize,Int64 processSize); 37 | }; 38 | 39 | public interface ICoder 40 | { 41 | /// 42 | /// Codes streams. 43 | /// 44 | /// 45 | /// input Stream. 46 | /// 47 | /// 48 | /// output Stream. 49 | /// 50 | /// 51 | /// input Size. -1 if unknown. 52 | /// 53 | /// 54 | /// output Size. -1 if unknown. 55 | /// 56 | /// 57 | /// callback progress reference. 58 | /// 59 | /// 60 | /// if input stream is not valid 61 | /// 62 | void Code(System.IO.Stream inStream, System.IO.Stream outStream, 63 | Int64 inSize, Int64 outSize, ICodeProgress progress); 64 | }; 65 | 66 | /* 67 | public interface ICoder2 68 | { 69 | void Code(ISequentialInStream []inStreams, 70 | const UInt64 []inSizes, 71 | ISequentialOutStream []outStreams, 72 | UInt64 []outSizes, 73 | ICodeProgress progress); 74 | }; 75 | */ 76 | 77 | /// 78 | /// Provides the fields that represent properties idenitifiers for compressing. 79 | /// 80 | public enum CoderPropID 81 | { 82 | /// 83 | /// Specifies default property. 84 | /// 85 | DefaultProp = 0, 86 | /// 87 | /// Specifies size of dictionary. 88 | /// 89 | DictionarySize, 90 | /// 91 | /// Specifies size of memory for PPM*. 92 | /// 93 | UsedMemorySize, 94 | /// 95 | /// Specifies order for PPM methods. 96 | /// 97 | Order, 98 | /// 99 | /// Specifies Block Size. 100 | /// 101 | BlockSize, 102 | /// 103 | /// Specifies number of postion state bits for LZMA (0 <= x <= 4). 104 | /// 105 | PosStateBits, 106 | /// 107 | /// Specifies number of literal context bits for LZMA (0 <= x <= 8). 108 | /// 109 | LitContextBits, 110 | /// 111 | /// Specifies number of literal position bits for LZMA (0 <= x <= 4). 112 | /// 113 | LitPosBits, 114 | /// 115 | /// Specifies number of fast bytes for LZ*. 116 | /// 117 | NumFastBytes, 118 | /// 119 | /// Specifies match finder. LZMA: "BT2", "BT4" or "BT4B". 120 | /// 121 | MatchFinder, 122 | /// 123 | /// Specifies the number of match finder cyckes. 124 | /// 125 | MatchFinderCycles, 126 | /// 127 | /// Specifies number of passes. 128 | /// 129 | NumPasses, 130 | /// 131 | /// Specifies number of algorithm. 132 | /// 133 | Algorithm, 134 | /// 135 | /// Specifies the number of threads. 136 | /// 137 | NumThreads, 138 | /// 139 | /// Specifies mode with end marker. 140 | /// 141 | EndMarker 142 | }; 143 | 144 | 145 | public interface ISetCoderProperties 146 | { 147 | void SetCoderProperties(CoderPropID[] propIDs, object[] properties); 148 | }; 149 | 150 | public interface IWriteCoderProperties 151 | { 152 | void WriteCoderProperties(System.IO.Stream outStream); 153 | } 154 | 155 | public interface ISetDecoderProperties 156 | { 157 | void SetDecoderProperties(byte[] properties); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /Compress.LZMA/7zip/ICoder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 943a137e616376b4c9762d766eed46e2 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Compress.LZMA/Compress.Info.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/Compress.Info.dll -------------------------------------------------------------------------------- /Compress.LZMA/Compress.LZMA.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {8984A52F-6477-4124-AC74-C524FB3B7442} 8 | Library 9 | Properties 10 | Compress.LZMA 11 | Compress.LZMA 12 | v3.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | false 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | false 34 | 35 | 36 | 37 | .\Compress.Info.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | .\UnityEngine.dll 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 115 | -------------------------------------------------------------------------------- /Compress.LZMA/LZMAFile.cs: -------------------------------------------------------------------------------- 1 | using SevenZip; 2 | using System; 3 | using System.IO; 4 | using System.Threading; 5 | using UnityEngine; 6 | using YZL.Compress.Info; 7 | 8 | namespace YZL.Compress.LZMA 9 | { 10 | public class LZMAFile 11 | { 12 | /** 进度 **/ 13 | public class CodeProgress : ICodeProgress 14 | { 15 | public ProgressDelegate m_ProgressDelegate = null; 16 | 17 | public CodeProgress(ProgressDelegate del) 18 | { 19 | m_ProgressDelegate = del; 20 | } 21 | 22 | public void SetProgress(Int64 inSize, Int64 outSize) 23 | { 24 | } 25 | 26 | public void SetProgressPercent(Int64 fileSize, Int64 processSize) 27 | { 28 | m_ProgressDelegate(fileSize, processSize); 29 | } 30 | } 31 | 32 | /** 异步压缩一个文件 **/ 33 | public static void CompressAsync(string inpath, string outpath, ProgressDelegate progress) 34 | { 35 | Thread compressThread = new Thread(new ParameterizedThreadStart(Compress)); 36 | FileChangeInfo info = new FileChangeInfo(); 37 | info.inpath = inpath; 38 | info.outpath = outpath; 39 | info.progressDelegate = progress; 40 | compressThread.Start(info); 41 | } 42 | 43 | /** 异步解压一个文件 **/ 44 | public static void DeCompressAsync(string inpath, string outpath, ProgressDelegate progress) 45 | { 46 | Thread decompressThread = new Thread(new ParameterizedThreadStart(DeCompress)); 47 | FileChangeInfo info = new FileChangeInfo(); 48 | info.inpath = inpath; 49 | info.outpath = outpath; 50 | info.progressDelegate = progress; 51 | decompressThread.Start(info); 52 | } 53 | 54 | 55 | /** 同步压缩一个文件 **/ 56 | private static void Compress(object obj) 57 | { 58 | FileChangeInfo info = (FileChangeInfo)obj; 59 | string inpath = info.inpath; 60 | string outpath = info.outpath; 61 | CodeProgress codeProgress = null; 62 | if(info.progressDelegate != null) 63 | codeProgress = new CodeProgress(info.progressDelegate); 64 | 65 | try 66 | { 67 | SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder(); 68 | FileStream inputFS = new FileStream(inpath, FileMode.Open); 69 | FileStream outputFS = new FileStream(outpath, FileMode.Create); 70 | 71 | encoder.WriteCoderProperties(outputFS); 72 | 73 | outputFS.Write(System.BitConverter.GetBytes(inputFS.Length), 0, 8); 74 | 75 | encoder.Code(inputFS, outputFS, inputFS.Length, -1, codeProgress); 76 | outputFS.Flush(); 77 | outputFS.Close(); 78 | inputFS.Close(); 79 | Debug.Log("压缩完毕"); 80 | } 81 | catch (Exception ex) 82 | { 83 | Debug.Log(ex); 84 | } 85 | } 86 | public static void Compress(string inpath, string outpath, ProgressDelegate progress) 87 | { 88 | FileChangeInfo info = new FileChangeInfo(); 89 | info.inpath = inpath; 90 | info.outpath = outpath; 91 | info.progressDelegate = progress; 92 | Compress(info); 93 | } 94 | 95 | /** 同步解压一个文件 **/ 96 | private static void DeCompress(object obj) 97 | { 98 | FileChangeInfo info = (FileChangeInfo)obj; 99 | string inpath = info.inpath; 100 | string outpath = info.outpath; 101 | CodeProgress codeProgress = null; 102 | if (info.progressDelegate != null) 103 | codeProgress = new CodeProgress(info.progressDelegate); 104 | 105 | try 106 | { 107 | SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder(); 108 | FileStream inputFS = new FileStream(inpath, FileMode.Open); 109 | FileStream outputFS = new FileStream(outpath, FileMode.Create); 110 | 111 | int propertiesSize = SevenZip.Compression.LZMA.Encoder.kPropSize; 112 | byte[] properties = new byte[propertiesSize]; 113 | inputFS.Read(properties, 0, properties.Length); 114 | 115 | byte[] fileLengthBytes = new byte[8]; 116 | inputFS.Read(fileLengthBytes, 0, 8); 117 | long fileLength = System.BitConverter.ToInt64(fileLengthBytes, 0); 118 | 119 | decoder.SetDecoderProperties(properties); 120 | decoder.Code(inputFS, outputFS, inputFS.Length, fileLength, codeProgress); 121 | outputFS.Flush(); 122 | outputFS.Close(); 123 | inputFS.Close(); 124 | Debug.Log("解压完毕"); 125 | } 126 | catch (Exception ex) 127 | { 128 | Debug.Log(ex); 129 | } 130 | } 131 | public static void DeCompress(string inpath, string outpath, ProgressDelegate progress) 132 | { 133 | FileChangeInfo info = new FileChangeInfo(); 134 | info.inpath = inpath; 135 | info.outpath = outpath; 136 | info.progressDelegate = progress; 137 | DeCompress(info); 138 | } 139 | } 140 | 141 | } 142 | 143 | -------------------------------------------------------------------------------- /Compress.LZMA/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Compress.LZMA")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Compress.LZMA")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("e34f4375-df10-485d-96d6-04ae1b32d7a0")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Compress.LZMA/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/README.md -------------------------------------------------------------------------------- /Compress.LZMA/UnityEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/UnityEngine.dll -------------------------------------------------------------------------------- /Compress.LZMA/bin/Debug/Compress.Info.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/bin/Debug/Compress.Info.dll -------------------------------------------------------------------------------- /Compress.LZMA/bin/Debug/Compress.LZMA.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/bin/Debug/Compress.LZMA.dll -------------------------------------------------------------------------------- /Compress.LZMA/bin/Debug/Compress.LZMA.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/bin/Debug/Compress.LZMA.pdb -------------------------------------------------------------------------------- /Compress.LZMA/bin/Debug/UnityEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/bin/Debug/UnityEngine.dll -------------------------------------------------------------------------------- /Compress.LZMA/obj/Debug/Compress.LZMA.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | d2db5f6bbfacfb3e059c623dd99a51419d1ec8d7 2 | -------------------------------------------------------------------------------- /Compress.LZMA/obj/Debug/Compress.LZMA.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.LZMA\Compress.LZMA\bin\Debug\Compress.LZMA.dll 2 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.LZMA\Compress.LZMA\bin\Debug\Compress.LZMA.pdb 3 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.LZMA\Compress.LZMA\bin\Debug\Compress.Info.dll 4 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.LZMA\Compress.LZMA\bin\Debug\UnityEngine.dll 5 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.LZMA\Compress.LZMA\obj\Debug\Compress.LZMA.dll 6 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.LZMA\Compress.LZMA\obj\Debug\Compress.LZMA.pdb 7 | C:\Users\Yzlah\documents\visual studio 2013\Projects\Compress.LZMA\Compress.LZMA\obj\Debug\Compress.LZMA.csprojResolveAssemblyReference.cache 8 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.LZMA\bin\Debug\Compress.LZMA.dll 9 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.LZMA\bin\Debug\Compress.LZMA.pdb 10 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.LZMA\bin\Debug\Compress.Info.dll 11 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.LZMA\bin\Debug\UnityEngine.dll 12 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.LZMA\obj\Debug\Compress.LZMA.csprojResolveAssemblyReference.cache 13 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.LZMA\obj\Debug\Compress.LZMA.dll 14 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.LZMA\obj\Debug\Compress.LZMA.pdb 15 | -------------------------------------------------------------------------------- /Compress.LZMA/obj/Debug/Compress.LZMA.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/obj/Debug/Compress.LZMA.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Compress.LZMA/obj/Debug/Compress.LZMA.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/obj/Debug/Compress.LZMA.dll -------------------------------------------------------------------------------- /Compress.LZMA/obj/Debug/Compress.LZMA.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/obj/Debug/Compress.LZMA.pdb -------------------------------------------------------------------------------- /Compress.LZMA/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /Compress.LZMA/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs -------------------------------------------------------------------------------- /Compress.LZMA/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs -------------------------------------------------------------------------------- /Compress.LZMA/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.LZMA/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs -------------------------------------------------------------------------------- /Compress.UPK/Compress.Info.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/Compress.Info.dll -------------------------------------------------------------------------------- /Compress.UPK/Compress.UPK.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {725752EC-70A0-41D7-83B3-13FF0D698096} 8 | Library 9 | Properties 10 | Compress.UPK 11 | Compress.UPK 12 | v3.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | .\Compress.Info.dll 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | .\UnityEngine.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 60 | -------------------------------------------------------------------------------- /Compress.UPK/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Compress.UPK")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Compress.UPK")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("f0551d92-ed2d-4c9e-ac9c-1c96fd6998e7")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Compress.UPK/UnityEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/UnityEngine.dll -------------------------------------------------------------------------------- /Compress.UPK/bin/Debug/Compress.Info.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/bin/Debug/Compress.Info.dll -------------------------------------------------------------------------------- /Compress.UPK/bin/Debug/Compress.UPK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/bin/Debug/Compress.UPK.dll -------------------------------------------------------------------------------- /Compress.UPK/bin/Debug/Compress.UPK.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/bin/Debug/Compress.UPK.pdb -------------------------------------------------------------------------------- /Compress.UPK/bin/Debug/UnityEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/bin/Debug/UnityEngine.dll -------------------------------------------------------------------------------- /Compress.UPK/obj/Debug/Compress.UPK.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | 3b32460ee9f8c0eea0bb6c557238d648a92283d3 2 | -------------------------------------------------------------------------------- /Compress.UPK/obj/Debug/Compress.UPK.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.UPK\Compress.UPK\bin\Debug\Compress.UPK.dll 2 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.UPK\Compress.UPK\bin\Debug\Compress.UPK.pdb 3 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.UPK\Compress.UPK\bin\Debug\Compress.Info.dll 4 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.UPK\Compress.UPK\bin\Debug\UnityEngine.dll 5 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.UPK\Compress.UPK\obj\Debug\Compress.UPK.csprojResolveAssemblyReference.cache 6 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.UPK\Compress.UPK\obj\Debug\Compress.UPK.dll 7 | c:\users\yzlah\documents\visual studio 2013\Projects\Compress.UPK\Compress.UPK\obj\Debug\Compress.UPK.pdb 8 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.UPK\bin\Debug\Compress.UPK.dll 9 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.UPK\bin\Debug\Compress.UPK.pdb 10 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.UPK\bin\Debug\Compress.Info.dll 11 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.UPK\bin\Debug\UnityEngine.dll 12 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.UPK\obj\Debug\Compress.UPK.csprojResolveAssemblyReference.cache 13 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.UPK\obj\Debug\Compress.UPK.dll 14 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\Compress.UPK\obj\Debug\Compress.UPK.pdb 15 | -------------------------------------------------------------------------------- /Compress.UPK/obj/Debug/Compress.UPK.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/obj/Debug/Compress.UPK.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Compress.UPK/obj/Debug/Compress.UPK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/obj/Debug/Compress.UPK.dll -------------------------------------------------------------------------------- /Compress.UPK/obj/Debug/Compress.UPK.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/obj/Debug/Compress.UPK.pdb -------------------------------------------------------------------------------- /Compress.UPK/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /Compress.UPK/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs -------------------------------------------------------------------------------- /Compress.UPK/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs -------------------------------------------------------------------------------- /Compress.UPK/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.UPK/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs -------------------------------------------------------------------------------- /Compress.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compress.Info", "Compress.Info\Compress.Info.csproj", "{5A0381AB-E0BC-443E-91D1-4F026A1051FB}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compress.LZMA", "Compress.LZMA\Compress.LZMA.csproj", "{8984A52F-6477-4124-AC74-C524FB3B7442}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compress.UPK", "Compress.UPK\Compress.UPK.csproj", "{725752EC-70A0-41D7-83B3-13FF0D698096}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpZipLib", "ICSharpCode.SharpZipLib\ICSharpCode.SharpZipLib.csproj", "{0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {5A0381AB-E0BC-443E-91D1-4F026A1051FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {5A0381AB-E0BC-443E-91D1-4F026A1051FB}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {5A0381AB-E0BC-443E-91D1-4F026A1051FB}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {5A0381AB-E0BC-443E-91D1-4F026A1051FB}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {8984A52F-6477-4124-AC74-C524FB3B7442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {8984A52F-6477-4124-AC74-C524FB3B7442}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {8984A52F-6477-4124-AC74-C524FB3B7442}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {8984A52F-6477-4124-AC74-C524FB3B7442}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {725752EC-70A0-41D7-83B3-13FF0D698096}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {725752EC-70A0-41D7-83B3-13FF0D698096}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {725752EC-70A0-41D7-83B3-13FF0D698096}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {725752EC-70A0-41D7-83B3-13FF0D698096}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /Compress.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/Compress.v12.suo -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyTitle("SharpZipLib")] 5 | [assembly: AssemblyDescription("A free C# compression library")] 6 | [assembly: AssemblyDefaultAlias("ICSharpCode.SharpZipLib")] 7 | [assembly: AssemblyCulture("")] 8 | 9 | [assembly: CLSCompliant(true)] 10 | 11 | // If SharpZipLib is strongly named it still allows partially trusted callers 12 | [assembly: System.Security.AllowPartiallyTrustedCallers] 13 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/BZip2/BZip2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace ICSharpCode.SharpZipLib.BZip2 5 | { 6 | /// 7 | /// An example class to demonstrate compression and decompression of BZip2 streams. 8 | /// 9 | public static class BZip2 10 | { 11 | /// 12 | /// Decompress the input writing 13 | /// uncompressed data to the output stream 14 | /// 15 | /// The readable stream containing data to decompress. 16 | /// The output stream to receive the decompressed data. 17 | /// Both streams are closed on completion if true. 18 | public static void Decompress(Stream inStream, Stream outStream, bool isStreamOwner) 19 | { 20 | if (inStream == null || outStream == null) { 21 | throw new Exception("Null Stream"); 22 | } 23 | 24 | try { 25 | using (BZip2InputStream bzipInput = new BZip2InputStream(inStream)) { 26 | bzipInput.IsStreamOwner = isStreamOwner; 27 | Core.StreamUtils.Copy(bzipInput, outStream, new byte[4096]); 28 | } 29 | } finally { 30 | if (isStreamOwner) { 31 | // inStream is closed by the BZip2InputStream if stream owner 32 | outStream.Close(); 33 | } 34 | } 35 | } 36 | 37 | /// 38 | /// Compress the input stream sending 39 | /// result data to output stream 40 | /// 41 | /// The readable stream to compress. 42 | /// The output stream to receive the compressed data. 43 | /// Both streams are closed on completion if true. 44 | /// Block size acts as compression level (1 to 9) with 1 giving 45 | /// the lowest compression and 9 the highest. 46 | public static void Compress(Stream inStream, Stream outStream, bool isStreamOwner, int level) 47 | { 48 | if (inStream == null || outStream == null) { 49 | throw new Exception("Null Stream"); 50 | } 51 | 52 | try { 53 | using (BZip2OutputStream bzipOutput = new BZip2OutputStream(outStream, level)) { 54 | bzipOutput.IsStreamOwner = isStreamOwner; 55 | Core.StreamUtils.Copy(inStream, bzipOutput, new byte[4096]); 56 | } 57 | } finally { 58 | if (isStreamOwner) { 59 | // outStream is closed by the BZip2OutputStream if stream owner 60 | inStream.Close(); 61 | } 62 | } 63 | } 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/BZip2/BZip2Constants.cs: -------------------------------------------------------------------------------- 1 | namespace ICSharpCode.SharpZipLib.BZip2 2 | { 3 | /// 4 | /// Defines internal values for both compression and decompression 5 | /// 6 | internal sealed class BZip2Constants 7 | { 8 | /// 9 | /// Random numbers used to randomise repetitive blocks 10 | /// 11 | public readonly static int[] RandomNumbers = { 12 | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 13 | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 14 | 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 15 | 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 16 | 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 17 | 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 18 | 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 19 | 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 20 | 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 21 | 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 22 | 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 23 | 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 24 | 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 25 | 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 26 | 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 27 | 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 28 | 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 29 | 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 30 | 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 31 | 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 32 | 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 33 | 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 34 | 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 35 | 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 36 | 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 37 | 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 38 | 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 39 | 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 40 | 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 41 | 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 42 | 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 43 | 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 44 | 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 45 | 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 46 | 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 47 | 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 48 | 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 49 | 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 50 | 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 51 | 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 52 | 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 53 | 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 54 | 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 55 | 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 56 | 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 57 | 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 58 | 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 59 | 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 60 | 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 61 | 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 62 | 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 63 | 936, 638 64 | }; 65 | 66 | /// 67 | /// When multiplied by compression parameter (1-9) gives the block size for compression 68 | /// 9 gives the best compression but uses the most memory. 69 | /// 70 | public const int BaseBlockSize = 100000; 71 | 72 | /// 73 | /// Backend constant 74 | /// 75 | public const int MaximumAlphaSize = 258; 76 | 77 | /// 78 | /// Backend constant 79 | /// 80 | public const int MaximumCodeLength = 23; 81 | 82 | /// 83 | /// Backend constant 84 | /// 85 | public const int RunA = 0; 86 | 87 | /// 88 | /// Backend constant 89 | /// 90 | public const int RunB = 1; 91 | 92 | /// 93 | /// Backend constant 94 | /// 95 | public const int GroupCount = 6; 96 | 97 | /// 98 | /// Backend constant 99 | /// 100 | public const int GroupSize = 50; 101 | 102 | /// 103 | /// Backend constant 104 | /// 105 | public const int NumberOfIterations = 4; 106 | 107 | /// 108 | /// Backend constant 109 | /// 110 | public const int MaximumSelectors = (2 + (900000 / GroupSize)); 111 | 112 | /// 113 | /// Backend constant 114 | /// 115 | public const int OvershootBytes = 20; 116 | 117 | private BZip2Constants() 118 | { 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/BZip2/BZip2Exception.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace ICSharpCode.SharpZipLib.BZip2 5 | { 6 | /// 7 | /// BZip2Exception represents exceptions specific to BZip2 classes and code. 8 | /// 9 | [Serializable] 10 | public class BZip2Exception : SharpZipBaseException 11 | { 12 | /// 13 | /// Deserialization constructor 14 | /// 15 | /// for this constructor 16 | /// for this constructor 17 | protected BZip2Exception(SerializationInfo info, StreamingContext context) 18 | : base(info, context) 19 | { 20 | } 21 | 22 | /// 23 | /// Initialise a new instance of . 24 | /// 25 | public BZip2Exception() 26 | { 27 | } 28 | 29 | /// 30 | /// Initialise a new instance of with its message string. 31 | /// 32 | /// A that describes the error. 33 | public BZip2Exception(string message) 34 | : base(message) 35 | { 36 | } 37 | 38 | /// 39 | /// Initialise a new instance of . 40 | /// 41 | /// A that describes the error. 42 | /// The that caused this exception. 43 | public BZip2Exception(string message, Exception innerException) 44 | : base(message, innerException) 45 | { 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Checksum/Adler32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ICSharpCode.SharpZipLib.Checksum 4 | { 5 | /// 6 | /// Computes Adler32 checksum for a stream of data. An Adler32 7 | /// checksum is not as reliable as a CRC32 checksum, but a lot faster to 8 | /// compute. 9 | /// 10 | /// The specification for Adler32 may be found in RFC 1950. 11 | /// ZLIB Compressed Data Format Specification version 3.3) 12 | /// 13 | /// 14 | /// From that document: 15 | /// 16 | /// "ADLER32 (Adler-32 checksum) 17 | /// This contains a checksum value of the uncompressed data 18 | /// (excluding any dictionary data) computed according to Adler-32 19 | /// algorithm. This algorithm is a 32-bit extension and improvement 20 | /// of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 21 | /// standard. 22 | /// 23 | /// Adler-32 is composed of two sums accumulated per byte: s1 is 24 | /// the sum of all bytes, s2 is the sum of all s1 values. Both sums 25 | /// are done modulo 65521. s1 is initialized to 1, s2 to zero. The 26 | /// Adler-32 checksum is stored as s2*65536 + s1 in most- 27 | /// significant-byte first (network) order." 28 | /// 29 | /// "8.2. The Adler-32 algorithm 30 | /// 31 | /// The Adler-32 algorithm is much faster than the CRC32 algorithm yet 32 | /// still provides an extremely low probability of undetected errors. 33 | /// 34 | /// The modulo on unsigned long accumulators can be delayed for 5552 35 | /// bytes, so the modulo operation time is negligible. If the bytes 36 | /// are a, b, c, the second sum is 3a + 2b + c + 3, and so is position 37 | /// and order sensitive, unlike the first sum, which is just a 38 | /// checksum. That 65521 is prime is important to avoid a possible 39 | /// large class of two-byte errors that leave the check unchanged. 40 | /// (The Fletcher checksum uses 255, which is not prime and which also 41 | /// makes the Fletcher check insensitive to single byte changes 0 - 42 | /// 255.) 43 | /// 44 | /// The sum s1 is initialized to 1 instead of zero to make the length 45 | /// of the sequence part of s2, so that the length does not have to be 46 | /// checked separately. (Any sequence of zeroes has a Fletcher 47 | /// checksum of zero.)" 48 | /// 49 | /// 50 | /// 51 | public sealed class Adler32 : IChecksum 52 | { 53 | #region Instance Fields 54 | /// 55 | /// largest prime smaller than 65536 56 | /// 57 | readonly static uint BASE = 65521; 58 | 59 | /// 60 | /// The CRC data checksum so far. 61 | /// 62 | uint checkValue; 63 | #endregion 64 | 65 | /// 66 | /// Initialise a default instance of 67 | /// 68 | public Adler32() 69 | { 70 | Reset(); 71 | } 72 | 73 | /// 74 | /// Resets the Adler32 data checksum as if no update was ever called. 75 | /// 76 | public void Reset() 77 | { 78 | checkValue = 1; 79 | } 80 | 81 | /// 82 | /// Returns the Adler32 data checksum computed so far. 83 | /// 84 | public long Value { 85 | get { 86 | return checkValue; 87 | } 88 | } 89 | 90 | /// 91 | /// Updates the checksum with the byte b. 92 | /// 93 | /// 94 | /// The data value to add. The high byte of the int is ignored. 95 | /// 96 | public void Update(int bval) 97 | { 98 | // We could make a length 1 byte array and call update again, but I 99 | // would rather not have that overhead 100 | uint s1 = checkValue & 0xFFFF; 101 | uint s2 = checkValue >> 16; 102 | 103 | s1 = (s1 + ((uint)bval & 0xFF)) % BASE; 104 | s2 = (s1 + s2) % BASE; 105 | 106 | checkValue = (s2 << 16) + s1; 107 | } 108 | 109 | /// 110 | /// Updates the Adler32 data checksum with the bytes taken from 111 | /// a block of data. 112 | /// 113 | /// Contains the data to update the checksum with. 114 | public void Update(byte[] buffer) 115 | { 116 | if (buffer == null) { 117 | throw new ArgumentNullException(nameof(buffer)); 118 | } 119 | 120 | Update(buffer, 0, buffer.Length); 121 | } 122 | 123 | /// 124 | /// Update Adler32 data checksum based on a portion of a block of data 125 | /// 126 | /// Contains the data to update the CRC with. 127 | /// The offset into the buffer where the data starts 128 | /// The number of data bytes to update the CRC with. 129 | public void Update(byte[] buffer, int offset, int count) 130 | { 131 | if (buffer == null) { 132 | throw new ArgumentNullException(nameof(buffer)); 133 | } 134 | 135 | if (offset < 0) { 136 | throw new ArgumentOutOfRangeException(nameof(offset), "cannot be less than zero"); 137 | } 138 | 139 | if (offset >= buffer.Length) { 140 | throw new ArgumentOutOfRangeException(nameof(offset), "not a valid index into buffer"); 141 | } 142 | 143 | if (count < 0) { 144 | throw new ArgumentOutOfRangeException(nameof(count), "cannot be less than zero"); 145 | } 146 | 147 | if (offset + count > buffer.Length) { 148 | throw new ArgumentOutOfRangeException(nameof(count), "exceeds buffer size"); 149 | } 150 | 151 | //(By Per Bothner) 152 | uint s1 = checkValue & 0xFFFF; 153 | uint s2 = checkValue >> 16; 154 | 155 | while (count > 0) { 156 | // We can defer the modulo operation: 157 | // s1 maximally grows from 65521 to 65521 + 255 * 3800 158 | // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31 159 | int n = 3800; 160 | if (n > count) { 161 | n = count; 162 | } 163 | count -= n; 164 | while (--n >= 0) { 165 | s1 = s1 + (uint)(buffer[offset++] & 0xff); 166 | s2 = s2 + s1; 167 | } 168 | s1 %= BASE; 169 | s2 %= BASE; 170 | } 171 | 172 | checkValue = (s2 << 16) | s1; 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Checksum/IChecksum.cs: -------------------------------------------------------------------------------- 1 | namespace ICSharpCode.SharpZipLib.Checksum 2 | { 3 | /// 4 | /// Interface to compute a data checksum used by checked input/output streams. 5 | /// A data checksum can be updated by one byte or with a byte array. After each 6 | /// update the value of the current checksum can be returned by calling 7 | /// getValue. The complete checksum object can also be reset 8 | /// so it can be used again with new data. 9 | /// 10 | public interface IChecksum 11 | { 12 | /// 13 | /// Resets the data checksum as if no update was ever called. 14 | /// 15 | void Reset(); 16 | 17 | /// 18 | /// Returns the data checksum computed so far. 19 | /// 20 | long Value { 21 | get; 22 | } 23 | 24 | /// 25 | /// Adds one byte to the data checksum. 26 | /// 27 | /// 28 | /// the data value to add. The high byte of the int is ignored. 29 | /// 30 | void Update(int bval); 31 | 32 | /// 33 | /// Updates the data checksum with the bytes taken from the array. 34 | /// 35 | /// 36 | /// buffer an array of bytes 37 | /// 38 | void Update(byte[] buffer); 39 | 40 | /// 41 | /// Adds the byte array to the data checksum. 42 | /// 43 | /// 44 | /// The buffer which contains the data 45 | /// 46 | /// 47 | /// The offset in the buffer where the data starts 48 | /// 49 | /// 50 | /// the number of data bytes to add. 51 | /// 52 | void Update(byte[] buffer, int offset, int count); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Compress.Info.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/Compress.Info.dll -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Core/INameTransform.cs: -------------------------------------------------------------------------------- 1 | namespace ICSharpCode.SharpZipLib.Core 2 | { 3 | /// 4 | /// INameTransform defines how file system names are transformed for use with archives, or vice versa. 5 | /// 6 | public interface INameTransform 7 | { 8 | /// 9 | /// Given a file name determine the transformed value. 10 | /// 11 | /// The name to transform. 12 | /// The transformed file name. 13 | string TransformFile(string name); 14 | 15 | /// 16 | /// Given a directory name determine the transformed value. 17 | /// 18 | /// The name to transform. 19 | /// The transformed directory name 20 | string TransformDirectory(string name); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Core/IScanFilter.cs: -------------------------------------------------------------------------------- 1 | namespace ICSharpCode.SharpZipLib.Core 2 | { 3 | /// 4 | /// Scanning filters support filtering of names. 5 | /// 6 | public interface IScanFilter 7 | { 8 | /// 9 | /// Test a name to see if it 'matches' the filter. 10 | /// 11 | /// The name to test. 12 | /// Returns true if the name matches the filter, false if it does not match. 13 | bool IsMatch(string name); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Core/WindowsPathUtils.cs: -------------------------------------------------------------------------------- 1 | namespace ICSharpCode.SharpZipLib.Core 2 | { 3 | /// 4 | /// WindowsPathUtils provides simple utilities for handling windows paths. 5 | /// 6 | public abstract class WindowsPathUtils 7 | { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | internal WindowsPathUtils() 12 | { 13 | } 14 | 15 | /// 16 | /// Remove any path root present in the path 17 | /// 18 | /// A containing path information. 19 | /// The path with the root removed if it was present; path otherwise. 20 | /// Unlike the class the path isnt otherwise checked for validity. 21 | public static string DropPathRoot(string path) 22 | { 23 | string result = path; 24 | 25 | if (!string.IsNullOrEmpty(path)) { 26 | if ((path[0] == '\\') || (path[0] == '/')) { 27 | // UNC name ? 28 | if ((path.Length > 1) && ((path[1] == '\\') || (path[1] == '/'))) { 29 | int index = 2; 30 | int elements = 2; 31 | 32 | // Scan for two separate elements \\machine\share\restofpath 33 | while ((index <= path.Length) && 34 | (((path[index] != '\\') && (path[index] != '/')) || (--elements > 0))) { 35 | index++; 36 | } 37 | 38 | index++; 39 | 40 | if (index < path.Length) { 41 | result = path.Substring(index); 42 | } else { 43 | result = ""; 44 | } 45 | } 46 | } else if ((path.Length > 1) && (path[1] == ':')) { 47 | int dropCount = 2; 48 | if ((path.Length > 2) && ((path[2] == '\\') || (path[2] == '/'))) { 49 | dropCount = 3; 50 | } 51 | result = result.Remove(0, dropCount); 52 | } 53 | } 54 | return result; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Security.Cryptography; 4 | 5 | namespace ICSharpCode.SharpZipLib.Encryption 6 | { 7 | /// 8 | /// Encrypts and decrypts AES ZIP 9 | /// 10 | /// 11 | /// Based on information from http://www.winzip.com/aes_info.htm 12 | /// and http://www.gladman.me.uk/cryptography_technology/fileencrypt/ 13 | /// 14 | internal class ZipAESStream : CryptoStream 15 | { 16 | 17 | /// 18 | /// Constructor 19 | /// 20 | /// The stream on which to perform the cryptographic transformation. 21 | /// Instance of ZipAESTransform 22 | /// Read or Write 23 | public ZipAESStream(Stream stream, ZipAESTransform transform, CryptoStreamMode mode) 24 | : base(stream, transform, mode) 25 | { 26 | 27 | _stream = stream; 28 | _transform = transform; 29 | _slideBuffer = new byte[1024]; 30 | 31 | _blockAndAuth = CRYPTO_BLOCK_SIZE + AUTH_CODE_LENGTH; 32 | 33 | // mode: 34 | // CryptoStreamMode.Read means we read from "stream" and pass decrypted to our Read() method. 35 | // Write bypasses this stream and uses the Transform directly. 36 | if (mode != CryptoStreamMode.Read) { 37 | throw new Exception("ZipAESStream only for read"); 38 | } 39 | } 40 | 41 | // The final n bytes of the AES stream contain the Auth Code. 42 | private const int AUTH_CODE_LENGTH = 10; 43 | 44 | private Stream _stream; 45 | private ZipAESTransform _transform; 46 | private byte[] _slideBuffer; 47 | private int _slideBufStartPos; 48 | private int _slideBufFreePos; 49 | // Blocksize is always 16 here, even for AES-256 which has transform.InputBlockSize of 32. 50 | private const int CRYPTO_BLOCK_SIZE = 16; 51 | private int _blockAndAuth; 52 | 53 | /// 54 | /// Reads a sequence of bytes from the current CryptoStream into buffer, 55 | /// and advances the position within the stream by the number of bytes read. 56 | /// 57 | public override int Read(byte[] buffer, int offset, int count) 58 | { 59 | int nBytes = 0; 60 | while (nBytes < count) { 61 | // Calculate buffer quantities vs read-ahead size, and check for sufficient free space 62 | int byteCount = _slideBufFreePos - _slideBufStartPos; 63 | 64 | // Need to handle final block and Auth Code specially, but don't know total data length. 65 | // Maintain a read-ahead equal to the length of (crypto block + Auth Code). 66 | // When that runs out we can detect these final sections. 67 | int lengthToRead = _blockAndAuth - byteCount; 68 | if (_slideBuffer.Length - _slideBufFreePos < lengthToRead) { 69 | // Shift the data to the beginning of the buffer 70 | int iTo = 0; 71 | for (int iFrom = _slideBufStartPos; iFrom < _slideBufFreePos; iFrom++, iTo++) { 72 | _slideBuffer[iTo] = _slideBuffer[iFrom]; 73 | } 74 | _slideBufFreePos -= _slideBufStartPos; // Note the -= 75 | _slideBufStartPos = 0; 76 | } 77 | int obtained = _stream.Read(_slideBuffer, _slideBufFreePos, lengthToRead); 78 | _slideBufFreePos += obtained; 79 | 80 | // Recalculate how much data we now have 81 | byteCount = _slideBufFreePos - _slideBufStartPos; 82 | if (byteCount >= _blockAndAuth) { 83 | // At least a 16 byte block and an auth code remains. 84 | _transform.TransformBlock(_slideBuffer, 85 | _slideBufStartPos, 86 | CRYPTO_BLOCK_SIZE, 87 | buffer, 88 | offset); 89 | nBytes += CRYPTO_BLOCK_SIZE; 90 | offset += CRYPTO_BLOCK_SIZE; 91 | _slideBufStartPos += CRYPTO_BLOCK_SIZE; 92 | } else { 93 | // Last round. 94 | if (byteCount > AUTH_CODE_LENGTH) { 95 | // At least one byte of data plus auth code 96 | int finalBlock = byteCount - AUTH_CODE_LENGTH; 97 | _transform.TransformBlock(_slideBuffer, 98 | _slideBufStartPos, 99 | finalBlock, 100 | buffer, 101 | offset); 102 | 103 | nBytes += finalBlock; 104 | _slideBufStartPos += finalBlock; 105 | } else if (byteCount < AUTH_CODE_LENGTH) 106 | throw new Exception("Internal error missed auth code"); // Coding bug 107 | // Final block done. Check Auth code. 108 | byte[] calcAuthCode = _transform.GetAuthCode(); 109 | for (int i = 0; i < AUTH_CODE_LENGTH; i++) { 110 | if (calcAuthCode[i] != _slideBuffer[_slideBufStartPos + i]) { 111 | throw new Exception("AES Authentication Code does not match. This is a super-CRC check on the data in the file after compression and encryption. \r\n" 112 | + "The file may be damaged."); 113 | } 114 | } 115 | 116 | break; // Reached the auth code 117 | } 118 | } 119 | return nBytes; 120 | } 121 | 122 | /// 123 | /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. 124 | /// 125 | /// An array of bytes. This method copies count bytes from buffer to the current stream. 126 | /// The byte offset in buffer at which to begin copying bytes to the current stream. 127 | /// The number of bytes to be written to the current stream. 128 | public override void Write(byte[] buffer, int offset, int count) 129 | { 130 | // ZipAESStream is used for reading but not for writing. Writing uses the ZipAESTransform directly. 131 | throw new NotImplementedException(); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.Cryptography; 3 | 4 | namespace ICSharpCode.SharpZipLib.Encryption 5 | { 6 | /// 7 | /// Transforms stream using AES in CTR mode 8 | /// 9 | internal class ZipAESTransform : ICryptoTransform 10 | { 11 | private const int PWD_VER_LENGTH = 2; 12 | 13 | // WinZip use iteration count of 1000 for PBKDF2 key generation 14 | private const int KEY_ROUNDS = 1000; 15 | 16 | // For 128-bit AES (16 bytes) the encryption is implemented as expected. 17 | // For 256-bit AES (32 bytes) WinZip do full 256 bit AES of the nonce to create the encryption 18 | // block but use only the first 16 bytes of it, and discard the second half. 19 | private const int ENCRYPT_BLOCK = 16; 20 | 21 | private int _blockSize; 22 | private readonly ICryptoTransform _encryptor; 23 | private readonly byte[] _counterNonce; 24 | private byte[] _encryptBuffer; 25 | private int _encrPos; 26 | private byte[] _pwdVerifier; 27 | private HMACSHA1 _hmacsha1; 28 | private bool _finalised; 29 | 30 | private bool _writeMode; 31 | 32 | /// 33 | /// Constructor. 34 | /// 35 | /// Password string 36 | /// Random bytes, length depends on encryption strength. 37 | /// 128 bits = 8 bytes, 192 bits = 12 bytes, 256 bits = 16 bytes. 38 | /// The encryption strength, in bytes eg 16 for 128 bits. 39 | /// True when creating a zip, false when reading. For the AuthCode. 40 | /// 41 | public ZipAESTransform(string key, byte[] saltBytes, int blockSize, bool writeMode) 42 | { 43 | 44 | if (blockSize != 16 && blockSize != 32) // 24 valid for AES but not supported by Winzip 45 | throw new Exception("Invalid blocksize " + blockSize + ". Must be 16 or 32."); 46 | if (saltBytes.Length != blockSize / 2) 47 | throw new Exception("Invalid salt len. Must be " + blockSize / 2 + " for blocksize " + blockSize); 48 | // initialise the encryption buffer and buffer pos 49 | _blockSize = blockSize; 50 | _encryptBuffer = new byte[_blockSize]; 51 | _encrPos = ENCRYPT_BLOCK; 52 | 53 | // Performs the equivalent of derive_key in Dr Brian Gladman's pwd2key.c 54 | var pdb = new Rfc2898DeriveBytes(key, saltBytes, KEY_ROUNDS); 55 | var rm = new RijndaelManaged(); 56 | rm.Mode = CipherMode.ECB; // No feedback from cipher for CTR mode 57 | _counterNonce = new byte[_blockSize]; 58 | byte[] byteKey1 = pdb.GetBytes(_blockSize); 59 | byte[] byteKey2 = pdb.GetBytes(_blockSize); 60 | _encryptor = rm.CreateEncryptor(byteKey1, byteKey2); 61 | _pwdVerifier = pdb.GetBytes(PWD_VER_LENGTH); 62 | // 63 | _hmacsha1 = new HMACSHA1(byteKey2); 64 | _writeMode = writeMode; 65 | } 66 | 67 | /// 68 | /// Implement the ICryptoTransform method. 69 | /// 70 | public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) 71 | { 72 | 73 | // Pass the data stream to the hash algorithm for generating the Auth Code. 74 | // This does not change the inputBuffer. Do this before decryption for read mode. 75 | if (!_writeMode) { 76 | _hmacsha1.TransformBlock(inputBuffer, inputOffset, inputCount, inputBuffer, inputOffset); 77 | } 78 | // Encrypt with AES in CTR mode. Regards to Dr Brian Gladman for this. 79 | int ix = 0; 80 | while (ix < inputCount) { 81 | if (_encrPos == ENCRYPT_BLOCK) { 82 | /* increment encryption nonce */ 83 | int j = 0; 84 | while (++_counterNonce[j] == 0) { 85 | ++j; 86 | } 87 | /* encrypt the nonce to form next xor buffer */ 88 | _encryptor.TransformBlock(_counterNonce, 0, _blockSize, _encryptBuffer, 0); 89 | _encrPos = 0; 90 | } 91 | outputBuffer[ix + outputOffset] = (byte)(inputBuffer[ix + inputOffset] ^ _encryptBuffer[_encrPos++]); 92 | // 93 | ix++; 94 | } 95 | if (_writeMode) { 96 | // This does not change the buffer. 97 | _hmacsha1.TransformBlock(outputBuffer, outputOffset, inputCount, outputBuffer, outputOffset); 98 | } 99 | return inputCount; 100 | } 101 | 102 | /// 103 | /// Returns the 2 byte password verifier 104 | /// 105 | public byte[] PwdVerifier { 106 | get { 107 | return _pwdVerifier; 108 | } 109 | } 110 | 111 | /// 112 | /// Returns the 10 byte AUTH CODE to be checked or appended immediately following the AES data stream. 113 | /// 114 | public byte[] GetAuthCode() 115 | { 116 | // We usually don't get advance notice of final block. Hash requres a TransformFinal. 117 | if (!_finalised) { 118 | byte[] dummy = new byte[0]; 119 | _hmacsha1.TransformFinalBlock(dummy, 0, 0); 120 | _finalised = true; 121 | } 122 | return _hmacsha1.Hash; 123 | } 124 | 125 | #region ICryptoTransform Members 126 | 127 | /// 128 | /// Not implemented. 129 | /// 130 | public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount) 131 | { 132 | 133 | throw new NotImplementedException("ZipAESTransform.TransformFinalBlock"); 134 | } 135 | 136 | /// 137 | /// Gets the size of the input data blocks in bytes. 138 | /// 139 | public int InputBlockSize { 140 | get { 141 | return _blockSize; 142 | } 143 | } 144 | 145 | /// 146 | /// Gets the size of the output data blocks in bytes. 147 | /// 148 | public int OutputBlockSize { 149 | get { 150 | return _blockSize; 151 | } 152 | } 153 | 154 | /// 155 | /// Gets a value indicating whether multiple blocks can be transformed. 156 | /// 157 | public bool CanTransformMultipleBlocks { 158 | get { 159 | return true; 160 | } 161 | } 162 | 163 | /// 164 | /// Gets a value indicating whether the current transform can be reused. 165 | /// 166 | public bool CanReuseTransform { 167 | get { 168 | return true; 169 | } 170 | } 171 | 172 | /// 173 | /// Cleanup internal state. 174 | /// 175 | public void Dispose() 176 | { 177 | _encryptor.Dispose(); 178 | } 179 | 180 | #endregion 181 | 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/GZip/GZip.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using YZL.Compress.GZip; 4 | 5 | namespace ICSharpCode.SharpZipLib.GZip 6 | { 7 | public static class GZip 8 | { 9 | public static void Decompress(Stream inStream, Stream outStream, bool isStreamOwner,GZipFile.CodeProgress progress) 10 | { 11 | if (inStream == null || outStream == null) 12 | { 13 | throw new Exception("Null Stream"); 14 | } 15 | 16 | try 17 | { 18 | using (GZipInputStream bzipInput = new GZipInputStream(inStream)) 19 | { 20 | bzipInput.IsStreamOwner = isStreamOwner; 21 | ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(bzipInput, outStream, new byte[4096], progress); 22 | } 23 | } 24 | finally 25 | { 26 | if (isStreamOwner) 27 | { 28 | // inStream is closed by the GZipInputStream if stream owner 29 | outStream.Close(); 30 | } 31 | } 32 | } 33 | 34 | public static void Compress(Stream inStream, Stream outStream, bool isStreamOwner, GZipFile.CodeProgress progress) 35 | { 36 | if (inStream == null || outStream == null) 37 | { 38 | throw new Exception("Null Stream"); 39 | } 40 | 41 | try 42 | { 43 | using (GZipOutputStream bzipOutput = new GZipOutputStream(outStream)) 44 | { 45 | bzipOutput.IsStreamOwner = isStreamOwner; ; 46 | ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(inStream, bzipOutput, new byte[4096], progress); 47 | } 48 | } 49 | finally 50 | { 51 | if (isStreamOwner) 52 | { 53 | // outStream is closed by the GZipOutputStream if stream owner 54 | inStream.Close(); 55 | } 56 | } 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/GZip/GZipConstants.cs: -------------------------------------------------------------------------------- 1 | namespace ICSharpCode.SharpZipLib.GZip 2 | { 3 | /// 4 | /// This class contains constants used for gzip. 5 | /// 6 | sealed public class GZipConstants 7 | { 8 | /// 9 | /// Magic number found at start of GZIP header 10 | /// 11 | public const int GZIP_MAGIC = 0x1F8B; 12 | 13 | /* The flag byte is divided into individual bits as follows: 14 | 15 | bit 0 FTEXT 16 | bit 1 FHCRC 17 | bit 2 FEXTRA 18 | bit 3 FNAME 19 | bit 4 FCOMMENT 20 | bit 5 reserved 21 | bit 6 reserved 22 | bit 7 reserved 23 | */ 24 | 25 | /// 26 | /// Flag bit mask for text 27 | /// 28 | public const int FTEXT = 0x1; 29 | 30 | /// 31 | /// Flag bitmask for Crc 32 | /// 33 | public const int FHCRC = 0x2; 34 | 35 | /// 36 | /// Flag bit mask for extra 37 | /// 38 | public const int FEXTRA = 0x4; 39 | 40 | /// 41 | /// flag bitmask for name 42 | /// 43 | public const int FNAME = 0x8; 44 | 45 | /// 46 | /// flag bit mask indicating comment is present 47 | /// 48 | public const int FCOMMENT = 0x10; 49 | 50 | /// 51 | /// Initialise default instance. 52 | /// 53 | /// Constructor is private to prevent instances being created. 54 | GZipConstants() 55 | { 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/GZip/GZipException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace ICSharpCode.SharpZipLib.GZip 5 | { 6 | /// 7 | /// GZipException represents exceptions specific to GZip classes and code. 8 | /// 9 | [Serializable] 10 | public class GZipException : SharpZipBaseException 11 | { 12 | /// 13 | /// Deserialization constructor 14 | /// 15 | /// for this constructor 16 | /// for this constructor 17 | protected GZipException(SerializationInfo info, StreamingContext context) 18 | : base(info, context) 19 | { 20 | } 21 | 22 | /// 23 | /// Initialise a new instance of . 24 | /// 25 | public GZipException() 26 | { 27 | } 28 | 29 | /// 30 | /// Initialise a new instance of with its message string. 31 | /// 32 | /// A that describes the error. 33 | public GZipException(string message) 34 | : base(message) 35 | { 36 | } 37 | 38 | /// 39 | /// Initialise a new instance of . 40 | /// 41 | /// A that describes the error. 42 | /// The that caused this exception. 43 | public GZipException(string message, Exception innerException) 44 | : base(message, innerException) 45 | { 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/GZip/GZipFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading; 4 | using YZL.Compress.Info; 5 | 6 | namespace YZL.Compress.GZip 7 | { 8 | public class GZipFile 9 | { 10 | /** 进度 **/ 11 | public class CodeProgress 12 | { 13 | public ProgressDelegate m_ProgressDelegate = null; 14 | 15 | public CodeProgress(ProgressDelegate del) 16 | { 17 | m_ProgressDelegate = del; 18 | } 19 | 20 | public void SetProgress(Int64 inSize, Int64 outSize) 21 | { 22 | } 23 | 24 | public void SetProgressPercent(Int64 fileSize, Int64 processSize) 25 | { 26 | m_ProgressDelegate(fileSize, processSize); 27 | } 28 | } 29 | 30 | /** 异步压缩一个文件 **/ 31 | public static void CompressAsync(string inpath, string outpath, ProgressDelegate progress) 32 | { 33 | Thread compressThread = new Thread(new ParameterizedThreadStart(Compress)); 34 | FileChangeInfo info = new FileChangeInfo(); 35 | info.inpath = inpath; 36 | info.outpath = outpath; 37 | info.progressDelegate = progress; 38 | compressThread.Start(info); 39 | } 40 | 41 | /** 异步解压一个文件 **/ 42 | public static void DeCompressAsync(string inpath, string outpath, ProgressDelegate progress) 43 | { 44 | Thread decompressThread = new Thread(new ParameterizedThreadStart(DeCompress)); 45 | FileChangeInfo info = new FileChangeInfo(); 46 | info.inpath = inpath; 47 | info.outpath = outpath; 48 | info.progressDelegate = progress; 49 | decompressThread.Start(info); 50 | } 51 | 52 | /** 同步压缩一个文件 **/ 53 | private static void Compress(object obj) 54 | { 55 | FileChangeInfo info = (FileChangeInfo)obj; 56 | string inpath = info.inpath; 57 | string outpath = info.outpath; 58 | CodeProgress codeProgress = null; 59 | if (info.progressDelegate != null) 60 | codeProgress = new CodeProgress(info.progressDelegate); 61 | 62 | ICSharpCode.SharpZipLib.GZip.GZip.Compress(File.OpenRead(inpath), File.Create(outpath), true, codeProgress); 63 | 64 | } 65 | 66 | public static void Compress(string inpath, string outpath, ProgressDelegate progress) 67 | { 68 | FileChangeInfo info = new FileChangeInfo(); 69 | info.inpath = inpath; 70 | info.outpath = outpath; 71 | info.progressDelegate = progress; 72 | Compress(info); 73 | } 74 | 75 | /** 同步解压一个文件 **/ 76 | private static void DeCompress(object obj) 77 | { 78 | FileChangeInfo info = (FileChangeInfo)obj; 79 | string inpath = info.inpath; 80 | string outpath = info.outpath; 81 | CodeProgress codeProgress = null; 82 | if (info.progressDelegate != null) 83 | codeProgress = new CodeProgress(info.progressDelegate); 84 | 85 | ICSharpCode.SharpZipLib.GZip.GZip.Decompress(File.OpenRead(inpath), File.Create(outpath), true, codeProgress); 86 | } 87 | 88 | public static void DeCompress(string inpath, string outpath, ProgressDelegate progress) 89 | { 90 | FileChangeInfo info = new FileChangeInfo(); 91 | info.inpath = inpath; 92 | info.outpath = outpath; 93 | info.progressDelegate = progress; 94 | DeCompress(info); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/GZip/GzipOutputStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using ICSharpCode.SharpZipLib.Checksum; 4 | using ICSharpCode.SharpZipLib.Zip.Compression; 5 | using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 6 | 7 | namespace ICSharpCode.SharpZipLib.GZip 8 | { 9 | /// 10 | /// This filter stream is used to compress a stream into a "GZIP" stream. 11 | /// The "GZIP" format is described in RFC 1952. 12 | /// 13 | /// author of the original java version : John Leuner 14 | /// 15 | /// This sample shows how to gzip a file 16 | /// 17 | /// using System; 18 | /// using System.IO; 19 | /// 20 | /// using ICSharpCode.SharpZipLib.GZip; 21 | /// using ICSharpCode.SharpZipLib.Core; 22 | /// 23 | /// class MainClass 24 | /// { 25 | /// public static void Main(string[] args) 26 | /// { 27 | /// using (Stream s = new GZipOutputStream(File.Create(args[0] + ".gz"))) 28 | /// using (FileStream fs = File.OpenRead(args[0])) { 29 | /// byte[] writeData = new byte[4096]; 30 | /// Streamutils.Copy(s, fs, writeData); 31 | /// } 32 | /// } 33 | /// } 34 | /// } 35 | /// 36 | /// 37 | public class GZipOutputStream : DeflaterOutputStream 38 | { 39 | enum OutputState 40 | { 41 | Header, 42 | Footer, 43 | Finished, 44 | Closed, 45 | }; 46 | 47 | #region Instance Fields 48 | /// 49 | /// CRC-32 value for uncompressed data 50 | /// 51 | protected Crc32 crc = new Crc32(); 52 | OutputState state_ = OutputState.Header; 53 | #endregion 54 | 55 | #region Constructors 56 | /// 57 | /// Creates a GzipOutputStream with the default buffer size 58 | /// 59 | /// 60 | /// The stream to read data (to be compressed) from 61 | /// 62 | public GZipOutputStream(Stream baseOutputStream) 63 | : this(baseOutputStream, 4096) 64 | { 65 | } 66 | 67 | /// 68 | /// Creates a GZipOutputStream with the specified buffer size 69 | /// 70 | /// 71 | /// The stream to read data (to be compressed) from 72 | /// 73 | /// 74 | /// Size of the buffer to use 75 | /// 76 | public GZipOutputStream(Stream baseOutputStream, int size) : base(baseOutputStream, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size) 77 | { 78 | } 79 | #endregion 80 | 81 | #region Public API 82 | /// 83 | /// Sets the active compression level (1-9). The new level will be activated 84 | /// immediately. 85 | /// 86 | /// The compression level to set. 87 | /// 88 | /// Level specified is not supported. 89 | /// 90 | /// 91 | public void SetLevel(int level) 92 | { 93 | if (level < Deflater.BEST_SPEED) { 94 | throw new ArgumentOutOfRangeException(nameof(level)); 95 | } 96 | deflater_.SetLevel(level); 97 | } 98 | 99 | /// 100 | /// Get the current compression level. 101 | /// 102 | /// The current compression level. 103 | public int GetLevel() 104 | { 105 | return deflater_.GetLevel(); 106 | } 107 | #endregion 108 | 109 | #region Stream overrides 110 | /// 111 | /// Write given buffer to output updating crc 112 | /// 113 | /// Buffer to write 114 | /// Offset of first byte in buf to write 115 | /// Number of bytes to write 116 | public override void Write(byte[] buffer, int offset, int count) 117 | { 118 | if (state_ == OutputState.Header) { 119 | WriteHeader(); 120 | } 121 | 122 | if (state_ != OutputState.Footer) { 123 | throw new InvalidOperationException("Write not permitted in current state"); 124 | } 125 | 126 | crc.Update(buffer, offset, count); 127 | base.Write(buffer, offset, count); 128 | } 129 | 130 | /// 131 | /// Writes remaining compressed output data to the output stream 132 | /// and closes it. 133 | /// 134 | public override void Close() 135 | { 136 | try { 137 | Finish(); 138 | } finally { 139 | if (state_ != OutputState.Closed) { 140 | state_ = OutputState.Closed; 141 | if (IsStreamOwner) { 142 | baseOutputStream_.Close(); 143 | } 144 | } 145 | } 146 | } 147 | #endregion 148 | 149 | #region DeflaterOutputStream overrides 150 | /// 151 | /// Finish compression and write any footer information required to stream 152 | /// 153 | public override void Finish() 154 | { 155 | // If no data has been written a header should be added. 156 | if (state_ == OutputState.Header) { 157 | WriteHeader(); 158 | } 159 | 160 | if (state_ == OutputState.Footer) { 161 | state_ = OutputState.Finished; 162 | base.Finish(); 163 | 164 | var totalin = (uint)(deflater_.TotalIn & 0xffffffff); 165 | var crcval = (uint)(crc.Value & 0xffffffff); 166 | 167 | byte[] gzipFooter; 168 | 169 | unchecked { 170 | gzipFooter = new byte[] { 171 | (byte) crcval, (byte) (crcval >> 8), 172 | (byte) (crcval >> 16), (byte) (crcval >> 24), 173 | 174 | (byte) totalin, (byte) (totalin >> 8), 175 | (byte) (totalin >> 16), (byte) (totalin >> 24) 176 | }; 177 | } 178 | 179 | baseOutputStream_.Write(gzipFooter, 0, gzipFooter.Length); 180 | } 181 | } 182 | #endregion 183 | 184 | #region Support Routines 185 | void WriteHeader() 186 | { 187 | if (state_ == OutputState.Header) { 188 | state_ = OutputState.Footer; 189 | 190 | var mod_time = (int)((DateTime.Now.Ticks - new DateTime(1970, 1, 1).Ticks) / 10000000L); // Ticks give back 100ns intervals 191 | byte[] gzipHeader = { 192 | // The two magic bytes 193 | (byte) (GZipConstants.GZIP_MAGIC >> 8), (byte) (GZipConstants.GZIP_MAGIC & 0xff), 194 | 195 | // The compression type 196 | (byte) Deflater.DEFLATED, 197 | 198 | // The flags (not set) 199 | 0, 200 | 201 | // The modification time 202 | (byte) mod_time, (byte) (mod_time >> 8), 203 | (byte) (mod_time >> 16), (byte) (mod_time >> 24), 204 | 205 | // The extra flags 206 | 0, 207 | 208 | // The OS type (unknown) 209 | (byte) 255 210 | }; 211 | baseOutputStream_.Write(gzipHeader, 0, gzipHeader.Length); 212 | } 213 | } 214 | #endregion 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/GlobalAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyCompany("ICSharpCode")] 8 | [assembly: AssemblyProduct("SharpZipLib (#ziplib)")] 9 | [assembly: AssemblyCopyright("Copyright © 2000-2016 SharpZipLib Contributors")] 10 | [assembly: AssemblyTrademark("")] 11 | 12 | #if DEBUG 13 | [assembly: AssemblyConfiguration("Debug")] 14 | #else 15 | [assembly: AssemblyConfiguration("Release")] 16 | #endif 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // Version information for an assembly consists of the following four values: 24 | // 25 | // Major Version 26 | // Minor Version 27 | // Build Number 28 | // Revision 29 | // 30 | // You can specify all the values or you can default the Build and Revision Numbers 31 | // by using the '*' as shown below: 32 | // [assembly: AssemblyVersion("1.0.*")] 33 | 34 | // https://blogs.msdn.microsoft.com/carloc/2008/02/22/version-numbers-in-a-compiled-assembly/ 35 | // 36 | // Build: the number of days since 1.1.2000 (you can modify this start date by setting Software\\Microsoft\\ALink\\VersionStartDate). i.e. 1879 = 02.22.2005 37 | // 38 | // Revision: the number of two second intervals since midnight in local time; i.e. 31308 = 17:23:36 local time. 39 | 40 | // Specifies the version of the assembly being attributed. 41 | [assembly: AssemblyVersion("1.0.*")] 42 | 43 | // Instructs a compiler to use a specific version number for the Win32 file version resource. 44 | // The Win32 file version is not required to be the same as the assembly's version number. 45 | [assembly: AssemblyFileVersion("1.0")] 46 | 47 | // Defines additional version information for an assembly manifest. 48 | [assembly: AssemblyInformationalVersion("1.0")] 49 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Lzw/LzwConstants.cs: -------------------------------------------------------------------------------- 1 | namespace ICSharpCode.SharpZipLib.Lzw 2 | { 3 | /// 4 | /// This class contains constants used for LZW 5 | /// 6 | sealed public class LzwConstants 7 | { 8 | /// 9 | /// Magic number found at start of LZW header: 0x1f 0x9d 10 | /// 11 | public const int MAGIC = 0x1f9d; 12 | 13 | /// 14 | /// Maximum number of bits per code 15 | /// 16 | public const int MAX_BITS = 16; 17 | 18 | /* 3rd header byte: 19 | * bit 0..4 Number of compression bits 20 | * bit 5 Extended header 21 | * bit 6 Free 22 | * bit 7 Block mode 23 | */ 24 | 25 | /// 26 | /// Mask for 'number of compression bits' 27 | /// 28 | public const int BIT_MASK = 0x1f; 29 | 30 | /// 31 | /// Indicates the presence of a fourth header byte 32 | /// 33 | public const int EXTENDED_MASK = 0x20; 34 | //public const int FREE_MASK = 0x40; 35 | 36 | /// 37 | /// Reserved bits 38 | /// 39 | public const int RESERVED_MASK = 0x60; 40 | 41 | /// 42 | /// Block compression: if table is full and compression rate is dropping, 43 | /// clear the dictionary. 44 | /// 45 | public const int BLOCK_MODE_MASK = 0x80; 46 | 47 | /// 48 | /// LZW file header size (in bytes) 49 | /// 50 | public const int HDR_SIZE = 3; 51 | 52 | /// 53 | /// Initial number of bits per code 54 | /// 55 | public const int INIT_BITS = 9; 56 | 57 | LzwConstants() 58 | { 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Lzw/LzwException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace ICSharpCode.SharpZipLib.Lzw 5 | { 6 | /// 7 | /// LzwException represents exceptions specific to LZW classes and code. 8 | /// 9 | [Serializable] 10 | public class LzwException : SharpZipBaseException 11 | { 12 | /// 13 | /// Deserialization constructor 14 | /// 15 | /// for this constructor 16 | /// for this constructor 17 | protected LzwException(SerializationInfo info, StreamingContext context) 18 | : base(info, context) 19 | { 20 | } 21 | 22 | /// 23 | /// Initialise a new instance of . 24 | /// 25 | public LzwException() 26 | { 27 | } 28 | 29 | /// 30 | /// Initialise a new instance of with its message string. 31 | /// 32 | /// A that describes the error. 33 | public LzwException(string message) 34 | : base(message) 35 | { 36 | } 37 | 38 | /// 39 | /// Initialise a new instance of . 40 | /// 41 | /// A that describes the error. 42 | /// The that caused this exception. 43 | public LzwException(string message, Exception innerException) 44 | : base(message, innerException) 45 | { 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/SharpZipBaseException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace ICSharpCode.SharpZipLib 5 | { 6 | /// 7 | /// SharpZipBaseException is the base exception class for SharpZipLib. 8 | /// All library exceptions are derived from this. 9 | /// 10 | /// NOTE: Not all exceptions thrown will be derived from this class. 11 | /// A variety of other exceptions are possible for example 12 | [Serializable] 13 | public class SharpZipBaseException : Exception 14 | { 15 | /// 16 | /// Deserialization constructor 17 | /// 18 | /// for this constructor 19 | /// for this constructor 20 | protected SharpZipBaseException(SerializationInfo info, StreamingContext context) 21 | : base(info, context) 22 | { 23 | } 24 | 25 | /// 26 | /// Initializes a new instance of the SharpZipBaseException class. 27 | /// 28 | public SharpZipBaseException() 29 | { 30 | } 31 | 32 | /// 33 | /// Initializes a new instance of the SharpZipBaseException class with a specified error message. 34 | /// 35 | /// A message describing the exception. 36 | public SharpZipBaseException(string message) 37 | : base(message) 38 | { 39 | } 40 | 41 | /// 42 | /// Initializes a new instance of the SharpZipBaseException class with a specified 43 | /// error message and a reference to the inner exception that is the cause of this exception. 44 | /// 45 | /// A message describing the exception. 46 | /// The inner exception 47 | public SharpZipBaseException(string message, Exception innerException) 48 | : base(message, innerException) 49 | { 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Tar/InvalidHeaderException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace ICSharpCode.SharpZipLib.Tar 5 | { 6 | /// 7 | /// This exception is used to indicate that there is a problem 8 | /// with a TAR archive header. 9 | /// 10 | [Serializable] 11 | public class InvalidHeaderException : TarException 12 | { 13 | 14 | /// 15 | /// Deserialization constructor 16 | /// 17 | /// for this constructor 18 | /// for this constructor 19 | protected InvalidHeaderException(SerializationInfo information, StreamingContext context) 20 | : base(information, context) 21 | 22 | { 23 | } 24 | 25 | /// 26 | /// Initialise a new instance of the InvalidHeaderException class. 27 | /// 28 | public InvalidHeaderException() 29 | { 30 | } 31 | 32 | /// 33 | /// Initialises a new instance of the InvalidHeaderException class with a specified message. 34 | /// 35 | /// Message describing the exception cause. 36 | public InvalidHeaderException(string message) 37 | : base(message) 38 | { 39 | } 40 | 41 | /// 42 | /// Initialise a new instance of InvalidHeaderException 43 | /// 44 | /// Message describing the problem. 45 | /// The exception that is the cause of the current exception. 46 | public InvalidHeaderException(string message, Exception exception) 47 | : base(message, exception) 48 | { 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Tar/TarException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace ICSharpCode.SharpZipLib.Tar 5 | { 6 | /// 7 | /// TarException represents exceptions specific to Tar classes and code. 8 | /// 9 | [Serializable] 10 | public class TarException : SharpZipBaseException 11 | { 12 | /// 13 | /// Deserialization constructor 14 | /// 15 | /// for this constructor 16 | /// for this constructor 17 | protected TarException(SerializationInfo info, StreamingContext context) 18 | : base(info, context) 19 | { 20 | } 21 | 22 | /// 23 | /// Initialise a new instance of . 24 | /// 25 | public TarException() 26 | { 27 | } 28 | 29 | /// 30 | /// Initialise a new instance of with its message string. 31 | /// 32 | /// A that describes the error. 33 | public TarException(string message) 34 | : base(message) 35 | { 36 | } 37 | 38 | /// 39 | /// Initialise a new instance of . 40 | /// 41 | /// A that describes the error. 42 | /// The that caused this exception. 43 | public TarException(string message, Exception innerException) 44 | : base(message, innerException) 45 | { 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/Compression/DeflaterConstants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ICSharpCode.SharpZipLib.Zip.Compression 4 | { 5 | /// 6 | /// This class contains constants used for deflation. 7 | /// 8 | public static class DeflaterConstants 9 | { 10 | /// 11 | /// Set to true to enable debugging 12 | /// 13 | public const bool DEBUGGING = false; 14 | 15 | /// 16 | /// Written to Zip file to identify a stored block 17 | /// 18 | public const int STORED_BLOCK = 0; 19 | 20 | /// 21 | /// Identifies static tree in Zip file 22 | /// 23 | public const int STATIC_TREES = 1; 24 | 25 | /// 26 | /// Identifies dynamic tree in Zip file 27 | /// 28 | public const int DYN_TREES = 2; 29 | 30 | /// 31 | /// Header flag indicating a preset dictionary for deflation 32 | /// 33 | public const int PRESET_DICT = 0x20; 34 | 35 | /// 36 | /// Sets internal buffer sizes for Huffman encoding 37 | /// 38 | public const int DEFAULT_MEM_LEVEL = 8; 39 | 40 | /// 41 | /// Internal compression engine constant 42 | /// 43 | public const int MAX_MATCH = 258; 44 | 45 | /// 46 | /// Internal compression engine constant 47 | /// 48 | public const int MIN_MATCH = 3; 49 | 50 | /// 51 | /// Internal compression engine constant 52 | /// 53 | public const int MAX_WBITS = 15; 54 | 55 | /// 56 | /// Internal compression engine constant 57 | /// 58 | public const int WSIZE = 1 << MAX_WBITS; 59 | 60 | /// 61 | /// Internal compression engine constant 62 | /// 63 | public const int WMASK = WSIZE - 1; 64 | 65 | /// 66 | /// Internal compression engine constant 67 | /// 68 | public const int HASH_BITS = DEFAULT_MEM_LEVEL + 7; 69 | 70 | /// 71 | /// Internal compression engine constant 72 | /// 73 | public const int HASH_SIZE = 1 << HASH_BITS; 74 | 75 | /// 76 | /// Internal compression engine constant 77 | /// 78 | public const int HASH_MASK = HASH_SIZE - 1; 79 | 80 | /// 81 | /// Internal compression engine constant 82 | /// 83 | public const int HASH_SHIFT = (HASH_BITS + MIN_MATCH - 1) / MIN_MATCH; 84 | 85 | /// 86 | /// Internal compression engine constant 87 | /// 88 | public const int MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1; 89 | 90 | /// 91 | /// Internal compression engine constant 92 | /// 93 | public const int MAX_DIST = WSIZE - MIN_LOOKAHEAD; 94 | 95 | /// 96 | /// Internal compression engine constant 97 | /// 98 | public const int PENDING_BUF_SIZE = 1 << (DEFAULT_MEM_LEVEL + 8); 99 | 100 | /// 101 | /// Internal compression engine constant 102 | /// 103 | public static int MAX_BLOCK_SIZE = Math.Min(65535, PENDING_BUF_SIZE - 5); 104 | 105 | /// 106 | /// Internal compression engine constant 107 | /// 108 | public const int DEFLATE_STORED = 0; 109 | 110 | /// 111 | /// Internal compression engine constant 112 | /// 113 | public const int DEFLATE_FAST = 1; 114 | 115 | /// 116 | /// Internal compression engine constant 117 | /// 118 | public const int DEFLATE_SLOW = 2; 119 | 120 | /// 121 | /// Internal compression engine constant 122 | /// 123 | public static int[] GOOD_LENGTH = { 0, 4, 4, 4, 4, 8, 8, 8, 32, 32 }; 124 | 125 | /// 126 | /// Internal compression engine constant 127 | /// 128 | public static int[] MAX_LAZY = { 0, 4, 5, 6, 4, 16, 16, 32, 128, 258 }; 129 | 130 | /// 131 | /// Internal compression engine constant 132 | /// 133 | public static int[] NICE_LENGTH = { 0, 8, 16, 32, 16, 32, 128, 128, 258, 258 }; 134 | 135 | /// 136 | /// Internal compression engine constant 137 | /// 138 | public static int[] MAX_CHAIN = { 0, 4, 8, 32, 16, 32, 128, 256, 1024, 4096 }; 139 | 140 | /// 141 | /// Internal compression engine constant 142 | /// 143 | public static int[] COMPR_FUNC = { 0, 1, 1, 1, 1, 2, 2, 2, 2, 2 }; 144 | 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/Compression/DeflaterPending.cs: -------------------------------------------------------------------------------- 1 | namespace ICSharpCode.SharpZipLib.Zip.Compression 2 | { 3 | /// 4 | /// This class stores the pending output of the Deflater. 5 | /// 6 | /// author of the original java version : Jochen Hoenicke 7 | /// 8 | public class DeflaterPending : PendingBuffer 9 | { 10 | /// 11 | /// Construct instance with default buffer size 12 | /// 13 | public DeflaterPending() : base(DeflaterConstants.PENDING_BUF_SIZE) 14 | { 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/Compression/InflaterDynHeader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 3 | 4 | namespace ICSharpCode.SharpZipLib.Zip.Compression 5 | { 6 | class InflaterDynHeader 7 | { 8 | #region Constants 9 | const int LNUM = 0; 10 | const int DNUM = 1; 11 | const int BLNUM = 2; 12 | const int BLLENS = 3; 13 | const int LENS = 4; 14 | const int REPS = 5; 15 | 16 | static readonly int[] repMin = { 3, 3, 11 }; 17 | static readonly int[] repBits = { 2, 3, 7 }; 18 | 19 | static readonly int[] BL_ORDER = 20 | { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; 21 | #endregion 22 | 23 | public bool Decode(StreamManipulator input) 24 | { 25 | decode_loop: 26 | for (;;) { 27 | switch (mode) { 28 | case LNUM: 29 | lnum = input.PeekBits(5); 30 | if (lnum < 0) { 31 | return false; 32 | } 33 | lnum += 257; 34 | input.DropBits(5); 35 | // System.err.println("LNUM: "+lnum); 36 | mode = DNUM; 37 | goto case DNUM; // fall through 38 | case DNUM: 39 | dnum = input.PeekBits(5); 40 | if (dnum < 0) { 41 | return false; 42 | } 43 | dnum++; 44 | input.DropBits(5); 45 | // System.err.println("DNUM: "+dnum); 46 | num = lnum + dnum; 47 | litdistLens = new byte[num]; 48 | mode = BLNUM; 49 | goto case BLNUM; // fall through 50 | case BLNUM: 51 | blnum = input.PeekBits(4); 52 | if (blnum < 0) { 53 | return false; 54 | } 55 | blnum += 4; 56 | input.DropBits(4); 57 | blLens = new byte[19]; 58 | ptr = 0; 59 | // System.err.println("BLNUM: "+blnum); 60 | mode = BLLENS; 61 | goto case BLLENS; // fall through 62 | case BLLENS: 63 | while (ptr < blnum) { 64 | int len = input.PeekBits(3); 65 | if (len < 0) { 66 | return false; 67 | } 68 | input.DropBits(3); 69 | // System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len); 70 | blLens[BL_ORDER[ptr]] = (byte)len; 71 | ptr++; 72 | } 73 | blTree = new InflaterHuffmanTree(blLens); 74 | blLens = null; 75 | ptr = 0; 76 | mode = LENS; 77 | goto case LENS; // fall through 78 | case LENS: { 79 | int symbol; 80 | while (((symbol = blTree.GetSymbol(input)) & ~15) == 0) { 81 | /* Normal case: symbol in [0..15] */ 82 | 83 | // System.err.println("litdistLens["+ptr+"]: "+symbol); 84 | litdistLens[ptr++] = lastLen = (byte)symbol; 85 | 86 | if (ptr == num) { 87 | /* Finished */ 88 | return true; 89 | } 90 | } 91 | 92 | /* need more input ? */ 93 | if (symbol < 0) { 94 | return false; 95 | } 96 | 97 | /* otherwise repeat code */ 98 | if (symbol >= 17) { 99 | /* repeat zero */ 100 | // System.err.println("repeating zero"); 101 | lastLen = 0; 102 | } else { 103 | if (ptr == 0) { 104 | throw new SharpZipBaseException(); 105 | } 106 | } 107 | repSymbol = symbol - 16; 108 | } 109 | mode = REPS; 110 | goto case REPS; // fall through 111 | case REPS: { 112 | int bits = repBits[repSymbol]; 113 | int count = input.PeekBits(bits); 114 | if (count < 0) { 115 | return false; 116 | } 117 | input.DropBits(bits); 118 | count += repMin[repSymbol]; 119 | // System.err.println("litdistLens repeated: "+count); 120 | 121 | if (ptr + count > num) { 122 | throw new SharpZipBaseException(); 123 | } 124 | while (count-- > 0) { 125 | litdistLens[ptr++] = lastLen; 126 | } 127 | 128 | if (ptr == num) { 129 | /* Finished */ 130 | return true; 131 | } 132 | } 133 | mode = LENS; 134 | goto decode_loop; 135 | } 136 | } 137 | } 138 | 139 | public InflaterHuffmanTree BuildLitLenTree() 140 | { 141 | byte[] litlenLens = new byte[lnum]; 142 | Array.Copy(litdistLens, 0, litlenLens, 0, lnum); 143 | return new InflaterHuffmanTree(litlenLens); 144 | } 145 | 146 | public InflaterHuffmanTree BuildDistTree() 147 | { 148 | byte[] distLens = new byte[dnum]; 149 | Array.Copy(litdistLens, lnum, distLens, 0, dnum); 150 | return new InflaterHuffmanTree(distLens); 151 | } 152 | 153 | #region Instance Fields 154 | byte[] blLens; 155 | byte[] litdistLens; 156 | 157 | InflaterHuffmanTree blTree; 158 | 159 | /// 160 | /// The current decode mode 161 | /// 162 | int mode; 163 | int lnum, dnum, blnum, num; 164 | int repSymbol; 165 | byte lastLen; 166 | int ptr; 167 | #endregion 168 | 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/Compression/InflaterHuffmanTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 3 | 4 | namespace ICSharpCode.SharpZipLib.Zip.Compression 5 | { 6 | /// 7 | /// Huffman tree used for inflation 8 | /// 9 | public class InflaterHuffmanTree 10 | { 11 | #region Constants 12 | const int MAX_BITLEN = 15; 13 | #endregion 14 | 15 | #region Instance Fields 16 | short[] tree; 17 | #endregion 18 | 19 | /// 20 | /// Literal length tree 21 | /// 22 | public static InflaterHuffmanTree defLitLenTree; 23 | 24 | /// 25 | /// Distance tree 26 | /// 27 | public static InflaterHuffmanTree defDistTree; 28 | 29 | static InflaterHuffmanTree() 30 | { 31 | try { 32 | byte[] codeLengths = new byte[288]; 33 | int i = 0; 34 | while (i < 144) { 35 | codeLengths[i++] = 8; 36 | } 37 | while (i < 256) { 38 | codeLengths[i++] = 9; 39 | } 40 | while (i < 280) { 41 | codeLengths[i++] = 7; 42 | } 43 | while (i < 288) { 44 | codeLengths[i++] = 8; 45 | } 46 | defLitLenTree = new InflaterHuffmanTree(codeLengths); 47 | 48 | codeLengths = new byte[32]; 49 | i = 0; 50 | while (i < 32) { 51 | codeLengths[i++] = 5; 52 | } 53 | defDistTree = new InflaterHuffmanTree(codeLengths); 54 | } catch (Exception) { 55 | throw new SharpZipBaseException("InflaterHuffmanTree: static tree length illegal"); 56 | } 57 | } 58 | 59 | #region Constructors 60 | /// 61 | /// Constructs a Huffman tree from the array of code lengths. 62 | /// 63 | /// 64 | /// the array of code lengths 65 | /// 66 | public InflaterHuffmanTree(byte[] codeLengths) 67 | { 68 | BuildTree(codeLengths); 69 | } 70 | #endregion 71 | 72 | void BuildTree(byte[] codeLengths) 73 | { 74 | int[] blCount = new int[MAX_BITLEN + 1]; 75 | int[] nextCode = new int[MAX_BITLEN + 1]; 76 | 77 | for (int i = 0; i < codeLengths.Length; i++) { 78 | int bits = codeLengths[i]; 79 | if (bits > 0) { 80 | blCount[bits]++; 81 | } 82 | } 83 | 84 | int code = 0; 85 | int treeSize = 512; 86 | for (int bits = 1; bits <= MAX_BITLEN; bits++) { 87 | nextCode[bits] = code; 88 | code += blCount[bits] << (16 - bits); 89 | if (bits >= 10) { 90 | /* We need an extra table for bit lengths >= 10. */ 91 | int start = nextCode[bits] & 0x1ff80; 92 | int end = code & 0x1ff80; 93 | treeSize += (end - start) >> (16 - bits); 94 | } 95 | } 96 | 97 | /* -jr comment this out! doesnt work for dynamic trees and pkzip 2.04g 98 | if (code != 65536) 99 | { 100 | throw new SharpZipBaseException("Code lengths don't add up properly."); 101 | } 102 | */ 103 | /* Now create and fill the extra tables from longest to shortest 104 | * bit len. This way the sub trees will be aligned. 105 | */ 106 | tree = new short[treeSize]; 107 | int treePtr = 512; 108 | for (int bits = MAX_BITLEN; bits >= 10; bits--) { 109 | int end = code & 0x1ff80; 110 | code -= blCount[bits] << (16 - bits); 111 | int start = code & 0x1ff80; 112 | for (int i = start; i < end; i += 1 << 7) { 113 | tree[DeflaterHuffman.BitReverse(i)] = (short)((-treePtr << 4) | bits); 114 | treePtr += 1 << (bits - 9); 115 | } 116 | } 117 | 118 | for (int i = 0; i < codeLengths.Length; i++) { 119 | int bits = codeLengths[i]; 120 | if (bits == 0) { 121 | continue; 122 | } 123 | code = nextCode[bits]; 124 | int revcode = DeflaterHuffman.BitReverse(code); 125 | if (bits <= 9) { 126 | do { 127 | tree[revcode] = (short)((i << 4) | bits); 128 | revcode += 1 << bits; 129 | } while (revcode < 512); 130 | } else { 131 | int subTree = tree[revcode & 511]; 132 | int treeLen = 1 << (subTree & 15); 133 | subTree = -(subTree >> 4); 134 | do { 135 | tree[subTree | (revcode >> 9)] = (short)((i << 4) | bits); 136 | revcode += 1 << bits; 137 | } while (revcode < treeLen); 138 | } 139 | nextCode[bits] = code + (1 << (16 - bits)); 140 | } 141 | 142 | } 143 | 144 | /// 145 | /// Reads the next symbol from input. The symbol is encoded using the 146 | /// huffman tree. 147 | /// 148 | /// 149 | /// input the input source. 150 | /// 151 | /// 152 | /// the next symbol, or -1 if not enough input is available. 153 | /// 154 | public int GetSymbol(StreamManipulator input) 155 | { 156 | int lookahead, symbol; 157 | if ((lookahead = input.PeekBits(9)) >= 0) { 158 | if ((symbol = tree[lookahead]) >= 0) { 159 | input.DropBits(symbol & 15); 160 | return symbol >> 4; 161 | } 162 | int subtree = -(symbol >> 4); 163 | int bitlen = symbol & 15; 164 | if ((lookahead = input.PeekBits(bitlen)) >= 0) { 165 | symbol = tree[subtree | (lookahead >> 9)]; 166 | input.DropBits(symbol & 15); 167 | return symbol >> 4; 168 | } else { 169 | int bits = input.AvailableBits; 170 | lookahead = input.PeekBits(bits); 171 | symbol = tree[subtree | (lookahead >> 9)]; 172 | if ((symbol & 15) <= bits) { 173 | input.DropBits(symbol & 15); 174 | return symbol >> 4; 175 | } else { 176 | return -1; 177 | } 178 | } 179 | } else { 180 | int bits = input.AvailableBits; 181 | lookahead = input.PeekBits(bits); 182 | symbol = tree[lookahead]; 183 | if (symbol >= 0 && (symbol & 15) <= bits) { 184 | input.DropBits(symbol & 15); 185 | return symbol >> 4; 186 | } else { 187 | return -1; 188 | } 189 | } 190 | } 191 | } 192 | } 193 | 194 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/Compression/PendingBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ICSharpCode.SharpZipLib.Zip.Compression 4 | { 5 | /// 6 | /// This class is general purpose class for writing data to a buffer. 7 | /// 8 | /// It allows you to write bits as well as bytes 9 | /// Based on DeflaterPending.java 10 | /// 11 | /// author of the original java version : Jochen Hoenicke 12 | /// 13 | public class PendingBuffer 14 | { 15 | readonly 16 | #region Instance Fields 17 | /// 18 | /// Internal work buffer 19 | /// 20 | byte[] buffer_; 21 | 22 | int start; 23 | int end; 24 | 25 | uint bits; 26 | int bitCount; 27 | #endregion 28 | 29 | #region Constructors 30 | /// 31 | /// construct instance using default buffer size of 4096 32 | /// 33 | public PendingBuffer() : this(4096) 34 | { 35 | } 36 | 37 | /// 38 | /// construct instance using specified buffer size 39 | /// 40 | /// 41 | /// size to use for internal buffer 42 | /// 43 | public PendingBuffer(int bufferSize) 44 | { 45 | buffer_ = new byte[bufferSize]; 46 | } 47 | 48 | #endregion 49 | 50 | /// 51 | /// Clear internal state/buffers 52 | /// 53 | public void Reset() 54 | { 55 | start = end = bitCount = 0; 56 | } 57 | 58 | /// 59 | /// Write a byte to buffer 60 | /// 61 | /// 62 | /// The value to write 63 | /// 64 | public void WriteByte(int value) 65 | { 66 | #if DebugDeflation 67 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 68 | { 69 | throw new SharpZipBaseException("Debug check: start != 0"); 70 | } 71 | #endif 72 | buffer_[end++] = unchecked((byte)value); 73 | } 74 | 75 | /// 76 | /// Write a short value to buffer LSB first 77 | /// 78 | /// 79 | /// The value to write. 80 | /// 81 | public void WriteShort(int value) 82 | { 83 | #if DebugDeflation 84 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 85 | { 86 | throw new SharpZipBaseException("Debug check: start != 0"); 87 | } 88 | #endif 89 | buffer_[end++] = unchecked((byte)value); 90 | buffer_[end++] = unchecked((byte)(value >> 8)); 91 | } 92 | 93 | /// 94 | /// write an integer LSB first 95 | /// 96 | /// The value to write. 97 | public void WriteInt(int value) 98 | { 99 | #if DebugDeflation 100 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 101 | { 102 | throw new SharpZipBaseException("Debug check: start != 0"); 103 | } 104 | #endif 105 | buffer_[end++] = unchecked((byte)value); 106 | buffer_[end++] = unchecked((byte)(value >> 8)); 107 | buffer_[end++] = unchecked((byte)(value >> 16)); 108 | buffer_[end++] = unchecked((byte)(value >> 24)); 109 | } 110 | 111 | /// 112 | /// Write a block of data to buffer 113 | /// 114 | /// data to write 115 | /// offset of first byte to write 116 | /// number of bytes to write 117 | public void WriteBlock(byte[] block, int offset, int length) 118 | { 119 | #if DebugDeflation 120 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 121 | { 122 | throw new SharpZipBaseException("Debug check: start != 0"); 123 | } 124 | #endif 125 | System.Array.Copy(block, offset, buffer_, end, length); 126 | end += length; 127 | } 128 | 129 | /// 130 | /// The number of bits written to the buffer 131 | /// 132 | public int BitCount { 133 | get { 134 | return bitCount; 135 | } 136 | } 137 | 138 | /// 139 | /// Align internal buffer on a byte boundary 140 | /// 141 | public void AlignToByte() 142 | { 143 | #if DebugDeflation 144 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 145 | { 146 | throw new SharpZipBaseException("Debug check: start != 0"); 147 | } 148 | #endif 149 | if (bitCount > 0) { 150 | buffer_[end++] = unchecked((byte)bits); 151 | if (bitCount > 8) { 152 | buffer_[end++] = unchecked((byte)(bits >> 8)); 153 | } 154 | } 155 | bits = 0; 156 | bitCount = 0; 157 | } 158 | 159 | /// 160 | /// Write bits to internal buffer 161 | /// 162 | /// source of bits 163 | /// number of bits to write 164 | public void WriteBits(int b, int count) 165 | { 166 | #if DebugDeflation 167 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 168 | { 169 | throw new SharpZipBaseException("Debug check: start != 0"); 170 | } 171 | 172 | // if (DeflaterConstants.DEBUGGING) { 173 | // //Console.WriteLine("writeBits("+b+","+count+")"); 174 | // } 175 | #endif 176 | bits |= (uint)(b << bitCount); 177 | bitCount += count; 178 | if (bitCount >= 16) { 179 | buffer_[end++] = unchecked((byte)bits); 180 | buffer_[end++] = unchecked((byte)(bits >> 8)); 181 | bits >>= 16; 182 | bitCount -= 16; 183 | } 184 | } 185 | 186 | /// 187 | /// Write a short value to internal buffer most significant byte first 188 | /// 189 | /// value to write 190 | public void WriteShortMSB(int s) 191 | { 192 | #if DebugDeflation 193 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 194 | { 195 | throw new SharpZipBaseException("Debug check: start != 0"); 196 | } 197 | #endif 198 | buffer_[end++] = unchecked((byte)(s >> 8)); 199 | buffer_[end++] = unchecked((byte)s); 200 | } 201 | 202 | /// 203 | /// Indicates if buffer has been flushed 204 | /// 205 | public bool IsFlushed { 206 | get { 207 | return end == 0; 208 | } 209 | } 210 | 211 | /// 212 | /// Flushes the pending buffer into the given output array. If the 213 | /// output array is to small, only a partial flush is done. 214 | /// 215 | /// The output array. 216 | /// The offset into output array. 217 | /// The maximum number of bytes to store. 218 | /// The number of bytes flushed. 219 | public int Flush(byte[] output, int offset, int length) 220 | { 221 | if (bitCount >= 8) { 222 | buffer_[end++] = unchecked((byte)bits); 223 | bits >>= 8; 224 | bitCount -= 8; 225 | } 226 | 227 | if (length > end - start) { 228 | length = end - start; 229 | System.Array.Copy(buffer_, start, output, offset, length); 230 | start = 0; 231 | end = 0; 232 | } else { 233 | System.Array.Copy(buffer_, start, output, offset, length); 234 | start += length; 235 | } 236 | return length; 237 | } 238 | 239 | /// 240 | /// Convert internal buffer to byte array. 241 | /// Buffer is empty on completion 242 | /// 243 | /// 244 | /// The internal buffer contents converted to a byte array. 245 | /// 246 | public byte[] ToByteArray() 247 | { 248 | AlignToByte(); 249 | 250 | byte[] result = new byte[end - start]; 251 | System.Array.Copy(buffer_, start, result, 0, result.Length); 252 | start = 0; 253 | end = 0; 254 | return result; 255 | } 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/Compression/Streams/OutputWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams 4 | { 5 | /// 6 | /// Contains the output from the Inflation process. 7 | /// We need to have a window so that we can refer backwards into the output stream 8 | /// to repeat stuff.
9 | /// Author of the original java version : John Leuner 10 | ///
11 | public class OutputWindow 12 | { 13 | #region Constants 14 | const int WindowSize = 1 << 15; 15 | const int WindowMask = WindowSize - 1; 16 | #endregion 17 | 18 | #region Instance Fields 19 | byte[] window = new byte[WindowSize]; //The window is 2^15 bytes 20 | int windowEnd; 21 | int windowFilled; 22 | #endregion 23 | 24 | /// 25 | /// Write a byte to this output window 26 | /// 27 | /// value to write 28 | /// 29 | /// if window is full 30 | /// 31 | public void Write(int value) 32 | { 33 | if (windowFilled++ == WindowSize) { 34 | throw new InvalidOperationException("Window full"); 35 | } 36 | window[windowEnd++] = (byte)value; 37 | windowEnd &= WindowMask; 38 | } 39 | 40 | 41 | private void SlowRepeat(int repStart, int length, int distance) 42 | { 43 | while (length-- > 0) { 44 | window[windowEnd++] = window[repStart++]; 45 | windowEnd &= WindowMask; 46 | repStart &= WindowMask; 47 | } 48 | } 49 | 50 | /// 51 | /// Append a byte pattern already in the window itself 52 | /// 53 | /// length of pattern to copy 54 | /// distance from end of window pattern occurs 55 | /// 56 | /// If the repeated data overflows the window 57 | /// 58 | public void Repeat(int length, int distance) 59 | { 60 | if ((windowFilled += length) > WindowSize) { 61 | throw new InvalidOperationException("Window full"); 62 | } 63 | 64 | int repStart = (windowEnd - distance) & WindowMask; 65 | int border = WindowSize - length; 66 | if ((repStart <= border) && (windowEnd < border)) { 67 | if (length <= distance) { 68 | System.Array.Copy(window, repStart, window, windowEnd, length); 69 | windowEnd += length; 70 | } else { 71 | // We have to copy manually, since the repeat pattern overlaps. 72 | while (length-- > 0) { 73 | window[windowEnd++] = window[repStart++]; 74 | } 75 | } 76 | } else { 77 | SlowRepeat(repStart, length, distance); 78 | } 79 | } 80 | 81 | /// 82 | /// Copy from input manipulator to internal window 83 | /// 84 | /// source of data 85 | /// length of data to copy 86 | /// the number of bytes copied 87 | public int CopyStored(StreamManipulator input, int length) 88 | { 89 | length = Math.Min(Math.Min(length, WindowSize - windowFilled), input.AvailableBytes); 90 | int copied; 91 | 92 | int tailLen = WindowSize - windowEnd; 93 | if (length > tailLen) { 94 | copied = input.CopyBytes(window, windowEnd, tailLen); 95 | if (copied == tailLen) { 96 | copied += input.CopyBytes(window, 0, length - tailLen); 97 | } 98 | } else { 99 | copied = input.CopyBytes(window, windowEnd, length); 100 | } 101 | 102 | windowEnd = (windowEnd + copied) & WindowMask; 103 | windowFilled += copied; 104 | return copied; 105 | } 106 | 107 | /// 108 | /// Copy dictionary to window 109 | /// 110 | /// source dictionary 111 | /// offset of start in source dictionary 112 | /// length of dictionary 113 | /// 114 | /// If window isnt empty 115 | /// 116 | public void CopyDict(byte[] dictionary, int offset, int length) 117 | { 118 | if (dictionary == null) { 119 | throw new ArgumentNullException(nameof(dictionary)); 120 | } 121 | 122 | if (windowFilled > 0) { 123 | throw new InvalidOperationException(); 124 | } 125 | 126 | if (length > WindowSize) { 127 | offset += length - WindowSize; 128 | length = WindowSize; 129 | } 130 | System.Array.Copy(dictionary, offset, window, 0, length); 131 | windowEnd = length & WindowMask; 132 | } 133 | 134 | /// 135 | /// Get remaining unfilled space in window 136 | /// 137 | /// Number of bytes left in window 138 | public int GetFreeSpace() 139 | { 140 | return WindowSize - windowFilled; 141 | } 142 | 143 | /// 144 | /// Get bytes available for output in window 145 | /// 146 | /// Number of bytes filled 147 | public int GetAvailable() 148 | { 149 | return windowFilled; 150 | } 151 | 152 | /// 153 | /// Copy contents of window to output 154 | /// 155 | /// buffer to copy to 156 | /// offset to start at 157 | /// number of bytes to count 158 | /// The number of bytes copied 159 | /// 160 | /// If a window underflow occurs 161 | /// 162 | public int CopyOutput(byte[] output, int offset, int len) 163 | { 164 | int copyEnd = windowEnd; 165 | if (len > windowFilled) { 166 | len = windowFilled; 167 | } else { 168 | copyEnd = (windowEnd - windowFilled + len) & WindowMask; 169 | } 170 | 171 | int copied = len; 172 | int tailLen = len - copyEnd; 173 | 174 | if (tailLen > 0) { 175 | System.Array.Copy(window, WindowSize - tailLen, output, offset, tailLen); 176 | offset += tailLen; 177 | len = copyEnd; 178 | } 179 | System.Array.Copy(window, copyEnd - len, output, offset, len); 180 | windowFilled -= copied; 181 | if (windowFilled < 0) { 182 | throw new InvalidOperationException(); 183 | } 184 | return copied; 185 | } 186 | 187 | /// 188 | /// Reset by clearing window so GetAvailable returns 0 189 | /// 190 | public void Reset() 191 | { 192 | windowFilled = windowEnd = 0; 193 | } 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/Compression/Streams/StreamManipulator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams 4 | { 5 | /// 6 | /// This class allows us to retrieve a specified number of bits from 7 | /// the input buffer, as well as copy big byte blocks. 8 | /// 9 | /// It uses an int buffer to store up to 31 bits for direct 10 | /// manipulation. This guarantees that we can get at least 16 bits, 11 | /// but we only need at most 15, so this is all safe. 12 | /// 13 | /// There are some optimizations in this class, for example, you must 14 | /// never peek more than 8 bits more than needed, and you must first 15 | /// peek bits before you may drop them. This is not a general purpose 16 | /// class but optimized for the behaviour of the Inflater. 17 | /// 18 | /// authors of the original java version : John Leuner, Jochen Hoenicke 19 | /// 20 | public class StreamManipulator 21 | { 22 | /// 23 | /// Get the next sequence of bits but don't increase input pointer. bitCount must be 24 | /// less or equal 16 and if this call succeeds, you must drop 25 | /// at least n - 8 bits in the next call. 26 | /// 27 | /// The number of bits to peek. 28 | /// 29 | /// the value of the bits, or -1 if not enough bits available. */ 30 | /// 31 | public int PeekBits(int bitCount) 32 | { 33 | if (bitsInBuffer_ < bitCount) { 34 | if (windowStart_ == windowEnd_) { 35 | return -1; // ok 36 | } 37 | buffer_ |= (uint)((window_[windowStart_++] & 0xff | 38 | (window_[windowStart_++] & 0xff) << 8) << bitsInBuffer_); 39 | bitsInBuffer_ += 16; 40 | } 41 | return (int)(buffer_ & ((1 << bitCount) - 1)); 42 | } 43 | 44 | /// 45 | /// Drops the next n bits from the input. You should have called PeekBits 46 | /// with a bigger or equal n before, to make sure that enough bits are in 47 | /// the bit buffer. 48 | /// 49 | /// The number of bits to drop. 50 | public void DropBits(int bitCount) 51 | { 52 | buffer_ >>= bitCount; 53 | bitsInBuffer_ -= bitCount; 54 | } 55 | 56 | /// 57 | /// Gets the next n bits and increases input pointer. This is equivalent 58 | /// to followed by , except for correct error handling. 59 | /// 60 | /// The number of bits to retrieve. 61 | /// 62 | /// the value of the bits, or -1 if not enough bits available. 63 | /// 64 | public int GetBits(int bitCount) 65 | { 66 | int bits = PeekBits(bitCount); 67 | if (bits >= 0) { 68 | DropBits(bitCount); 69 | } 70 | return bits; 71 | } 72 | 73 | /// 74 | /// Gets the number of bits available in the bit buffer. This must be 75 | /// only called when a previous PeekBits() returned -1. 76 | /// 77 | /// 78 | /// the number of bits available. 79 | /// 80 | public int AvailableBits { 81 | get { 82 | return bitsInBuffer_; 83 | } 84 | } 85 | 86 | /// 87 | /// Gets the number of bytes available. 88 | /// 89 | /// 90 | /// The number of bytes available. 91 | /// 92 | public int AvailableBytes { 93 | get { 94 | return windowEnd_ - windowStart_ + (bitsInBuffer_ >> 3); 95 | } 96 | } 97 | 98 | /// 99 | /// Skips to the next byte boundary. 100 | /// 101 | public void SkipToByteBoundary() 102 | { 103 | buffer_ >>= (bitsInBuffer_ & 7); 104 | bitsInBuffer_ &= ~7; 105 | } 106 | 107 | /// 108 | /// Returns true when SetInput can be called 109 | /// 110 | public bool IsNeedingInput { 111 | get { 112 | return windowStart_ == windowEnd_; 113 | } 114 | } 115 | 116 | /// 117 | /// Copies bytes from input buffer to output buffer starting 118 | /// at output[offset]. You have to make sure, that the buffer is 119 | /// byte aligned. If not enough bytes are available, copies fewer 120 | /// bytes. 121 | /// 122 | /// 123 | /// The buffer to copy bytes to. 124 | /// 125 | /// 126 | /// The offset in the buffer at which copying starts 127 | /// 128 | /// 129 | /// The length to copy, 0 is allowed. 130 | /// 131 | /// 132 | /// The number of bytes copied, 0 if no bytes were available. 133 | /// 134 | /// 135 | /// Length is less than zero 136 | /// 137 | /// 138 | /// Bit buffer isnt byte aligned 139 | /// 140 | public int CopyBytes(byte[] output, int offset, int length) 141 | { 142 | if (length < 0) { 143 | throw new ArgumentOutOfRangeException(nameof(length)); 144 | } 145 | 146 | if ((bitsInBuffer_ & 7) != 0) { 147 | // bits_in_buffer may only be 0 or a multiple of 8 148 | throw new InvalidOperationException("Bit buffer is not byte aligned!"); 149 | } 150 | 151 | int count = 0; 152 | while ((bitsInBuffer_ > 0) && (length > 0)) { 153 | output[offset++] = (byte)buffer_; 154 | buffer_ >>= 8; 155 | bitsInBuffer_ -= 8; 156 | length--; 157 | count++; 158 | } 159 | 160 | if (length == 0) { 161 | return count; 162 | } 163 | 164 | int avail = windowEnd_ - windowStart_; 165 | if (length > avail) { 166 | length = avail; 167 | } 168 | System.Array.Copy(window_, windowStart_, output, offset, length); 169 | windowStart_ += length; 170 | 171 | if (((windowStart_ - windowEnd_) & 1) != 0) { 172 | // We always want an even number of bytes in input, see peekBits 173 | buffer_ = (uint)(window_[windowStart_++] & 0xff); 174 | bitsInBuffer_ = 8; 175 | } 176 | return count + length; 177 | } 178 | 179 | /// 180 | /// Resets state and empties internal buffers 181 | /// 182 | public void Reset() 183 | { 184 | buffer_ = 0; 185 | windowStart_ = windowEnd_ = bitsInBuffer_ = 0; 186 | } 187 | 188 | /// 189 | /// Add more input for consumption. 190 | /// Only call when IsNeedingInput returns true 191 | /// 192 | /// data to be input 193 | /// offset of first byte of input 194 | /// number of bytes of input to add. 195 | public void SetInput(byte[] buffer, int offset, int count) 196 | { 197 | if (buffer == null) { 198 | throw new ArgumentNullException(nameof(buffer)); 199 | } 200 | 201 | if (offset < 0) { 202 | throw new ArgumentOutOfRangeException(nameof(offset), "Cannot be negative"); 203 | } 204 | 205 | if (count < 0) { 206 | throw new ArgumentOutOfRangeException(nameof(count), "Cannot be negative"); 207 | } 208 | 209 | if (windowStart_ < windowEnd_) { 210 | throw new InvalidOperationException("Old input was not completely processed"); 211 | } 212 | 213 | int end = offset + count; 214 | 215 | // We want to throw an ArrayIndexOutOfBoundsException early. 216 | // Note the check also handles integer wrap around. 217 | if ((offset > end) || (end > buffer.Length)) { 218 | throw new ArgumentOutOfRangeException(nameof(count)); 219 | } 220 | 221 | if ((count & 1) != 0) { 222 | // We always want an even number of bytes in input, see PeekBits 223 | buffer_ |= (uint)((buffer[offset++] & 0xff) << bitsInBuffer_); 224 | bitsInBuffer_ += 8; 225 | } 226 | 227 | window_ = buffer; 228 | windowStart_ = offset; 229 | windowEnd_ = end; 230 | } 231 | 232 | #region Instance Fields 233 | private byte[] window_; 234 | private int windowStart_; 235 | private int windowEnd_; 236 | 237 | private uint buffer_; 238 | private int bitsInBuffer_; 239 | #endregion 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/IEntryFactory.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.SharpZipLib.Core; 2 | 3 | namespace ICSharpCode.SharpZipLib.Zip 4 | { 5 | /// 6 | /// Defines factory methods for creating new values. 7 | /// 8 | public interface IEntryFactory 9 | { 10 | /// 11 | /// Create a for a file given its name 12 | /// 13 | /// The name of the file to create an entry for. 14 | /// Returns a file entry based on the passed. 15 | ZipEntry MakeFileEntry(string fileName); 16 | 17 | /// 18 | /// Create a for a file given its name 19 | /// 20 | /// The name of the file to create an entry for. 21 | /// If true get details from the file system if the file exists. 22 | /// Returns a file entry based on the passed. 23 | ZipEntry MakeFileEntry(string fileName, bool useFileSystem); 24 | 25 | /// 26 | /// Create a for a file given its actual name and optional override name 27 | /// 28 | /// The name of the file to create an entry for. 29 | /// An alternative name to be used for the new entry. Null if not applicable. 30 | /// If true get details from the file system if the file exists. 31 | /// Returns a file entry based on the passed. 32 | ZipEntry MakeFileEntry(string fileName, string entryName, bool useFileSystem); 33 | 34 | /// 35 | /// Create a for a directory given its name 36 | /// 37 | /// The name of the directory to create an entry for. 38 | /// Returns a directory entry based on the passed. 39 | ZipEntry MakeDirectoryEntry(string directoryName); 40 | 41 | /// 42 | /// Create a for a directory given its name 43 | /// 44 | /// The name of the directory to create an entry for. 45 | /// If true get details from the file system for this directory if it exists. 46 | /// Returns a directory entry based on the passed. 47 | ZipEntry MakeDirectoryEntry(string directoryName, bool useFileSystem); 48 | 49 | /// 50 | /// Get/set the applicable. 51 | /// 52 | INameTransform NameTransform { get; set; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/WindowsNameTransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using ICSharpCode.SharpZipLib.Core; 5 | 6 | namespace ICSharpCode.SharpZipLib.Zip 7 | { 8 | /// 9 | /// WindowsNameTransform transforms names to windows compatible ones. 10 | /// 11 | public class WindowsNameTransform : INameTransform 12 | { 13 | /// 14 | /// Initialises a new instance of 15 | /// 16 | /// 17 | public WindowsNameTransform(string baseDirectory) 18 | { 19 | if (baseDirectory == null) { 20 | throw new ArgumentNullException(nameof(baseDirectory), "Directory name is invalid"); 21 | } 22 | 23 | BaseDirectory = baseDirectory; 24 | } 25 | 26 | /// 27 | /// Initialise a default instance of 28 | /// 29 | public WindowsNameTransform() 30 | { 31 | // Do nothing. 32 | } 33 | 34 | /// 35 | /// Gets or sets a value containing the target directory to prefix values with. 36 | /// 37 | public string BaseDirectory { 38 | get { return _baseDirectory; } 39 | set { 40 | if (value == null) { 41 | throw new ArgumentNullException(nameof(value)); 42 | } 43 | 44 | _baseDirectory = Path.GetFullPath(value); 45 | } 46 | } 47 | 48 | /// 49 | /// Gets or sets a value indicating wether paths on incoming values should be removed. 50 | /// 51 | public bool TrimIncomingPaths { 52 | get { return _trimIncomingPaths; } 53 | set { _trimIncomingPaths = value; } 54 | } 55 | 56 | /// 57 | /// Transform a Zip directory name to a windows directory name. 58 | /// 59 | /// The directory name to transform. 60 | /// The transformed name. 61 | public string TransformDirectory(string name) 62 | { 63 | name = TransformFile(name); 64 | if (name.Length > 0) { 65 | while (name.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) { 66 | name = name.Remove(name.Length - 1, 1); 67 | } 68 | } else { 69 | throw new ZipException("Cannot have an empty directory name"); 70 | } 71 | return name; 72 | } 73 | 74 | /// 75 | /// Transform a Zip format file name to a windows style one. 76 | /// 77 | /// The file name to transform. 78 | /// The transformed name. 79 | public string TransformFile(string name) 80 | { 81 | if (name != null) { 82 | name = MakeValidName(name, _replacementChar); 83 | 84 | if (_trimIncomingPaths) { 85 | name = Path.GetFileName(name); 86 | } 87 | 88 | // This may exceed windows length restrictions. 89 | // Combine will throw a PathTooLongException in that case. 90 | if (_baseDirectory != null) { 91 | name = Path.Combine(_baseDirectory, name); 92 | } 93 | } else { 94 | name = string.Empty; 95 | } 96 | return name; 97 | } 98 | 99 | /// 100 | /// Test a name to see if it is a valid name for a windows filename as extracted from a Zip archive. 101 | /// 102 | /// The name to test. 103 | /// Returns true if the name is a valid zip name; false otherwise. 104 | /// The filename isnt a true windows path in some fundamental ways like no absolute paths, no rooted paths etc. 105 | public static bool IsValidName(string name) 106 | { 107 | bool result = 108 | (name != null) && 109 | (name.Length <= MaxPath) && 110 | (string.Compare(name, MakeValidName(name, '_'), StringComparison.Ordinal) == 0) 111 | ; 112 | 113 | return result; 114 | } 115 | 116 | /// 117 | /// Initialise static class information. 118 | /// 119 | static WindowsNameTransform() 120 | { 121 | char[] invalidPathChars; 122 | 123 | invalidPathChars = Path.GetInvalidPathChars(); 124 | int howMany = invalidPathChars.Length + 3; 125 | 126 | InvalidEntryChars = new char[howMany]; 127 | Array.Copy(invalidPathChars, 0, InvalidEntryChars, 0, invalidPathChars.Length); 128 | InvalidEntryChars[howMany - 1] = '*'; 129 | InvalidEntryChars[howMany - 2] = '?'; 130 | InvalidEntryChars[howMany - 3] = ':'; 131 | } 132 | 133 | /// 134 | /// Force a name to be valid by replacing invalid characters with a fixed value 135 | /// 136 | /// The name to make valid 137 | /// The replacement character to use for any invalid characters. 138 | /// Returns a valid name 139 | public static string MakeValidName(string name, char replacement) 140 | { 141 | if (name == null) { 142 | throw new ArgumentNullException(nameof(name)); 143 | } 144 | 145 | name = WindowsPathUtils.DropPathRoot(name.Replace("/", Path.DirectorySeparatorChar.ToString())); 146 | 147 | // Drop any leading slashes. 148 | while ((name.Length > 0) && (name[0] == Path.DirectorySeparatorChar)) { 149 | name = name.Remove(0, 1); 150 | } 151 | 152 | // Drop any trailing slashes. 153 | while ((name.Length > 0) && (name[name.Length - 1] == Path.DirectorySeparatorChar)) { 154 | name = name.Remove(name.Length - 1, 1); 155 | } 156 | 157 | // Convert consecutive \\ characters to \ 158 | int index = name.IndexOf(string.Format("{0}{0}", Path.DirectorySeparatorChar), StringComparison.Ordinal); 159 | while (index >= 0) { 160 | name = name.Remove(index, 1); 161 | index = name.IndexOf(string.Format("{0}{0}", Path.DirectorySeparatorChar), StringComparison.Ordinal); 162 | } 163 | 164 | // Convert any invalid characters using the replacement one. 165 | index = name.IndexOfAny(InvalidEntryChars); 166 | if (index >= 0) { 167 | var builder = new StringBuilder(name); 168 | 169 | while (index >= 0) { 170 | builder[index] = replacement; 171 | 172 | if (index >= name.Length) { 173 | index = -1; 174 | } else { 175 | index = name.IndexOfAny(InvalidEntryChars, index + 1); 176 | } 177 | } 178 | name = builder.ToString(); 179 | } 180 | 181 | // Check for names greater than MaxPath characters. 182 | // TODO: Were is CLR version of MaxPath defined? Can't find it in Environment. 183 | if (name.Length > MaxPath) { 184 | throw new PathTooLongException(); 185 | } 186 | 187 | return name; 188 | } 189 | 190 | /// 191 | /// Gets or set the character to replace invalid characters during transformations. 192 | /// 193 | public char Replacement { 194 | get { return _replacementChar; } 195 | set { 196 | for (int i = 0; i < InvalidEntryChars.Length; ++i) { 197 | if (InvalidEntryChars[i] == value) { 198 | throw new ArgumentException("invalid path character"); 199 | } 200 | } 201 | 202 | if ((value == Path.DirectorySeparatorChar) || (value == Path.AltDirectorySeparatorChar)) { 203 | throw new ArgumentException("invalid replacement character"); 204 | } 205 | 206 | _replacementChar = value; 207 | } 208 | } 209 | 210 | /// 211 | /// The maximum windows path name permitted. 212 | /// 213 | /// This may not valid for all windows systems - CE?, etc but I cant find the equivalent in the CLR. 214 | const int MaxPath = 260; 215 | 216 | #region Instance Fields 217 | string _baseDirectory; 218 | bool _trimIncomingPaths; 219 | char _replacementChar = '_'; 220 | #endregion 221 | 222 | #region Class Fields 223 | static readonly char[] InvalidEntryChars; 224 | #endregion 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/ZipException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace ICSharpCode.SharpZipLib.Zip 5 | { 6 | /// 7 | /// ZipException represents exceptions specific to Zip classes and code. 8 | /// 9 | [Serializable] 10 | public class ZipException : SharpZipBaseException 11 | { 12 | /// 13 | /// Deserialization constructor 14 | /// 15 | /// for this constructor 16 | /// for this constructor 17 | protected ZipException(SerializationInfo info, StreamingContext context) 18 | : base(info, context) 19 | { 20 | } 21 | 22 | /// 23 | /// Initialise a new instance of . 24 | /// 25 | public ZipException() 26 | { 27 | } 28 | 29 | /// 30 | /// Initialise a new instance of with its message string. 31 | /// 32 | /// A that describes the error. 33 | public ZipException(string message) 34 | : base(message) 35 | { 36 | } 37 | 38 | /// 39 | /// Initialise a new instance of . 40 | /// 41 | /// A that describes the error. 42 | /// The that caused this exception. 43 | public ZipException(string message, Exception innerException) 44 | : base(message, innerException) 45 | { 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/Zip/ZipNameTransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using ICSharpCode.SharpZipLib.Core; 5 | 6 | namespace ICSharpCode.SharpZipLib.Zip 7 | { 8 | /// 9 | /// ZipNameTransform transforms names as per the Zip file naming convention. 10 | /// 11 | /// The use of absolute names is supported although its use is not valid 12 | /// according to Zip naming conventions, and should not be used if maximum compatability is desired. 13 | public class ZipNameTransform : INameTransform 14 | { 15 | #region Constructors 16 | /// 17 | /// Initialize a new instance of 18 | /// 19 | public ZipNameTransform() 20 | { 21 | } 22 | 23 | /// 24 | /// Initialize a new instance of 25 | /// 26 | /// The string to trim from the front of paths if found. 27 | public ZipNameTransform(string trimPrefix) 28 | { 29 | TrimPrefix = trimPrefix; 30 | } 31 | #endregion 32 | 33 | /// 34 | /// Static constructor. 35 | /// 36 | static ZipNameTransform() 37 | { 38 | char[] invalidPathChars; 39 | invalidPathChars = Path.GetInvalidPathChars(); 40 | int howMany = invalidPathChars.Length + 2; 41 | 42 | InvalidEntryCharsRelaxed = new char[howMany]; 43 | Array.Copy(invalidPathChars, 0, InvalidEntryCharsRelaxed, 0, invalidPathChars.Length); 44 | InvalidEntryCharsRelaxed[howMany - 1] = '*'; 45 | InvalidEntryCharsRelaxed[howMany - 2] = '?'; 46 | 47 | howMany = invalidPathChars.Length + 4; 48 | InvalidEntryChars = new char[howMany]; 49 | Array.Copy(invalidPathChars, 0, InvalidEntryChars, 0, invalidPathChars.Length); 50 | InvalidEntryChars[howMany - 1] = ':'; 51 | InvalidEntryChars[howMany - 2] = '\\'; 52 | InvalidEntryChars[howMany - 3] = '*'; 53 | InvalidEntryChars[howMany - 4] = '?'; 54 | } 55 | 56 | /// 57 | /// Transform a windows directory name according to the Zip file naming conventions. 58 | /// 59 | /// The directory name to transform. 60 | /// The transformed name. 61 | public string TransformDirectory(string name) 62 | { 63 | name = TransformFile(name); 64 | if (name.Length > 0) { 65 | if (!name.EndsWith("/", StringComparison.Ordinal)) { 66 | name += "/"; 67 | } 68 | } else { 69 | throw new ZipException("Cannot have an empty directory name"); 70 | } 71 | return name; 72 | } 73 | 74 | /// 75 | /// Transform a windows file name according to the Zip file naming conventions. 76 | /// 77 | /// The file name to transform. 78 | /// The transformed name. 79 | public string TransformFile(string name) 80 | { 81 | if (name != null) { 82 | string lowerName = name.ToLower(); 83 | if ((trimPrefix_ != null) && (lowerName.IndexOf(trimPrefix_, StringComparison.Ordinal) == 0)) { 84 | name = name.Substring(trimPrefix_.Length); 85 | } 86 | 87 | name = name.Replace(@"\", "/"); 88 | name = WindowsPathUtils.DropPathRoot(name); 89 | 90 | // Drop any leading slashes. 91 | while ((name.Length > 0) && (name[0] == '/')) { 92 | name = name.Remove(0, 1); 93 | } 94 | 95 | // Drop any trailing slashes. 96 | while ((name.Length > 0) && (name[name.Length - 1] == '/')) { 97 | name = name.Remove(name.Length - 1, 1); 98 | } 99 | 100 | // Convert consecutive // characters to / 101 | int index = name.IndexOf("//", StringComparison.Ordinal); 102 | while (index >= 0) { 103 | name = name.Remove(index, 1); 104 | index = name.IndexOf("//", StringComparison.Ordinal); 105 | } 106 | 107 | name = MakeValidName(name, '_'); 108 | } else { 109 | name = string.Empty; 110 | } 111 | return name; 112 | } 113 | 114 | /// 115 | /// Get/set the path prefix to be trimmed from paths if present. 116 | /// 117 | /// The prefix is trimmed before any conversion from 118 | /// a windows path is done. 119 | public string TrimPrefix { 120 | get { return trimPrefix_; } 121 | set { 122 | trimPrefix_ = value; 123 | if (trimPrefix_ != null) { 124 | trimPrefix_ = trimPrefix_.ToLower(); 125 | } 126 | } 127 | } 128 | 129 | /// 130 | /// Force a name to be valid by replacing invalid characters with a fixed value 131 | /// 132 | /// The name to force valid 133 | /// The replacement character to use. 134 | /// Returns a valid name 135 | static string MakeValidName(string name, char replacement) 136 | { 137 | int index = name.IndexOfAny(InvalidEntryChars); 138 | if (index >= 0) { 139 | var builder = new StringBuilder(name); 140 | 141 | while (index >= 0) { 142 | builder[index] = replacement; 143 | 144 | if (index >= name.Length) { 145 | index = -1; 146 | } else { 147 | index = name.IndexOfAny(InvalidEntryChars, index + 1); 148 | } 149 | } 150 | name = builder.ToString(); 151 | } 152 | 153 | if (name.Length > 0xffff) { 154 | throw new PathTooLongException(); 155 | } 156 | 157 | return name; 158 | } 159 | 160 | /// 161 | /// Test a name to see if it is a valid name for a zip entry. 162 | /// 163 | /// The name to test. 164 | /// If true checking is relaxed about windows file names and absolute paths. 165 | /// Returns true if the name is a valid zip name; false otherwise. 166 | /// Zip path names are actually in Unix format, and should only contain relative paths. 167 | /// This means that any path stored should not contain a drive or 168 | /// device letter, or a leading slash. All slashes should forward slashes '/'. 169 | /// An empty name is valid for a file where the input comes from standard input. 170 | /// A null name is not considered valid. 171 | /// 172 | public static bool IsValidName(string name, bool relaxed) 173 | { 174 | bool result = (name != null); 175 | 176 | if (result) { 177 | if (relaxed) { 178 | result = name.IndexOfAny(InvalidEntryCharsRelaxed) < 0; 179 | } else { 180 | result = 181 | (name.IndexOfAny(InvalidEntryChars) < 0) && 182 | (name.IndexOf('/') != 0); 183 | } 184 | } 185 | 186 | return result; 187 | } 188 | 189 | /// 190 | /// Test a name to see if it is a valid name for a zip entry. 191 | /// 192 | /// The name to test. 193 | /// Returns true if the name is a valid zip name; false otherwise. 194 | /// Zip path names are actually in unix format, 195 | /// and should only contain relative paths if a path is present. 196 | /// This means that the path stored should not contain a drive or 197 | /// device letter, or a leading slash. All slashes should forward slashes '/'. 198 | /// An empty name is valid where the input comes from standard input. 199 | /// A null name is not considered valid. 200 | /// 201 | public static bool IsValidName(string name) 202 | { 203 | bool result = 204 | (name != null) && 205 | (name.IndexOfAny(InvalidEntryChars) < 0) && 206 | (name.IndexOf('/') != 0) 207 | ; 208 | return result; 209 | } 210 | 211 | #region Instance Fields 212 | string trimPrefix_; 213 | #endregion 214 | 215 | #region Class Fields 216 | static readonly char[] InvalidEntryChars; 217 | static readonly char[] InvalidEntryCharsRelaxed; 218 | #endregion 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/bin/Debug/Compress.Info.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/bin/Debug/Compress.Info.dll -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/bin/Debug/ICSharpCode.SharpZipLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/bin/Debug/ICSharpCode.SharpZipLib.dll -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/bin/Debug/ICSharpCode.SharpZipLib.dll.lastcodeanalysissucceeded: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/bin/Debug/ICSharpCode.SharpZipLib.dll.lastcodeanalysissucceeded -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/bin/Debug/ICSharpCode.SharpZipLib.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/bin/Debug/ICSharpCode.SharpZipLib.pdb -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/bin/Debug/ICSharpCode.SharpZipLib.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/bin/Debug/ICSharpCode.SharpZipLib.vshost.exe -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/obj/Debug/ICSharpCode.SharpZipLib.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | d99b20307bdc132f9a676a7c6a2eb976d1c96883 2 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/obj/Debug/ICSharpCode.SharpZipLib.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\Users\zhangyx_xyz\Desktop\icsharpcode-SharpZipLib-41c14c5\bin\Debug\ICSharpCode.SharpZipLib.xml 2 | C:\Users\zhangyx_xyz\Desktop\icsharpcode-SharpZipLib-41c14c5\bin\Debug\ICSharpCode.SharpZipLib.pdb 3 | C:\Users\zhangyx_xyz\Desktop\icsharpcode-SharpZipLib-41c14c5\ICSharpCode.SharpZipLib\obj\Debug\ICSharpCode.SharpZipLib.pdb 4 | C:\Users\zhangyx_xyz\Desktop\icsharpcode-SharpZipLib-41c14c5\bin\Debug\ICSharpCode.SharpZipLib.dll 5 | C:\Users\zhangyx_xyz\Desktop\icsharpcode-SharpZipLib-41c14c5\bin\Debug\ICSharpCode.SharpZipLib.dll.CodeAnalysisLog.xml 6 | C:\Users\zhangyx_xyz\Desktop\icsharpcode-SharpZipLib-41c14c5\bin\Debug\ICSharpCode.SharpZipLib.dll.lastcodeanalysissucceeded 7 | C:\Users\zhangyx_xyz\Desktop\icsharpcode-SharpZipLib-41c14c5\ICSharpCode.SharpZipLib\obj\Debug\ICSharpCode.SharpZipLib.dll 8 | C:\Users\zhangyx_xyz\Desktop\icsharpcode-SharpZipLib-41c14c5\ICSharpCode.SharpZipLib\obj\Debug\ICSharpCode.SharpZipLib.csprojResolveAssemblyReference.cache 9 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\ICSharpCode.SharpZipLib\obj\Debug\ICSharpCode.SharpZipLib.csprojResolveAssemblyReference.cache 10 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\ICSharpCode.SharpZipLib\obj\Debug\ICSharpCode.SharpZipLib.dll 11 | C:\Users\Yzlah\Documents\Visual Studio 2013\Projects\Compress\ICSharpCode.SharpZipLib\obj\Debug\ICSharpCode.SharpZipLib.pdb 12 | -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs -------------------------------------------------------------------------------- /ICSharpCode.SharpZipLib/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l2xin/UnityCompressLZMA/077079064acf635e6e882d63787420cc2c95369e/ICSharpCode.SharpZipLib/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityCompressLZMA 2 | 3 | **可以实现Files->UPK->LZMA压缩** 4 | 5 | * LZMA压缩方式:Compress.Info.dll和Compress.LZMA.dll 文件 6 | 7 | * GZip压缩方式:Compress.Info.dll和ICSharpCode.SharpZipLib.dll 文件 8 | 9 | ### 示例 10 | ``` 11 | LZMAFile.CompressAsync(Application.dataPath + "/music.mp3", Application.dataPath + "/music.lzma", null); 12 | GZipFile.CompressAsync(Application.dataPath + "/music.mp3", Application.dataPath + "/music.gzip", null); 13 | LZMAFile.DeCompressAsync(Application.dataPath + "/music.lzma", Application.dataPath + "/lzmamusic.mp3", null); 14 | GZipFile.DeCompressAsync(Application.dataPath + "/music.gzip", Application.dataPath + "/gzipmusic.mp3", null); 15 | 16 | UPKFolder.PackFolderAsync(Application.dataPath + "/picture", Application.dataPath + "/picture.upk", ShowProgress); 17 | UPKFolder.UnPackFolderAsync(Application.dataPath + "/picture.upk", Application.dataPath + "/", ShowProgress); 18 | 19 | void ShowProgress(long all,long now) { 20 | double progress = (double)now /all; 21 | Debug.Log("当前进度为: " + progress); 22 | } 23 | ``` 24 | --------------------------------------------------------------------------------