]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Merge branch 'Applications/19.08'
authorAlexander Potashev <aspotashev@gmail.com>
Tue, 16 Jul 2019 12:06:34 +0000 (15:06 +0300)
committerAlexander Potashev <aspotashev@gmail.com>
Tue, 16 Jul 2019 12:06:34 +0000 (15:06 +0300)
1  2 
src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp

index 6969647aa82f969da2e38cd9e0be4acfffa3a30d,c06a71c23741d6e04646d4acf0e1c3c213d48e67..c0b1cd14a006e3ba23a65d302c94c3f29adf97a6
@@@ -24,7 -24,6 +24,7 @@@
  #include <QDir>
  #include <QDirIterator>
  #include <QCommandLineParser>
 +#include <QMimeDatabase>
  
  #include <KLocalizedString>
  
@@@ -43,6 -42,41 +43,6 @@@ Q_NORETURN void fail(const QString &str
      exit(1);
  }
  
 -bool evaluateShell(const QString &program, const QStringList &arguments, QString &output, QString &errorText)
 -{
 -    QProcess process;
 -    process.start(program, arguments, QIODevice::ReadOnly);
 -    if (!process.waitForStarted()) {
 -        fail(i18n("Failed to run process: %1 %2", program, arguments.join(" ")));
 -    }
 -
 -    if (!process.waitForFinished()) {
 -        fail(i18n("Process did not finish in reasonable time: %1 %2", program, arguments.join(" ")));
 -    }
 -
 -    const auto stdoutResult = QString::fromUtf8(process.readAllStandardOutput()).trimmed();
 -    const auto stderrResult = QString::fromUtf8(process.readAllStandardError()).trimmed();
 -
 -    if (process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0) {
 -        output = stdoutResult;
 -        return true;
 -    } else {
 -        errorText = stderrResult + stdoutResult;
 -        return false;
 -    }
 -}
 -
 -QString mimeType(const QString &path)
 -{
 -    QString result;
 -    QString errorText;
 -    if (evaluateShell("xdg-mime", QStringList{"query", "filetype", path}, result, errorText)) {
 -        return result;
 -    } else {
 -        fail(i18n("Failed to run xdg-mime %1: %2", path, errorText));
 -    }
 -}
 -
  QString getServiceMenusDir()
  {
      const QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
@@@ -80,7 -114,7 +80,7 @@@ void runUncompress(const QString &input
                                            "multipart/x-zip"},
                                UncompressCommand{"unzip", QStringList{}, QStringList{"-d"}}});
  
 -    const auto mime = mimeType(inputPath);
 +    const auto mime = QMimeDatabase().mimeTypeForFile(inputPath).name();
  
      UncompressCommand command{};
      for (const auto &pair : mimeTypeToCommand) {
@@@ -123,10 -157,11 +123,11 @@@ QString findRecursive(const QString &di
      return QString();
  }
  
- bool runInstallerScriptOnce(const QString &path, const QStringList &args, const QString &dir)
+ bool runInstallerScriptOnce(const QString &path, const QStringList &args)
  {
      QProcess process;
-     process.setWorkingDirectory(dir);
+     process.setWorkingDirectory(QFileInfo(path).absolutePath());
      process.start(path, args, QIODevice::NotOpen);
      if (!process.waitForStarted()) {
          fail(i18n("Failed to run installer script %1", path));
  
  // If hasArgVariants is true, run "path".
  // If hasArgVariants is false, run "path argVariants[i]" until successful.
- bool runInstallerScript(const QString &path, bool hasArgVariants, const QStringList &argVariants, const QString &dir,
-     QString &errorText)
+ bool runInstallerScript(const QString &path, bool hasArgVariants, const QStringList &argVariants, QString &errorText)
  {
      QFile file(path);
      if (!file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)) {
      qInfo() << "[servicemenuinstaller]: Trying to run installer/uninstaller" << path;
      if (hasArgVariants) {
          for (const auto &arg : argVariants) {
-             if (runInstallerScriptOnce(path, QStringList{arg}, dir)) {
+             if (runInstallerScriptOnce(path, QStringList{arg})) {
                  return true;
              }
          }
      } else {
-         if (runInstallerScriptOnce(path, QStringList{}, dir)) {
+         if (runInstallerScriptOnce(path, QStringList{})) {
              return true;
          }
      }
@@@ -227,7 -261,7 +227,7 @@@ bool cmdInstall(const QString &archive
          }
  
          if (!installItPath.isEmpty()) {
-             return runInstallerScript(installItPath, false, QStringList{}, dir, errorText);
+             return runInstallerScript(installItPath, false, QStringList{}, errorText);
          }
  
          // If "install-it" is missing, try "install"
          }
  
          if (!installerPath.isEmpty()) {
-             return runInstallerScript(installerPath, true, QStringList{"--local", "--local-install", "--install"}, dir, errorText);
+             return runInstallerScript(installerPath, true, QStringList{"--local", "--local-install", "--install"}, errorText);
          }
  
          fail(i18n("Failed to find an installation script in %1", dir));
@@@ -277,7 -311,7 +277,7 @@@ bool cmdUninstall(const QString &archiv
          }
  
          if (!deinstallPath.isEmpty()) {
-             bool ok = runInstallerScript(deinstallPath, false, QStringList{}, dir, errorText);
+             bool ok = runInstallerScript(deinstallPath, false, QStringList{}, errorText);
              if (!ok) {
                  return ok;
              }
  
              if (!installerPath.isEmpty()) {
                  bool ok = runInstallerScript(
-                     installerPath, true, QStringList{"--remove", "--delete", "--uninstall", "--deinstall"}, dir, errorText);
+                     installerPath, true, QStringList{"--remove", "--delete", "--uninstall", "--deinstall"}, errorText);
                  if (!ok) {
                      return ok;
                  }