HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */) { QStringList searchOrder; #if !defined(QT_BOOTSTRAPPED) if (!onlySystemDirectory) searchOrder << QFileInfo(qAppFileName()).path(); #endif searchOrder << qSystemDirectory(); if (!onlySystemDirectory) { const QString PATH = QString::fromWCharArray((const wchar_t *)_wgetenv(L"PATH")); searchOrder << PATH.split(QLatin1Char(';'), QString::SkipEmptyParts); } const QString fileName = QString::fromWCharArray(libraryName) + QLatin1String(".dll"); // Start looking in the order specified for (int i = 0; i < searchOrder.count(); ++i) { QString fullPathAttempt = searchOrder.at(i); if (!fullPathAttempt.endsWith(QLatin1Char('\\'))) fullPathAttempt.append(QLatin1Char('\\')); fullPathAttempt.append(fileName); HINSTANCE inst = ::LoadLibrary((const wchar_t *)fullPathAttempt.utf16()); if (inst != 0) return inst; } return 0; }
QString QCoreApplicationPrivate::appName() const { return QFileInfo(qAppFileName()).baseName(); }
PHIApplication::PHIApplication( int &argc, char **argv, const char *name , const char *version, Type type ) : QObject( 0 ), _app( 0 ), _settings( 0 ), _serverSettings( 0 ), _type( type ) { qDebug( "PHIApplication::PHIApplication()" ); Q_ASSERT( argc>0 ); _instance=this; setObjectName( QString::fromLatin1( name ) ); const QString phis=L1( "phis" ); _usrDocPath=QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation ); QDir rootDir; #ifdef PHIAPPSTORE // needed for Apple AppStore: const QString domain=QString::fromLatin1( "phisys.com" ); const QString org=QString::fromLatin1( "Phisys AG" ); #else const QString domain=QString::fromLatin1( PHIDOM ); const QString org=QString::fromLatin1( PHIORG ); #endif #ifdef Q_OS_WIN _serverSettings=new QSettings( QSettings::NativeFormat, QSettings::SystemScope, org, phis, this ); rootDir=QFileInfo( qAppFileName() ).dir(); rootDir.cdUp(); _rootPath=rootDir.canonicalPath(); _binPath=_rootPath+L1( "/bin" ); _libPath=_binPath; _pluginsPath=_binPath+L1( "/plugins" ); _modulesPath=_pluginsPath+L1( "/modules" ); _itemsPath=_pluginsPath+L1( "/items" ); _tsPath=_rootPath+L1( "/ts" ); _serverBin=_binPath+L1( "/Phis.exe" ); _appBin=_binPath+L1( "/PhiApp.exe" ); #elif defined Q_OS_MAC _serverSettings=new QSettings( domain, phis, this ); rootDir=QFileInfo( QString::fromLocal8Bit( argv[0] ) ).dir(); // bundleID/Contents/MacOS _binPath=rootDir.canonicalPath(); rootDir.cdUp(); // bundleID/Contents _libPath=rootDir.canonicalPath()+L1( "/Frameworks" ); rootDir.cdUp(); // bundleID _rootPath=rootDir.canonicalPath(); _pluginsPath=_rootPath+L1( "/Contents/PlugIns" ); _modulesPath=_pluginsPath+L1( "/modules" ); _itemsPath=_pluginsPath+L1( "/items" ); _tsPath=_rootPath+L1( "/Contents/Resources/ts" ); _serverBin=_binPath+L1( "/Phis" ); _appBin=_binPath+L1( "/PhiApp" ); _dataPath=QStandardPaths::writableLocation( QStandardPaths::DataLocation )+L1( "/" )+objectName(); #elif defined Q_OS_LINUX Q_UNUSED( phis ) QString conf; if ( PHISysInfo::effUserId()==0 ) conf=L1( "/etc/phi/phis.conf" ); else conf=QStandardPaths::writableLocation( QStandardPaths::HomeLocation )+L1( "/.phi/phis.conf" ); _serverSettings=new QSettings( conf, QSettings::IniFormat, this ); if ( type!=ApacheModule ) { // normal application QFileInfo fi( QString::fromLatin1( "/proc/%1/exe" ).arg( PHISysInfo::processId() ) ); if ( fi.exists() && fi.isSymLink() ) _binPath=fi.canonicalPath(); else _binPath=QFileInfo( QString::fromLocal8Bit( argv[0] ) ).canonicalPath(); rootDir.setPath( _binPath ); rootDir.cdUp(); _rootPath=rootDir.canonicalPath(); } else { // Apache module conf=L1( "/opt/phi" ); // fallback _rootPath=_serverSettings->value( L1( "RootDir" ), conf ).toString(); _binPath=_rootPath+L1( "/bin" ); conf=_rootPath+L1( "/plugins" ); // fallback _usrDocPath=L1( "/root/Documents" ); } _pluginsPath=_rootPath+L1( "/plugins" ); _modulesPath=_pluginsPath+L1( "/modules" ); _itemsPath=_pluginsPath+L1( "/items" ); _libPath=_rootPath+L1( "/lib" ); _tsPath=_rootPath+L1( "/ts" ); _serverBin=_binPath+L1( "/phis" ); _appBin=_binPath+L1( "/phiapp" ); if ( PHISysInfo::effUserId()==0 ) _dataPath=L1( "/var/phis/" ); else _dataPath=QStandardPaths::writableLocation( QStandardPaths::HomeLocation )+L1( "/.phi/phis" ); #else #error Unsupported system #endif Q_ASSERT( _serverSettings ); // Fix for QPA (Qt5 needs to find platform plugins - better way could be qt.conf) _pluginsPath=_serverSettings->value( L1( "PluginsPath" ), _pluginsPath ).toString(); qputenv( "QT_PLUGIN_PATH", _pluginsPath.toUtf8() ); if ( type==ApacheModule || type==Service ) { #ifdef Q_OS_MAC qputenv( "QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM", "1" ); #elif defined Q_OS_LINUX QByteArray fdir=_serverSettings->value( L1( "FontDir" ), _libPath+L1( "/fonts" ) ).toString().toUtf8(); qputenv( "QT_QPA_FONTDIR", fdir ); #endif _app=new QGuiApplication( argc, argv ); delete _settings; _settings=_serverSettings; } else { PHIPrivateApplication *pApp=new PHIPrivateApplication( argc, argv ); connect( pApp, &PHIPrivateApplication::openFileRequest, this, &PHIApplication::openFileRequest, Qt::QueuedConnection ); _app=pApp; #ifdef Q_OS_MAC _settings=new QSettings( QSettings::UserScope, domain, objectName(), this ); #elif defined Q_OS_WIN _settings=new QSettings( QSettings::UserScope, org, objectName(), this ); #elif defined Q_OS_LINUX QString s=QStandardPaths::writableLocation( QStandardPaths::HomeLocation ) +L1( "/.phi/" )+objectName()+L1( ".conf" ); _settings=new QSettings( s, QSettings::IniFormat, this ); qobject_cast<QApplication*>(_app)->setStyle( L1( "fusion" ) ); #else #error Unsupported system #endif } Q_ASSERT( _settings ); _cachePath=QStandardPaths::writableLocation( QStandardPaths::CacheLocation ); #ifdef Q_OS_WIN _dataPath=_settings->value( L1( "BaseDir" ), _rootPath+L1( "/data" ) ).toString(); _tmpPath=_dataPath+L1( "/temp" ); #elif defined Q_OS_MAC _tmpPath=QStandardPaths::writableLocation( QStandardPaths::TempLocation )+QLatin1Char( '/' )+objectName(); #else _tmpPath=L1( "/tmp/" )+objectName(); #endif _tmpPath=_settings->value( L1( "TempDir" ), _tmpPath ).toString(); if ( type==Service || type==ApacheModule ) { _cachePath=_tmpPath+L1( "/cache" ); _settings->beginGroup( PHI::defaultString() ); _dataPath=_settings->value( L1( "BaseDir" ), _dataPath ).toString(); _settings->endGroup(); } else { if ( !QFileInfo( _cachePath ).exists() ) QDir( _cachePath ).mkpath( _cachePath ); if ( !QFileInfo( _tmpPath ).exists() ) QDir( _tmpPath ).mkpath( _tmpPath ); } qRegisterMetaTypeStreamOperators<PHIRectHash>("PHIRectHash"); qRegisterMetaTypeStreamOperators<PHIByteArrayList>("PHIByteArrayList"); qRegisterMetaTypeStreamOperators<PHIImageHash>("PHIImageHash"); qRegisterMetaTypeStreamOperators<QGradientStops>("QGradientStops"); qRegisterMetaTypeStreamOperators<PHIListChar>("PHIListChar"); qRegisterMetaTypeStreamOperators<PHIListWord>("PHIListWord"); qRegisterMetaType<QDateTime>("QDateTime"); qRegisterMetaType<PHIRC>("PHIRC"); qRegisterMetaType<PHIWID>("PHIWID"); qRegisterMetaType<QSizePolicy>("QSizePolicy"); #ifdef PHIDEBUG _rootPath=L1( PHIDIR ); _binPath=L1( PHIDIR )+L1( "/bin" ); _pluginsPath=L1( PHIDIR )+L1( "/plugins" ); _itemsPath=_pluginsPath+L1( "/items" ); _serverBin=L1( PHIDIR )+L1( "/bin/Phisd" ); _appBin=L1( PHIDIR )+L1( "/bin/PhiAppd" ); _tsPath=L1( PHIDIR )+L1( "/src/ts" ); _libPath=L1( PHIDIR )+L1( "/lib" ); _modulesPath=_libPath+L1( "/modules" ); #ifdef Q_OS_WIN _libPath=L1( PHIDIR )+L1( "/bin" ); _pluginsPath=_libPath+L1( "/plugins" ); _itemsPath=_pluginsPath+L1( "/items" ); _modulesPath=_pluginsPath+L1( "/modules" ); _serverBin=L1( PHIDIR )+L1( "/bin/Phisd.exe" ); _appBin=L1( PHIDIR )+L1( "/bin/PhiAppd.exe" ); #elif defined Q_OS_LINUX _serverBin=L1( PHIDIR )+L1( "/bin/phis_debug" ); _appBin=L1( PHIDIR )+L1( "/bin/phiapp_debug" ); #endif #endif #ifdef PHIEMBEDEDSERVER _serverBin=QString(); #endif #ifdef PHIEMBEDEDAPP _appBin=QString(); #endif _pluginsPath=QDir::toNativeSeparators( _pluginsPath ); _itemsPath=QDir::toNativeSeparators( _itemsPath ); _modulesPath=QDir::toNativeSeparators( _modulesPath ); _binPath=QDir::toNativeSeparators( _binPath ); _serverBin=QDir::toNativeSeparators( _serverBin ); _appBin=QDir::toNativeSeparators( _appBin ); _tsPath=QDir::toNativeSeparators( _tsPath ); _rootPath=QDir::toNativeSeparators( _rootPath ); _libPath=QDir::toNativeSeparators( _libPath ); _tmpPath=QDir::toNativeSeparators( _tmpPath ); _cachePath=QDir::toNativeSeparators( _cachePath ); _dataPath=QDir::toNativeSeparators( _dataPath ); _usrDocPath=QDir::toNativeSeparators( _usrDocPath ); #ifdef PHIPRINTDIRS qWarning( "App name: %s", name ); qWarning( "Version: %s", version ); qWarning( "Settings file: %s", qPrintable( _settings->fileName() ) ); qWarning( "Server setings: %s", qPrintable( _serverSettings->fileName() ) ); qWarning( "Root dir: %s", qPrintable( _rootPath ) ); qWarning( "Plug-in dir: %s", qPrintable( _pluginsPath ) ); qWarning( "Items dir: %s", qPrintable( _itemsPath ) ); qWarning( "Modules dir: %s", qPrintable( _modulesPath ) ); qWarning( "Bin dir: %s", qPrintable( _binPath ) ); qWarning( "Server bin: %s", qPrintable( _serverBin ) ); qWarning( "PhiApp bin: %s", qPrintable( _appBin ) ); qWarning( "TS dir: %s", qPrintable( _tsPath ) ); qWarning( "Lib dir: %s", qPrintable( _libPath ) ); qWarning( "Tmp dir: %s", qPrintable( _tmpPath ) ); qWarning( "Cache dir: %s", qPrintable( _cachePath ) ); qWarning( "Data dir: %s", qPrintable( _dataPath ) ); qWarning( "User doc dir: %s", qPrintable( _usrDocPath ) ); #endif Q_ASSERT( _app ); _app->setApplicationName( objectName() ); _app->setApplicationVersion( QString::fromLatin1( version ) ); _app->setOrganizationDomain( domain ); _app->setOrganizationName( org ); _app->addLibraryPath( _pluginsPath ); loadTranslations(); PHINetManager::instance(); new PHIItemFactory( _itemsPath, this ); #ifdef PHIWEBKIT QWebSettings *ws=QWebSettings::globalSettings(); ws->setAttribute( QWebSettings::PluginsEnabled, true ); ws->setAttribute( QWebSettings::JavascriptCanOpenWindows, true ); ws->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true ); ws->setAttribute( QWebSettings::JavascriptEnabled, true ); ws->setIconDatabasePath( _cachePath ); #endif }