diff --git a/src/main.cpp b/src/main.cpp index 1a3d004..cc03d27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,9 @@ #include #include #include +#include +#include + /* #include @@ -55,6 +58,9 @@ #ifdef Q_WS_WIN #include #endif +#ifdef Q_WS_MAC +#include +#endif using namespace std; @@ -496,13 +502,21 @@ QString applicationFilePath() return filePath.filePath(); #elif defined(Q_WS_MAC) - QString qAppFileName_str = qAppFileName(); - if(!qAppFileName_str.isEmpty()) { - QFileInfo fi(qAppFileName_str); - return fi.exists() ? fi.canonicalFilePath() : QString(); - } - #endif - #if defined( Q_OS_UNIX ) + + CFURLRef bundleURL(CFBundleCopyExecutableURL(CFBundleGetMainBundle())); + assert(bundleURL); + CFStringRef cfPath(CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle)); + assert(cfPath); + CFIndex length = CFStringGetLength(cfPath); + const UniChar *chars = CFStringGetCharactersPtr(cfPath); + if (chars) + return QString(reinterpret_cast(chars), length); + + QVarLengthArray buffer(length); + CFStringGetCharacters(cfPath, CFRangeMake(0, length), buffer.data()); + return QString(reinterpret_cast(buffer.constData()), length); + + #elif defined( Q_OS_UNIX ) #ifdef Q_OS_LINUX // Try looking for a /proc//exe symlink first which points to // the absolute path of the executable diff --git a/src/src.pro b/src/src.pro index 04e886f..2e7b803 100644 --- a/src/src.pro +++ b/src/src.pro @@ -50,6 +50,7 @@ macx { isEmpty(PREFIX):PREFIX = /Applications target.path = $${PREFIX} data.path = $${PREFIX}/keepassx.app/Contents/share/keepass + LIBS += -framework CoreFoundation } isEqual(QMAKE_WIN32,1) {