Fix QuickPlay on Linux, add more robust executable validation

This commit is contained in:
Phillip Stephens 2019-05-27 00:13:15 -07:00
parent 7819b07df5
commit cd9601d6aa
2 changed files with 36 additions and 6 deletions

View File

@ -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())
{

View File

@ -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);