diff --git a/krArc/krarc.cpp b/krArc/krarc.cpp --- a/krArc/krarc.cpp +++ b/krArc/krarc.cpp @@ -1564,8 +1564,9 @@ putCmd << fullPathName("zip") << "-ry"; } - if (!QStandardPaths::findExecutable(QStringLiteral("7za")).isEmpty()) { - renCmd << fullPathName("7za") << "rn"; + QString a7zExecutable = find7zExecutable(); + if (!a7zExecutable.isEmpty()) { + renCmd << a7zExecutable << "rn"; } if (!getPassword().isEmpty()) { @@ -1673,9 +1674,10 @@ putCmd = QStringList(); } else if (arcType == "7z") { noencoding = true; - cmd = fullPathName("7z"); - if (QStandardPaths::findExecutable(cmd).isEmpty()) - cmd = fullPathName("7za"); + cmd = find7zExecutable(); + if (cmd.isEmpty()) { + return false; + } listCmd << cmd << "l" << "-y"; getCmd << cmd << "e" << "-y"; @@ -1728,20 +1730,15 @@ encrypted = true; else { // we try to find whether the 7z archive is encrypted // this is hard as the headers are also compressed - QString tester = fullPathName("7z"); - if (QStandardPaths::findExecutable(tester).isEmpty()) { - KRDEBUG("A 7z program was not found"); - tester = fullPathName("7za"); - if (QStandardPaths::findExecutable(tester).isEmpty()) { - KRDEBUG("A 7za program was not found"); - return; - } + QString a7zExecutable = find7zExecutable(); + if (a7zExecutable.isEmpty()) { + return; } lastData = encryptedArchPath = ""; KrLinecountingProcess proc; - proc << tester << "-y" << "t" << fileName; + proc << a7zExecutable << "-y" << "t" << fileName; connect(&proc, &KrLinecountingProcess::newOutputData, this, &kio_krarcProtocol::check7zOutputForPassword); proc.start(); proc.waitForFinished(); diff --git a/krArc/krarcbasemanager.h b/krArc/krarcbasemanager.h --- a/krArc/krarcbasemanager.h +++ b/krArc/krarcbasemanager.h @@ -54,6 +54,8 @@ //! Search for the full path to a program QString fullPathName(const QString& name); + //! Find the path to a 7z (or 7za) executable + QString find7zExecutable(); static bool checkStatus(const QString &, int); diff --git a/krArc/krarcbasemanager.cpp b/krArc/krarcbasemanager.cpp --- a/krArc/krarcbasemanager.cpp +++ b/krArc/krarcbasemanager.cpp @@ -66,6 +66,21 @@ return supposedName; } +QString KrArcBaseManager::find7zExecutable() +{ + KRFUNC; + QString program = fullPathName("7z"); + if (program.isEmpty()) { + KRDEBUG("A 7z program was not found"); + program = fullPathName("7za"); + if (program.isEmpty()) { + KRDEBUG("A 7za program was not found"); + } + } + + return program; +} + //! Checks if a returned status ("exit code") of an archiving-related process is OK /*! \param arcType A short QString which contains an identifier of the type of the archive.