1 /***************************************************************************
2 * Copyright (C) 1992-2008 Trolltech ASA *
4 * Copyright (C) 2005-2008 by Tarek Saidi *
5 * tarek.saidi@arcor.de *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; version 2 of the License. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
25 void initAppPaths(int argc,char** argv) {
26 // Try looking for a /proc/<pid>/exe symlink first which points to
27 // the absolute path of the executable
28 QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(getpid()));
29 if (pfi.exists() && pfi.isSymLink()) {
30 AppDir = pfi.canonicalFilePath();
33 QString argv0 = QFile::decodeName(QByteArray(argv[0]));
36 if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) {
38 If argv0 starts with a slash, it is already an absolute
42 } else if (argv0.contains(QLatin1Char('/'))) {
44 If argv0 contains one or more slashes, it is a file path
45 relative to the current directory.
47 absPath = QDir::current().absoluteFilePath(argv0);
50 Otherwise, the file path has to be determined using the
51 PATH environment variable.
53 QByteArray pEnv = qgetenv("PATH");
54 QDir currentDir = QDir::current();
55 QStringList paths = QString::fromLocal8Bit(pEnv.constData()).split(QLatin1String(":"));
56 for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) {
59 QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0);
60 QFileInfo candidate_fi(candidate);
61 if (candidate_fi.exists() && !candidate_fi.isDir()) {
67 absPath = QDir::cleanPath(absPath);
68 QFileInfo fi(absPath);
69 AppDir = fi.exists() ? fi.canonicalFilePath() : QString();
71 AppDir.truncate(AppDir.lastIndexOf("/"));
72 DataDir=AppDir+"/../share/keepassx";
73 if (!QFile::exists(DataDir) && QFile::exists(AppDir+"/share"))
74 DataDir=AppDir+"/share";
75 HomeDir = QDir::homePath()+"/.keepassx";