#include <QDir>
#include <QDirIterator>
#include <QCommandLineParser>
+#include <QMimeDatabase>
#include <KLocalizedString>
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);
"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) {
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;
}
}
}
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));
}
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;
}