Mercurial > hg > svcore
diff plugin/PluginPathSetter.cpp @ 1473:f52bf66b9096 plugin-path-config
Provide means of getting the initial environment values
author | Chris Cannam |
---|---|
date | Mon, 04 Jun 2018 15:43:27 +0100 |
parents | 5d7057af0c68 |
children | 5ac102155409 |
line wrap: on
line diff
--- a/plugin/PluginPathSetter.cpp Fri May 25 16:04:42 2018 +0100 +++ b/plugin/PluginPathSetter.cpp Mon Jun 04 15:43:27 2018 +0100 @@ -30,14 +30,14 @@ PluginPathSetter::m_defaultPaths; PluginPathSetter::Paths -PluginPathSetter::getDefaultPaths() +PluginPathSetter::m_environmentPaths; + +std::map<QString, QString> +PluginPathSetter::m_originalEnvValues; + +PluginPathSetter::Paths +PluginPathSetter::getEnvironmentPathsUncached() { - QMutexLocker locker(&m_mutex); - - if (!m_defaultPaths.empty()) { - return m_defaultPaths; - } - Paths paths; auto vampPath = Vamp::PluginHostAdapter::getPluginPath(); @@ -64,14 +64,53 @@ } paths["LADSPA"] = { qLadspaPath, "LADSPA_PATH", true }; + return paths; +} + +PluginPathSetter::Paths +PluginPathSetter::getDefaultPaths() +{ + QMutexLocker locker(&m_mutex); + + if (!m_defaultPaths.empty()) { + return m_defaultPaths; + } + + QString savedPathVamp = qEnvironmentVariable("VAMP_PATH"); + QString savedPathDssi = qEnvironmentVariable("DSSI_PATH"); + QString savedPathLadspa = qEnvironmentVariable("LADSPA_PATH"); + + qunsetenv("VAMP_PATH"); + qunsetenv("DSSI_PATH"); + qunsetenv("LADSPA_PATH"); + + Paths paths = getEnvironmentPathsUncached(); + + qputenv("VAMP_PATH", savedPathVamp.toUtf8()); + qputenv("DSSI_PATH", savedPathDssi.toUtf8()); + qputenv("LADSPA_PATH", savedPathLadspa.toUtf8()); + m_defaultPaths = paths; return m_defaultPaths; } PluginPathSetter::Paths +PluginPathSetter::getEnvironmentPaths() +{ + QMutexLocker locker(&m_mutex); + + if (!m_environmentPaths.empty()) { + return m_environmentPaths; + } + + m_environmentPaths = getEnvironmentPathsUncached(); + return m_environmentPaths; +} + +PluginPathSetter::Paths PluginPathSetter::getPaths() { - Paths paths = getDefaultPaths(); + Paths paths = getEnvironmentPaths(); QSettings settings; settings.beginGroup("Plugins"); @@ -132,8 +171,18 @@ settings.endGroup(); } +QString +PluginPathSetter::getOriginalEnvironmentValue(QString envVariable) +{ + if (m_originalEnvValues.find(envVariable) != m_originalEnvValues.end()) { + return m_originalEnvValues.at(envVariable); + } else { + return QString(); + } +} + void -PluginPathSetter::setEnvironmentVariables() +PluginPathSetter::initialiseEnvironmentVariables() { // Set the relevant environment variables from user configuration, // so that later lookups through the standard APIs will follow the @@ -143,6 +192,7 @@ // we don't erroneously re-read them from the environment // variables we've just set (void)getDefaultPaths(); + (void)getEnvironmentPaths(); Paths paths = getPaths(); @@ -150,6 +200,7 @@ QString envVariable = p.second.envVariable; std::string envVarStr = envVariable.toStdString(); QString currentValue = qEnvironmentVariable(envVarStr.c_str()); + m_originalEnvValues[envVariable] = currentValue; if (currentValue != QString() && p.second.useEnvVariable) { // don't override continue;