├── .github └── workflows │ ├── deploy.yml │ └── pr.yml ├── .gitignore ├── SevenZip.Tests ├── FileCheckerTests.cs ├── LibraryManagerTests.cs ├── MiscellaneousTests.cs ├── Properties │ └── AssemblyInfo.cs ├── SevenZip.Tests.csproj ├── SevenZipCompressorAsynchronousTests.cs ├── SevenZipCompressorCustomParameterTests.cs ├── SevenZipCompressorTests.cs ├── SevenZipExtractorAsynchronousTests.cs ├── SevenZipExtractorTests.cs ├── SevenZipTests.snk ├── TestBase.cs ├── TestData │ ├── 7z_LZMA2.7z │ ├── arj.arj │ ├── bzip2.bz2 │ ├── gzip.gz │ ├── long_path.7z │ ├── multiple_files.7z │ ├── multivolume.part0001.rar │ ├── multivolume.part0002.rar │ ├── rar4.rar │ ├── rar5.rar │ ├── tar.tar │ ├── wim.wim │ ├── xz.xz │ └── zip.zip └── TestData_LongerDirectoryName │ └── emptyfile.txt ├── SevenZip.sln ├── SevenZip.sln.DotSettings ├── SevenZip ├── 7z.dll ├── 7z64.dll ├── ArchiveEmulationStreamProxy.cs ├── ArchiveExtractCallback.cs ├── ArchiveFileInfo.cs ├── ArchiveOpenCallback.cs ├── ArchiveProperty.cs ├── ArchiveUpdateCallback.cs ├── COM.cs ├── CallbackBase.cs ├── CompressionMode.cs ├── EventArguments │ ├── ExtractFileCallbackArgs.cs │ ├── ExtractFileCallbackReason.cs │ ├── FileInfoEventArgs.cs │ ├── FileNameEventArgs.cs │ ├── FileOverwriteEventArgs.cs │ ├── IntEventArgs.cs │ ├── OpenEventArgs.cs │ ├── PercentDoneEventArgs.cs │ └── ProgressEventArgs.cs ├── EventSynchronizationStrategy.cs ├── Exceptions │ ├── CompressionFailedException.cs │ ├── ExtractionFailedException.cs │ ├── LzmaException.cs │ ├── SevenZipArchiveException.cs │ ├── SevenZipCompressionFailedException.cs │ ├── SevenZipException.cs │ ├── SevenZipExtractionFailedException.cs │ ├── SevenZipInvalidFileNamesException.cs │ ├── SevenZipLibraryException.cs │ ├── SevenZipOpenFailedException.cs │ └── SevenZipSfxValidationException.cs ├── ExtractFileCallback.cs ├── FileChecker.cs ├── Formats.cs ├── ICancellable.cs ├── InternalCompressionMode.cs ├── LZMA │ ├── LzmaDecodeStream.cs │ ├── LzmaEncodeStream.cs │ └── LzmaProgressCallback.cs ├── LibraryFeature.cs ├── LibraryManager.cs ├── NativeMethods.cs ├── Properties │ └── AssemblyInfo.cs ├── SevenZip.csproj ├── SevenZip.csproj.DotSettings ├── SevenZip.snk ├── SevenZipBase.cs ├── SevenZipCompressor.cs ├── SevenZipCompressorAsynchronous.cs ├── SevenZipExtractor.cs ├── SevenZipExtractorAsynchronous.cs ├── SevenZipSfx.cs ├── StreamWrappers.cs ├── UpdateData.cs ├── ZipEncryptionMethod.cs ├── arch │ ├── Test.bzip2.7z │ ├── Test.lzma.7z │ ├── Test.lzma2.7z │ ├── Test.ppmd.7z │ ├── Test.rar │ ├── Test.tar │ ├── Test.txt │ ├── Test.txt.bz2 │ ├── Test.txt.gz │ ├── Test.txt.xz │ └── Test.zip ├── gpl.txt ├── lgpl.txt ├── sdk │ ├── Common │ │ ├── CRC.cs │ │ ├── InBuffer.cs │ │ └── OutBuffer.cs │ ├── Compress │ │ ├── LZ │ │ │ ├── IMatchFinder.cs │ │ │ ├── LzBinTree.cs │ │ │ ├── LzInWindow.cs │ │ │ └── LzOutWindow.cs │ │ ├── LZMA │ │ │ ├── LzmaBase.cs │ │ │ ├── LzmaDecoder.cs │ │ │ └── LzmaEncoder.cs │ │ └── RangeCoder │ │ │ ├── RangeCoder.cs │ │ │ ├── RangeCoderBit.cs │ │ │ └── RangeCoderBitTree.cs │ └── ICoder.cs └── sfx │ ├── 7z.sfx │ ├── 7zCon.sfx │ ├── 7zS.sfx │ ├── 7zSD.sfx │ ├── 7zxSD_All.sfx │ ├── 7zxSD_All_x64.sfx │ ├── 7zxSD_Deflate.sfx │ ├── 7zxSD_Deflate_x64.sfx │ ├── 7zxSD_LZMA.sfx │ ├── 7zxSD_LZMA2.sfx │ ├── 7zxSD_LZMA2_x64.sfx │ ├── 7zxSD_LZMA_x64.sfx │ ├── 7zxSD_PPMd.sfx │ ├── 7zxSD_PPMd_x64.sfx │ ├── Configs.xml │ ├── Configs.xsd │ ├── Configs.xslt │ └── sample.txt ├── TestApp ├── Program.cs └── TestApp.csproj ├── changelog.md ├── license ├── package.lite.nuspec ├── package.regular.nuspec └── readme.md /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: [ "master" ] 4 | 5 | env: 6 | VERSION: '1.6.1.${{ github.run_number }}' 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: windows-latest 12 | 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v3 16 | with: 17 | fetch-depth: 0 18 | 19 | - name: Install .NET Core 20 | uses: actions/setup-dotnet@v3 21 | with: 22 | dotnet-version: 6.0.x 23 | 24 | - name: Compile solution 25 | run: | 26 | dotnet build -c Release /p:AssemblyVersion=${{ env.VERSION }} /p:Version=${{ env.VERSION }} 27 | dotnet build -c LiteRelease /p:AssemblyVersion=${{ env.VERSION }} /p:Version=${{ env.VERSION }} 28 | 29 | - name: Pack NuGets 30 | run: | 31 | nuget pack package.regular.nuspec -version ${{ env.VERSION }} 32 | nuget pack package.lite.nuspec -version ${{ env.VERSION }} 33 | 34 | - name: Push NuGet packages 35 | run: nuget push Squid-Box.SevenZipSharp*.nupkg -ApiKey ${{ secrets.NUGET_API_KEY }} -Source https://api.nuget.org/v3/index.json 36 | -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: [ "dev" ] 4 | pull_request: 5 | branches: [ "dev", "master" ] 6 | 7 | jobs: 8 | build: 9 | strategy: 10 | matrix: 11 | configuration: [Desktop] 12 | 13 | runs-on: windows-latest 14 | 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v3 18 | with: 19 | fetch-depth: 0 20 | 21 | - name: Install .NET Core 22 | uses: actions/setup-dotnet@v3 23 | with: 24 | dotnet-version: 6.0.x 25 | 26 | - name: Execute unit tests 27 | run: dotnet test -c $env:Configuration 28 | env: 29 | Configuration: ${{ matrix.configuration }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | Backup/ 3 | *.user 4 | /*/bin/** 5 | /*/obj/** 6 | /SevenZip/UpgradeLog.htm 7 | /SevenZip/.vs/** 8 | .vs/** 9 | /packages/** 10 | /[Ss]tage/** 11 | /TestResult.xml 12 | /coverage.xml 13 | *.nupkg -------------------------------------------------------------------------------- /SevenZip.Tests/FileCheckerTests.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Tests 2 | { 3 | using System.Collections.Generic; 4 | using System.IO; 5 | 6 | using SevenZip; 7 | 8 | using NUnit.Framework; 9 | 10 | /// 11 | /// Test data to use for CheckFileSignatureTest. 12 | /// 13 | public struct FileCheckerTestData 14 | { 15 | public FileCheckerTestData(string testDataFilePath, InArchiveFormat expectedFormat) 16 | { 17 | TestDataFilePath = testDataFilePath; 18 | ExpectedFormat = expectedFormat; 19 | } 20 | 21 | /// 22 | /// Format this test expects to find. 23 | /// 24 | public InArchiveFormat ExpectedFormat { get; } 25 | 26 | /// 27 | /// Path to archive file to test against. 28 | /// 29 | public string TestDataFilePath { get; } 30 | 31 | public override string ToString() 32 | { 33 | // Used to get useful test results. 34 | return ExpectedFormat.ToString(); 35 | } 36 | } 37 | 38 | [TestFixture] 39 | public class FileCheckerTests 40 | { 41 | /// 42 | /// Test data for CheckFileSignature test. 43 | /// 44 | public static List TestData = new List 45 | { 46 | new FileCheckerTestData(@"TestData\arj.arj", InArchiveFormat.Arj), 47 | new FileCheckerTestData(@"TestData\bzip2.bz2", InArchiveFormat.BZip2), 48 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Cab), 49 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Chm), 50 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Compound), 51 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Cpio), 52 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Deb), 53 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Dmg), 54 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Elf), 55 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Flv), 56 | new FileCheckerTestData(@"TestData\gzip.gz", InArchiveFormat.GZip), 57 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Hfs), 58 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Iso), 59 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Lzh), 60 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Lzma), 61 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Lzw), 62 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Msi), 63 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Mslz), 64 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Mub), 65 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Nsis), 66 | new FileCheckerTestData(@"TestData\", InArchiveFormat.PE), 67 | new FileCheckerTestData(@"TestData\rar5.rar", InArchiveFormat.Rar), 68 | new FileCheckerTestData(@"TestData\rar4.rar", InArchiveFormat.Rar4), 69 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Rpm), 70 | new FileCheckerTestData(@"TestData\7z_LZMA2.7z", InArchiveFormat.SevenZip), 71 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Split), 72 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Swf), 73 | new FileCheckerTestData(@"TestData\tar.tar", InArchiveFormat.Tar), 74 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Udf), 75 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Vhd), 76 | new FileCheckerTestData(@"TestData\wim.wim", InArchiveFormat.Wim), 77 | new FileCheckerTestData(@"TestData\xz.xz", InArchiveFormat.XZ), 78 | new FileCheckerTestData(@"TestData\", InArchiveFormat.Xar), 79 | new FileCheckerTestData(@"TestData\zip.zip", InArchiveFormat.Zip) 80 | }; 81 | 82 | [SetUp] 83 | public void SetUp() 84 | { 85 | // Ensures we're in the correct working directory (for test data files). 86 | Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); 87 | } 88 | 89 | [TestCaseSource(nameof(TestData))] 90 | public void CheckFileSignatureTest(FileCheckerTestData data) 91 | { 92 | if (!File.Exists(data.TestDataFilePath)) 93 | { 94 | Assert.Ignore("No test data found for this format."); 95 | } 96 | else 97 | { 98 | int ignored; 99 | bool ignored2; 100 | Assert.AreEqual(data.ExpectedFormat, FileChecker.CheckSignature(data.TestDataFilePath, out ignored, out ignored2)); 101 | } 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /SevenZip.Tests/LibraryManagerTests.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Tests 2 | { 3 | using NUnit.Framework; 4 | 5 | [TestFixture] 6 | public class LibraryManagerTests : TestBase 7 | { 8 | [Test] 9 | public void SetNonExistant7zDllLocationTest() 10 | { 11 | Assert.Throws(() => SevenZipLibraryManager.SetLibraryPath("null")); 12 | } 13 | 14 | [Test] 15 | public void CurrentLibraryFeaturesTest() 16 | { 17 | //var features = SevenZipBase.CurrentLibraryFeatures; 18 | 19 | // Exercising more code paths... 20 | //features = SevenZipLibraryManager.CurrentLibraryFeatures; 21 | 22 | //Assert.IsTrue(features.HasFlag(LibraryFeature.ExtractAll)); 23 | //Assert.IsTrue(features.HasFlag(LibraryFeature.CompressAll)); 24 | //Assert.IsTrue(features.HasFlag(LibraryFeature.Modify)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SevenZip.Tests/MiscellaneousTests.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Tests 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using System.IO; 6 | using System.Runtime.Serialization.Formatters.Binary; 7 | using NUnit.Framework; 8 | 9 | using SevenZip; 10 | 11 | [TestFixture] 12 | public class MiscellaneousTests : TestBase 13 | { 14 | [Test] 15 | public void SerializationTest() 16 | { 17 | var argumentException = new ArgumentException("blahblah"); 18 | var binaryFormatter = new BinaryFormatter(); 19 | 20 | using (var ms = new MemoryStream()) 21 | { 22 | using (var fileStream = File.Create(TemporaryFile)) 23 | { 24 | binaryFormatter.Serialize(ms, argumentException); 25 | var compressor = new SevenZipCompressor(); 26 | compressor.CompressStream(ms, fileStream); 27 | } 28 | } 29 | } 30 | 31 | #if SFX 32 | [Test] 33 | public void CreateSfxArchiveTest([Values]SfxModule sfxModule) 34 | { 35 | if (sfxModule.HasFlag(SfxModule.Custom)) 36 | { 37 | Assert.Ignore("No idea how to use SfxModule \"Custom\"."); 38 | } 39 | 40 | var sfxFile = Path.Combine(OutputDirectory, "sfx.exe"); 41 | var sfx = new SevenZipSfx(sfxModule); 42 | var compressor = new SevenZipCompressor {DirectoryStructure = false}; 43 | 44 | compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip"); 45 | 46 | sfx.MakeSfx(TemporaryFile, sfxFile); 47 | 48 | Assert.IsTrue(File.Exists(sfxFile)); 49 | 50 | using (var extractor = new SevenZipExtractor(sfxFile)) 51 | { 52 | Assert.AreEqual(1, extractor.FilesCount); 53 | Assert.AreEqual("zip.zip", extractor.ArchiveFileNames[0]); 54 | } 55 | 56 | if (sfxModule == SfxModule.Installer) 57 | { 58 | // Installer modules need to be run with elevation. 59 | Assert.Pass("Assume SFX installer works..."); 60 | return; 61 | } 62 | 63 | Assert.DoesNotThrow(() => 64 | { 65 | var process = Process.Start(sfxFile); 66 | process?.Kill(); 67 | }); 68 | } 69 | #endif 70 | 71 | [Test] 72 | public void LzmaEncodeDecodeTest() 73 | { 74 | using (var output = new FileStream(TemporaryFile, FileMode.Create)) 75 | { 76 | var encoder = new LzmaEncodeStream(output); 77 | using (var inputSample = new FileStream(@"TestData\zip.zip", FileMode.Open)) 78 | { 79 | int bufSize = 24576, count; 80 | var buf = new byte[bufSize]; 81 | 82 | while ((count = inputSample.Read(buf, 0, bufSize)) > 0) 83 | { 84 | encoder.Write(buf, 0, count); 85 | } 86 | } 87 | 88 | encoder.Close(); 89 | } 90 | 91 | var newZip = Path.Combine(OutputDirectory, "new.zip"); 92 | 93 | using (var input = new FileStream(TemporaryFile, FileMode.Open)) 94 | { 95 | var decoder = new LzmaDecodeStream(input); 96 | using (var output = new FileStream(newZip, FileMode.Create)) 97 | { 98 | 99 | int bufSize = 24576, count; 100 | var buf = new byte[bufSize]; 101 | 102 | while ((count = decoder.Read(buf, 0, bufSize)) > 0) 103 | { 104 | output.Write(buf, 0, count); 105 | } 106 | } 107 | } 108 | 109 | Assert.IsTrue(File.Exists(newZip)); 110 | 111 | using (var extractor = new SevenZipExtractor(newZip)) 112 | { 113 | 114 | Assert.AreEqual(1, extractor.FilesCount); 115 | Assert.AreEqual("zip.txt", extractor.ArchiveFileNames[0]); 116 | } 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /SevenZip.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | // Setting ComVisible to false makes the types in this assembly not visible 4 | // to COM components. If you need to access a type in this assembly from 5 | // COM, set the ComVisible attribute to true on that type. 6 | [assembly: ComVisible(false)] 7 | 8 | // The following GUID is for the ID of the typelib if this project is exposed to COM 9 | [assembly: Guid("67192e62-c7fe-485f-bec4-05734a943faa")] 10 | -------------------------------------------------------------------------------- /SevenZip.Tests/SevenZip.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net6.0 4 | SevenZip.Tests 5 | SevenZipTests 6 | Copyright © Joel Ahlgren 2023 7 | true 8 | SevenZipTests.snk 9 | Debug;Release 10 | x86 11 | 12 | 13 | 14 | 15 | 16 | 17 | true 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | PreserveNewest 29 | 30 | 31 | PreserveNewest 32 | 33 | 34 | PreserveNewest 35 | 36 | 37 | PreserveNewest 38 | 39 | 40 | PreserveNewest 41 | 42 | 43 | PreserveNewest 44 | 45 | 46 | PreserveNewest 47 | 48 | 49 | PreserveNewest 50 | 51 | 52 | PreserveNewest 53 | 54 | 55 | PreserveNewest 56 | 57 | 58 | PreserveNewest 59 | 60 | 61 | PreserveNewest 62 | 63 | 64 | PreserveNewest 65 | 66 | 67 | PreserveNewest 68 | 69 | 70 | PreserveNewest 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /SevenZip.Tests/SevenZipCompressorCustomParameterTests.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Tests 2 | { 3 | using System; 4 | using NUnit.Framework; 5 | 6 | /// 7 | /// See https://sevenzip.osdn.jp/chm/cmdline/switches/method.htm for parameter details. 8 | /// 9 | [TestFixture] 10 | public class SevenZipCompressorCustomParameterTests : TestBase 11 | { 12 | [Test] 13 | public void CompressWithCustomParameters_OnlyWorksWithCorrectMethod() 14 | { 15 | var compressor = new SevenZipCompressor 16 | { 17 | ArchiveFormat = OutArchiveFormat.Zip, 18 | CompressionMethod = CompressionMethod.Lzma 19 | }; 20 | 21 | // Check parameters for PPMd compression. 22 | compressor.CustomParameters.Add("mem", "25"); 23 | Assert.Throws(() => compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip")); 24 | compressor.CustomParameters.Remove("mem"); 25 | compressor.CustomParameters.Add("o", "10"); 26 | Assert.Throws(() => compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip")); 27 | compressor.CustomParameters.Remove("o"); 28 | } 29 | 30 | [Test] 31 | public void InvalidCustomParameters_Throws() 32 | { 33 | var compressor = new SevenZipCompressor 34 | { 35 | ArchiveFormat = OutArchiveFormat.Zip 36 | }; 37 | 38 | compressor.CustomParameters.Add("x", "3"); 39 | Assert.Throws(() => compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip")); 40 | compressor.CustomParameters.Remove("x"); 41 | 42 | compressor.CustomParameters.Add("em", "AES128"); 43 | Assert.Throws(() => compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip")); 44 | } 45 | 46 | [Test] 47 | public void Zip_Deflate_WithCustomParameters() 48 | { 49 | var compressor = new SevenZipCompressor 50 | { 51 | ArchiveFormat = OutArchiveFormat.Zip, 52 | CompressionMethod = CompressionMethod.Deflate 53 | }; 54 | 55 | compressor.CustomParameters.Add("fb", "4"); 56 | compressor.CustomParameters.Add("pass", "4"); 57 | compressor.CustomParameters.Add("mt", "off"); 58 | compressor.CustomParameters.Add("tc", "off"); 59 | compressor.CustomParameters.Add("cl", "on"); 60 | compressor.CustomParameters.Add("cu", "on"); 61 | compressor.CustomParameters.Add("cp", "866"); 62 | 63 | compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip"); 64 | } 65 | 66 | [Test] 67 | public void Zip_Deflate64_WithCustomParameters() 68 | { 69 | var compressor = new SevenZipCompressor 70 | { 71 | ArchiveFormat = OutArchiveFormat.Zip, 72 | CompressionMethod = CompressionMethod.Deflate64 73 | }; 74 | 75 | compressor.CustomParameters.Add("fb", "4"); 76 | compressor.CustomParameters.Add("pass", "4"); 77 | compressor.CustomParameters.Add("mt", "off"); 78 | compressor.CustomParameters.Add("tc", "off"); 79 | compressor.CustomParameters.Add("cl", "on"); 80 | compressor.CustomParameters.Add("cu", "on"); 81 | compressor.CustomParameters.Add("cp", "866"); 82 | 83 | compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip"); 84 | } 85 | 86 | [Test] 87 | public void Zip_PPMd_WithCustomParameters() 88 | { 89 | var compressor = new SevenZipCompressor 90 | { 91 | ArchiveFormat = OutArchiveFormat.Zip, 92 | CompressionMethod = CompressionMethod.Ppmd 93 | }; 94 | 95 | compressor.CustomParameters.Add("mem", "128m"); 96 | compressor.CustomParameters.Add("o", "9"); 97 | 98 | compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip"); 99 | } 100 | 101 | [Test] 102 | public void Zip_BZip2_WithCustomParameters() 103 | { 104 | var compressor = new SevenZipCompressor 105 | { 106 | ArchiveFormat = OutArchiveFormat.Zip, 107 | CompressionMethod = CompressionMethod.BZip2 108 | }; 109 | 110 | compressor.CustomParameters.Add("d", "1048576b"); 111 | compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip"); 112 | 113 | compressor.CustomParameters.Remove("d"); 114 | compressor.CustomParameters.Add("d", "16"); 115 | compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip"); 116 | } 117 | 118 | [Test] 119 | public void SevenZip_Default_WithCustomParameters() 120 | { 121 | var compressor = new SevenZipCompressor 122 | { 123 | ArchiveFormat = OutArchiveFormat.SevenZip, 124 | CompressionMethod = CompressionMethod.Default 125 | }; 126 | 127 | compressor.CustomParameters.Add("yx", "7"); 128 | compressor.CustomParameters.Add("s", "off"); 129 | compressor.CustomParameters.Add("qs", "on"); 130 | compressor.CustomParameters.Add("f", "off"); 131 | compressor.CustomParameters.Add("hc", "off"); 132 | compressor.CustomParameters.Add("he", "on"); 133 | compressor.CustomParameters.Add("mt", "off"); 134 | compressor.CustomParameters.Add("mtf", "off"); 135 | compressor.CustomParameters.Add("tm", "off"); 136 | compressor.CustomParameters.Add("tc", "on"); 137 | compressor.CustomParameters.Add("ta", "on"); 138 | compressor.CustomParameters.Add("tr", "off"); 139 | 140 | compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip"); 141 | } 142 | 143 | [Test] 144 | public void SevenZip_Lzma_WithCustomParameters() 145 | { 146 | var compressor = new SevenZipCompressor 147 | { 148 | ArchiveFormat = OutArchiveFormat.SevenZip, 149 | CompressionMethod = CompressionMethod.Lzma 150 | }; 151 | 152 | compressor.CustomParameters.Add("a", "0"); 153 | compressor.CustomParameters.Add("d", "25"); 154 | compressor.CustomParameters.Add("mf", "bt3"); 155 | compressor.CustomParameters.Add("fb", "24"); 156 | compressor.CustomParameters.Add("mc", "24"); 157 | compressor.CustomParameters.Add("lc", "4"); 158 | compressor.CustomParameters.Add("lp", "1"); 159 | compressor.CustomParameters.Add("pb", "3"); 160 | 161 | compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip"); 162 | } 163 | 164 | [Test] 165 | public void SevenZip_Lzma2_WithCustomParameters() 166 | { 167 | var compressor = new SevenZipCompressor 168 | { 169 | ArchiveFormat = OutArchiveFormat.SevenZip, 170 | CompressionMethod = CompressionMethod.Lzma2 171 | }; 172 | 173 | compressor.CustomParameters.Add("c", "512m"); 174 | 175 | compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip"); 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /SevenZip.Tests/SevenZipExtractorAsynchronousTests.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Tests 2 | { 3 | using System.IO; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using NUnit.Framework; 7 | 8 | [TestFixture] 9 | public class SevenZipExtractorAsynchronousTests : TestBase 10 | { 11 | [Test] 12 | public void AsynchronousExtractArchiveEventsTest() 13 | { 14 | var extractingInvoked = 0; 15 | var extractionFinishedInvoked = 0; 16 | var fileExistsInvoked = 0; 17 | var fileExtractionStartedInvoked = 0; 18 | var fileExtractionFinishedInvoked = 0; 19 | 20 | using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z")) 21 | { 22 | extractor.EventSynchronization = EventSynchronizationStrategy.AlwaysSynchronous; 23 | 24 | extractor.Extracting += (o, e) => extractingInvoked++; 25 | extractor.ExtractionFinished += (o, e) => extractionFinishedInvoked++; 26 | extractor.FileExists += (o, e) => fileExistsInvoked++; 27 | extractor.FileExtractionStarted += (o, e) => fileExtractionStartedInvoked++; 28 | extractor.FileExtractionFinished += (o, e) => fileExtractionFinishedInvoked++; 29 | 30 | extractor.BeginExtractArchive(OutputDirectory); 31 | 32 | var timeToWait = 2000; 33 | while (extractionFinishedInvoked == 0) 34 | { 35 | if (timeToWait <= 0) 36 | { 37 | break; 38 | } 39 | 40 | Thread.Sleep(25); 41 | timeToWait -= 25; 42 | } 43 | 44 | Assert.AreEqual(3, extractingInvoked); 45 | Assert.AreEqual(1, extractionFinishedInvoked); 46 | Assert.AreEqual(0, fileExistsInvoked); 47 | Assert.AreEqual(3, fileExtractionStartedInvoked); 48 | Assert.AreEqual(3, fileExtractionFinishedInvoked); 49 | 50 | extractionFinishedInvoked = 0; 51 | extractor.BeginExtractArchive(OutputDirectory); 52 | 53 | timeToWait = 1000; 54 | while (extractionFinishedInvoked == 0) 55 | { 56 | if (timeToWait <= 0) 57 | { 58 | break; 59 | } 60 | 61 | Thread.Sleep(25); 62 | timeToWait -= 25; 63 | } 64 | 65 | Assert.AreEqual(3, fileExistsInvoked); 66 | } 67 | } 68 | 69 | [Test] 70 | public void AsynchronousExtractFileEventsTest() 71 | { 72 | var extractionFinishedInvoked = false; 73 | 74 | using (var fileStream = File.Create(TemporaryFile)) 75 | { 76 | using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z")) 77 | { 78 | extractor.EventSynchronization = EventSynchronizationStrategy.AlwaysSynchronous; 79 | extractor.ExtractionFinished += (o, e) => extractionFinishedInvoked = true; 80 | extractor.BeginExtractFile(0, fileStream); 81 | 82 | var maximumTimeToWait = 1000; 83 | 84 | while (!extractionFinishedInvoked) 85 | { 86 | if (maximumTimeToWait <= 0) 87 | { 88 | break; 89 | } 90 | 91 | Thread.Sleep(25); 92 | maximumTimeToWait -= 25; 93 | } 94 | } 95 | } 96 | 97 | Assert.IsTrue(extractionFinishedInvoked); 98 | Assert.AreEqual("file1", File.ReadAllText(TemporaryFile)); 99 | } 100 | 101 | [Test] 102 | public void AsynchronousExtractFilesEventsTest() 103 | { 104 | var extractionFinishedInvoked = false; 105 | 106 | using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z")) 107 | { 108 | extractor.EventSynchronization = EventSynchronizationStrategy.AlwaysSynchronous; 109 | 110 | extractor.ExtractionFinished += (o, e) => extractionFinishedInvoked = true; 111 | 112 | extractor.BeginExtractFiles(OutputDirectory, 0, 2); 113 | 114 | var timeToWait = 250; 115 | while (!extractionFinishedInvoked) 116 | { 117 | if (timeToWait <= 0) 118 | { 119 | break; 120 | } 121 | 122 | Thread.Sleep(25); 123 | timeToWait -= 25; 124 | } 125 | } 126 | 127 | Assert.IsTrue(extractionFinishedInvoked); 128 | Assert.AreEqual(2, Directory.GetFiles(OutputDirectory).Length); 129 | } 130 | 131 | [Test] 132 | public async Task ExtractArchiveAsync() 133 | { 134 | using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z")) 135 | { 136 | await extractor.ExtractArchiveAsync(OutputDirectory); 137 | } 138 | 139 | Assert.AreEqual(3, Directory.GetFiles(OutputDirectory).Length); 140 | } 141 | 142 | [Test] 143 | public async Task ExtractFileAsync_ByIndex() 144 | { 145 | using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z")) 146 | { 147 | using (var fileStream = File.Create(TemporaryFile)) 148 | { 149 | await extractor.ExtractFileAsync(0, fileStream); 150 | } 151 | } 152 | 153 | Assert.AreEqual(1, Directory.GetFiles(OutputDirectory).Length); 154 | Assert.AreEqual("file1", File.ReadAllText(TemporaryFile)); 155 | } 156 | 157 | [Test] 158 | public async Task ExtractFileAsync_ByFileName() 159 | { 160 | using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z")) 161 | { 162 | using (var fileStream = File.Create(TemporaryFile)) 163 | { 164 | await extractor.ExtractFileAsync("file1.txt", fileStream); 165 | } 166 | } 167 | 168 | Assert.AreEqual(1, Directory.GetFiles(OutputDirectory).Length); 169 | Assert.AreEqual("file1", File.ReadAllText(TemporaryFile)); 170 | } 171 | 172 | [Test] 173 | public async Task ExtractFilesAsync_ByCallback() 174 | { 175 | using (var extractor = new SevenZipExtractor(@"TestData\zip.zip")) 176 | { 177 | await extractor.ExtractFilesAsync(args => { args.ExtractToFile = TemporaryFile; }); 178 | } 179 | 180 | Assert.AreEqual(1, Directory.GetFiles(OutputDirectory).Length); 181 | } 182 | 183 | [Test] 184 | public async Task ExtractFilesAsync_ByIndex() 185 | { 186 | using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z")) 187 | { 188 | await extractor.ExtractFilesAsync(OutputDirectory, 0, 2); 189 | } 190 | 191 | Assert.AreEqual(2, Directory.GetFiles(OutputDirectory).Length); 192 | } 193 | 194 | [Test] 195 | public async Task ExtractFilesAsync_ByFileName() 196 | { 197 | using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z")) 198 | { 199 | await extractor.ExtractFilesAsync(OutputDirectory, "file1.txt", "file3.txt"); 200 | } 201 | 202 | Assert.AreEqual(2, Directory.GetFiles(OutputDirectory).Length); 203 | } 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /SevenZip.Tests/SevenZipTests.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/SevenZipTests.snk -------------------------------------------------------------------------------- /SevenZip.Tests/TestBase.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Tests 2 | { 3 | using System.IO; 4 | using System.Threading; 5 | 6 | using NUnit.Framework; 7 | 8 | public abstract class TestBase 9 | { 10 | protected const string OutputDirectory = "output"; 11 | protected readonly string TemporaryFile = Path.Combine(OutputDirectory, "tmp.7z"); 12 | 13 | [SetUp] 14 | public void SetUp() 15 | { 16 | // Ensures we're in the correct working directory (for test data files). 17 | Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); 18 | Directory.CreateDirectory(OutputDirectory); 19 | } 20 | 21 | [TearDown] 22 | public void TearDown() 23 | { 24 | // Sometimes the Sfx test locks the .exe file for a few milliseconds. 25 | for (var n = 0; n < 10; n++) 26 | { 27 | try 28 | { 29 | Directory.Delete(OutputDirectory, true); 30 | break; 31 | } 32 | catch 33 | { 34 | Thread.Sleep(20); 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/7z_LZMA2.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/7z_LZMA2.7z -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/arj.arj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/arj.arj -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/bzip2.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/bzip2.bz2 -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/gzip.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/gzip.gz -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/long_path.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/long_path.7z -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/multiple_files.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/multiple_files.7z -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/multivolume.part0001.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/multivolume.part0001.rar -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/multivolume.part0002.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/multivolume.part0002.rar -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/rar4.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/rar4.rar -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/rar5.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/rar5.rar -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/tar.tar: -------------------------------------------------------------------------------- 1 | tar.txt0100777000000000000000000000000513324433767007352 0ustar00tar 2 | -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/wim.wim: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/wim.wim -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/xz.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/xz.xz -------------------------------------------------------------------------------- /SevenZip.Tests/TestData/zip.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData/zip.zip -------------------------------------------------------------------------------- /SevenZip.Tests/TestData_LongerDirectoryName/emptyfile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip.Tests/TestData_LongerDirectoryName/emptyfile.txt -------------------------------------------------------------------------------- /SevenZip.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32630.192 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SevenZip", "SevenZip\SevenZip.csproj", "{4960DD14-3431-47EC-B9D9-9D2730A98DC3}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SevenZip.Tests", "SevenZip.Tests\SevenZip.Tests.csproj", "{67192E62-C7FE-485F-BEC4-05734A943FAA}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{043464C6-413E-4D0F-8A43-B23F674B1804}" 11 | ProjectSection(SolutionItems) = preProject 12 | appveyor.yml = appveyor.yml 13 | changelog.md = changelog.md 14 | license = license 15 | nuget.config = nuget.config 16 | package.lite.nuspec = package.lite.nuspec 17 | package.regular.nuspec = package.regular.nuspec 18 | readme.md = readme.md 19 | EndProjectSection 20 | EndProject 21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{E9F8B694-4AB0-42C4-BAE8-F4880D0F6D90}" 22 | EndProject 23 | Global 24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 25 | Debug|x86 = Debug|x86 26 | Release|x86 = Release|x86 27 | Desktop|x86 = Desktop|x86 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Debug|x86.ActiveCfg = Debug|Any CPU 31 | {4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Debug|x86.Build.0 = Debug|Any CPU 32 | {4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Desktop|x86.ActiveCfg = Desktop|Any CPU 33 | {4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Desktop|x86.Build.0 = Desktop|Any CPU 34 | {4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Release|x86.ActiveCfg = Release|Any CPU 35 | {4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Release|x86.Build.0 = Release|Any CPU 36 | {67192E62-C7FE-485F-BEC4-05734A943FAA}.Debug|x86.ActiveCfg = Debug|x86 37 | {67192E62-C7FE-485F-BEC4-05734A943FAA}.Debug|x86.Build.0 = Debug|x86 38 | {67192E62-C7FE-485F-BEC4-05734A943FAA}.Desktop|x86.ActiveCfg = Debug|x86 39 | {67192E62-C7FE-485F-BEC4-05734A943FAA}.Desktop|x86.Build.0 = Debug|x86 40 | {67192E62-C7FE-485F-BEC4-05734A943FAA}.Release|x86.ActiveCfg = Release|x86 41 | {67192E62-C7FE-485F-BEC4-05734A943FAA}.Release|x86.Build.0 = Release|x86 42 | {E9F8B694-4AB0-42C4-BAE8-F4880D0F6D90}.Debug|x86.ActiveCfg = Debug|Any CPU 43 | {E9F8B694-4AB0-42C4-BAE8-F4880D0F6D90}.Debug|x86.Build.0 = Debug|Any CPU 44 | {E9F8B694-4AB0-42C4-BAE8-F4880D0F6D90}.Desktop|x86.ActiveCfg = Debug|Any CPU 45 | {E9F8B694-4AB0-42C4-BAE8-F4880D0F6D90}.Desktop|x86.Build.0 = Debug|Any CPU 46 | {E9F8B694-4AB0-42C4-BAE8-F4880D0F6D90}.Release|x86.ActiveCfg = Release|Any CPU 47 | {E9F8B694-4AB0-42C4-BAE8-F4880D0F6D90}.Release|x86.Build.0 = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(SolutionProperties) = preSolution 50 | HideSolutionNode = FALSE 51 | EndGlobalSection 52 | GlobalSection(ExtensibilityGlobals) = postSolution 53 | SolutionGuid = {19073074-52EC-4B1E-921D-3DCD50092504} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /SevenZip.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True -------------------------------------------------------------------------------- /SevenZip/7z.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/7z.dll -------------------------------------------------------------------------------- /SevenZip/7z64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/7z64.dll -------------------------------------------------------------------------------- /SevenZip/ArchiveEmulationStreamProxy.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | using System.IO; 5 | 6 | /// 7 | /// The Stream extension class to emulate the archive part of a stream. 8 | /// 9 | internal class ArchiveEmulationStreamProxy : Stream, IDisposable 10 | { 11 | private readonly bool _leaveOpen; 12 | 13 | /// 14 | /// Initializes a new instance of the ArchiveEmulationStream class. 15 | /// 16 | /// The stream to wrap. 17 | /// The stream offset. 18 | /// Whether or not the stream should be closed after operation completes. 19 | public ArchiveEmulationStreamProxy(Stream stream, int offset, bool leaveOpen = false) 20 | { 21 | Source = stream; 22 | Offset = offset; 23 | Source.Position = offset; 24 | 25 | _leaveOpen = leaveOpen; 26 | } 27 | 28 | /// 29 | /// Gets the file offset. 30 | /// 31 | public int Offset { get; } 32 | 33 | /// 34 | /// The source wrapped stream. 35 | /// 36 | public Stream Source { get; } 37 | 38 | /// 39 | public override bool CanRead => Source.CanRead; 40 | 41 | /// 42 | public override bool CanSeek => Source.CanSeek; 43 | 44 | /// 45 | public override bool CanWrite => Source.CanWrite; 46 | 47 | /// 48 | public override void Flush() 49 | { 50 | Source.Flush(); 51 | } 52 | 53 | /// 54 | public override long Length => Source.Length - Offset; 55 | 56 | /// 57 | public override long Position 58 | { 59 | get => Source.Position - Offset; 60 | set => Source.Position = value; 61 | } 62 | 63 | /// 64 | public override int Read(byte[] buffer, int offset, int count) 65 | { 66 | return Source.Read(buffer, offset, count); 67 | } 68 | 69 | /// 70 | public override long Seek(long offset, SeekOrigin origin) 71 | { 72 | return Source.Seek(origin == SeekOrigin.Begin ? offset + Offset : offset, 73 | origin) - Offset; 74 | } 75 | 76 | /// 77 | public override void SetLength(long value) 78 | { 79 | Source.SetLength(value); 80 | } 81 | 82 | /// 83 | public override void Write(byte[] buffer, int offset, int count) 84 | { 85 | Source.Write(buffer, offset, count); 86 | } 87 | 88 | /// 89 | public new void Dispose() 90 | { 91 | if (!_leaveOpen) 92 | { 93 | Source.Dispose(); 94 | } 95 | } 96 | 97 | /// 98 | public override void Close() 99 | { 100 | if (!_leaveOpen) 101 | { 102 | Source.Close(); 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /SevenZip/ArchiveFileInfo.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.Globalization; 7 | 8 | /// 9 | /// Struct for storing information about files in the 7-zip archive. 10 | /// 11 | public struct ArchiveFileInfo 12 | { 13 | /// 14 | /// Gets or sets index of the file in the archive file table. 15 | /// 16 | [CLSCompliant(false)] 17 | public int Index { get; set; } 18 | 19 | /// 20 | /// Gets or sets file name 21 | /// 22 | public string FileName { get; set; } 23 | 24 | /// 25 | /// Gets or sets the file last write time. 26 | /// 27 | public DateTime LastWriteTime { get; set; } 28 | 29 | /// 30 | /// Gets or sets the file creation time. 31 | /// 32 | public DateTime CreationTime { get; set; } 33 | 34 | /// 35 | /// Gets or sets the file creation time. 36 | /// 37 | public DateTime LastAccessTime { get; set; } 38 | 39 | /// 40 | /// Gets or sets size of the file (unpacked). 41 | /// 42 | [CLSCompliant(false)] 43 | public ulong Size { get; set; } 44 | 45 | /// 46 | /// Gets or sets CRC checksum of the file. 47 | /// 48 | [CLSCompliant(false)] 49 | public uint Crc { get; set; } 50 | 51 | /// 52 | /// Gets or sets file attributes. 53 | /// 54 | [CLSCompliant(false)] 55 | public uint Attributes { get; set; } 56 | 57 | /// 58 | /// Gets or sets being a directory. 59 | /// 60 | public bool IsDirectory { get; set; } 61 | 62 | /// 63 | /// Gets or sets being encrypted. 64 | /// 65 | public bool Encrypted { get; set; } 66 | 67 | /// 68 | /// Gets or sets comment for the file. 69 | /// 70 | public string Comment { get; set; } 71 | 72 | /// 73 | /// Compression method for the file. 74 | /// 75 | public string Method { get; set; } 76 | 77 | /// 78 | /// Determines whether the specified System.Object is equal to the current ArchiveFileInfo. 79 | /// 80 | /// The System.Object to compare with the current ArchiveFileInfo. 81 | /// true if the specified System.Object is equal to the current ArchiveFileInfo; otherwise, false. 82 | public override bool Equals(object obj) 83 | { 84 | return obj is ArchiveFileInfo info && Equals(info); 85 | } 86 | 87 | /// 88 | /// Determines whether the specified ArchiveFileInfo is equal to the current ArchiveFileInfo. 89 | /// 90 | /// The ArchiveFileInfo to compare with the current ArchiveFileInfo. 91 | /// true if the specified ArchiveFileInfo is equal to the current ArchiveFileInfo; otherwise, false. 92 | public bool Equals(ArchiveFileInfo afi) 93 | { 94 | return afi.Index == Index && afi.FileName == FileName; 95 | } 96 | 97 | /// 98 | /// Serves as a hash function for a particular type. 99 | /// 100 | /// A hash code for the current ArchiveFileInfo. 101 | public override int GetHashCode() 102 | { 103 | return FileName.GetHashCode() ^ Index; 104 | } 105 | 106 | /// 107 | /// Returns a System.String that represents the current ArchiveFileInfo. 108 | /// 109 | /// A System.String that represents the current ArchiveFileInfo. 110 | public override string ToString() 111 | { 112 | return "[" + Index.ToString(CultureInfo.CurrentCulture) + "] " + FileName; 113 | } 114 | 115 | /// 116 | /// Determines whether the specified ArchiveFileInfo instances are considered equal. 117 | /// 118 | /// The first ArchiveFileInfo to compare. 119 | /// The second ArchiveFileInfo to compare. 120 | /// true if the specified ArchiveFileInfo instances are considered equal; otherwise, false. 121 | public static bool operator ==(ArchiveFileInfo afi1, ArchiveFileInfo afi2) 122 | { 123 | return afi1.Equals(afi2); 124 | } 125 | 126 | /// 127 | /// Determines whether the specified ArchiveFileInfo instances are not considered equal. 128 | /// 129 | /// The first ArchiveFileInfo to compare. 130 | /// The second ArchiveFileInfo to compare. 131 | /// true if the specified ArchiveFileInfo instances are not considered equal; otherwise, false. 132 | public static bool operator !=(ArchiveFileInfo afi1, ArchiveFileInfo afi2) 133 | { 134 | return !afi1.Equals(afi2); 135 | } 136 | } 137 | } 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /SevenZip/ArchiveOpenCallback.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Runtime.InteropServices; 7 | 8 | #if UNMANAGED 9 | /// 10 | /// Callback to handle the archive opening 11 | /// 12 | internal sealed class ArchiveOpenCallback : CallbackBase, IArchiveOpenCallback, IArchiveOpenVolumeCallback, 13 | ICryptoGetTextPassword, IDisposable 14 | { 15 | private FileInfo _fileInfo; 16 | private Dictionary _wrappers = 17 | new Dictionary(); 18 | private readonly List _volumeFileNames = new List(); 19 | 20 | /// 21 | /// Occurs during archive opening if a password is required 22 | /// 23 | public event EventHandler PasswordRequested; 24 | 25 | /// 26 | /// Gets the list of volume file names. 27 | /// 28 | public IList VolumeFileNames => _volumeFileNames; 29 | 30 | /// 31 | /// Performs the common initialization. 32 | /// 33 | /// Volume file name. 34 | private void Init(string fileName) 35 | { 36 | if (!string.IsNullOrEmpty(fileName)) 37 | { 38 | _fileInfo = new FileInfo(fileName); 39 | _volumeFileNames.Add(fileName); 40 | if (fileName.EndsWith("001")) 41 | { 42 | int index = 2; 43 | var baseName = fileName.Substring(0, fileName.Length - 3); 44 | var volName = baseName + (index > 99 ? index.ToString() : 45 | index > 9 ? "0" + index : "00" + index); 46 | while (File.Exists(volName)) 47 | { 48 | _volumeFileNames.Add(volName); 49 | index++; 50 | volName = baseName + (index > 99 ? index.ToString() : 51 | index > 9 ? "0" + index : "00" + index); 52 | } 53 | } 54 | } 55 | } 56 | 57 | /// 58 | /// Initializes a new instance of the ArchiveOpenCallback class. 59 | /// 60 | /// The archive file name. 61 | public ArchiveOpenCallback(string fileName) 62 | { 63 | Init(fileName); 64 | } 65 | 66 | /// 67 | /// Initializes a new instance of the ArchiveOpenCallback class. 68 | /// 69 | /// The archive file name. 70 | /// Password for the archive. 71 | public ArchiveOpenCallback(string fileName, string password) : base(password) 72 | { 73 | Init(fileName); 74 | } 75 | 76 | #region IArchiveOpenCallback Members 77 | 78 | public void SetTotal(IntPtr files, IntPtr bytes) {} 79 | 80 | public void SetCompleted(IntPtr files, IntPtr bytes) {} 81 | 82 | #endregion 83 | 84 | #region IArchiveOpenVolumeCallback Members 85 | 86 | public int GetProperty(ItemPropId propId, ref PropVariant value) 87 | { 88 | if (_fileInfo == null) 89 | { 90 | // We are likely opening an archive from a Stream, and no file or _fileInfo exists. 91 | return 0; 92 | } 93 | 94 | switch (propId) 95 | { 96 | case ItemPropId.Name: 97 | value.VarType = VarEnum.VT_BSTR; 98 | value.Value = Marshal.StringToBSTR(_fileInfo.FullName); 99 | break; 100 | case ItemPropId.IsDirectory: 101 | value.VarType = VarEnum.VT_BOOL; 102 | value.UInt64Value = (byte) (_fileInfo.Attributes & FileAttributes.Directory); 103 | break; 104 | case ItemPropId.Size: 105 | value.VarType = VarEnum.VT_UI8; 106 | value.UInt64Value = (ulong) _fileInfo.Length; 107 | break; 108 | case ItemPropId.Attributes: 109 | value.VarType = VarEnum.VT_UI4; 110 | value.UInt32Value = (uint) _fileInfo.Attributes; 111 | break; 112 | case ItemPropId.CreationTime: 113 | value.VarType = VarEnum.VT_FILETIME; 114 | value.Int64Value = _fileInfo.CreationTime.ToFileTime(); 115 | break; 116 | case ItemPropId.LastAccessTime: 117 | value.VarType = VarEnum.VT_FILETIME; 118 | value.Int64Value = _fileInfo.LastAccessTime.ToFileTime(); 119 | break; 120 | case ItemPropId.LastWriteTime: 121 | value.VarType = VarEnum.VT_FILETIME; 122 | value.Int64Value = _fileInfo.LastWriteTime.ToFileTime(); 123 | break; 124 | } 125 | 126 | return 0; 127 | } 128 | 129 | public int GetStream(string name, out IInStream inStream) 130 | { 131 | if (!File.Exists(name)) 132 | { 133 | name = Path.Combine(Path.GetDirectoryName(_fileInfo.FullName), name); 134 | if (!File.Exists(name)) 135 | { 136 | inStream = null; 137 | AddException(new FileNotFoundException("The volume \"" + name + "\" was not found. Extraction can be impossible.")); 138 | return 1; 139 | } 140 | } 141 | _volumeFileNames.Add(name); 142 | if (_wrappers.ContainsKey(name)) 143 | { 144 | _wrappers[name].Seek(0, SeekOrigin.Begin, IntPtr.Zero); 145 | inStream = _wrappers[name]; 146 | } 147 | else 148 | { 149 | try 150 | { 151 | var wrapper = new InStreamWrapper( 152 | new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), true); 153 | _wrappers.Add(name, wrapper); 154 | inStream = wrapper; 155 | } 156 | catch (Exception) 157 | { 158 | AddException(new FileNotFoundException("Failed to open the volume \"" + name + "\". Extraction is impossible.")); 159 | inStream = null; 160 | return 1; 161 | } 162 | } 163 | return 0; 164 | } 165 | 166 | #endregion 167 | 168 | #region ICryptoGetTextPassword Members 169 | 170 | /// 171 | /// Sets password for the archive 172 | /// 173 | /// Password for the archive 174 | /// Zero if everything is OK 175 | public int CryptoGetTextPassword(out string password) 176 | { 177 | PasswordRequested?.Invoke(this, null); 178 | password = Password; 179 | return 0; 180 | } 181 | 182 | #endregion 183 | 184 | #region IDisposable Members 185 | 186 | public void Dispose() 187 | { 188 | if (_wrappers != null) 189 | { 190 | foreach (InStreamWrapper wrap in _wrappers.Values) 191 | { 192 | wrap.Dispose(); 193 | } 194 | _wrappers = null; 195 | } 196 | 197 | GC.SuppressFinalize(this); 198 | } 199 | 200 | #endregion 201 | } 202 | #endif 203 | } 204 | -------------------------------------------------------------------------------- /SevenZip/ArchiveProperty.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | /// 6 | /// Archive property struct. 7 | /// 8 | public struct ArchiveProperty 9 | { 10 | /// 11 | /// Gets the name of the archive property. 12 | /// 13 | public string Name { get; internal set; } 14 | 15 | /// 16 | /// Gets the value of the archive property. 17 | /// 18 | public object Value { get; internal set; } 19 | 20 | /// 21 | /// Determines whether the specified System.Object is equal to the current ArchiveProperty. 22 | /// 23 | /// The System.Object to compare with the current ArchiveProperty. 24 | /// true if the specified System.Object is equal to the current ArchiveProperty; otherwise, false. 25 | public override bool Equals(object obj) 26 | { 27 | return (obj is ArchiveProperty property) && Equals(property); 28 | } 29 | 30 | /// 31 | /// Determines whether the specified ArchiveProperty is equal to the current ArchiveProperty. 32 | /// 33 | /// The ArchiveProperty to compare with the current ArchiveProperty. 34 | /// true if the specified ArchiveProperty is equal to the current ArchiveProperty; otherwise, false. 35 | public bool Equals(ArchiveProperty afi) 36 | { 37 | return afi.Name == Name && afi.Value == Value; 38 | } 39 | 40 | /// 41 | /// Serves as a hash function for a particular type. 42 | /// 43 | /// A hash code for the current ArchiveProperty. 44 | public override int GetHashCode() 45 | { 46 | return Name.GetHashCode() ^ Value.GetHashCode(); 47 | } 48 | 49 | /// 50 | /// Returns a System.String that represents the current ArchiveProperty. 51 | /// 52 | /// A System.String that represents the current ArchiveProperty. 53 | public override string ToString() 54 | { 55 | return Name + " = " + Value; 56 | } 57 | 58 | /// 59 | /// Determines whether the specified ArchiveProperty instances are considered equal. 60 | /// 61 | /// The first ArchiveProperty to compare. 62 | /// The second ArchiveProperty to compare. 63 | /// true if the specified ArchiveProperty instances are considered equal; otherwise, false. 64 | public static bool operator ==(ArchiveProperty afi1, ArchiveProperty afi2) 65 | { 66 | return afi1.Equals(afi2); 67 | } 68 | 69 | /// 70 | /// Determines whether the specified ArchiveProperty instances are not considered equal. 71 | /// 72 | /// The first ArchiveProperty to compare. 73 | /// The second ArchiveProperty to compare. 74 | /// true if the specified ArchiveProperty instances are not considered equal; otherwise, false. 75 | public static bool operator !=(ArchiveProperty afi1, ArchiveProperty afi2) 76 | { 77 | return !afi1.Equals(afi2); 78 | } 79 | } 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /SevenZip/CallbackBase.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Collections.ObjectModel; 8 | 9 | internal class CallbackBase : MarshalByRefObject 10 | { 11 | /// 12 | /// User exceptions thrown during the requested operations, for example, in events. 13 | /// 14 | private readonly List _exceptions = new List(); 15 | 16 | /// 17 | /// Initializes a new instance of the CallbackBase class. 18 | /// 19 | protected CallbackBase() 20 | { 21 | Password = ""; 22 | ReportErrors = true; 23 | } 24 | 25 | /// 26 | /// Initializes a new instance of the CallbackBase class. 27 | /// 28 | /// The archive password. 29 | protected CallbackBase(string password) 30 | { 31 | if (string.IsNullOrEmpty(password)) 32 | { 33 | throw new SevenZipException("Empty password was specified."); 34 | } 35 | 36 | Password = password; 37 | ReportErrors = true; 38 | } 39 | 40 | /// 41 | /// Gets or sets the archive password 42 | /// 43 | public string Password { get; } 44 | 45 | /// 46 | /// Gets or sets the value indicating whether the current procedure was cancelled. 47 | /// 48 | public bool Canceled { get; set; } 49 | 50 | /// 51 | /// Gets or sets throw exceptions on archive errors flag 52 | /// 53 | public bool ReportErrors { get; } 54 | 55 | /// 56 | /// Gets the user exceptions thrown during the requested operations, for example, in events. 57 | /// 58 | public ReadOnlyCollection Exceptions => new ReadOnlyCollection(_exceptions); 59 | 60 | public void AddException(Exception e) 61 | { 62 | _exceptions.Add(e); 63 | } 64 | 65 | public void ClearExceptions() 66 | { 67 | _exceptions.Clear(); 68 | } 69 | 70 | public bool HasExceptions => _exceptions.Count > 0; 71 | 72 | /// 73 | /// Throws the specified exception when is able to. 74 | /// 75 | /// The exception to throw. 76 | /// The handler responsible for the exception. 77 | public bool ThrowException(CallbackBase handler, params Exception[] e) 78 | { 79 | if (ReportErrors && (handler == null || !handler.Canceled)) 80 | { 81 | throw e[0]; 82 | } 83 | 84 | return false; 85 | } 86 | 87 | /// 88 | /// Throws the first exception in the list if any exists. 89 | /// 90 | /// True means no exceptions. 91 | public bool ThrowException() 92 | { 93 | if (HasExceptions && ReportErrors) 94 | { 95 | throw _exceptions[0]; 96 | } 97 | 98 | return true; 99 | } 100 | 101 | public void ThrowUserException() 102 | { 103 | if (HasExceptions) 104 | { 105 | throw new SevenZipException(SevenZipException.USER_EXCEPTION_MESSAGE); 106 | } 107 | } 108 | } 109 | } 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /SevenZip/CompressionMode.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | /// 6 | /// Archive compression mode. 7 | /// 8 | public enum CompressionMode 9 | { 10 | /// 11 | /// Create a new archive; overwrite the existing one. 12 | /// 13 | Create, 14 | /// 15 | /// Add data to the archive. 16 | /// 17 | Append, 18 | } 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /SevenZip/EventArguments/ExtractFileCallbackArgs.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.IO; 7 | 8 | /// 9 | /// The arguments passed to . 10 | /// 11 | /// 12 | /// For each file, is first called with 13 | /// set to . If the callback chooses to extract the 14 | /// file data by setting or , the callback 15 | /// will be called a second time with set to 16 | /// or 17 | /// to allow for any cleanup task like closing the stream. 18 | /// 19 | public class ExtractFileCallbackArgs : EventArgs 20 | { 21 | private readonly ArchiveFileInfo _archiveFileInfo; 22 | private Stream _extractToStream; 23 | 24 | /// 25 | /// Initializes a new instance of the class. 26 | /// 27 | /// The information about file in the archive. 28 | public ExtractFileCallbackArgs(ArchiveFileInfo archiveFileInfo) 29 | { 30 | Reason = ExtractFileCallbackReason.Start; 31 | _archiveFileInfo = archiveFileInfo; 32 | } 33 | 34 | /// 35 | /// Information about file in the archive. 36 | /// 37 | /// Information about file in the archive. 38 | public ArchiveFileInfo ArchiveFileInfo => _archiveFileInfo; 39 | 40 | /// 41 | /// The reason for calling . 42 | /// 43 | /// 44 | /// If neither nor is set, 45 | /// will not be called after . 46 | /// 47 | /// The reason. 48 | public ExtractFileCallbackReason Reason { get; internal set; } 49 | 50 | /// 51 | /// The exception that occurred during extraction. 52 | /// 53 | /// The _Exception. 54 | /// 55 | /// If the callback is called with set to , 56 | /// this member contains the _Exception that occurred. 57 | /// The default behavior is to rethrow the _Exception after return of the callback. 58 | /// However the callback can set to null to swallow the _Exception 59 | /// and continue extraction with the next file. 60 | /// 61 | public Exception Exception { get; set; } 62 | 63 | /// 64 | /// Gets or sets a value indicating whether to cancel the extraction. 65 | /// 66 | /// true to cancel the extraction; false to continue. The default is false. 67 | public bool CancelExtraction { get; set; } 68 | 69 | /// 70 | /// Gets or sets whether and where to extract the file. 71 | /// 72 | /// The path where to extract the file to. 73 | /// 74 | /// If is set, this mmember will be ignored. 75 | /// 76 | public string ExtractToFile { get; set; } 77 | 78 | /// 79 | /// Gets or sets whether and where to extract the file. 80 | /// 81 | /// The the extracted data is written to. 82 | /// 83 | /// If both this member and are null (the defualt), the file 84 | /// will not be extracted and the callback will be be executed a second time with the 85 | /// set to or . 86 | /// 87 | public Stream ExtractToStream 88 | { 89 | get => _extractToStream; 90 | set 91 | { 92 | if (_extractToStream != null && !_extractToStream.CanWrite) 93 | { 94 | throw new SevenZipExtractionFailedException("The specified stream is not writable!"); 95 | } 96 | 97 | _extractToStream = value; 98 | } 99 | } 100 | 101 | /// 102 | /// Gets or sets any data that will be preserved between the callback call 103 | /// and the or calls. 104 | /// 105 | /// The data. 106 | public object ObjectData { get; set; } 107 | } 108 | } 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /SevenZip/EventArguments/ExtractFileCallbackReason.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | /// 6 | /// The reason for calling . 7 | /// 8 | public enum ExtractFileCallbackReason 9 | { 10 | /// 11 | /// is called the first time for a file. 12 | /// 13 | Start, 14 | 15 | /// 16 | /// All data has been written to the target without any exceptions. 17 | /// 18 | Done, 19 | 20 | /// 21 | /// An exception occurred during extraction of the file. 22 | /// 23 | Failure 24 | } 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /SevenZip/EventArguments/FileInfoEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | /// 4 | /// EventArgs used to report the file information which is going to be packed. 5 | /// 6 | public sealed class FileInfoEventArgs : PercentDoneEventArgs, ICancellable 7 | { 8 | /// 9 | /// Initializes a new instance of the FileInfoEventArgs class. 10 | /// 11 | /// The current ArchiveFileInfo. 12 | /// The percent of finished work. 13 | public FileInfoEventArgs(ArchiveFileInfo fileInfo, byte percentDone) 14 | : base(percentDone) 15 | { 16 | FileInfo = fileInfo; 17 | } 18 | 19 | /// 20 | /// Gets or sets whether to stop the current archive operation. 21 | /// 22 | public bool Cancel { get; set; } 23 | 24 | /// 25 | /// Gets or sets whether to skip the current file. 26 | /// 27 | public bool Skip { get; set; } 28 | 29 | /// 30 | /// Gets the corresponding FileInfo to the event. 31 | /// 32 | public ArchiveFileInfo FileInfo { get; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /SevenZip/EventArguments/FileNameEventArgs.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | 7 | /// 8 | /// EventArgs class which stores the file name. 9 | /// 10 | public sealed class FileNameEventArgs : PercentDoneEventArgs, ICancellable 11 | { 12 | /// 13 | /// Initializes a new instance of the FileNameEventArgs class. 14 | /// 15 | /// The file name. 16 | /// The percent of finished work 17 | public FileNameEventArgs(string fileName, string filePath, byte percentDone) : 18 | base(percentDone) 19 | { 20 | FileName = fileName; 21 | FilePath = filePath; 22 | } 23 | 24 | /// 25 | /// Gets or sets whether to stop the current archive operation. 26 | /// 27 | public bool Cancel { get; set; } 28 | 29 | /// 30 | /// Gets or sets whether to stop the current archive operation. 31 | /// 32 | public bool Skip 33 | { 34 | get => false; 35 | set => throw new NotImplementedException(); 36 | } 37 | 38 | /// 39 | /// Gets the file name. 40 | /// 41 | public string FileName { get; } 42 | 43 | public string FilePath { get; } 44 | } 45 | } 46 | 47 | #endif -------------------------------------------------------------------------------- /SevenZip/EventArguments/FileOverwriteEventArgs.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | 7 | /// 8 | /// EventArgs for FileExists event, stores the file name and asks whether to overwrite it in case it already exists. 9 | /// 10 | public sealed class FileOverwriteEventArgs : EventArgs 11 | { 12 | /// 13 | /// Initializes a new instance of the FileOverwriteEventArgs class 14 | /// 15 | /// The file name. 16 | public FileOverwriteEventArgs(string fileName) 17 | { 18 | FileName = fileName; 19 | } 20 | 21 | /// 22 | /// Gets or sets the value indicating whether to cancel the extraction. 23 | /// 24 | public bool Cancel { get; set; } 25 | 26 | /// 27 | /// Gets or sets the file name to extract to. Null means skip. 28 | /// 29 | public string FileName { get; set; } 30 | } 31 | } 32 | 33 | #endif -------------------------------------------------------------------------------- /SevenZip/EventArguments/IntEventArgs.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | 7 | /// 8 | /// Stores an int number 9 | /// 10 | public sealed class IntEventArgs : ValueEventArgs 11 | { 12 | public IntEventArgs(int value) : base(value) 13 | { 14 | } 15 | } 16 | 17 | public class ValueEventArgs : EventArgs 18 | { 19 | private readonly T _value; 20 | 21 | /// 22 | /// Initializes a new instance of the IntEventArgs class 23 | /// 24 | /// Useful data carried by the IntEventArgs class 25 | public ValueEventArgs(T value) 26 | { 27 | _value = value; 28 | } 29 | 30 | /// 31 | /// Gets the value of the IntEventArgs class 32 | /// 33 | public T Value => _value; 34 | } 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /SevenZip/EventArguments/OpenEventArgs.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | 7 | /// 8 | /// EventArgs used to report the size of unpacked archive data 9 | /// 10 | public sealed class OpenEventArgs : EventArgs 11 | { 12 | private readonly ulong _totalSize; 13 | 14 | /// 15 | /// Initializes a new instance of the OpenEventArgs class 16 | /// 17 | /// Size of unpacked archive data 18 | [CLSCompliant(false)] 19 | public OpenEventArgs(ulong totalSize) 20 | { 21 | _totalSize = totalSize; 22 | } 23 | 24 | /// 25 | /// Gets the size of unpacked archive data 26 | /// 27 | [CLSCompliant(false)] 28 | public ulong TotalSize => _totalSize; 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /SevenZip/EventArguments/PercentDoneEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | 5 | /// 6 | /// EventArgs for storing PercentDone property. 7 | /// 8 | public class PercentDoneEventArgs : EventArgs 9 | { 10 | /// 11 | /// Initializes a new instance of the PercentDoneEventArgs class. 12 | /// 13 | /// The percent of finished work. 14 | /// 15 | public PercentDoneEventArgs(byte percentDone) 16 | { 17 | if (percentDone > 100 || percentDone < 0) 18 | { 19 | throw new ArgumentOutOfRangeException(nameof(percentDone), 20 | "The percent of finished work must be between 0 and 100."); 21 | } 22 | 23 | PercentDone = percentDone; 24 | } 25 | 26 | /// 27 | /// Gets the percent of finished work. 28 | /// 29 | public byte PercentDone { get; } 30 | 31 | /// 32 | /// Converts a [0, 1] rate to its percent equivalent. 33 | /// 34 | /// The rate of the done work. 35 | /// Percent integer equivalent. 36 | /// 37 | internal static byte ProducePercentDone(float doneRate) 38 | { 39 | return (byte)Math.Round(Math.Min(100 * doneRate, 100), MidpointRounding.AwayFromZero); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /SevenZip/EventArguments/ProgressEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | /// 4 | /// The EventArgs class for accurate progress handling. 5 | /// 6 | public sealed class ProgressEventArgs : PercentDoneEventArgs 7 | { 8 | /// 9 | /// Initializes a new instance of the ProgressEventArgs class. 10 | /// 11 | /// The percent of finished work. 12 | /// The percent of work done after the previous event. 13 | public ProgressEventArgs(byte percentDone, byte percentDelta, long bytesProcessed, long bytesCount) 14 | : base(percentDone) 15 | { 16 | PercentDelta = percentDelta; 17 | BytesProcessed = bytesProcessed; 18 | BytesCount = bytesCount; 19 | } 20 | 21 | /// 22 | /// Gets the change in done work percentage. 23 | /// 24 | public byte PercentDelta { get; } 25 | 26 | public long BytesProcessed { get; } 27 | 28 | public long BytesCount { get; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SevenZip/EventSynchronizationStrategy.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | /// 6 | /// The way of the event synchronization. 7 | /// 8 | public enum EventSynchronizationStrategy 9 | { 10 | /// 11 | /// Events are called synchronously if user can do some action; that is, cancel the execution process for example. 12 | /// 13 | Default, 14 | /// 15 | /// Always call events asynchronously. 16 | /// 17 | AlwaysAsynchronous, 18 | /// 19 | /// Always call events synchronously. 20 | /// 21 | AlwaysSynchronous 22 | } 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/CompressionFailedException.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.Runtime.Serialization; 7 | 8 | /// 9 | /// Exception class for ArchiveUpdateCallback. 10 | /// 11 | [Serializable] 12 | public class CompressionFailedException : SevenZipException 13 | { 14 | /// 15 | /// Exception default message which is displayed if no extra information is specified 16 | /// 17 | public const string DEFAULT_MESSAGE = "Could not pack files!"; 18 | 19 | /// 20 | /// Initializes a new instance of the CompressionFailedException class 21 | /// 22 | public CompressionFailedException() : base(DEFAULT_MESSAGE) { } 23 | 24 | /// 25 | /// Initializes a new instance of the CompressionFailedException class 26 | /// 27 | /// Additional detailed message 28 | public CompressionFailedException(string message) : base(DEFAULT_MESSAGE, message) { } 29 | 30 | /// 31 | /// Initializes a new instance of the CompressionFailedException class 32 | /// 33 | /// Additional detailed message 34 | /// Inner exception occurred 35 | public CompressionFailedException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) { } 36 | 37 | /// 38 | /// Initializes a new instance of the CompressionFailedException class 39 | /// 40 | /// All data needed for serialization or deserialization 41 | /// Serialized stream descriptor 42 | protected CompressionFailedException( 43 | SerializationInfo info, StreamingContext context) 44 | : base(info, context) { } 45 | 46 | } 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /SevenZip/Exceptions/ExtractionFailedException.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.Runtime.Serialization; 7 | 8 | /// 9 | /// Exception class for ArchiveExtractCallback. 10 | /// 11 | [Serializable] 12 | public class ExtractionFailedException : SevenZipException 13 | { 14 | /// 15 | /// Exception default message which is displayed if no extra information is specified 16 | /// 17 | public const string DEFAULT_MESSAGE = "Could not extract files!"; 18 | 19 | public OperationResult Result { get; protected set; } 20 | 21 | /// 22 | /// Initializes a new instance of the ExtractionFailedException class 23 | /// 24 | public ExtractionFailedException(OperationResult result) : this(DEFAULT_MESSAGE, result) 25 | { 26 | } 27 | 28 | /// 29 | /// Initializes a new instance of the ExtractionFailedException class 30 | /// 31 | /// Additional detailed message 32 | public ExtractionFailedException(string message, OperationResult result) : base(message) 33 | { 34 | Result = result; 35 | } 36 | 37 | public ExtractionFailedException(OperationResult result, bool passwordRequested) : this(DEFAULT_MESSAGE, result, passwordRequested) 38 | { 39 | } 40 | 41 | public ExtractionFailedException(string message, OperationResult result, bool passwordRequested) : base(message) 42 | { 43 | if (result == OperationResult.DataError) 44 | { 45 | if (passwordRequested) 46 | { 47 | result = OperationResult.WrongPassword; 48 | } 49 | } 50 | Result = result; 51 | } 52 | } 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/LzmaException.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | using System.Runtime.Serialization; 5 | 6 | /// 7 | /// Exception class for LZMA operations. 8 | /// 9 | [Serializable] 10 | public class LzmaException : SevenZipException 11 | { 12 | /// 13 | /// Exception default message which is displayed if no extra information is specified 14 | /// 15 | public const string DEFAULT_MESSAGE = "Specified stream is not a valid LZMA compressed stream!"; 16 | 17 | /// 18 | /// Initializes a new instance of the LzmaException class 19 | /// 20 | public LzmaException() : base(DEFAULT_MESSAGE) { } 21 | 22 | /// 23 | /// Initializes a new instance of the LzmaException class 24 | /// 25 | /// Additional detailed message 26 | public LzmaException(string message) : base(DEFAULT_MESSAGE, message) { } 27 | 28 | /// 29 | /// Initializes a new instance of the LzmaException class 30 | /// 31 | /// Additional detailed message 32 | /// Inner exception occurred 33 | public LzmaException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) { } 34 | 35 | /// 36 | /// Initializes a new instance of the LzmaException class 37 | /// 38 | /// All data needed for serialization or deserialization 39 | /// Serialized stream descriptor 40 | protected LzmaException( 41 | SerializationInfo info, StreamingContext context) 42 | : base(info, context) { } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/SevenZipArchiveException.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.Runtime.Serialization; 7 | 8 | /// 9 | /// Exception class for 7-zip archive open or read operations. 10 | /// 11 | [Serializable] 12 | public class SevenZipArchiveException : SevenZipException 13 | { 14 | /// 15 | /// Exception default message which is displayed if no extra information is specified 16 | /// 17 | public static string DefaultMessage = 18 | $"Invalid archive: open/read error! Is it encrypted and a wrong password was provided?{Environment.NewLine}" + 19 | "If your archive is an exotic one, it is possible that SevenZipSharp has no signature for " + 20 | "its format and thus decided it is TAR by mistake."; 21 | 22 | /// 23 | /// Initializes a new instance of the SevenZipArchiveException class 24 | /// 25 | public SevenZipArchiveException() : base(DefaultMessage) { } 26 | 27 | /// 28 | /// Initializes a new instance of the SevenZipArchiveException class 29 | /// 30 | /// Additional detailed message 31 | public SevenZipArchiveException(string message) : base(DefaultMessage, message) { } 32 | 33 | /// 34 | /// Initializes a new instance of the SevenZipArchiveException class 35 | /// 36 | /// Additional detailed message 37 | /// Inner exception occurred 38 | public SevenZipArchiveException(string message, Exception inner) : base(DefaultMessage, message, inner) { } 39 | 40 | /// 41 | /// Initializes a new instance of the SevenZipArchiveException class 42 | /// 43 | /// All data needed for serialization or deserialization 44 | /// Serialized stream descriptor 45 | protected SevenZipArchiveException( 46 | SerializationInfo info, StreamingContext context) 47 | : base(info, context) { } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/SevenZipCompressionFailedException.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.Runtime.Serialization; 7 | 8 | /// 9 | /// Exception class for fail to create an archive in SevenZipCompressor. 10 | /// 11 | [Serializable] 12 | public class SevenZipCompressionFailedException : SevenZipException 13 | { 14 | /// 15 | /// Exception default message which is displayed if no extra information is specified 16 | /// 17 | public const string DEFAULT_MESSAGE = "The compression has failed for an unknown reason with code "; 18 | 19 | /// 20 | /// Initializes a new instance of the SevenZipCompressionFailedException class 21 | /// 22 | public SevenZipCompressionFailedException() : base(DEFAULT_MESSAGE) { } 23 | 24 | /// 25 | /// Initializes a new instance of the SevenZipCompressionFailedException class 26 | /// 27 | /// Additional detailed message 28 | public SevenZipCompressionFailedException(string message) : base(DEFAULT_MESSAGE, message) { } 29 | 30 | /// 31 | /// Initializes a new instance of the SevenZipCompressionFailedException class 32 | /// 33 | /// Additional detailed message 34 | /// Inner exception occurred 35 | public SevenZipCompressionFailedException(string message, Exception inner) 36 | : base(DEFAULT_MESSAGE, message, inner) { } 37 | 38 | /// 39 | /// Initializes a new instance of the SevenZipCompressionFailedException class 40 | /// 41 | /// All data needed for serialization or deserialization 42 | /// Serialized stream descriptor 43 | protected SevenZipCompressionFailedException( 44 | SerializationInfo info, StreamingContext context) 45 | : base(info, context) { } 46 | } 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/SevenZipException.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | using System.Runtime.Serialization; 5 | 6 | /// 7 | /// Base SevenZip exception class. 8 | /// 9 | [Serializable] 10 | public class SevenZipException : Exception 11 | { 12 | /// 13 | /// The message for thrown user exceptions. 14 | /// 15 | internal const string USER_EXCEPTION_MESSAGE = "The extraction was successful but" + 16 | "some exceptions were thrown in your events. Check UserExceptions for details."; 17 | 18 | /// 19 | /// Initializes a new instance of the SevenZipException class 20 | /// 21 | public SevenZipException() : base("SevenZip unknown exception.") { } 22 | 23 | /// 24 | /// Initializes a new instance of the SevenZipException class 25 | /// 26 | /// Default exception message 27 | public SevenZipException(string defaultMessage) 28 | : base(defaultMessage) { } 29 | 30 | /// 31 | /// Initializes a new instance of the SevenZipException class 32 | /// 33 | /// Default exception message 34 | /// Additional detailed message 35 | public SevenZipException(string defaultMessage, string message) 36 | : base(defaultMessage + " Message: " + message) { } 37 | 38 | /// 39 | /// Initializes a new instance of the SevenZipException class 40 | /// 41 | /// Default exception message 42 | /// Additional detailed message 43 | /// Inner exception occurred 44 | public SevenZipException(string defaultMessage, string message, Exception inner) 45 | : base( 46 | defaultMessage + (defaultMessage.EndsWith(" ", StringComparison.CurrentCulture) ? "" : " Message: ") + 47 | message, inner) 48 | { } 49 | 50 | /// 51 | /// Initializes a new instance of the SevenZipException class 52 | /// 53 | /// Default exception message 54 | /// Inner exception occurred 55 | public SevenZipException(string defaultMessage, Exception inner) 56 | : base(defaultMessage, inner) { } 57 | /// 58 | /// Initializes a new instance of the SevenZipException class 59 | /// 60 | /// All data needed for serialization or deserialization 61 | /// Serialized stream descriptor 62 | protected SevenZipException( 63 | SerializationInfo info, StreamingContext context) 64 | : base(info, context) { } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/SevenZipExtractionFailedException.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.Runtime.Serialization; 7 | 8 | /// 9 | /// Exception class for fail to extract an archive in SevenZipExtractor. 10 | /// 11 | [Serializable] 12 | public class SevenZipExtractionFailedException : SevenZipException 13 | { 14 | /// 15 | /// Exception default message which is displayed if no extra information is specified 16 | /// 17 | public const string DEFAULT_MESSAGE = "The extraction has failed for an unknown reason with code "; 18 | 19 | /// 20 | /// Initializes a new instance of the SevenZipExtractionFailedException class 21 | /// 22 | public SevenZipExtractionFailedException() : base(DEFAULT_MESSAGE) { } 23 | 24 | /// 25 | /// Initializes a new instance of the SevenZipExtractionFailedException class 26 | /// 27 | /// Additional detailed message 28 | public SevenZipExtractionFailedException(string message) : base(DEFAULT_MESSAGE, message) { } 29 | 30 | /// 31 | /// Initializes a new instance of the SevenZipExtractionFailedException class 32 | /// 33 | /// Additional detailed message 34 | /// Inner exception occurred 35 | public SevenZipExtractionFailedException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) { } 36 | 37 | /// 38 | /// Initializes a new instance of the SevenZipExtractionFailedException class 39 | /// 40 | /// All data needed for serialization or deserialization 41 | /// Serialized stream descriptor 42 | protected SevenZipExtractionFailedException( 43 | SerializationInfo info, StreamingContext context) 44 | : base(info, context) { } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/SevenZipInvalidFileNamesException.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.Runtime.Serialization; 7 | 8 | /// 9 | /// Exception class for empty common root if file name array in SevenZipCompressor. 10 | /// 11 | [Serializable] 12 | public class SevenZipInvalidFileNamesException : SevenZipException 13 | { 14 | /// 15 | /// Exception default message which is displayed if no extra information is specified 16 | /// 17 | public const string DEFAULT_MESSAGE = "Invalid file names have been specified: "; 18 | 19 | /// 20 | /// Initializes a new instance of the SevenZipInvalidFileNamesException class 21 | /// 22 | public SevenZipInvalidFileNamesException() : base(DEFAULT_MESSAGE) { } 23 | 24 | /// 25 | /// Initializes a new instance of the SevenZipInvalidFileNamesException class 26 | /// 27 | /// Additional detailed message 28 | public SevenZipInvalidFileNamesException(string message) : base(DEFAULT_MESSAGE, message) { } 29 | 30 | /// 31 | /// Initializes a new instance of the SevenZipInvalidFileNamesException class 32 | /// 33 | /// Additional detailed message 34 | /// Inner exception occurred 35 | public SevenZipInvalidFileNamesException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) { } 36 | 37 | /// 38 | /// Initializes a new instance of the SevenZipInvalidFileNamesException class 39 | /// 40 | /// All data needed for serialization or deserialization 41 | /// Serialized stream descriptor 42 | protected SevenZipInvalidFileNamesException( 43 | SerializationInfo info, StreamingContext context) 44 | : base(info, context) { } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/SevenZipLibraryException.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System; 6 | using System.Runtime.Serialization; 7 | 8 | /// 9 | /// Exception class for 7-zip library operations. 10 | /// 11 | [Serializable] 12 | public class SevenZipLibraryException : SevenZipException 13 | { 14 | /// 15 | /// Exception default message which is displayed if no extra information is specified 16 | /// 17 | public const string DEFAULT_MESSAGE = "Can not load 7-zip library or internal COM error!"; 18 | 19 | /// 20 | /// Initializes a new instance of the SevenZipLibraryException class 21 | /// 22 | public SevenZipLibraryException() : base(DEFAULT_MESSAGE) { } 23 | 24 | /// 25 | /// Initializes a new instance of the SevenZipLibraryException class 26 | /// 27 | /// Additional detailed message 28 | public SevenZipLibraryException(string message) : base(DEFAULT_MESSAGE, message) { } 29 | 30 | /// 31 | /// Initializes a new instance of the SevenZipLibraryException class 32 | /// 33 | /// Additional detailed message 34 | /// Inner exception occurred 35 | public SevenZipLibraryException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) { } 36 | 37 | /// 38 | /// Initializes a new instance of the SevenZipLibraryException class 39 | /// 40 | /// All data needed for serialization or deserialization 41 | /// Serialized stream descriptor 42 | protected SevenZipLibraryException( 43 | SerializationInfo info, StreamingContext context) 44 | : base(info, context) { } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/SevenZipOpenFailedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SevenZip 6 | { 7 | public class SevenZipOpenFailedException : SevenZipException 8 | { 9 | /// 10 | /// Exception default message which is displayed if no extra information is specified 11 | /// 12 | public static string DefaultMessage = 13 | $"Invalid archive: open/read error! Is it encrypted and a wrong password was provided?{Environment.NewLine}" + 14 | "If your archive is an exotic one, it is possible that SevenZipSharp has no signature for " + 15 | "its format and thus decided it is TAR by mistake."; 16 | 17 | public OperationResult Result { get; protected set; } 18 | 19 | public SevenZipOpenFailedException(OperationResult result) : this(DefaultMessage, result) 20 | { 21 | } 22 | 23 | public SevenZipOpenFailedException(string message, OperationResult result) : base(message) 24 | { 25 | Result = result; 26 | } 27 | 28 | public SevenZipOpenFailedException(OperationResult result, bool passwordRequested) : this(DefaultMessage, result, passwordRequested) 29 | { 30 | } 31 | 32 | public SevenZipOpenFailedException(string message, OperationResult result, bool passwordRequested) : base(message) 33 | { 34 | if (result == OperationResult.UnsupportedMethod) 35 | { 36 | if (passwordRequested) 37 | { 38 | result = OperationResult.WrongPassword; 39 | } 40 | } 41 | Result = result; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SevenZip/Exceptions/SevenZipSfxValidationException.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | using System.Runtime.Serialization; 5 | 6 | /// 7 | /// Exception class for 7-zip sfx settings validation. 8 | /// 9 | [Serializable] 10 | public class SevenZipSfxValidationException : SevenZipException 11 | { 12 | /// 13 | /// Exception default message which is displayed if no extra information is specified 14 | /// 15 | public static readonly string DefaultMessage = "Sfx settings validation failed."; 16 | 17 | /// 18 | /// Initializes a new instance of the SevenZipSfxValidationException class 19 | /// 20 | public SevenZipSfxValidationException() : base(DefaultMessage) { } 21 | 22 | /// 23 | /// Initializes a new instance of the SevenZipSfxValidationException class 24 | /// 25 | /// Additional detailed message 26 | public SevenZipSfxValidationException(string message) : base(DefaultMessage, message) { } 27 | 28 | /// 29 | /// Initializes a new instance of the SevenZipSfxValidationException class 30 | /// 31 | /// Additional detailed message 32 | /// Inner exception occurred 33 | public SevenZipSfxValidationException(string message, Exception inner) : base(DefaultMessage, message, inner) { } 34 | 35 | /// 36 | /// Initializes a new instance of the SevenZipSfxValidationException class 37 | /// 38 | /// All data needed for serialization or deserialization 39 | /// Serialized stream descriptor 40 | protected SevenZipSfxValidationException( 41 | SerializationInfo info, StreamingContext context) 42 | : base(info, context) { } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SevenZip/ExtractFileCallback.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | /// 6 | /// Callback delegate for . 7 | /// 8 | public delegate void ExtractFileCallback(ExtractFileCallbackArgs extractFileCallbackArgs); 9 | } 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /SevenZip/ICancellable.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | /// 4 | /// The definition of the interface which supports the cancellation of a process. 5 | /// 6 | public interface ICancellable 7 | { 8 | /// 9 | /// Gets or sets whether to stop the current archive operation. 10 | /// 11 | bool Cancel { get; set; } 12 | 13 | /// 14 | /// Gets or sets whether to skip the current file. 15 | /// 16 | bool Skip { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SevenZip/InternalCompressionMode.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | internal enum InternalCompressionMode 6 | { 7 | /// 8 | /// Create a new archive; overwrite the existing one. 9 | /// 10 | Create, 11 | /// 12 | /// Add data to the archive. 13 | /// 14 | Append, 15 | /// 16 | /// Modify archive data. 17 | /// 18 | Modify 19 | } 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /SevenZip/LZMA/LzmaDecodeStream.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | using System.IO; 5 | 6 | using SevenZip.Sdk.Compression.Lzma; 7 | 8 | /// 9 | /// The stream which decompresses data with LZMA on the fly. 10 | /// 11 | public class LzmaDecodeStream : Stream 12 | { 13 | private readonly MemoryStream _buffer = new MemoryStream(); 14 | private readonly Decoder _decoder = new Decoder(); 15 | private readonly Stream _input; 16 | private byte[] _commonProperties; 17 | private bool _error; 18 | private bool _firstChunkRead; 19 | 20 | /// 21 | /// Initializes a new instance of the LzmaDecodeStream class. 22 | /// 23 | /// A compressed stream. 24 | public LzmaDecodeStream(Stream encodedStream) 25 | { 26 | if (!encodedStream.CanRead) 27 | { 28 | throw new ArgumentException("The specified stream can not read.", "encodedStream"); 29 | } 30 | _input = encodedStream; 31 | } 32 | 33 | /// 34 | /// Gets the chunk size. 35 | /// 36 | public int ChunkSize => (int) _buffer.Length; 37 | 38 | /// 39 | /// Gets a value indicating whether the current stream supports reading. 40 | /// 41 | public override bool CanRead => true; 42 | 43 | /// 44 | /// Gets a value indicating whether the current stream supports seeking. 45 | /// 46 | public override bool CanSeek => false; 47 | 48 | /// 49 | /// Gets a value indicating whether the current stream supports writing. 50 | /// 51 | public override bool CanWrite => false; 52 | 53 | /// 54 | /// Gets the length in bytes of the output stream. 55 | /// 56 | public override long Length 57 | { 58 | get 59 | { 60 | if (_input.CanSeek) 61 | { 62 | return _input.Length; 63 | } 64 | 65 | return _buffer.Length; 66 | } 67 | } 68 | 69 | /// 70 | /// Gets or sets the position within the output stream. 71 | /// 72 | public override long Position 73 | { 74 | get 75 | { 76 | if (_input.CanSeek) 77 | { 78 | return _input.Position; 79 | } 80 | return _buffer.Position; 81 | } 82 | set => throw new NotSupportedException(); 83 | } 84 | 85 | private void ReadChunk() 86 | { 87 | long size; 88 | byte[] properties; 89 | try 90 | { 91 | properties = SevenZipExtractor.GetLzmaProperties(_input, out size); 92 | } 93 | catch (LzmaException) 94 | { 95 | _error = true; 96 | return; 97 | } 98 | if (!_firstChunkRead) 99 | { 100 | _commonProperties = properties; 101 | } 102 | if (_commonProperties[0] != properties[0] || 103 | _commonProperties[1] != properties[1] || 104 | _commonProperties[2] != properties[2] || 105 | _commonProperties[3] != properties[3] || 106 | _commonProperties[4] != properties[4]) 107 | { 108 | _error = true; 109 | return; 110 | } 111 | if (_buffer.Capacity < (int) size) 112 | { 113 | _buffer.Capacity = (int) size; 114 | } 115 | _buffer.SetLength(size); 116 | _decoder.SetDecoderProperties(properties); 117 | _buffer.Position = 0; 118 | _decoder.Code( 119 | _input, _buffer, 0, size, null); 120 | _buffer.Position = 0; 121 | } 122 | 123 | /// 124 | /// Does nothing. 125 | /// 126 | public override void Flush() {} 127 | 128 | /// 129 | /// Reads a sequence of bytes from the current stream and decompresses data if necessary. 130 | /// 131 | /// An array of bytes. 132 | /// The zero-based byte offset in buffer at which to begin storing the data read from the current stream. 133 | /// The maximum number of bytes to be read from the current stream. 134 | /// The total number of bytes read into the buffer. 135 | public override int Read(byte[] buffer, int offset, int count) 136 | { 137 | if (_error) 138 | { 139 | return 0; 140 | } 141 | 142 | if (!_firstChunkRead) 143 | { 144 | ReadChunk(); 145 | _firstChunkRead = true; 146 | } 147 | int readCount = 0; 148 | while (count > _buffer.Length - _buffer.Position && !_error) 149 | { 150 | var buf = new byte[_buffer.Length - _buffer.Position]; 151 | _buffer.Read(buf, 0, buf.Length); 152 | buf.CopyTo(buffer, offset); 153 | offset += buf.Length; 154 | count -= buf.Length; 155 | readCount += buf.Length; 156 | ReadChunk(); 157 | } 158 | if (!_error) 159 | { 160 | _buffer.Read(buffer, offset, count); 161 | readCount += count; 162 | } 163 | return readCount; 164 | } 165 | 166 | /// 167 | /// Sets the position within the current stream. 168 | /// 169 | /// A byte offset relative to the origin parameter. 170 | /// A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position. 171 | /// The new position within the current stream. 172 | public override long Seek(long offset, SeekOrigin origin) 173 | { 174 | throw new NotSupportedException(); 175 | } 176 | 177 | /// 178 | /// Sets the length of the current stream. 179 | /// 180 | /// The desired length of the current stream in bytes. 181 | public override void SetLength(long value) 182 | { 183 | throw new NotSupportedException(); 184 | } 185 | 186 | /// 187 | /// Writes a sequence of bytes to the current stream. 188 | /// 189 | /// An array of bytes. 190 | /// The zero-based byte offset in buffer at which to begin storing the data read from the current stream. 191 | /// The maximum number of bytes to be read from the current stream. 192 | public override void Write(byte[] buffer, int offset, int count) 193 | { 194 | throw new NotSupportedException(); 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /SevenZip/LZMA/LzmaProgressCallback.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | 5 | using SevenZip.Sdk; 6 | 7 | /// 8 | /// Callback to implement the ICodeProgress interface 9 | /// 10 | internal sealed class LzmaProgressCallback : ICodeProgress 11 | { 12 | private readonly long _inSize; 13 | private float _oldPercentDone; 14 | 15 | /// 16 | /// Initializes a new instance of the LzmaProgressCallback class 17 | /// 18 | /// The input size 19 | /// Progress event handler 20 | public LzmaProgressCallback(long inSize, EventHandler working) 21 | { 22 | _inSize = inSize; 23 | Working += working; 24 | } 25 | 26 | #region ICodeProgress Members 27 | 28 | /// 29 | /// Sets the progress 30 | /// 31 | /// The processed input size 32 | /// The processed output size 33 | public void SetProgress(long inSize, long outSize) 34 | { 35 | if (Working != null) 36 | { 37 | float newPercentDone = (inSize + 0.0f) / _inSize; 38 | float delta = newPercentDone - _oldPercentDone; 39 | if (delta * 100 < 1.0) 40 | { 41 | delta = 0; 42 | } 43 | else 44 | { 45 | _oldPercentDone = newPercentDone; 46 | } 47 | Working(this, new ProgressEventArgs( 48 | PercentDoneEventArgs.ProducePercentDone(newPercentDone), 49 | delta > 0 ? PercentDoneEventArgs.ProducePercentDone(delta) : (byte)0, 50 | inSize, _inSize)); 51 | } 52 | } 53 | 54 | #endregion 55 | 56 | public event EventHandler Working; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /SevenZip/LibraryFeature.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | 5 | /// 6 | /// The set of features supported by the library. 7 | /// 8 | [Flags] 9 | [CLSCompliant(false)] 10 | public enum LibraryFeature : uint 11 | { 12 | /// 13 | /// Default feature. 14 | /// 15 | None = 0, 16 | /// 17 | /// The library can extract 7zip archives compressed with LZMA method. 18 | /// 19 | Extract7z = 0x1, 20 | /// 21 | /// The library can extract 7zip archives compressed with LZMA2 method. 22 | /// 23 | Extract7zLZMA2 = 0x2, 24 | /// 25 | /// The library can extract 7z archives compressed with all known methods. 26 | /// 27 | Extract7zAll = Extract7z|Extract7zLZMA2|0x4, 28 | /// 29 | /// The library can extract zip archives. 30 | /// 31 | ExtractZip = 0x8, 32 | /// 33 | /// The library can extract rar archives. 34 | /// 35 | ExtractRar = 0x10, 36 | /// 37 | /// The library can extract gzip archives. 38 | /// 39 | ExtractGzip = 0x20, 40 | /// 41 | /// The library can extract bzip2 archives. 42 | /// 43 | ExtractBzip2 = 0x40, 44 | /// 45 | /// The library can extract tar archives. 46 | /// 47 | ExtractTar = 0x80, 48 | /// 49 | /// The library can extract xz archives. 50 | /// 51 | ExtractXz = 0x100, 52 | /// 53 | /// The library can extract all types of archives supported. 54 | /// 55 | ExtractAll = Extract7zAll|ExtractZip|ExtractRar|ExtractGzip|ExtractBzip2|ExtractTar|ExtractXz, 56 | /// 57 | /// The library can compress data to 7zip archives with LZMA method. 58 | /// 59 | Compress7z = 0x200, 60 | /// 61 | /// The library can compress data to 7zip archives with LZMA2 method. 62 | /// 63 | Compress7zLZMA2 = 0x400, 64 | /// 65 | /// The library can compress data to 7zip archives with all methods known. 66 | /// 67 | Compress7zAll = Compress7z|Compress7zLZMA2|0x800, 68 | /// 69 | /// The library can compress data to tar archives. 70 | /// 71 | CompressTar = 0x1000, 72 | /// 73 | /// The library can compress data to gzip archives. 74 | /// 75 | CompressGzip = 0x2000, 76 | /// 77 | /// The library can compress data to bzip2 archives. 78 | /// 79 | CompressBzip2 = 0x4000, 80 | /// 81 | /// The library can compress data to xz archives. 82 | /// 83 | CompressXz = 0x8000, 84 | /// 85 | /// The library can compress data to zip archives. 86 | /// 87 | CompressZip = 0x10000, 88 | /// 89 | /// The library can compress data to all types of archives supported. 90 | /// 91 | CompressAll = Compress7zAll|CompressTar|CompressGzip|CompressBzip2|CompressXz|CompressZip, 92 | /// 93 | /// The library can modify archives. 94 | /// 95 | Modify = 0x20000 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /SevenZip/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip 2 | { 3 | using System; 4 | using System.Runtime.InteropServices; 5 | 6 | #if UNMANAGED 7 | internal static class NativeMethods 8 | { 9 | [UnmanagedFunctionPointer(CallingConvention.StdCall)] 10 | public delegate int CreateObjectDelegate( 11 | [In] ref Guid classID, 12 | [In] ref Guid interfaceID, 13 | [MarshalAs(UnmanagedType.Interface)] out object outObject); 14 | 15 | #if DESKTOP 16 | [DllImport("kernel32.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)] 17 | public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string fileName); 18 | #else 19 | [DllImport("api-ms-win-core-libraryloader-l2-1-0.dll", SetLastError = true, EntryPoint = "LoadPackagedLibrary")] 20 | public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPWStr)] string libraryName, int reserved = 0); 21 | #endif 22 | 23 | #if DESKTOP 24 | [DllImport("kernel32.dll")] 25 | [return: MarshalAs(UnmanagedType.Bool)] 26 | public static extern bool FreeLibrary(IntPtr hModule); 27 | #else 28 | [DllImport("api-ms-win-core-libraryloader-l1-2-0.dll")] 29 | [return: MarshalAs(UnmanagedType.Bool)] 30 | public static extern bool FreeLibrary(IntPtr hModule); 31 | #endif 32 | 33 | #if DESKTOP 34 | [DllImport("kernel32.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)] 35 | public static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string procName); 36 | #else 37 | [DllImport("api-ms-win-core-libraryloader-l1-2-0.dll", CharSet = CharSet.Ansi, SetLastError = true)] 38 | public static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string procName); 39 | #endif 40 | 41 | public static T SafeCast(PropVariant var, T def) 42 | { 43 | object obj; 44 | 45 | try 46 | { 47 | obj = var.Object; 48 | } 49 | catch (Exception) 50 | { 51 | return def; 52 | } 53 | 54 | if (obj is T expected) 55 | { 56 | return expected; 57 | } 58 | 59 | return def; 60 | } 61 | } 62 | #endif 63 | } -------------------------------------------------------------------------------- /SevenZip/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: CLSCompliant(true)] 6 | 7 | // Setting ComVisible to false makes the types in this assembly not visible 8 | // to COM components. If you need to access a type in this assembly from 9 | // COM, set the ComVisible attribute to true on that type. 10 | [assembly: ComVisible(false)] 11 | 12 | // The following GUID is for the ID of the typelib if this project is exposed to COM 13 | 14 | [assembly: Guid("80ed772d-f5a7-4314-b5bb-2be78e5f5f06")] 15 | [assembly: InternalsVisibleTo("SevenZip.Tests, PublicKey=" + 16 | "0024000004800000940000000602000000240000525341310004000001000100b9b5dbb5ceaf0f" + 17 | "4e693ffc862eca145aebd32558a40edc97b83704e97807fa6f16b444d6c189d11421c16b71de01" + 18 | "4db0149e1bd71f314943b667ac6f1374ce06a32ce8db9d8389385cbbd3a0bc1d9e9ad9ce51b440" + 19 | "08d909c438dc9473a79c088ffc51e9f9b26d89c89fe93c17e8fc2d6e771c400423608bea1577b6" + 20 | "a2c3cdad")] 21 | -------------------------------------------------------------------------------- /SevenZip/SevenZip.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | SevenZipSharp 4 | netstandard2.0 5 | 9.0 6 | Debug;Release;Desktop 7 | True 8 | Joel Ahlgren 9 | SevenZipSharp 10 | Markovtsev Vadim 11 | SevenZipSharp 12 | 7-zip native library wrapper 13 | Copyright (C) Markovtsev Vadim 2009, 2010, licensed under LGPLv3 14 | false 15 | 16 | 17 | 1.0.2 18 | 19 | 20 | $(DefineConstants)TRACE;DEBUG;UNMANAGED 21 | 22 | 23 | $(DefineConstants)TRACE;UNMANAGED 24 | 25 | 26 | $(DefineConstants)TRACE;DEBUG;UNMANAGED;DESKTOP 27 | 28 | 29 | 30 | PreserveNewest 31 | 32 | 33 | PreserveNewest 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /SevenZip/SevenZip.csproj.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True 3 | True -------------------------------------------------------------------------------- /SevenZip/SevenZip.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/SevenZip.snk -------------------------------------------------------------------------------- /SevenZip/UpdateData.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | using System.Collections.Generic; 6 | 7 | /// 8 | /// Archive update data for UpdateCallback. 9 | /// 10 | internal struct UpdateData 11 | { 12 | public uint FilesCount; 13 | public InternalCompressionMode Mode; 14 | 15 | public IDictionary FileNamesToModify { get; set; } 16 | 17 | public List ArchiveFileData { get; set; } 18 | } 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /SevenZip/ZipEncryptionMethod.cs: -------------------------------------------------------------------------------- 1 | #if UNMANAGED 2 | 3 | namespace SevenZip 4 | { 5 | /// 6 | /// Zip encryption method enum. 7 | /// 8 | public enum ZipEncryptionMethod 9 | { 10 | /// 11 | /// ZipCrypto encryption method. 12 | /// 13 | ZipCrypto, 14 | /// 15 | /// AES 128 bit encryption method. 16 | /// 17 | Aes128, 18 | /// 19 | /// AES 192 bit encryption method. 20 | /// 21 | Aes192, 22 | /// 23 | /// AES 256 bit encryption method. 24 | /// 25 | Aes256 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /SevenZip/arch/Test.bzip2.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/arch/Test.bzip2.7z -------------------------------------------------------------------------------- /SevenZip/arch/Test.lzma.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/arch/Test.lzma.7z -------------------------------------------------------------------------------- /SevenZip/arch/Test.lzma2.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/arch/Test.lzma2.7z -------------------------------------------------------------------------------- /SevenZip/arch/Test.ppmd.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/arch/Test.ppmd.7z -------------------------------------------------------------------------------- /SevenZip/arch/Test.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/arch/Test.rar -------------------------------------------------------------------------------- /SevenZip/arch/Test.tar: -------------------------------------------------------------------------------- 1 | Test.txt100777 0 0 4 11335207571 5573 0Test -------------------------------------------------------------------------------- /SevenZip/arch/Test.txt: -------------------------------------------------------------------------------- 1 | Test -------------------------------------------------------------------------------- /SevenZip/arch/Test.txt.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/arch/Test.txt.bz2 -------------------------------------------------------------------------------- /SevenZip/arch/Test.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/arch/Test.txt.gz -------------------------------------------------------------------------------- /SevenZip/arch/Test.txt.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/arch/Test.txt.xz -------------------------------------------------------------------------------- /SevenZip/arch/Test.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/arch/Test.zip -------------------------------------------------------------------------------- /SevenZip/lgpl.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /SevenZip/sdk/Common/CRC.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk 2 | { 3 | internal class CRC 4 | { 5 | public static readonly uint[] Table; 6 | 7 | private uint _value = 0xFFFFFFFF; 8 | 9 | static CRC() 10 | { 11 | Table = new uint[256]; 12 | const uint kPoly = 0xEDB88320; 13 | 14 | for (uint i = 0; i < 256; i++) 15 | { 16 | var r = i; 17 | 18 | for (var j = 0; j < 8; j++) 19 | { 20 | if ((r & 1) != 0) 21 | { 22 | r = (r >> 1) ^ kPoly; 23 | } 24 | else 25 | { 26 | r >>= 1; 27 | } 28 | } 29 | 30 | Table[i] = r; 31 | } 32 | } 33 | 34 | public void Init() 35 | { 36 | _value = 0xFFFFFFFF; 37 | } 38 | 39 | public void UpdateByte(byte b) 40 | { 41 | _value = Table[(((byte) (_value)) ^ b)] ^ (_value >> 8); 42 | } 43 | 44 | public void Update(byte[] data, uint offset, uint size) 45 | { 46 | for (uint i = 0; i < size; i++) 47 | _value = Table[(((byte) (_value)) ^ data[offset + i])] ^ (_value >> 8); 48 | } 49 | 50 | public uint GetDigest() 51 | { 52 | return _value ^ 0xFFFFFFFF; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /SevenZip/sdk/Common/InBuffer.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk.Buffer 2 | { 3 | using System.IO; 4 | 5 | /// 6 | /// Implements the input buffer work 7 | /// 8 | internal class InBuffer 9 | { 10 | private readonly byte[] m_Buffer; 11 | private readonly uint m_BufferSize; 12 | private uint m_Limit; 13 | private uint m_Pos; 14 | private ulong m_ProcessedSize; 15 | private Stream m_Stream; 16 | private bool m_StreamWasExhausted; 17 | 18 | /// 19 | /// Initializes the input buffer 20 | /// 21 | /// 22 | private InBuffer(uint bufferSize) 23 | { 24 | m_Buffer = new byte[bufferSize]; 25 | m_BufferSize = bufferSize; 26 | } 27 | 28 | /// 29 | /// Initializes the class 30 | /// 31 | /// 32 | private void Init(Stream stream) 33 | { 34 | m_Stream = stream; 35 | m_ProcessedSize = 0; 36 | m_Limit = 0; 37 | m_Pos = 0; 38 | m_StreamWasExhausted = false; 39 | } 40 | 41 | /// 42 | /// Reads the whole block 43 | /// 44 | /// 45 | private bool ReadBlock() 46 | { 47 | if (m_StreamWasExhausted) 48 | return false; 49 | m_ProcessedSize += m_Pos; 50 | int aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int) m_BufferSize); 51 | m_Pos = 0; 52 | m_Limit = (uint) aNumProcessedBytes; 53 | m_StreamWasExhausted = (aNumProcessedBytes == 0); 54 | return (!m_StreamWasExhausted); 55 | } 56 | 57 | /// 58 | /// Releases the stream 59 | /// 60 | private void ReleaseStream() 61 | { 62 | // m_Stream.Close(); 63 | m_Stream = null; 64 | } 65 | 66 | /// 67 | /// Reads the byte to check it 68 | /// 69 | /// 70 | /// 71 | private bool ReadByte(out byte b) 72 | { 73 | b = 0; 74 | if (m_Pos >= m_Limit) 75 | if (!ReadBlock()) 76 | return false; 77 | b = m_Buffer[m_Pos++]; 78 | return true; 79 | } 80 | 81 | /// 82 | /// Reads the next byte 83 | /// 84 | /// 85 | private byte ReadByte() 86 | { 87 | // return (byte)m_Stream.ReadByte(); 88 | if (m_Pos >= m_Limit) 89 | if (!ReadBlock()) 90 | return 0xFF; 91 | return m_Buffer[m_Pos++]; 92 | } 93 | 94 | /// 95 | /// Gets processed size 96 | /// 97 | /// 98 | private ulong GetProcessedSize() 99 | { 100 | return m_ProcessedSize + m_Pos; 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /SevenZip/sdk/Common/OutBuffer.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk.Buffer 2 | { 3 | using System.IO; 4 | 5 | internal class OutBuffer 6 | { 7 | private readonly byte[] m_Buffer; 8 | private readonly uint m_BufferSize; 9 | private uint m_Pos; 10 | private ulong m_ProcessedSize; 11 | private Stream m_Stream; 12 | 13 | /// 14 | /// Initializes a new instance of the OutBuffer class 15 | /// 16 | /// 17 | public OutBuffer(uint bufferSize) 18 | { 19 | m_Buffer = new byte[bufferSize]; 20 | m_BufferSize = bufferSize; 21 | } 22 | 23 | public void SetStream(Stream stream) 24 | { 25 | m_Stream = stream; 26 | } 27 | 28 | public void FlushStream() 29 | { 30 | m_Stream.Flush(); 31 | } 32 | 33 | public void CloseStream() 34 | { 35 | m_Stream.Close(); 36 | } 37 | 38 | public void ReleaseStream() 39 | { 40 | m_Stream = null; 41 | } 42 | 43 | public void Init() 44 | { 45 | m_ProcessedSize = 0; 46 | m_Pos = 0; 47 | } 48 | 49 | public void WriteByte(byte b) 50 | { 51 | m_Buffer[m_Pos++] = b; 52 | if (m_Pos >= m_BufferSize) 53 | FlushData(); 54 | } 55 | 56 | public void FlushData() 57 | { 58 | if (m_Pos == 0) 59 | return; 60 | m_Stream.Write(m_Buffer, 0, (int) m_Pos); 61 | m_Pos = 0; 62 | } 63 | 64 | public ulong GetProcessedSize() 65 | { 66 | return m_ProcessedSize + m_Pos; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /SevenZip/sdk/Compress/LZ/IMatchFinder.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk.Compression.LZ 2 | { 3 | using System; 4 | using System.IO; 5 | 6 | internal interface IInWindowStream 7 | { 8 | void SetStream(Stream inStream); 9 | void Init(); 10 | void ReleaseStream(); 11 | byte GetIndexByte(int index); 12 | uint GetMatchLen(int index, uint distance, uint limit); 13 | uint GetNumAvailableBytes(); 14 | } 15 | 16 | internal interface IMatchFinder : IInWindowStream 17 | { 18 | void Create(uint historySize, uint keepAddBufferBefore, 19 | uint matchMaxLen, uint keepAddBufferAfter); 20 | 21 | uint GetMatches(uint[] distances); 22 | void Skip(uint num); 23 | } 24 | } -------------------------------------------------------------------------------- /SevenZip/sdk/Compress/LZ/LzInWindow.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk.Compression.LZ 2 | { 3 | using System; 4 | using System.IO; 5 | 6 | /// 7 | /// Input window class 8 | /// 9 | internal class InWindow 10 | { 11 | /// 12 | /// Size of Allocated memory block 13 | /// 14 | public uint _blockSize; 15 | 16 | /// 17 | /// The pointer to buffer with data 18 | /// 19 | public byte[] _bufferBase; 20 | 21 | /// 22 | /// Buffer offset value 23 | /// 24 | public uint _bufferOffset; 25 | 26 | /// 27 | /// How many BYTEs must be kept buffer after _pos 28 | /// 29 | private uint _keepSizeAfter; 30 | 31 | /// 32 | /// How many BYTEs must be kept in buffer before _pos 33 | /// 34 | private uint _keepSizeBefore; 35 | 36 | private uint _pointerToLastSafePosition; 37 | 38 | /// 39 | /// Offset (from _buffer) of curent byte 40 | /// 41 | public uint _pos; 42 | 43 | private uint _posLimit; // offset (from _buffer) of first byte when new block reading must be done 44 | private Stream _stream; 45 | private bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream 46 | 47 | /// 48 | /// Offset (from _buffer) of first not read byte from Stream 49 | /// 50 | public uint _streamPos; 51 | 52 | public void MoveBlock() 53 | { 54 | uint offset = (_bufferOffset) + _pos - _keepSizeBefore; 55 | // we need one additional byte, since MovePos moves on 1 byte. 56 | if (offset > 0) 57 | offset--; 58 | 59 | uint numBytes = (_bufferOffset) + _streamPos - offset; 60 | 61 | // check negative offset ???? 62 | for (uint i = 0; i < numBytes; i++) 63 | _bufferBase[i] = _bufferBase[offset + i]; 64 | _bufferOffset -= offset; 65 | } 66 | 67 | public virtual void ReadBlock() 68 | { 69 | if (_streamEndWasReached) 70 | return; 71 | while (true) 72 | { 73 | var size = (int) ((0 - _bufferOffset) + _blockSize - _streamPos); 74 | if (size == 0) 75 | return; 76 | int numReadBytes = _stream.Read(_bufferBase, (int) (_bufferOffset + _streamPos), size); 77 | if (numReadBytes == 0) 78 | { 79 | _posLimit = _streamPos; 80 | uint pointerToPostion = _bufferOffset + _posLimit; 81 | if (pointerToPostion > _pointerToLastSafePosition) 82 | _posLimit = (_pointerToLastSafePosition - _bufferOffset); 83 | 84 | _streamEndWasReached = true; 85 | return; 86 | } 87 | _streamPos += (uint) numReadBytes; 88 | if (_streamPos >= _pos + _keepSizeAfter) 89 | _posLimit = _streamPos - _keepSizeAfter; 90 | } 91 | } 92 | 93 | private void Free() 94 | { 95 | _bufferBase = null; 96 | } 97 | 98 | public void Create(uint keepSizeBefore, uint keepSizeAfter, uint keepSizeReserv) 99 | { 100 | _keepSizeBefore = keepSizeBefore; 101 | _keepSizeAfter = keepSizeAfter; 102 | uint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv; 103 | if (_bufferBase == null || _blockSize != blockSize) 104 | { 105 | Free(); 106 | _blockSize = blockSize; 107 | _bufferBase = new byte[_blockSize]; 108 | } 109 | _pointerToLastSafePosition = _blockSize - keepSizeAfter; 110 | } 111 | 112 | public void SetStream(Stream stream) 113 | { 114 | _stream = stream; 115 | } 116 | 117 | public void ReleaseStream() 118 | { 119 | _stream = null; 120 | } 121 | 122 | public void Init() 123 | { 124 | _bufferOffset = 0; 125 | _pos = 0; 126 | _streamPos = 0; 127 | _streamEndWasReached = false; 128 | ReadBlock(); 129 | } 130 | 131 | public void MovePos() 132 | { 133 | _pos++; 134 | if (_pos > _posLimit) 135 | { 136 | uint pointerToPostion = _bufferOffset + _pos; 137 | if (pointerToPostion > _pointerToLastSafePosition) 138 | MoveBlock(); 139 | ReadBlock(); 140 | } 141 | } 142 | 143 | public byte GetIndexByte(int index) 144 | { 145 | return _bufferBase[_bufferOffset + _pos + index]; 146 | } 147 | 148 | /// 149 | /// index + limit have not to exceed _keepSizeAfter 150 | /// 151 | /// 152 | /// 153 | /// 154 | /// 155 | public uint GetMatchLen(int index, uint distance, uint limit) 156 | { 157 | if (_streamEndWasReached) 158 | if ((_pos + index) + limit > _streamPos) 159 | limit = _streamPos - (uint) (_pos + index); 160 | distance++; 161 | // Byte *pby = _buffer + (size_t)_pos + index; 162 | uint pby = _bufferOffset + _pos + (uint) index; 163 | 164 | uint i; 165 | for (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++) ; 166 | return i; 167 | } 168 | 169 | public uint GetNumAvailableBytes() 170 | { 171 | return _streamPos - _pos; 172 | } 173 | 174 | public void ReduceOffsets(int subValue) 175 | { 176 | _bufferOffset += (uint) subValue; 177 | _posLimit -= (uint) subValue; 178 | _pos -= (uint) subValue; 179 | _streamPos -= (uint) subValue; 180 | } 181 | } 182 | } -------------------------------------------------------------------------------- /SevenZip/sdk/Compress/LZ/LzOutWindow.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk.Compression.LZ 2 | { 3 | using System.IO; 4 | 5 | internal class OutWindow 6 | { 7 | private byte[] _buffer; 8 | private uint _pos; 9 | private Stream _stream; 10 | private uint _streamPos; 11 | private uint _windowSize; 12 | public uint TrainSize; 13 | 14 | public void Create(uint windowSize) 15 | { 16 | if (_windowSize != windowSize) 17 | { 18 | // System.GC.Collect(); 19 | _buffer = new byte[windowSize]; 20 | } 21 | _windowSize = windowSize; 22 | _pos = 0; 23 | _streamPos = 0; 24 | } 25 | 26 | public void Init(Stream stream, bool solid) 27 | { 28 | ReleaseStream(); 29 | _stream = stream; 30 | if (!solid) 31 | { 32 | _streamPos = 0; 33 | _pos = 0; 34 | TrainSize = 0; 35 | } 36 | } 37 | 38 | public bool Train(Stream stream) 39 | { 40 | long len = stream.Length; 41 | uint size = (len < _windowSize) ? (uint) len : _windowSize; 42 | TrainSize = size; 43 | stream.Position = len - size; 44 | _streamPos = _pos = 0; 45 | while (size > 0) 46 | { 47 | uint curSize = _windowSize - _pos; 48 | if (size < curSize) 49 | curSize = size; 50 | int numReadBytes = stream.Read(_buffer, (int) _pos, (int) curSize); 51 | if (numReadBytes == 0) 52 | return false; 53 | size -= (uint) numReadBytes; 54 | _pos += (uint) numReadBytes; 55 | _streamPos += (uint) numReadBytes; 56 | if (_pos == _windowSize) 57 | _streamPos = _pos = 0; 58 | } 59 | return true; 60 | } 61 | 62 | public void ReleaseStream() 63 | { 64 | Flush(); 65 | _stream = null; 66 | } 67 | 68 | public void Flush() 69 | { 70 | uint size = _pos - _streamPos; 71 | if (size == 0) 72 | return; 73 | _stream.Write(_buffer, (int) _streamPos, (int) size); 74 | if (_pos >= _windowSize) 75 | _pos = 0; 76 | _streamPos = _pos; 77 | } 78 | 79 | public void CopyBlock(uint distance, uint len) 80 | { 81 | uint pos = _pos - distance - 1; 82 | if (pos >= _windowSize) 83 | pos += _windowSize; 84 | for (; len > 0; len--) 85 | { 86 | if (pos >= _windowSize) 87 | pos = 0; 88 | _buffer[_pos++] = _buffer[pos++]; 89 | if (_pos >= _windowSize) 90 | Flush(); 91 | } 92 | } 93 | 94 | public void PutByte(byte b) 95 | { 96 | _buffer[_pos++] = b; 97 | if (_pos >= _windowSize) 98 | Flush(); 99 | } 100 | 101 | public byte GetByte(uint distance) 102 | { 103 | uint pos = _pos - distance - 1; 104 | if (pos >= _windowSize) 105 | pos += _windowSize; 106 | return _buffer[pos]; 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /SevenZip/sdk/Compress/LZMA/LzmaBase.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk.Compression.Lzma 2 | { 3 | internal abstract class Base 4 | { 5 | public const uint kAlignMask = (kAlignTableSize - 1); 6 | public const uint kAlignTableSize = 1 << kNumAlignBits; 7 | public const int kDicLogSizeMin = 0; 8 | public const uint kEndPosModelIndex = 14; 9 | public const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1; 10 | // public const int kDicLogSizeMax = 30; 11 | // public const uint kDistTableSizeMax = kDicLogSizeMax * 2; 12 | 13 | public const uint kMatchMinLen = 2; 14 | 15 | public const int kNumAlignBits = 4; 16 | 17 | public const uint kNumFullDistances = 1 << ((int) kEndPosModelIndex/2); 18 | public const int kNumHighLenBits = 8; 19 | 20 | public const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols + 21 | (1 << kNumHighLenBits); 22 | 23 | public const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits; 24 | public const int kNumLenToPosStatesBits = 2; // it's for speed optimization 25 | 26 | public const uint kNumLitContextBitsMax = 8; 27 | public const uint kNumLitPosStatesBitsEncodingMax = 4; 28 | 29 | public const int kNumLowLenBits = 3; 30 | public const uint kNumLowLenSymbols = 1 << kNumLowLenBits; 31 | public const int kNumMidLenBits = 3; 32 | public const uint kNumMidLenSymbols = 1 << kNumMidLenBits; 33 | public const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; 34 | public const int kNumPosSlotBits = 6; 35 | public const int kNumPosStatesBitsEncodingMax = 4; 36 | public const int kNumPosStatesBitsMax = 4; 37 | public const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax); 38 | public const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax); 39 | public const uint kNumRepDistances = 4; 40 | public const uint kNumStates = 12; 41 | public const uint kStartPosModelIndex = 4; 42 | 43 | public static uint GetLenToPosState(uint len) 44 | { 45 | len -= kMatchMinLen; 46 | if (len < kNumLenToPosStates) 47 | return len; 48 | return (kNumLenToPosStates - 1); 49 | } 50 | 51 | #region Nested type: State 52 | 53 | public struct State 54 | { 55 | public uint Index; 56 | 57 | public void Init() 58 | { 59 | Index = 0; 60 | } 61 | 62 | public void UpdateChar() 63 | { 64 | if (Index < 4) Index = 0; 65 | else if (Index < 10) Index -= 3; 66 | else Index -= 6; 67 | } 68 | 69 | public void UpdateMatch() 70 | { 71 | Index = (uint) (Index < 7 ? 7 : 10); 72 | } 73 | 74 | public void UpdateRep() 75 | { 76 | Index = (uint) (Index < 7 ? 8 : 11); 77 | } 78 | 79 | public void UpdateShortRep() 80 | { 81 | Index = (uint) (Index < 7 ? 9 : 11); 82 | } 83 | 84 | public bool IsCharState() 85 | { 86 | return Index < 7; 87 | } 88 | } 89 | 90 | #endregion 91 | } 92 | } -------------------------------------------------------------------------------- /SevenZip/sdk/Compress/RangeCoder/RangeCoder.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk.Compression.RangeCoder 2 | { 3 | using System; 4 | using System.IO; 5 | 6 | internal class Encoder 7 | { 8 | public const uint kTopValue = (1 << 24); 9 | private byte _cache; 10 | private uint _cacheSize; 11 | 12 | public ulong Low; 13 | public uint Range; 14 | 15 | private long StartPosition; 16 | private Stream Stream; 17 | 18 | public void SetStream(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 < 0xFF000000 || (uint) (Low >> 32) == 1) 68 | { 69 | byte temp = _cache; 70 | do 71 | { 72 | Stream.WriteByte((byte) (temp + (Low >> 32))); 73 | temp = 0xFF; 74 | } while (--_cacheSize != 0); 75 | _cache = (byte) (((uint) Low) >> 24); 76 | } 77 | _cacheSize++; 78 | Low = ((uint) Low) << 8; 79 | } 80 | 81 | public void EncodeDirectBits(uint v, int numTotalBits) 82 | { 83 | for (int i = numTotalBits - 1; i >= 0; i--) 84 | { 85 | Range >>= 1; 86 | if (((v >> i) & 1) == 1) 87 | Low += Range; 88 | if (Range < kTopValue) 89 | { 90 | Range <<= 8; 91 | ShiftLow(); 92 | } 93 | } 94 | } 95 | 96 | /*public void EncodeBit(uint size0, int numTotalBits, uint symbol) 97 | { 98 | uint newBound = (Range >> numTotalBits) * size0; 99 | if (symbol == 0) 100 | Range = newBound; 101 | else 102 | { 103 | Low += newBound; 104 | Range -= newBound; 105 | } 106 | while (Range < kTopValue) 107 | { 108 | Range <<= 8; 109 | ShiftLow(); 110 | } 111 | }*/ 112 | 113 | public long GetProcessedSizeAdd() 114 | { 115 | return _cacheSize + 116 | Stream.Position - StartPosition + 4; 117 | // (long)Stream.GetProcessedSize(); 118 | } 119 | } 120 | 121 | internal class Decoder 122 | { 123 | public const uint kTopValue = (1 << 24); 124 | public uint Code; 125 | public uint Range; 126 | // public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16); 127 | public Stream Stream; 128 | 129 | public void Init(Stream stream) 130 | { 131 | // Stream.Init(stream); 132 | Stream = stream; 133 | 134 | Code = 0; 135 | Range = 0xFFFFFFFF; 136 | for (int i = 0; i < 5; i++) 137 | Code = (Code << 8) | (byte) Stream.ReadByte(); 138 | } 139 | 140 | public void ReleaseStream() 141 | { 142 | // Stream.ReleaseStream(); 143 | Stream = null; 144 | } 145 | 146 | /*public void CloseStream() 147 | { 148 | Stream.Close(); 149 | }*/ 150 | 151 | /*public void Normalize() 152 | { 153 | while (Range < kTopValue) 154 | { 155 | Code = (Code << 8) | (byte)Stream.ReadByte(); 156 | Range <<= 8; 157 | } 158 | }*/ 159 | 160 | /*public void Normalize2() 161 | { 162 | if (Range < kTopValue) 163 | { 164 | Code = (Code << 8) | (byte)Stream.ReadByte(); 165 | Range <<= 8; 166 | } 167 | }*/ 168 | 169 | /*public uint GetThreshold(uint total) 170 | { 171 | return Code / (Range /= total); 172 | }*/ 173 | 174 | /*public void Decode(uint start, uint size, uint total) 175 | { 176 | Code -= start * Range; 177 | Range *= size; 178 | Normalize(); 179 | }*/ 180 | 181 | public uint DecodeDirectBits(int numTotalBits) 182 | { 183 | uint range = Range; 184 | uint code = Code; 185 | uint result = 0; 186 | for (int i = numTotalBits; i > 0; i--) 187 | { 188 | range >>= 1; 189 | /* 190 | result <<= 1; 191 | if (code >= range) 192 | { 193 | code -= range; 194 | result |= 1; 195 | } 196 | */ 197 | uint t = (code - range) >> 31; 198 | code -= range & (t - 1); 199 | result = (result << 1) | (1 - t); 200 | 201 | if (range < kTopValue) 202 | { 203 | code = (code << 8) | (byte) Stream.ReadByte(); 204 | range <<= 8; 205 | } 206 | } 207 | Range = range; 208 | Code = code; 209 | return result; 210 | } 211 | 212 | /*public uint DecodeBit(uint size0, int numTotalBits) 213 | { 214 | uint newBound = (Range >> numTotalBits) * size0; 215 | uint symbol; 216 | if (Code < newBound) 217 | { 218 | symbol = 0; 219 | Range = newBound; 220 | } 221 | else 222 | { 223 | symbol = 1; 224 | Code -= newBound; 225 | Range -= newBound; 226 | } 227 | Normalize(); 228 | return symbol; 229 | }*/ 230 | 231 | // ulong GetProcessedSize() {return Stream.GetProcessedSize(); } 232 | } 233 | } -------------------------------------------------------------------------------- /SevenZip/sdk/Compress/RangeCoder/RangeCoderBit.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk.Compression.RangeCoder 2 | { 3 | using System; 4 | 5 | internal struct BitEncoder 6 | { 7 | public const uint kBitModelTotal = (1 << kNumBitModelTotalBits); 8 | public const int kNumBitModelTotalBits = 11; 9 | public const int kNumBitPriceShiftBits = 6; 10 | private const int kNumMoveBits = 5; 11 | private const int kNumMoveReducingBits = 2; 12 | private static readonly uint[] ProbPrices = new uint[kBitModelTotal >> kNumMoveReducingBits]; 13 | 14 | private uint Prob; 15 | 16 | static BitEncoder() 17 | { 18 | const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits); 19 | for (int i = kNumBits - 1; i >= 0; i--) 20 | { 21 | uint start = (uint) 1 << (kNumBits - i - 1); 22 | uint end = (uint) 1 << (kNumBits - i); 23 | for (uint j = start; j < end; j++) 24 | ProbPrices[j] = ((uint) i << kNumBitPriceShiftBits) + 25 | (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1)); 26 | } 27 | } 28 | 29 | public void Init() 30 | { 31 | Prob = kBitModelTotal >> 1; 32 | } 33 | 34 | /*public void UpdateModel(uint symbol) 35 | { 36 | if (symbol == 0) 37 | Prob += (kBitModelTotal - Prob) >> kNumMoveBits; 38 | else 39 | Prob -= (Prob) >> kNumMoveBits; 40 | }*/ 41 | 42 | public void Encode(Encoder encoder, uint symbol) 43 | { 44 | // encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol); 45 | // UpdateModel(symbol); 46 | uint newBound = (encoder.Range >> kNumBitModelTotalBits)*Prob; 47 | if (symbol == 0) 48 | { 49 | encoder.Range = newBound; 50 | Prob += (kBitModelTotal - Prob) >> kNumMoveBits; 51 | } 52 | else 53 | { 54 | encoder.Low += newBound; 55 | encoder.Range -= newBound; 56 | Prob -= (Prob) >> kNumMoveBits; 57 | } 58 | if (encoder.Range < Encoder.kTopValue) 59 | { 60 | encoder.Range <<= 8; 61 | encoder.ShiftLow(); 62 | } 63 | } 64 | 65 | public uint GetPrice(uint symbol) 66 | { 67 | return ProbPrices[(((Prob - symbol) ^ ((-(int) symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits]; 68 | } 69 | 70 | public uint GetPrice0() 71 | { 72 | return ProbPrices[Prob >> kNumMoveReducingBits]; 73 | } 74 | 75 | public uint GetPrice1() 76 | { 77 | return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; 78 | } 79 | } 80 | 81 | internal struct BitDecoder 82 | { 83 | public const uint kBitModelTotal = (1 << kNumBitModelTotalBits); 84 | public const int kNumBitModelTotalBits = 11; 85 | private const int kNumMoveBits = 5; 86 | 87 | private uint Prob; 88 | 89 | /*public void UpdateModel(int numMoveBits, uint symbol) 90 | { 91 | if (symbol == 0) 92 | Prob += (kBitModelTotal - Prob) >> numMoveBits; 93 | else 94 | Prob -= (Prob) >> numMoveBits; 95 | }*/ 96 | 97 | public void Init() 98 | { 99 | Prob = kBitModelTotal >> 1; 100 | } 101 | 102 | public uint Decode(Decoder rangeDecoder) 103 | { 104 | uint newBound = (rangeDecoder.Range >> kNumBitModelTotalBits)*Prob; 105 | if (rangeDecoder.Code < newBound) 106 | { 107 | rangeDecoder.Range = newBound; 108 | Prob += (kBitModelTotal - Prob) >> kNumMoveBits; 109 | if (rangeDecoder.Range < Decoder.kTopValue) 110 | { 111 | rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte) rangeDecoder.Stream.ReadByte(); 112 | rangeDecoder.Range <<= 8; 113 | } 114 | return 0; 115 | } 116 | else 117 | { 118 | rangeDecoder.Range -= newBound; 119 | rangeDecoder.Code -= newBound; 120 | Prob -= (Prob) >> kNumMoveBits; 121 | if (rangeDecoder.Range < Decoder.kTopValue) 122 | { 123 | rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte) rangeDecoder.Stream.ReadByte(); 124 | rangeDecoder.Range <<= 8; 125 | } 126 | return 1; 127 | } 128 | } 129 | } 130 | } -------------------------------------------------------------------------------- /SevenZip/sdk/Compress/RangeCoder/RangeCoderBitTree.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk.Compression.RangeCoder 2 | { 3 | using System; 4 | 5 | internal struct BitTreeEncoder 6 | { 7 | private readonly BitEncoder[] Models; 8 | private readonly 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, uint symbol) 23 | { 24 | uint m = 1; 25 | for (int bitIndex = NumBitLevels; bitIndex > 0;) 26 | { 27 | bitIndex--; 28 | uint bit = (symbol >> bitIndex) & 1; 29 | Models[m].Encode(rangeEncoder, bit); 30 | m = (m << 1) | bit; 31 | } 32 | } 33 | 34 | public void ReverseEncode(Encoder rangeEncoder, uint symbol) 35 | { 36 | uint m = 1; 37 | for (uint i = 0; i < NumBitLevels; i++) 38 | { 39 | uint bit = symbol & 1; 40 | Models[m].Encode(rangeEncoder, bit); 41 | m = (m << 1) | bit; 42 | symbol >>= 1; 43 | } 44 | } 45 | 46 | public uint GetPrice(uint symbol) 47 | { 48 | uint price = 0; 49 | uint m = 1; 50 | for (int bitIndex = NumBitLevels; bitIndex > 0;) 51 | { 52 | bitIndex--; 53 | uint bit = (symbol >> bitIndex) & 1; 54 | price += Models[m].GetPrice(bit); 55 | m = (m << 1) + bit; 56 | } 57 | return price; 58 | } 59 | 60 | public uint ReverseGetPrice(uint symbol) 61 | { 62 | uint price = 0; 63 | uint m = 1; 64 | for (int i = NumBitLevels; i > 0; i--) 65 | { 66 | uint 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 uint ReverseGetPrice(BitEncoder[] Models, uint startIndex, 75 | int NumBitLevels, uint symbol) 76 | { 77 | uint price = 0; 78 | uint m = 1; 79 | for (int i = NumBitLevels; i > 0; i--) 80 | { 81 | uint 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, uint startIndex, 90 | Encoder rangeEncoder, int NumBitLevels, uint symbol) 91 | { 92 | uint m = 1; 93 | for (int i = 0; i < NumBitLevels; i++) 94 | { 95 | uint bit = symbol & 1; 96 | Models[startIndex + m].Encode(rangeEncoder, bit); 97 | m = (m << 1) | bit; 98 | symbol >>= 1; 99 | } 100 | } 101 | } 102 | 103 | internal struct BitTreeDecoder 104 | { 105 | private readonly BitDecoder[] Models; 106 | private readonly 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(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(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, uint startIndex, 143 | 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 | } -------------------------------------------------------------------------------- /SevenZip/sdk/ICoder.cs: -------------------------------------------------------------------------------- 1 | namespace SevenZip.Sdk 2 | { 3 | using System; 4 | using System.IO; 5 | 6 | /// 7 | /// The exception that is thrown when an error in input stream occurs during decoding. 8 | /// 9 | [Serializable] 10 | internal 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 | [Serializable] 19 | internal class InvalidParamException : ApplicationException 20 | { 21 | public InvalidParamException() : base("Invalid Parameter") {} 22 | } 23 | 24 | /// 25 | /// Callback progress interface. 26 | /// 27 | public interface ICodeProgress 28 | { 29 | /// 30 | /// Callback progress. 31 | /// 32 | /// 33 | /// Processed input size. -1 if unknown. 34 | /// 35 | /// 36 | /// Processed output size. -1 if unknown. 37 | /// 38 | void SetProgress(long inSize, long outSize); 39 | } ; 40 | 41 | /// 42 | /// Stream coder interface 43 | /// 44 | public interface ICoder 45 | { 46 | /// 47 | /// Codes streams. 48 | /// 49 | /// 50 | /// input Stream. 51 | /// 52 | /// 53 | /// output Stream. 54 | /// 55 | /// 56 | /// input Size. -1 if unknown. 57 | /// 58 | /// 59 | /// output Size. -1 if unknown. 60 | /// 61 | /// 62 | /// callback progress reference. 63 | /// 64 | /// 65 | /// if input stream is not valid 66 | /// 67 | void Code(Stream inStream, Stream outStream, 68 | long inSize, long outSize, ICodeProgress progress); 69 | } ; 70 | 71 | /* 72 | public interface ICoder2 73 | { 74 | void Code(ISequentialInStream []inStreams, 75 | const UInt64 []inSizes, 76 | ISequentialOutStream []outStreams, 77 | UInt64 []outSizes, 78 | ICodeProgress progress); 79 | }; 80 | */ 81 | 82 | /// 83 | /// Provides the fields that represent properties idenitifiers for compressing. 84 | /// 85 | public enum CoderPropId 86 | { 87 | /// 88 | /// Specifies default property. 89 | /// 90 | DefaultProp = 0, 91 | /// 92 | /// Specifies size of dictionary. 93 | /// 94 | DictionarySize, 95 | /// 96 | /// Specifies size of memory for PPM*. 97 | /// 98 | UsedMemorySize, 99 | /// 100 | /// Specifies order for PPM methods. 101 | /// 102 | Order, 103 | /// 104 | /// Specifies Block Size. 105 | /// 106 | BlockSize, 107 | /// 108 | /// Specifies number of postion state bits for LZMA (0 <= x <= 4). 109 | /// 110 | PosStateBits, 111 | /// 112 | /// Specifies number of literal context bits for LZMA (0 <= x <= 8). 113 | /// 114 | LitContextBits, 115 | /// 116 | /// Specifies number of literal position bits for LZMA (0 <= x <= 4). 117 | /// 118 | LitPosBits, 119 | /// 120 | /// Specifies number of fast bytes for LZ*. 121 | /// 122 | NumFastBytes, 123 | /// 124 | /// Specifies match finder. LZMA: "BT2", "BT4" or "BT4B". 125 | /// 126 | MatchFinder, 127 | /// 128 | /// Specifies the number of match finder cyckes. 129 | /// 130 | MatchFinderCycles, 131 | /// 132 | /// Specifies number of passes. 133 | /// 134 | NumPasses, 135 | /// 136 | /// Specifies number of algorithm. 137 | /// 138 | Algorithm, 139 | /// 140 | /// Specifies the number of threads. 141 | /// 142 | NumThreads, 143 | /// 144 | /// Specifies mode with end marker. 145 | /// 146 | EndMarker = 0x490 147 | } ; 148 | 149 | /// 150 | /// The ISetCoderProperties interface 151 | /// 152 | internal interface ISetCoderProperties 153 | { 154 | void SetCoderProperties(CoderPropId[] propIDs, object[] properties); 155 | } ; 156 | 157 | /// 158 | /// The IWriteCoderProperties interface 159 | /// 160 | internal interface IWriteCoderProperties 161 | { 162 | void WriteCoderProperties(Stream outStream); 163 | } 164 | 165 | /// 166 | /// The ISetDecoderPropertiesinterface 167 | /// 168 | internal interface ISetDecoderProperties 169 | { 170 | /// 171 | /// Sets decoder properties 172 | /// 173 | /// Array of byte properties 174 | void SetDecoderProperties(byte[] properties); 175 | } 176 | } -------------------------------------------------------------------------------- /SevenZip/sfx/7z.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7z.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zCon.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zCon.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zS.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zS.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zSD.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zSD.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_All.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_All.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_All_x64.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_All_x64.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_Deflate.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_Deflate.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_Deflate_x64.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_Deflate_x64.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_LZMA.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_LZMA.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_LZMA2.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_LZMA2.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_LZMA2_x64.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_LZMA2_x64.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_LZMA_x64.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_LZMA_x64.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_PPMd.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_PPMd.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/7zxSD_PPMd_x64.sfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/SevenZipSharp/f9f1f1a4097b401f870225cf1f634d0882b5f13c/SevenZip/sfx/7zxSD_PPMd_x64.sfx -------------------------------------------------------------------------------- /SevenZip/sfx/Configs.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /SevenZip/sfx/Configs.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /SevenZip/sfx/Configs.xslt: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | 6 | 7 | 7-Zip Sfx Configurations 8 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 37 | 40 | 41 | 42 | 45 | 48 | 49 | 50 | 51 | 52 | 53 |
21 |

