diff --git a/autotests/plugins/cli7zplugin/cli7ztest.cpp b/autotests/plugins/cli7zplugin/cli7ztest.cpp --- a/autotests/plugins/cli7zplugin/cli7ztest.cpp +++ b/autotests/plugins/cli7zplugin/cli7ztest.cpp @@ -229,33 +229,37 @@ QTest::addColumn("archiveName"); QTest::addColumn("password"); QTest::addColumn("encryptHeader"); + QTest::addColumn("compressionLevel"); QTest::addColumn("expectedArgs"); QTest::newRow("unencrypted") << QStringLiteral("/tmp/foo.7z") - << QString() << false + << QString() << false << 5 << QStringList { QStringLiteral("a"), - QStringLiteral("/tmp/foo.7z") + QStringLiteral("/tmp/foo.7z"), + QStringLiteral("-mx=5") }; QTest::newRow("encrypted") << QStringLiteral("/tmp/foo.7z") - << QStringLiteral("1234") << false + << QStringLiteral("1234") << false << 5 << QStringList { QStringLiteral("a"), QStringLiteral("/tmp/foo.7z"), - QStringLiteral("-p1234") + QStringLiteral("-p1234"), + QStringLiteral("-mx=5") }; QTest::newRow("header-encrypted") << QStringLiteral("/tmp/foo.7z") - << QStringLiteral("1234") << true + << QStringLiteral("1234") << true << 5 << QStringList { QStringLiteral("a"), QStringLiteral("/tmp/foo.7z"), QStringLiteral("-p1234"), - QStringLiteral("-mhe=on") + QStringLiteral("-mhe=on"), + QStringLiteral("-mx=5") }; } @@ -268,12 +272,14 @@ const QStringList addArgs = { QStringLiteral("a"), QStringLiteral("$Archive"), QStringLiteral("$PasswordSwitch"), + QStringLiteral("$CompressionLevelSwitch"), QStringLiteral("$Files") }; QFETCH(QString, password); QFETCH(bool, encryptHeader); + QFETCH(int, compressionLevel); - QStringList replacedArgs = plugin->substituteAddVariables(addArgs, {}, QDir::current(), password, encryptHeader); + QStringList replacedArgs = plugin->substituteAddVariables(addArgs, {}, QDir::current(), password, encryptHeader, compressionLevel); QFETCH(QStringList, expectedArgs); QCOMPARE(replacedArgs, expectedArgs); diff --git a/autotests/plugins/clirarplugin/clirartest.cpp b/autotests/plugins/clirarplugin/clirartest.cpp --- a/autotests/plugins/clirarplugin/clirartest.cpp +++ b/autotests/plugins/clirarplugin/clirartest.cpp @@ -263,32 +263,36 @@ QTest::addColumn("archiveName"); QTest::addColumn("password"); QTest::addColumn("encryptHeader"); + QTest::addColumn("compressionLevel"); QTest::addColumn("expectedArgs"); QTest::newRow("unencrypted") << QStringLiteral("/tmp/foo.rar") - << QString() << false + << QString() << false << 3 << QStringList { QStringLiteral("a"), - QStringLiteral("/tmp/foo.rar") + QStringLiteral("/tmp/foo.rar"), + QStringLiteral("-m3") }; QTest::newRow("encrypted") << QStringLiteral("/tmp/foo.rar") - << QStringLiteral("1234") << false + << QStringLiteral("1234") << false << 3 << QStringList { QStringLiteral("a"), QStringLiteral("/tmp/foo.rar"), - QStringLiteral("-p1234") + QStringLiteral("-p1234"), + QStringLiteral("-m3") }; QTest::newRow("header-encrypted") << QStringLiteral("/tmp/foo.rar") - << QStringLiteral("1234") << true + << QStringLiteral("1234") << true << 3 << QStringList { QStringLiteral("a"), QStringLiteral("/tmp/foo.rar"), - QStringLiteral("-hp1234") + QStringLiteral("-hp1234"), + QStringLiteral("-m3") }; } @@ -301,12 +305,14 @@ const QStringList addArgs = { QStringLiteral("a"), QStringLiteral("$Archive"), QStringLiteral("$PasswordSwitch"), + QStringLiteral("$CompressionLevelSwitch"), QStringLiteral("$Files") }; QFETCH(QString, password); QFETCH(bool, encryptHeader); + QFETCH(int, compressionLevel); - QStringList replacedArgs = rarPlugin->substituteAddVariables(addArgs, {}, QDir::current(), password, encryptHeader); + QStringList replacedArgs = rarPlugin->substituteAddVariables(addArgs, {}, QDir::current(), password, encryptHeader, compressionLevel); QFETCH(QStringList, expectedArgs); QCOMPARE(replacedArgs, expectedArgs); diff --git a/kerfuffle/cliinterface.h b/kerfuffle/cliinterface.h --- a/kerfuffle/cliinterface.h +++ b/kerfuffle/cliinterface.h @@ -147,6 +147,13 @@ */ PasswordSwitch, /** + * QStringList (default empty) + * The format of the compression level switch. The variable $CompressionLevel + * will be substituted for the level. + * Example: ("-mx=$CompressionLevel) + */ + CompressionLevelSwitch, + /** * QStringList * This is a stringlist with regexps, defining how to recognize the last * line in a "File already exists" prompt when extracting. @@ -309,7 +316,7 @@ QStringList substituteListVariables(const QStringList &listArgs, const QString &password); QStringList substituteCopyVariables(const QStringList &extractArgs, const QVariantList &files, bool preservePaths, const QString &password, const QString &rootNode); - QStringList substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QDir &workDir, const QString &password, bool encryptHeader); + QStringList substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QDir &workDir, const QString &password, bool encryptHeader, int compLevel); /** * @return The preserve path switch, according to the @p preservePaths extraction option. @@ -327,6 +334,11 @@ QStringList passwordSwitch(const QString& password) const; /** + * @return The compression level switch with the given @p level. + */ + QStringList compressionLevelSwitch(int level) const; + + /** * @return The root node switch with the given @p rootNode. */ QStringList rootNodeSwitch(const QString& rootNode) const; diff --git a/kerfuffle/cliinterface.cpp b/kerfuffle/cliinterface.cpp --- a/kerfuffle/cliinterface.cpp +++ b/kerfuffle/cliinterface.cpp @@ -256,7 +256,8 @@ files, workDir, password(), - isHeaderEncryptionEnabled()); + isHeaderEncryptionEnabled(), + options.contains(QStringLiteral("CompressionLevel"))); if (!runProcess(m_param.value(AddProgram).toStringList(), args)) { failOperation(); @@ -627,7 +628,7 @@ return args; } -QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QDir &workDir, const QString &password, bool encryptHeader) +QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QDir &workDir, const QString &password, bool encryptHeader, int compLevel) { // Required if we call this function from unit tests. cacheParameterList(); @@ -646,6 +647,11 @@ continue; } + if (arg == QLatin1String("$CompressionLevelSwitch")) { + args << compressionLevelSwitch(compLevel); + continue; + } + if (arg == QLatin1String("$Files")) { args << addFilesList(files, workDir); continue; @@ -710,6 +716,23 @@ return passwordSwitch; } +QStringList CliInterface::compressionLevelSwitch(int level) const +{ + Q_ASSERT(m_param.contains(CompressionLevelSwitch)); + + QStringList compLevelSwitch = m_param.value(CompressionLevelSwitch).toStringList(); + Q_ASSERT(!compLevelSwitch.isEmpty() && compLevelSwitch.size() <= 2); + Q_ASSERT(level >= 0 && level <= 9); + + if (compLevelSwitch.size() == 1) { + compLevelSwitch[0].replace(QLatin1String("$CompressionLevel"), QString::number(level)); + } else { + compLevelSwitch[1] = QString::number(level); + } + + return compLevelSwitch; +} + QStringList CliInterface::rootNodeSwitch(const QString &rootNode) const { if (rootNode.isEmpty()) { diff --git a/plugins/cli7zplugin/cliplugin.cpp b/plugins/cli7zplugin/cliplugin.cpp --- a/plugins/cli7zplugin/cliplugin.cpp +++ b/plugins/cli7zplugin/cliplugin.cpp @@ -74,9 +74,11 @@ p[PasswordSwitch] = QStringList() << QStringLiteral("-p$Password"); p[PasswordHeaderSwitch] = QStringList { QStringLiteral("-p$Password"), QStringLiteral("-mhe=on") }; p[WrongPasswordPatterns] = QStringList() << QStringLiteral("Wrong password"); + p[CompressionLevelSwitch] = QStringList() << QStringLiteral("-mx=$CompressionLevel"); p[AddArgs] = QStringList() << QStringLiteral("a") << QStringLiteral("$Archive") << QStringLiteral("$PasswordSwitch") + << QStringLiteral("$CompressionLevelSwitch") << QStringLiteral("$Files"); p[DeleteArgs] = QStringList() << QStringLiteral("d") << QStringLiteral("$Archive") diff --git a/plugins/clirarplugin/cliplugin.cpp b/plugins/clirarplugin/cliplugin.cpp --- a/plugins/clirarplugin/cliplugin.cpp +++ b/plugins/clirarplugin/cliplugin.cpp @@ -97,6 +97,7 @@ p[RootNodeSwitch] = QStringList() << QStringLiteral( "-ap$Path" ); p[PasswordSwitch] = QStringList() << QStringLiteral( "-p$Password" ); p[PasswordHeaderSwitch] = QStringList() << QStringLiteral("-hp$Password"); + p[CompressionLevelSwitch] = QStringList() << QStringLiteral("-m$CompressionLevel"); p[DeleteArgs] = QStringList() << QStringLiteral( "d" ) << QStringLiteral( "$Archive" ) << QStringLiteral( "$Files" ); @@ -112,6 +113,7 @@ p[AddArgs] = QStringList() << QStringLiteral( "a" ) << QStringLiteral( "$Archive" ) << QStringLiteral("$PasswordSwitch") + << QStringLiteral("$CompressionLevelSwitch") << QStringLiteral( "$Files" ); p[PasswordPromptPattern] = QLatin1String("Enter password \\(will not be echoed\\) for"); p[WrongPasswordPatterns] = QStringList() << QStringLiteral("password incorrect") << QStringLiteral("wrong password"); diff --git a/plugins/clizipplugin/cliplugin.cpp b/plugins/clizipplugin/cliplugin.cpp --- a/plugins/clizipplugin/cliplugin.cpp +++ b/plugins/clizipplugin/cliplugin.cpp @@ -96,6 +96,7 @@ p[PreservePathSwitch] = QStringList() << QStringLiteral("") << QStringLiteral("-j"); p[PasswordSwitch] = QStringList() << QStringLiteral("-P$Password"); + p[CompressionLevelSwitch] = QStringList() << QStringLiteral("-$CompressionLevel"); p[DeleteArgs] = QStringList() << QStringLiteral("-d") << QStringLiteral("$Archive") @@ -112,6 +113,7 @@ p[AddArgs] = QStringList() << QStringLiteral("-r") << QStringLiteral("$Archive") << QStringLiteral("$PasswordSwitch") + << QStringLiteral("$CompressionLevelSwitch") << QStringLiteral("$Files"); p[PasswordPromptPattern] = QStringLiteral(" password: ");