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
master
sniperbeamer 17 years ago
parent 5db29eafed
commit 97bac939dd
  1. 13
      src/main.cpp
  2. 2
      src/main_macx.cpp
  3. 56
      src/main_unix.cpp
  4. 17
      src/main_win32.cpp
  5. 6
      src/src.pro

@ -58,7 +58,7 @@ QPixmap* EntryIcons;
inline void loadImages(); inline void loadImages();
inline void parseCmdLineArgs(int argc, char** argv,QString &ArgFile,QString& ArgCfg,QString& ArgLang,bool& ArgMin,bool& ArgLock); 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); 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) int main(int argc, char **argv)
{ {
@ -68,7 +68,7 @@ int main(int argc, char **argv)
#else #else
app = new QApplication(argc,argv); app = new QApplication(argc,argv);
#endif #endif
initAppPaths(argc,argv); initAppPaths();
CmdLineArgs args; CmdLineArgs args;
args.parse(QApplication::arguments()); args.parse(QApplication::arguments());
qDebug(CSTR(AppDir)); qDebug(CSTR(AppDir));
@ -288,10 +288,6 @@ void CmdLineArgs::printHelp(){
cout << " pt_BR Portuguese(Brazil)"<<endl; cout << " pt_BR Portuguese(Brazil)"<<endl;
} }
//TODO Plugins //TODO Plugins
/* /*
QString findPlugin(const QString& filename){ QString findPlugin(const QString& filename){
@ -304,8 +300,3 @@ QString findPlugin(const QString& filename){
return QString(); return QString();
} }
*/ */

@ -19,6 +19,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <QVarLengthArray>
#include <QDir>
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include "main.h" #include "main.h"

@ -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";
} }

@ -19,22 +19,13 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <QApplication>
#include <QDir>
#include <windows.h> #include <windows.h>
#include "main.h" #include "main.h"
void initAppPaths(int argc,char** argv){ void initAppPaths(){
QFileInfo filePath; AppDir = QApplication::applicationDirPath();
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("/"));
HomeDir = QString::fromLocal8Bit(qgetenv("APPDATA").constData()); HomeDir = QString::fromLocal8Bit(qgetenv("APPDATA").constData());
if(!HomeDir.isEmpty() && QFile::exists(HomeDir)) if(!HomeDir.isEmpty() && QFile::exists(HomeDir))

@ -32,7 +32,7 @@ unix : !macx : !isEqual(QMAKE_WIN32,1) {
} }
TARGET = ../bin/keepassx TARGET = ../bin/keepassx
target.path = $${PREFIX}/bin target.path = $${PREFIX}/bin
data.files += ../share/keepassx data.files = ../share/keepassx
data.path = $${PREFIX}/share data.path = $${PREFIX}/share
pixmaps.files = ../share/pixmaps/* pixmaps.files = ../share/pixmaps/*
pixmaps.path = $${PREFIX}/share/pixmaps pixmaps.path = $${PREFIX}/share/pixmaps
@ -59,7 +59,7 @@ macx {
isEmpty(PREFIX):PREFIX = /Applications isEmpty(PREFIX):PREFIX = /Applications
TARGET = ../bin/KeePassX TARGET = ../bin/KeePassX
target.path = $${PREFIX} target.path = $${PREFIX}
data.files += ../share/keepassx data.files = ../share/keepassx
data.path = Contents/Resources data.path = Contents/Resources
LIBS += -framework CoreFoundation LIBS += -framework CoreFoundation
isEqual(LINK,DYNAMIC) { isEqual(LINK,DYNAMIC) {
@ -90,7 +90,7 @@ isEqual(QMAKE_WIN32,1) {
isEmpty(PREFIX):PREFIX = "C:/Program files/KeePassX" isEmpty(PREFIX):PREFIX = "C:/Program files/KeePassX"
TARGET = ../bin/KeePassX TARGET = ../bin/KeePassX
target.path = $${PREFIX} target.path = $${PREFIX}
data.files += ../share/keepassx/* data.files = ../share/keepassx/*
data.path = $${PREFIX}/share data.path = $${PREFIX}/share
!isEqual(INSTALL_QTLIB,0) { !isEqual(INSTALL_QTLIB,0) {
qt_libs.files = $${QMAKE_LIBDIR_QT}/QtCore4.dll $${QMAKE_LIBDIR_QT}/QtGui4.dll $${QMAKE_LIBDIR_QT}/QtXml4.dll qt_libs.files = $${QMAKE_LIBDIR_QT}/QtCore4.dll $${QMAKE_LIBDIR_QT}/QtGui4.dll $${QMAKE_LIBDIR_QT}/QtXml4.dll