From 97bac939dd7109e6aad981aef17e05cae1a69f3b Mon Sep 17 00:00:00 2001 From: sniperbeamer Date: Thu, 6 Mar 2008 19:40:27 +0000 Subject: [PATCH] Apply parts of patch #1908868 Use QApplication::applicationDirPath() on unix and win32 git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@173 b624d157-de02-0410-bad0-e51aec6abb33 --- src/main.cpp | 13 ++--------- src/main_macx.cpp | 2 ++ src/main_unix.cpp | 56 ++++++---------------------------------------- src/main_win32.cpp | 19 +++++----------- src/src.pro | 6 ++--- 5 files changed, 19 insertions(+), 77 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1adc4d3..a0b6156 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,7 +58,7 @@ QPixmap* EntryIcons; inline void loadImages(); inline void parseCmdLineArgs(int argc, char** argv,QString &ArgFile,QString& ArgCfg,QString& ArgLang,bool& ArgMin,bool& ArgLock); bool loadTranslation(QTranslator* tr,const QString& prefix,const QString& LocaleCode,const QStringList& SearchPaths); -void initAppPaths(int argc, char **argv); +void initAppPaths(); int main(int argc, char **argv) { @@ -68,7 +68,7 @@ int main(int argc, char **argv) #else app = new QApplication(argc,argv); #endif - initAppPaths(argc,argv); + initAppPaths(); CmdLineArgs args; args.parse(QApplication::arguments()); qDebug(CSTR(AppDir)); @@ -288,10 +288,6 @@ void CmdLineArgs::printHelp(){ cout << " pt_BR Portuguese(Brazil)"< +#include #include #include "main.h" diff --git a/src/main_unix.cpp b/src/main_unix.cpp index fff6c27..c4aa9b8 100644 --- a/src/main_unix.cpp +++ b/src/main_unix.cpp @@ -19,56 +19,14 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include +#include +#include +#include +#include #include "main.h" -void initAppPaths(int argc,char** argv) { - // Try looking for a /proc//exe symlink first which points to - // the absolute path of the executable - 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"; +void initAppPaths() { + AppDir = QApplication::applicationDirPath(); + DataDir = QDir(AppDir+"/../share/keepassx").canonicalPath(); HomeDir = QDir::homePath()+"/.keepassx"; } diff --git a/src/main_win32.cpp b/src/main_win32.cpp index e567425..fe4acca 100644 --- a/src/main_win32.cpp +++ b/src/main_win32.cpp @@ -19,22 +19,13 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include +#include #include #include "main.h" -void initAppPaths(int argc,char** argv){ - QFileInfo filePath; - QT_WA({ - wchar_t module_name[256]; - GetModuleFileNameW(0, module_name, sizeof(module_name) / sizeof(wchar_t)); - filePath = QString::fromUtf16((ushort *)module_name); - }, { - char module_name[256]; - GetModuleFileNameA(0, module_name, sizeof(module_name)); - filePath = QString::fromLocal8Bit(module_name); - }); - AppDir = filePath.filePath(); - AppDir.truncate(AppDir.lastIndexOf("/")); +void initAppPaths(){ + AppDir = QApplication::applicationDirPath(); HomeDir = QString::fromLocal8Bit(qgetenv("APPDATA").constData()); if(!HomeDir.isEmpty() && QFile::exists(HomeDir)) @@ -43,4 +34,4 @@ void initAppPaths(int argc,char** argv){ HomeDir = QDir::homePath()+"/KeePassX"; DataDir=AppDir+"/share"; -} \ No newline at end of file +} diff --git a/src/src.pro b/src/src.pro index e28c49c..02538f8 100644 --- a/src/src.pro +++ b/src/src.pro @@ -32,7 +32,7 @@ unix : !macx : !isEqual(QMAKE_WIN32,1) { } TARGET = ../bin/keepassx target.path = $${PREFIX}/bin - data.files += ../share/keepassx + data.files = ../share/keepassx data.path = $${PREFIX}/share pixmaps.files = ../share/pixmaps/* pixmaps.path = $${PREFIX}/share/pixmaps @@ -59,7 +59,7 @@ macx { isEmpty(PREFIX):PREFIX = /Applications TARGET = ../bin/KeePassX target.path = $${PREFIX} - data.files += ../share/keepassx + data.files = ../share/keepassx data.path = Contents/Resources LIBS += -framework CoreFoundation isEqual(LINK,DYNAMIC) { @@ -90,7 +90,7 @@ isEqual(QMAKE_WIN32,1) { isEmpty(PREFIX):PREFIX = "C:/Program files/KeePassX" TARGET = ../bin/KeePassX target.path = $${PREFIX} - data.files += ../share/keepassx/* + data.files = ../share/keepassx/* data.path = $${PREFIX}/share !isEqual(INSTALL_QTLIB,0) { qt_libs.files = $${QMAKE_LIBDIR_QT}/QtCore4.dll $${QMAKE_LIBDIR_QT}/QtGui4.dll $${QMAKE_LIBDIR_QT}/QtXml4.dll