diff --git a/Linphone/core/setting/Settings.cpp b/Linphone/core/setting/Settings.cpp index 91d9fc0e2..632735983 100644 --- a/Linphone/core/setting/Settings.cpp +++ b/Linphone/core/setting/Settings.cpp @@ -40,6 +40,6 @@ QString Settings::getConfigPath(const QCommandLineParser &parser) { // Utils::coreStringToAppString(Paths::getConfigDirPath(false)), true)); } if (configPath == "") configPath = Paths::getConfigFilePath(filePath, false); - if (configPath == "") configPath = Paths::getConfigFilePath("", false); + if (configPath == "" && !filePath.isEmpty()) configPath = Paths::getConfigFilePath("", false); return configPath; -} \ No newline at end of file +} diff --git a/Linphone/model/core/CoreModel.cpp b/Linphone/model/core/CoreModel.cpp index 14fc49cfc..22a2596be 100644 --- a/Linphone/model/core/CoreModel.cpp +++ b/Linphone/model/core/CoreModel.cpp @@ -27,6 +27,7 @@ #include #include +#include "core/path/Paths.hpp" #include "tool/Utils.hpp" // ============================================================================= @@ -41,10 +42,14 @@ CoreModel::~CoreModel() { } void CoreModel::start() { - auto configPath = Utils::appStringToCoreString(mConfigPath); - mCore = linphone::Factory::get()->createCore(configPath, "", nullptr); - mCore->enableAutoIterate(true); + setPathBeforeCreation(); + mCore = + linphone::Factory::get()->createCore(Utils::appStringToCoreString(Paths::getConfigFilePath(mConfigPath)), + Utils::appStringToCoreString(Paths::getFactoryConfigFilePath()), nullptr); + setPathsAfterCreation(); mCore->start(); + setPathAfterStart(); + mCore->enableAutoIterate(true); } // ----------------------------------------------------------------------------- @@ -55,3 +60,56 @@ CoreModel *CoreModel::getInstance() { std::shared_ptr CoreModel::getCore() { return mCore; } + +//------------------------------------------------------------------------------- +void CoreModel::setConfigPath(QString path) { + if (mConfigPath != path) { + mConfigPath = path; + if (!mCore) { + qWarning() << "[CoreModel] Setting config path after core creation is not yet supported"; + } + } +} + +//------------------------------------------------------------------------------- +// PATHS +//------------------------------------------------------------------------------- +#define SET_FACTORY_PATH(TYPE, PATH) \ + do { \ + qInfo() << QStringLiteral("[CoreModel] Set `%1` factory path: `%2`").arg(#TYPE).arg(PATH); \ + factory->set##TYPE##Dir(Utils::appStringToCoreString(PATH)); \ + } while (0); + +void CoreModel::setPathBeforeCreation() { + std::shared_ptr factory = linphone::Factory::get(); + SET_FACTORY_PATH(Msplugins, Paths::getPackageMsPluginsDirPath()); + SET_FACTORY_PATH(TopResources, Paths::getPackageTopDirPath()); + SET_FACTORY_PATH(SoundResources, Paths::getPackageSoundsResourcesDirPath()); + SET_FACTORY_PATH(DataResources, Paths::getPackageDataDirPath()); + SET_FACTORY_PATH(Data, Paths::getAppLocalDirPath()); + SET_FACTORY_PATH(Download, Paths::getDownloadDirPath()); + SET_FACTORY_PATH(Config, Paths::getConfigDirPath(true)); +} + +void CoreModel::setPathsAfterCreation() { + QString friendsDb = Paths::getFriendsListFilePath(); + qInfo() << QStringLiteral("[CoreModel] Set Database `Friends` path: `%1`").arg(friendsDb); + mCore->setFriendsDatabasePath(Utils::appStringToCoreString(friendsDb)); +} + +void CoreModel::setPathAfterStart() { + // Use application path if Linphone default is not available + if (mCore->getZrtpSecretsFile().empty() || + !Paths::filePathExists(Utils::coreStringToAppString(mCore->getZrtpSecretsFile()), true)) + mCore->setZrtpSecretsFile(Utils::appStringToCoreString(Paths::getZrtpSecretsFilePath())); + qInfo() << "[CoreModel] Using ZrtpSecrets path : " << QString::fromStdString(mCore->getZrtpSecretsFile()); + // Use application path if Linphone default is not available + if (mCore->getUserCertificatesPath().empty() || + !Paths::filePathExists(Utils::coreStringToAppString(mCore->getUserCertificatesPath()), true)) + mCore->setUserCertificatesPath(Utils::appStringToCoreString(Paths::getUserCertificatesDirPath())); + qInfo() << "[CoreModel] Using UserCertificate path : " << QString::fromStdString(mCore->getUserCertificatesPath()); + // Use application path if Linphone default is not available + if (mCore->getRootCa().empty() || !Paths::filePathExists(Utils::coreStringToAppString(mCore->getRootCa()))) + mCore->setRootCa(Utils::appStringToCoreString(Paths::getRootCaFilePath())); + qInfo() << "[CoreModel] Using RootCa path : " << QString::fromStdString(mCore->getRootCa()); +} diff --git a/Linphone/model/core/CoreModel.hpp b/Linphone/model/core/CoreModel.hpp index 77e76a250..6534e66ae 100644 --- a/Linphone/model/core/CoreModel.hpp +++ b/Linphone/model/core/CoreModel.hpp @@ -42,15 +42,24 @@ public: void start(); static CoreModel *getInstance(); + + void setConfigPath(QString path); + bool mEnd = false; - QString mConfigPath; std::shared_ptr mCore; std::shared_ptr mLogger; signals: void loggerInitialized(); +private: + QString mConfigPath; + + void setPathBeforeCreation(); + void setPathsAfterCreation(); + void setPathAfterStart(); + }; #endif