Esempio n. 1
0
static QString
applicationFileName()
{
    static QString appFileName;

    if ( appFileName.isEmpty() ) {
        NatronCFType<CFURLRef> bundleURL( CFBundleCopyExecutableURL( CFBundleGetMainBundle() ) );
        if (bundleURL) {
            NatronCFString cfPath( CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle) );
            if (cfPath) {
                appFileName = cfPath;
            }
        }
    }

    return appFileName;
}
Esempio n. 2
0
NATRON_NAMESPACE_ANONYMOUS_EXIT


QString
ProcInfo::applicationFilePath(const char* argv0Param)
{
#if defined(Q_OS_WIN)
    Q_UNUSED(argv0Param);
    
    //The only viable solution
    return applicationFileName();
#elif defined(Q_OS_MAC)
    //First guess this way, then use the fallback solution
    static QString appFileName;

    if ( appFileName.isEmpty() ) {
        NatronCFType<CFURLRef> bundleURL( CFBundleCopyExecutableURL( CFBundleGetMainBundle() ) );
        if (bundleURL) {
            NatronCFString cfPath( CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle) );
            if (cfPath) {
                appFileName = cfPath;
            }
        }
    }
    if ( !appFileName.isEmpty() ) {
        return appFileName;
    } else {
        return applicationFilePath_fromArgv(argv0Param);
    }
#elif defined(Q_OS_LINUX)
    // Try looking for a /proc/<pid>/exe symlink first which points to
    // the absolute path of the executable
    std::stringstream ss;
    ss << "/proc/" << getpid() << "/exe";
    std::string filename = ss.str();
    char buf[2048] = {0};
    ssize_t sizeofbuf = sizeof(char) * 2048;
    ssize_t size = readlink(filename.c_str(), buf, sizeofbuf);
    if ( (size != 0) && (size != sizeofbuf) ) {
        //detected symlink
        return QString::fromUtf8( QByteArray(buf) );
    } else {
        return applicationFilePath_fromArgv(argv0Param);
    }
#endif
}
QT_BEGIN_NAMESPACE

/*****************************************************************************
  QCoreApplication utility functions
 *****************************************************************************/
QString qAppFileName()
{
    static QString appFileName;
    if (appFileName.isEmpty()) {
        QCFType<CFURLRef> bundleURL(CFBundleCopyExecutableURL(CFBundleGetMainBundle()));
        if(bundleURL) {
            QCFString cfPath(CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle));
            if(cfPath)
                appFileName = cfPath;
        }
    }
    return appFileName;
}
Esempio n. 4
0
bool InjectedBundle::load(APIObject* initializationUserData)
{
    if (m_sandboxExtension) {
        if (!m_sandboxExtension->consume()) {
            fprintf(stderr, "InjectedBundle::load failed - Could not consume bundle sandbox extension for [%s].\n", m_path.utf8().data());
            return false;
        }

        m_sandboxExtension = 0;
    }
    
    RetainPtr<CFStringRef> injectedBundlePathStr(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(m_path.characters()), m_path.length()));
    if (!injectedBundlePathStr) {
        fprintf(stderr, "InjectedBundle::load failed - Could not create the path string.\n");
        return false;
    }
    
    RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(0, injectedBundlePathStr.get(), kCFURLPOSIXPathStyle, false));
    if (!bundleURL) {
        fprintf(stderr, "InjectedBundle::load failed - Could not create the url from the path string.\n");
        return false;
    }

    m_platformBundle = CFBundleCreate(0, bundleURL.get());
    if (!m_platformBundle) {
        fprintf(stderr, "InjectedBundle::load failed - Could not create the bundle.\n");
        return false;
    }
        
    if (!CFBundleLoadExecutable(m_platformBundle)) {
        fprintf(stderr, "InjectedBundle::load failed - Could not load the executable from the bundle.\n");
        return false;
    }

    WKBundleInitializeFunctionPtr initializeFunction = reinterpret_cast<WKBundleInitializeFunctionPtr>(CFBundleGetFunctionPointerForName(m_platformBundle, CFSTR("WKBundleInitialize")));
    if (!initializeFunction) {
        fprintf(stderr, "InjectedBundle::load failed - Could not find the initialize function in the bundle executable.\n");
        return false;
    }

    initializeFunction(toAPI(this), toAPI(initializationUserData));
    return true;
}
Esempio n. 5
0
void initAppPaths(int argc,char** argv) {
    CFURLRef bundleURL(CFBundleCopyExecutableURL(CFBundleGetMainBundle()));
    //assert(bundleURL);
    CFStringRef cfPath(CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle));
    //assert(cfPath);
    CFIndex length = CFStringGetLength(cfPath);
    const UniChar *chars = CFStringGetCharactersPtr(cfPath);
    if (chars) {
        AppDir = QString(reinterpret_cast<const QChar *>(chars), length);
    }
    else {
        QVarLengthArray<UniChar> buffer(length);
        CFStringGetCharacters(cfPath, CFRangeMake(0, length), buffer.data());
        AppDir = QString(reinterpret_cast<const QChar *>(buffer.constData()), length);
    }
    AppDir.truncate(AppDir.lastIndexOf("/"));
    HomeDir = QDir::homePath()+"/.keepassx";
    DataDir=AppDir+"/../Resources/keepassx";
}