21
#include <QCoreApplication>
25
#include "config-keepassx.h"
26
#include "core/Config.h"
27
#include "core/Global.h"
29
Resources* Resources::m_instance(nullptr);
31
QString Resources::dataPath(const QString& name) const
33
if (name.isEmpty() || name.startsWith('/')) {
34
return m_dataPath + name;
36
return m_dataPath + "/" + name;
39
QString Resources::pluginPath(const QString& name) const
41
QStringList pluginPaths;
43
QDir buildDir(QCoreApplication::applicationDirPath() + "/autotype");
44
const QStringList buildDirEntryList = buildDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
45
for (const QString& dir : buildDirEntryList) {
46
pluginPaths << QCoreApplication::applicationDirPath() + "/autotype/" + dir;
50
pluginPaths << QCoreApplication::applicationDirPath() + "/../src/autotype/test";
52
#if defined(Q_OS_MACOS) && defined(WITH_APP_BUNDLE)
53
pluginPaths << QCoreApplication::applicationDirPath() + "/../PlugIns";
56
pluginPaths << QCoreApplication::applicationDirPath();
58
QString configuredPluginDir = KEEPASSX_PLUGIN_DIR;
59
if (configuredPluginDir != ".") {
60
if (QDir(configuredPluginDir).isAbsolute()) {
61
pluginPaths << configuredPluginDir;
63
QString relativePluginDir =
64
QStringLiteral("%1/../%2").arg(QCoreApplication::applicationDirPath(), configuredPluginDir);
65
pluginPaths << QDir(relativePluginDir).canonicalPath();
67
QString absolutePluginDir = QStringLiteral("%1/%2").arg(KEEPASSX_PREFIX_DIR, configuredPluginDir);
68
pluginPaths << QDir(absolutePluginDir).canonicalPath();
72
QStringList dirFilter;
73
dirFilter << QStringLiteral("*%1*").arg(name);
75
for (const QString& path : asConst(pluginPaths)) {
76
const QStringList fileCandidates = QDir(path).entryList(dirFilter, QDir::Files);
78
for (const QString& file : fileCandidates) {
79
QString filePath = path + "/" + file;
81
if (QLibrary::isLibrary(filePath)) {
90
QString Resources::wordlistPath(const QString& name) const
92
return dataPath(QStringLiteral("wordlists/%1").arg(name));
95
QString Resources::userWordlistPath(const QString& name) const
97
QString configPath = QFileInfo(config()->getFileName()).absolutePath();
98
return configPath + QStringLiteral("/wordlists/%1").arg(name);
101
Resources::Resources()
103
const QString appDirPath = QCoreApplication::applicationDirPath();
104
#if defined(Q_OS_UNIX) && !(defined(Q_OS_MACOS) && defined(WITH_APP_BUNDLE))
105
trySetResourceDir(KEEPASSX_DATA_DIR) || trySetResourceDir(QString("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))
106
|| trySetResourceDir(QString("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR));
107
#elif defined(Q_OS_MACOS) && defined(WITH_APP_BUNDLE)
108
trySetResourceDir(appDirPath + QStringLiteral("/../Resources"));
109
#elif defined(Q_OS_WIN)
110
trySetResourceDir(appDirPath + QStringLiteral("/share"));
113
if (m_dataPath.isEmpty()) {
115
trySetResourceDir(appDirPath + QStringLiteral("/../share"))
116
|| trySetResourceDir(appDirPath + QStringLiteral("/../../share"));
119
if (m_dataPath.isEmpty()) {
120
qWarning("Resources::DataPath: can't find data dir");
124
bool Resources::trySetResourceDir(const QString& path)
128
m_dataPath = dir.canonicalPath();
134
Resources* Resources::instance()
137
m_instance = new Resources();