From cd9601d6aa4cde82c988cead9dd50af20e0a346f Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Mon, 27 May 2019 00:13:15 -0700 Subject: [PATCH] Fix QuickPlay on Linux, add more robust executable validation --- src/Editor/CQuickplayPropertyEditor.cpp | 4 +-- src/Editor/NDolphinIntegration.cpp | 38 ++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Editor/CQuickplayPropertyEditor.cpp b/src/Editor/CQuickplayPropertyEditor.cpp index d821913f..7414098e 100644 --- a/src/Editor/CQuickplayPropertyEditor.cpp +++ b/src/Editor/CQuickplayPropertyEditor.cpp @@ -19,7 +19,7 @@ public: static bool PathValid(const QString& kPath) { QFileInfo FileInfo(kPath); - return FileInfo.exists() && FileInfo.suffix() == "exe"; + return FileInfo.exists() && FileInfo.isExecutable(); } }; @@ -74,7 +74,7 @@ CQuickplayPropertyEditor::~CQuickplayPropertyEditor() void CQuickplayPropertyEditor::BrowseForDolphin() { - QString Path = UICommon::OpenFileDialog(this, "Open Dolphin", "Dolphin.exe"); + QString Path = UICommon::OpenFileDialog(this, "Open Dolphin", "Dolphin"); if (!Path.isEmpty()) { diff --git a/src/Editor/NDolphinIntegration.cpp b/src/Editor/NDolphinIntegration.cpp index 17b50718..86456ce0 100644 --- a/src/Editor/NDolphinIntegration.cpp +++ b/src/Editor/NDolphinIntegration.cpp @@ -41,7 +41,6 @@ void CQuickplayRelay::QuickplayStarted() void CQuickplayRelay::QuickplayFinished(int ReturnCode) { debugf("Quickplay session finished."); - disconnect(gpDolphinProcess, 0, this, 0); CleanupQuickplayFiles(gpQuickplayProject); gpDolphinProcess->waitForFinished(); @@ -95,7 +94,7 @@ EQuickplayLaunchResult LaunchQuickplay(QWidget* pParentWidget, if (Path.isEmpty()) { // Allow the user to select the Dolphin exe. - Path = UICommon::OpenFileDialog(pParentWidget, "Open Dolphin", "Dolphin.exe"); + Path = UICommon::OpenFileDialog(pParentWidget, "Open Dolphin", "Dolphin"); } bool bGotDolphin = (!Path.isEmpty() && SetDolphinPath(pParentWidget, Path, true)); @@ -254,15 +253,46 @@ bool SetDolphinPath(QWidget* pParentWidget, const QString& kDolphinPath, bool bS //@todo Validate the build version to make sure the build supports quickplay? Necessary? QFileInfo DolphinFile(kDolphinPath); - if (!DolphinFile.exists() || DolphinFile.suffix() != "exe") + if (!DolphinFile.exists() || !DolphinFile.isExecutable()) { if (!bSilent) { - UICommon::ErrorMsg(pParentWidget, "The selected file is not a Dolphin exe!"); + UICommon::ErrorMsg(pParentWidget, "The selected file is not a Dolphin executable!"); } return false; } + // Try to obtain the version from Dolphin + QProcess DolphinProcess; + DolphinProcess.start(kDolphinPath, QStringList() << "--version"); + DolphinProcess.waitForFinished(); + QString VersionString = DolphinProcess.readLine().trimmed(); + + // Make sure we have a valid string + if (VersionString.isNull()) + { + if (!bSilent) + { + UICommon::ErrorMsg(pParentWidget, "Unable to validate version string, the selected file is likely not a Dolphin executable"); + } + return false; + } + + // Dolphin's version string is broken into two parts, the first part is the name the second is the version + // Dolphin unfortunately collide's with KDE Plasma's file manager which also happens to be named "Dolphin" + // Fortunately the latter uses a lowercase name so we can differentiate. + QStringList VersionParts = VersionString.split(' '); + if (VersionParts.count() != 2 || VersionParts[0] != "Dolphin") + { + if (!bSilent) + { + UICommon::ErrorMsg(pParentWidget, "The selected file is not a Dolphin executable!"); + } + return false; + } + + debugf("Found dolphin version %s", *TO_TSTRING(VersionParts[1])); + // Build is legit, stash it QSettings Settings; Settings.setValue(gkDolphinPathSetting, kDolphinPath);