Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Better handling of data types of custom compression parameters. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
squid-box committed Aug 15, 2021
1 parent a864e93 commit 6153867
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions SevenZip/SevenZipCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,37 +338,19 @@ private void SetCompressionProperties()

foreach (var pair in CustomParameters)
{
#region Validate parameters against compression method.
#region Validate parameters against compression method.

if (_compressionMethod != CompressionMethod.Ppmd && (pair.Key.Equals("mem") || pair.Key.Equals("o")))
{
ThrowException(null, new CompressionFailedException($"Parameter \"{pair.Key}\" is only valid with the PPMd compression method."));
}

#endregion
#endregion

names.Add(Marshal.StringToBSTR(pair.Key));
var pv = new PropVariant();

#region List of parameters to cast as integers

var integerParameters = new HashSet<string>
{
"fb",
"pass",
"o",
"yx",
"a",
"mc",
"lc",
"lp",
"pb",
"cp"
};

#endregion

if (integerParameters.Contains(pair.Key))
if (pair.Value.All(char.IsDigit))
{
pv.VarType = VarEnum.VT_UI4;
pv.UInt32Value = Convert.ToUInt32(pair.Value, CultureInfo.InvariantCulture);
Expand Down

0 comments on commit 6153867

Please sign in to comment.