diff --git a/Duplicati/Library/Compression/SevenZipCompression.cs b/Duplicati/Library/Compression/SevenZipCompression.cs index 04796c1f1..1622c9701 100644 --- a/Duplicati/Library/Compression/SevenZipCompression.cs +++ b/Duplicati/Library/Compression/SevenZipCompression.cs @@ -21,6 +21,8 @@ namespace Duplicati.Library.Compression private int m_threadCount; private bool m_lowOverheadMode; + private ManagedLzma.LZMA.Master.LZMA.CLzma2EncProps m_encoderProps; + /// /// Gets or sets a value indicating whether this /// is in low overhead mode. @@ -70,7 +72,20 @@ namespace Duplicati.Library.Compression m_threadCount = threadCountValue; } + + string cplvl; + int tmplvl; + if (options.TryGetValue(COMPRESSION_LEVEL_OPTION, out cplvl) && int.TryParse(cplvl, out tmplvl)) + tmplvl = Math.Max(Math.Min(9, tmplvl), 0); + else + tmplvl = DEFAULT_COMPRESSION_LEVEL; + m_encoderProps = new ManagedLzma.LZMA.Master.LZMA.CLzma2EncProps(); + m_encoderProps.Lzma2EncProps_Init(); + + m_encoderProps.mLzmaProps.mLevel = tmplvl; + m_encoderProps.mLzmaProps.mAlgo = Library.Utility.Utility.ParseBoolOption(options, COMPRESSION_FASTALGO_OPTION) ? 0 : 1; + var file = new FileInfo(filename); if(file.Exists && file.Length > 0) InitializeArchiveReader(filename); @@ -254,7 +269,7 @@ namespace Duplicati.Library.Compression if(m_lowOverheadMode) m_lzma2Encoder = new ManagedLzma.LZMA.Master.SevenZip.ArchiveWriter.LzmaEncoder(); else - m_lzma2Encoder = new ManagedLzma.LZMA.Master.SevenZip.ArchiveWriter.Lzma2Encoder(m_threadCount); + m_lzma2Encoder = new ManagedLzma.LZMA.Master.SevenZip.ArchiveWriter.Lzma2Encoder(m_threadCount, m_encoderProps); m_lzma2Encoder.OnOutputThresholdReached += mLzma2Encoder_OnOutputThresholdReached; m_lzma2Encoder.SetOutputThreshold(kStreamThreshold); @@ -339,6 +354,26 @@ namespace Duplicati.Library.Compression /// private static readonly int DEFAULT_THREAD_COUNT = Environment.ProcessorCount; + /// + /// The commandline option for toggling the compression level + /// + private const string COMPRESSION_LEVEL_OPTION = "7z-compression-level"; + + /// + /// The default compression level + /// + private const int DEFAULT_COMPRESSION_LEVEL = 5; + + /// + /// The commandline option for toggling the compression algorithm + /// + private const string COMPRESSION_FASTALGO_OPTION = "7z-compression-fast-algorithm"; + + /// + /// The default setting for the fast-algorithm option + /// + private const bool DEFAULT_FASTALGO = false; + /// /// Arbitrary limit to avoid problems with unreasonable user input. /// @@ -354,7 +389,23 @@ namespace Duplicati.Library.Compression CommandLineArgument.ArgumentType.Integer, Strings.SevenZipCompression.ThreadcountShort, Strings.SevenZipCompression.ThreadcountLong, - DEFAULT_THREAD_COUNT.ToString()) + DEFAULT_THREAD_COUNT.ToString()), + + new CommandLineArgument( + COMPRESSION_LEVEL_OPTION, + CommandLineArgument.ArgumentType.Enumeration, + Strings.SevenZipCompression.CompressionlevelShort, + Strings.SevenZipCompression.CompressionlevelLong, + DEFAULT_COMPRESSION_LEVEL.ToString(), + null, + new string[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}), + + new CommandLineArgument( + COMPRESSION_FASTALGO_OPTION, + CommandLineArgument.ArgumentType.Boolean, + Strings.SevenZipCompression.FastalgoShort, + Strings.SevenZipCompression.FastalgoLong, + DEFAULT_FASTALGO.ToString()), }; } } diff --git a/Duplicati/Library/Compression/Strings.cs b/Duplicati/Library/Compression/Strings.cs index d53dbd667..a3fe180e5 100644 --- a/Duplicati/Library/Compression/Strings.cs +++ b/Duplicati/Library/Compression/Strings.cs @@ -18,5 +18,9 @@ namespace Duplicati.Library.Compression.Strings { public static string DisplayName { get { return LC.L(@"7z Archive"); } } public static string ThreadcountLong { get { return LC.L(@"The number of threads used in LZMA 2 compression. Defaults to the number of processor cores.."); } } public static string ThreadcountShort { get { return LC.L(@"Number of threads used in compression"); } } + public static string CompressionlevelLong { get { return LC.L(@"This option controls the compression level used. A setting of zero gives no compression, and a setting of 9 gives maximum compression."); } } + public static string CompressionlevelShort { get { return LC.L(@"Sets the 7z compression level"); } } + public static string FastalgoLong { get { return LC.L(@"This option controls the compression algorithm used. Enabling this option will cause 7z to use the fast algorithm, which produces slightly less compression."); } } + public static string FastalgoShort { get { return LC.L(@"Sets the 7z fast algorithm usage"); } } } } diff --git a/thirdparty/ManagedLZMA/README.txt b/thirdparty/ManagedLZMA/README.txt index 65f387726..eccb09a19 100644 --- a/thirdparty/ManagedLZMA/README.txt +++ b/thirdparty/ManagedLZMA/README.txt @@ -1,5 +1,5 @@ -The binaries here are obtained by checking out the source for r50: -http://code.google.com/p/managed-lzma +The binaries here are obtained by checking out the source for e12204c6: +https://github.com/weltkante/managed-lzma/commit/3e12204c60ada8164561a841bb8dcb4c96078c99 And building the "master" project in Release mode with Mono. This is done because there were no released binaries to base it on. diff --git a/thirdparty/ManagedLZMA/download.txt b/thirdparty/ManagedLZMA/download.txt index 224525b31..59b1afc9e 100644 --- a/thirdparty/ManagedLZMA/download.txt +++ b/thirdparty/ManagedLZMA/download.txt @@ -1 +1 @@ -http://code.google.com/p/managed-lzma \ No newline at end of file +https://github.com/weltkante/managed-lzma \ No newline at end of file diff --git a/thirdparty/ManagedLZMA/licensedata.json b/thirdparty/ManagedLZMA/licensedata.json index 7a41985a4..8e9bd95e4 100644 --- a/thirdparty/ManagedLZMA/licensedata.json +++ b/thirdparty/ManagedLZMA/licensedata.json @@ -1,7 +1,7 @@ { "name": "ManagedLZMA", "description": "An LZMA/7z compression library by Tobias Käs", - "link": "http://code.google.com/p/managed-lzma", + "link": "https://github.com/weltkante/managed-lzma", "license": "MIT", "notes": "" } \ No newline at end of file diff --git a/thirdparty/ManagedLZMA/managed-lzma.dll b/thirdparty/ManagedLZMA/managed-lzma.dll old mode 100644 new mode 100755 index cce7142d3..8b1d81804 Binary files a/thirdparty/ManagedLZMA/managed-lzma.dll and b/thirdparty/ManagedLZMA/managed-lzma.dll differ