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. 19
      src/main_win32.cpp
  5. 6
      src/src.pro

@ -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)"<<endl;
}
//TODO Plugins
/*
QString findPlugin(const QString& filename){
@ -304,8 +300,3 @@ QString findPlugin(const QString& filename){
return QString();
}
*/

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

@ -19,56 +19,14 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QtCore>
#include <QApplication>
#include <QByteArray>
#include <QDir>
#include <QFileInfo>
#include "main.h"
void initAppPaths(int argc,char** argv) {
// Try looking for a /proc/<pid>/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";
}

@ -19,22 +19,13 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QApplication>
#include <QDir>
#include <windows.h>
#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";
}
}

@ -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