From eeb940c0dc7d4b888564d82734c27f25ae94981a Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Tue, 12 May 2015 22:20:42 +0200 Subject: [PATCH] Fix plugin path detection when installed with DESTDIR. This is in no way perfect but should cover most common cases. Closes #291 --- CMakeLists.txt | 6 +++--- src/config-keepassx.h.cmake | 2 +- src/core/FilePath.cpp | 32 ++++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bc6e316f..400c68480 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,9 +149,9 @@ elseif(APPLE) else() include(GNUInstallDirs) - set(BIN_INSTALL_DIR "${CMAKE_INSTALL_FULL_BINDIR}") - set(PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/keepassx") - set(DATA_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/keepassx") + set(BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}") + set(PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/keepassx") + set(DATA_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/keepassx") endif() if(WITH_TESTS) diff --git a/src/config-keepassx.h.cmake b/src/config-keepassx.h.cmake index 305da341f..197c0d328 100644 --- a/src/config-keepassx.h.cmake +++ b/src/config-keepassx.h.cmake @@ -8,8 +8,8 @@ #define KEEPASSX_SOURCE_DIR "${CMAKE_SOURCE_DIR}" #define KEEPASSX_BINARY_DIR "${CMAKE_BINARY_DIR}" +#define KEEPASSX_PREFIX_DIR "${CMAKE_INSTALL_PREFIX}" #define KEEPASSX_PLUGIN_DIR "${PLUGIN_INSTALL_DIR}" - #define KEEPASSX_DATA_DIR "${DATA_INSTALL_DIR}" #cmakedefine HAVE_PR_SET_DUMPABLE 1 diff --git a/src/core/FilePath.cpp b/src/core/FilePath.cpp index e414fdec1..5366fe5c7 100644 --- a/src/core/FilePath.cpp +++ b/src/core/FilePath.cpp @@ -49,13 +49,20 @@ QString FilePath::pluginPath(const QString& name) pluginPaths << QCoreApplication::applicationDirPath(); - QString systemPluginDir = KEEPASSX_PLUGIN_DIR; - if (systemPluginDir != ".") { - if (!QDir(systemPluginDir).isAbsolute()) { - systemPluginDir = QCoreApplication::applicationDirPath() + "/../" + systemPluginDir; - systemPluginDir = QDir(systemPluginDir).canonicalPath(); + QString configuredPluginDir = KEEPASSX_PLUGIN_DIR; + if (configuredPluginDir != ".") { + if (QDir(configuredPluginDir).isAbsolute()) { + pluginPaths << configuredPluginDir; + } + else { + QString relativePluginDir = QString("%1/../%2") + .arg(QCoreApplication::applicationDirPath(), configuredPluginDir); + pluginPaths << QDir(relativePluginDir).canonicalPath(); + + QString absolutePluginDir = QString("%1/%2") + .arg(KEEPASSX_PREFIX_DIR, configuredPluginDir); + pluginPaths << QDir(absolutePluginDir).canonicalPath(); } - pluginPaths << systemPluginDir; } QStringList dirFilter; @@ -164,6 +171,9 @@ QIcon FilePath::onOffIcon(const QString& category, const QString& name) FilePath::FilePath() { + const QString appDirPath = QCoreApplication::applicationDirPath(); + bool isDataDirAbsolute = QDir::isAbsolutePath(KEEPASSX_DATA_DIR); + if (false) { } #ifdef QT_DEBUG @@ -171,17 +181,19 @@ FilePath::FilePath() } #endif #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) - else if (testSetDir(QCoreApplication::applicationDirPath() + "/../share/keepassx")) { + else if (isDataDirAbsolute && testSetDir(KEEPASSX_DATA_DIR)) { } - else if (testSetDir(KEEPASSX_DATA_DIR)) { + else if (!isDataDirAbsolute && testSetDir(QString("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))) { + } + else if (!isDataDirAbsolute && testSetDir(QString("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR))) { } #endif #ifdef Q_OS_MAC - else if (testSetDir(QCoreApplication::applicationDirPath() + "/../Resources")) { + else if (testSetDir(appDirPath + "/../Resources")) { } #endif #ifdef Q_OS_WIN - else if (testSetDir(QCoreApplication::applicationDirPath() + "/share")) { + else if (testSetDir(appDirPath + "/share")) { } #endif