Updated managed-lzma and added option to set compression-level for 7z.

This closes #1050.
This commit is contained in:
Kenneth Skovhede
2015-03-05 21:08:19 +01:00
parent b650838180
commit 37622262af
6 changed files with 61 additions and 6 deletions
@@ -21,6 +21,8 @@ namespace Duplicati.Library.Compression
private int m_threadCount;
private bool m_lowOverheadMode;
private ManagedLzma.LZMA.Master.LZMA.CLzma2EncProps m_encoderProps;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Duplicati.Library.Compression.SevenZipCompression"/>
/// 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
/// </summary>
private static readonly int DEFAULT_THREAD_COUNT = Environment.ProcessorCount;
/// <summary>
/// The commandline option for toggling the compression level
/// </summary>
private const string COMPRESSION_LEVEL_OPTION = "7z-compression-level";
/// <summary>
/// The default compression level
/// </summary>
private const int DEFAULT_COMPRESSION_LEVEL = 5;
/// <summary>
/// The commandline option for toggling the compression algorithm
/// </summary>
private const string COMPRESSION_FASTALGO_OPTION = "7z-compression-fast-algorithm";
/// <summary>
/// The default setting for the fast-algorithm option
/// </summary>
private const bool DEFAULT_FASTALGO = false;
/// <summary>
/// Arbitrary limit to avoid problems with unreasonable user input.
/// </summary>
@@ -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()),
};
}
}
+4
View File
@@ -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"); } }
}
}
+2 -2
View File
@@ -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.
+1 -1
View File
@@ -1 +1 @@
http://code.google.com/p/managed-lzma
https://github.com/weltkante/managed-lzma
+1 -1
View File
@@ -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": ""
}
Vendored Regular → Executable
BIN
View File
Binary file not shown.