|
|
@ -19,56 +19,14 @@ |
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|
|
|
***************************************************************************/ |
|
|
|
***************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
#include <QtCore> |
|
|
|
#include <QApplication> |
|
|
|
|
|
|
|
#include <QByteArray> |
|
|
|
|
|
|
|
#include <QDir> |
|
|
|
|
|
|
|
#include <QFileInfo> |
|
|
|
#include "main.h" |
|
|
|
#include "main.h" |
|
|
|
|
|
|
|
|
|
|
|
void initAppPaths(int argc,char** argv) { |
|
|
|
void initAppPaths() { |
|
|
|
// Try looking for a /proc/<pid>/exe symlink first which points to
|
|
|
|
AppDir = QApplication::applicationDirPath(); |
|
|
|
// the absolute path of the executable
|
|
|
|
DataDir = QDir(AppDir+"/../share/keepassx").canonicalPath(); |
|
|
|
QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(getpid())); |
|
|
|
|
|
|
|
if (pfi.exists() && pfi.isSymLink()) { |
|
|
|
|
|
|
|
AppDir = pfi.canonicalFilePath(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
QString argv0 = QFile::decodeName(QByteArray(argv[0])); |
|
|
|
|
|
|
|
QString absPath; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) { |
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
If argv0 starts with a slash, it is already an absolute |
|
|
|
|
|
|
|
file path. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
absPath = argv0; |
|
|
|
|
|
|
|
} else if (argv0.contains(QLatin1Char('/'))) { |
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
If argv0 contains one or more slashes, it is a file path |
|
|
|
|
|
|
|
relative to the current directory. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
absPath = QDir::current().absoluteFilePath(argv0); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Otherwise, the file path has to be determined using the |
|
|
|
|
|
|
|
PATH environment variable. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
QByteArray pEnv = qgetenv("PATH"); |
|
|
|
|
|
|
|
QDir currentDir = QDir::current(); |
|
|
|
|
|
|
|
QStringList paths = QString::fromLocal8Bit(pEnv.constData()).split(QLatin1String(":")); |
|
|
|
|
|
|
|
for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) { |
|
|
|
|
|
|
|
if ((*p).isEmpty()) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0); |
|
|
|
|
|
|
|
QFileInfo candidate_fi(candidate); |
|
|
|
|
|
|
|
if (candidate_fi.exists() && !candidate_fi.isDir()) { |
|
|
|
|
|
|
|
absPath = candidate; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
absPath = QDir::cleanPath(absPath);
|
|
|
|
|
|
|
|
QFileInfo fi(absPath); |
|
|
|
|
|
|
|
AppDir = fi.exists() ? fi.canonicalFilePath() : QString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
AppDir.truncate(AppDir.lastIndexOf("/")); |
|
|
|
|
|
|
|
DataDir=AppDir+"/../share/keepassx"; |
|
|
|
|
|
|
|
HomeDir = QDir::homePath()+"/.keepassx"; |
|
|
|
HomeDir = QDir::homePath()+"/.keepassx"; |
|
|
|
} |
|
|
|
} |
|
|
|