From: Alexander Potashev Date: Tue, 16 Jul 2019 12:06:34 +0000 (+0300) Subject: Merge branch 'Applications/19.08' X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/0e16dbc78b7f92418f4787871cd628975fccd01e?hp=-c Merge branch 'Applications/19.08' --- 0e16dbc78b7f92418f4787871cd628975fccd01e diff --combined src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp index 6969647aa,c06a71c23..c0b1cd14a --- a/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp +++ b/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp @@@ -24,7 -24,6 +24,7 @@@ #include #include #include +#include #include @@@ -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)); @@@ -148,8 -183,7 +149,7 @@@ // 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)) { @@@ -160,12 -194,12 +160,12 @@@ 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" @@@ -242,7 -276,7 +242,7 @@@ } 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; } @@@ -297,7 -331,7 +297,7 @@@ 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; }