22 | 23 |

24 |
CommandDescription
35 | 36 | 38 | 39 | 43 | 44 | 46 | 47 |
54 |
Applicable to modules: .
55 |
56 | 57 | 58 |
59 |
60 | -------------------------------------------------------------------------------- /SevenZip/sfx/sample.txt: -------------------------------------------------------------------------------- 1 | ;!@Install@!UTF-8! 2 | GUIMode="0" 3 | InstallPath="." 4 | GUIFlags="128+8" 5 | ExtractPathTitle="Hi!" 6 | ExtractPathText="Path" 7 | ;!@InstallEnd@! -------------------------------------------------------------------------------- /TestApp/Program.cs: -------------------------------------------------------------------------------- 1 | using SevenZip; 2 | 3 | namespace TestApp 4 | { 5 | internal class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var filePath = @"C:\Users\gavet\Documents\Test\Archives\temp_p.7z"; 10 | var password = ""; 11 | try 12 | { 13 | var arch = new SevenZipExtractor(File.OpenRead(filePath), password); 14 | arch.ArchiveProperties.ToList().ForEach(p => Console.WriteLine($"{p.Name}: {p.Value}")); 15 | Console.WriteLine($"Contains: {arch.ArchiveFileData.Count} files"); 16 | var enc = arch.ArchiveFileData.Any(file => file.Encrypted || file.Method.Contains("Crypto") || file.Method.Contains("AES")); 17 | Console.WriteLine($"Encrypted: {enc}, {arch.ArchiveProperties.FirstOrDefault(x => x.Name == "Encrypted").Value}"); 18 | arch.ExtractFile("orig\\dxwebsetup.exe", new MemoryStream()); 19 | } 20 | catch(SevenZipOpenFailedException ex) 21 | { 22 | Console.WriteLine($"Error: {ex.Result}"); 23 | } 24 | catch (ExtractionFailedException ex) 25 | { 26 | Console.WriteLine($"Error: {ex.Result}"); 27 | } 28 | 29 | /*var compressor = new SevenZipCompressor() 30 | { 31 | ArchiveFormat = OutArchiveFormat.Zip 32 | }; 33 | compressor.Compressing += Compressor_Compressing; 34 | compressor.CompressDirectory(@"C:\Users\gavet\Documents\Test", @"C:\Users\gavet\Documents\Test.zip");*/ 35 | } 36 | 37 | private static void Compressor_Compressing(object? sender, ProgressEventArgs e) 38 | { 39 | Console.WriteLine(e.BytesProcessed / (double)e.BytesCount * 100); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /TestApp/TestApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.5.2 (2023-03-22) 4 | - Fixed an issue when seeking in streams with SeekOrigin.End, thanks to GitHub user bneidhold. 5 | - Fixed an issue when checking multi-volume 7z archives, thanks to GitHub user panda73111. 6 | - Changed CI from AppVeyor to GitHub Actions. 7 | - .NET Framework version bumped from 4.5 to 4.7.2. 8 | 9 | ## 1.5.0 (2021-08-15) 10 | - Added separate NuGet (Lite) excluding creation of self-extracting archives. 11 | 12 | ## 1.4.0 (2021-04-12) 13 | - Added a work-around to allow UWP apps to use SevenZipSharp in Release builds. 14 | - Fix issue limiting split archive volume size to 2GB. 15 | 16 | ## 1.3.318 (2021-03-05) 17 | - Fixed issue with SFN paths during compression. 18 | - Fixed issue with library path detection during initialization, thanks to GitHub user thoemmi. 19 | - Fixed issue detecting .deb archives, thanks to GitHub user NickHarmer. 20 | - Added ability to skip files during archive extraction, thanks to GitHub user NickHarmer. 21 | 22 | ## 1.3.283 (2020-05-01) 23 | - Added awaitable extraction functions, thanks to GitHub user kikijiki. 24 | - Added awaitable compression functions. 25 | 26 | ## 1.2.265 (2020-03-21) 27 | - Fixed problem where a UNC destination path would fail extraction. 28 | 29 | ## 1.2.258 (2020-02-21) 30 | - Fixed several bugs in custom parameters for the SevenZipCompressor class. 31 | 32 | ## 1.2.242 (2019-12-24) 33 | - Improved Operation Result handling and better performance by removing excessive GC, thanks to GitHub user zylab-official. 34 | 35 | ## 1.2.231 (2019-10-05) 36 | - Improved support for non-solid extraction of 7z "Copy" file from solid archive using index, thanks to GitHub user Mgamerz. 37 | - Fixed issue related to invalid character in directory and file name, thanks to GitHub user Ramkaran Yadav. 38 | 39 | ## 1.2.219 (2019-09-19) 40 | - Fixed issue when SevenZipSharp is embedded, thanks to GitHub user Mgamerz. 41 | 42 | ## 1.2.201 (2019-09-12) 43 | - Added NuGet dependencies for .NET Standard 2.0 projects. 44 | - Improved error handling. 45 | 46 | ## 1.2.191 (2019-09-12) 47 | - Re-added support for detecting RAR4 sfx archives. 48 | 49 | ## 1.2.184 (2019-06-08) 50 | - Now supports both .NET45 and .NET Standard 2.0, thanks to Github user frblondin. 51 | 52 | ## 1.1.144 (2019-04-20) 53 | - Now accepts IDictionaries where applicable, thanks to GitHub user rotvel. 54 | 55 | ## 1.1.136 (2019-03-05) 56 | - Archive property VolumeIndex now exposed through SevenZipSharp, thanks to Ravi Patel (ravibpatel). 57 | 58 | ## 1.1.126 (2019-02-06) 59 | - Improved error output a little, no new functionality or bugfixes. 60 | 61 | ## 1.1.106 (2018-08-13) 62 | - Fixed problem when modifying encrypted archives. 63 | 64 | ## 1.1.96 (2018-08-01) 65 | - Added support for new archive formats supported by 7-Zip (thanks to Artem Tarasov). 66 | 67 | ## 1.1.91 (2018-07-31) 68 | - Fixed problems with creating self-extracting archives. 69 | 70 | ## 1.1.53 (2018-07-27) 71 | - Fixed bugs when: 72 | + extracting .gz archives 73 | + extracting .bz2 archives 74 | + extracting zip file from stream 75 | + compressing a stream into another stream 76 | 77 | ## 1.1.22 (2018-07-22) 78 | - Includes support for extracting RAR v5 archives. 79 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /package.lite.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Squid-Box.SevenZipSharp.Lite 5 | 1.0.0 6 | Joel Ahlgren 7 | Managed 7-zip library written in C# that provides data extraction and compression (all 7-zip formats are supported). 8 | Wraps 7z.dll or any compatible one and makes use of LZMA SDK. Excludes creation of self-extracting executables, reducing file size. 9 | docs\readme.md 10 | en-US 11 | LGPL-3.0-only 12 | https://github.com/squid-box/SevenZipSharp 13 | 7z sevenzip sevenzipsharp 7-zip 14 | Fixed broken asynchronous extraction. 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /package.regular.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Squid-Box.SevenZipSharp 5 | 1.0.0 6 | Joel Ahlgren 7 | Managed 7-zip library written in C# that provides data (self-)extraction and compression (all 7-zip formats are supported). 8 | Wraps 7z.dll or any compatible one and makes use of LZMA SDK, includes self-extraction functionality. 9 | docs\readme.md 10 | en-US 11 | LGPL-3.0-only 12 | https://github.com/squid-box/SevenZipSharp 13 | 7z sevenzip sevenzipsharp 7-zip 14 | Fixed broken asynchronous extraction. 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | This is a fork from [squid-box](https://github.com/squid-box/SevenZipSharp) of [tomap's fork](https://github.com/tomap/SevenZipSharp) of the [original CodePlex project](https://archive.codeplex.com/?p=sevenzipsharp). Changes include support for UWP & integration with [Files](https://github.com/files-community/Files/). 2 | 3 | ## Continuous Integration 4 | 5 | | Squid-Box.SevenZipSharp | Squid-Box.SevenZipSharp.Lite | 6 | |----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------| 7 | | [![NuGet Badge](https://buildstats.info/nuget/Squid-Box.SevenZipSharp)](https://www.nuget.org/packages/Squid-Box.SevenZipSharp/) | [![NuGet Badge](https://buildstats.info/nuget/Squid-Box.SevenZipSharp.Lite)](https://www.nuget.org/packages/Squid-Box.SevenZipSharp.Lite/) | 8 | 9 | ## Changes from original project 10 | As required by the GNU GPL 3.0 license, here's a rough list of what has changed since the original CodePlex project, including changes made in tomap's fork. 11 | 12 | * Target .NET version changed from .NET Framework 2.0 to .NET Standard 2.0, .NET Framework 4.7.2 and .NET Core 3.1. 13 | * Produces two NuGet packages, one full-feature package and a `Lite` variant without SFX support (and significantly smaller size). 14 | * Continous Integration added, both building and deploying. 15 | * Tests re-written to NUnit 3 test cases. 16 | * General code cleanup. 17 | 18 | As well as a number of improvements and bug fixes. 19 | 20 | ------------------------------------------------------------- 21 | 22 | Original project information below, some information might be outdated or won't apply to this fork: 23 | 24 | ------------------------------------------------------------- 25 | 26 | ## Project Description 27 | Managed 7-zip library written in C# that provides data (self-)extraction and compression (all 7-zip formats are supported). It wraps 7z.dll or any compatible one and makes use of LZMA SDK. 28 | 29 | ## General 30 | SevenZipSharp is an open source wrapper for 7-zip released under LGPL v3.0. It exploits the native 7zip dynamic link library through its COM interface and exports classes to work with various file archives. The project appeared as an improvement of http://www.codeproject.com/KB/DLL/cs_interface_7zip.aspx. It supports .NET and Windows Mobile .NET Compact. 31 | 32 | The solution consists of SevenZipSharp library itself, console, WinForms and WPF test applications and the documentation. All are built with Microsoft Visual Studio 2008 or 2010 and under .NET 2.0 (up to 4.0). 33 | Sandcastle is used to build the library documentation. 34 | SevenZipSharp uses JetBrains ReSharper to maintain the quality of the code and NDepend to collect code statistics and audit the whole project. Special thanks to SciTech Software for .NET Memory Profiler. 35 | 36 | Check SVN for the latest version of SevenZipSharp. 37 | 38 | ## Quick start 39 | SevenZipSharp exports three main classes - SevenZipExtractor, SevenZipCompressor and SevenZipSfx. 40 | SevenZipExtractor is a 7-zip unpacking front-end, it allows either to extract archives or LZMA-compressed byte arrays. 41 | SevenZipCompressor is a 7-zip pack ingfront-end, it allows either to compress archives or byte arrays. 42 | SevenZipSfx is a special class to create self-extracting archives. It uses the embedded sfx module by Oleg Scherbakov . 43 | LzmaEncodeStream/LzmaDecodeStream are special fully managed classes derived from Stream to store data compressed with LZMA and extract it. 44 | See SevenZipTest/Program.cs for simple code examples; SevenZipTestForms is the GUI demo application. 45 | You may find useful the SevenZipSharp documentation provided in CHM format. On Windows XP SP2 or later or Vista unblock the file to view it correctly. 46 | 47 | ## Native libraries 48 | SevenZipSharp requires a 7-zip native library to function. You can specify the path to a 7-zip dll (7z.dll, 7za.dll, etc.) in LibraryManager.cs at compile time, your app.config or via SetLibraryPath() method at runtime. + "7z.dll" is the default path. For 64-bit systems, you must use the 64-bit versions of those libraries. 49 | 7-zip ships with 7z.dll, which is used for all archive operations (usually it is "Program Files\7-Zip\7z.dll"). 7za.dll is a light version of 7z.dll, it supports only 7zip archives. You may even build your own library with formats you want from 7-zip sources. SevenZipSharp will work with them all. 50 | 51 | ## Main features 52 | * Encryption and passwords are supported. 53 | * Since the 0.26 release, archive properties are supported. 54 | * Since the 0.28 release, multi-threading is supported. 55 | * Since the 0.29 release, streaming is supported. 56 | * Since the 0.41 release, you can specify the compression level and method. 57 | * Since the 0.50 release, archive volumes are supported. 58 | * Since the 0.51 release, archive updates are supported (0.52 - ModifyArchive). You must use the most recent 7z.dll (v>=9.04) for this feature. 59 | * Since the 0.61 release, Windows Mobile ARM platforms are supported. 60 | * Since the 0.62 release, extraction from SFX archives, as well as some other formats with embedded archives is supported. 61 | 62 | Extraction is supported from any archive format in InArchiveFormat - such as 7-zip itself, zip, rar or cab and the format is automatically guessed by the archive signature (since the 0.43 release). 63 | You can compress streams, files or whole directories in OutArchiveFormat - 7-zip, Xz, Zip, GZip, BZip2 and Tar. 64 | Please note that GZip and BZip2 compresses only one file at a time. 65 | 66 | SevenZipSharpMobile (SevenZipSharp for Windows Mobile) does not differ much from its big brother. See the difference table below. 67 | 68 | ## Self-extracting archives 69 | SevenZipSfx appeared in the 0.42 release. It supports custom sfx modules. The most powerful one is embedded in the assembly, the other lie in SevenZip/sfx directory. Apart from usual sfx, you can make even small installations with the help of SfxSettings scenarios. Refer to the "configuration file parameters" for the complete command list. 70 | 71 | ## Advanced work with SevenZipCompressor 72 | SevenZipCompressor.CustomParameters is a special property to set compression switches, compatible with command line switches of 7z.exe. The complete list of those switches is in 7-zip.chm of 7-Zip installation. For example, to turn on multi-threaded compression, code 73 | .CustomParameters.Add("mt", "on"); 74 | For the complete switches list, refer to SevenZipDoc.chm in the 7-zip installation. 75 | 76 | ## Conditional compilation symbols 77 | These compilation symbols are supported: UNMANAGED. 78 | * UNMANAGED allows the main COM part of SevenZipSharp to be built. 79 | --------------------------------------------------------------------------------