comparison 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
comparison
equal deleted inserted replaced
1472:5d7057af0c68 1473:f52bf66b9096
28 28
29 PluginPathSetter::Paths 29 PluginPathSetter::Paths
30 PluginPathSetter::m_defaultPaths; 30 PluginPathSetter::m_defaultPaths;
31 31
32 PluginPathSetter::Paths 32 PluginPathSetter::Paths
33 PluginPathSetter::getDefaultPaths() 33 PluginPathSetter::m_environmentPaths;
34 { 34
35 QMutexLocker locker(&m_mutex); 35 std::map<QString, QString>
36 36 PluginPathSetter::m_originalEnvValues;
37 if (!m_defaultPaths.empty()) { 37
38 return m_defaultPaths; 38 PluginPathSetter::Paths
39 } 39 PluginPathSetter::getEnvironmentPathsUncached()
40 40 {
41 Paths paths; 41 Paths paths;
42 42
43 auto vampPath = Vamp::PluginHostAdapter::getPluginPath(); 43 auto vampPath = Vamp::PluginHostAdapter::getPluginPath();
44 44
45 QStringList qVampPath; 45 QStringList qVampPath;
62 for (auto s: ladspaPath) { 62 for (auto s: ladspaPath) {
63 qLadspaPath.push_back(s); 63 qLadspaPath.push_back(s);
64 } 64 }
65 paths["LADSPA"] = { qLadspaPath, "LADSPA_PATH", true }; 65 paths["LADSPA"] = { qLadspaPath, "LADSPA_PATH", true };
66 66
67 return paths;
68 }
69
70 PluginPathSetter::Paths
71 PluginPathSetter::getDefaultPaths()
72 {
73 QMutexLocker locker(&m_mutex);
74
75 if (!m_defaultPaths.empty()) {
76 return m_defaultPaths;
77 }
78
79 QString savedPathVamp = qEnvironmentVariable("VAMP_PATH");
80 QString savedPathDssi = qEnvironmentVariable("DSSI_PATH");
81 QString savedPathLadspa = qEnvironmentVariable("LADSPA_PATH");
82
83 qunsetenv("VAMP_PATH");
84 qunsetenv("DSSI_PATH");
85 qunsetenv("LADSPA_PATH");
86
87 Paths paths = getEnvironmentPathsUncached();
88
89 qputenv("VAMP_PATH", savedPathVamp.toUtf8());
90 qputenv("DSSI_PATH", savedPathDssi.toUtf8());
91 qputenv("LADSPA_PATH", savedPathLadspa.toUtf8());
92
67 m_defaultPaths = paths; 93 m_defaultPaths = paths;
68 return m_defaultPaths; 94 return m_defaultPaths;
69 } 95 }
70 96
71 PluginPathSetter::Paths 97 PluginPathSetter::Paths
98 PluginPathSetter::getEnvironmentPaths()
99 {
100 QMutexLocker locker(&m_mutex);
101
102 if (!m_environmentPaths.empty()) {
103 return m_environmentPaths;
104 }
105
106 m_environmentPaths = getEnvironmentPathsUncached();
107 return m_environmentPaths;
108 }
109
110 PluginPathSetter::Paths
72 PluginPathSetter::getPaths() 111 PluginPathSetter::getPaths()
73 { 112 {
74 Paths paths = getDefaultPaths(); 113 Paths paths = getEnvironmentPaths();
75 114
76 QSettings settings; 115 QSettings settings;
77 settings.beginGroup("Plugins"); 116 settings.beginGroup("Plugins");
78 117
79 for (auto p: paths) { 118 for (auto p: paths) {
130 } 169 }
131 170
132 settings.endGroup(); 171 settings.endGroup();
133 } 172 }
134 173
174 QString
175 PluginPathSetter::getOriginalEnvironmentValue(QString envVariable)
176 {
177 if (m_originalEnvValues.find(envVariable) != m_originalEnvValues.end()) {
178 return m_originalEnvValues.at(envVariable);
179 } else {
180 return QString();
181 }
182 }
183
135 void 184 void
136 PluginPathSetter::setEnvironmentVariables() 185 PluginPathSetter::initialiseEnvironmentVariables()
137 { 186 {
138 // Set the relevant environment variables from user configuration, 187 // Set the relevant environment variables from user configuration,
139 // so that later lookups through the standard APIs will follow the 188 // so that later lookups through the standard APIs will follow the
140 // same paths as we have in the user config 189 // same paths as we have in the user config
141 190
142 // First ensure the default paths have been recorded for later, so 191 // First ensure the default paths have been recorded for later, so
143 // we don't erroneously re-read them from the environment 192 // we don't erroneously re-read them from the environment
144 // variables we've just set 193 // variables we've just set
145 (void)getDefaultPaths(); 194 (void)getDefaultPaths();
195 (void)getEnvironmentPaths();
146 196
147 Paths paths = getPaths(); 197 Paths paths = getPaths();
148 198
149 for (auto p: paths) { 199 for (auto p: paths) {
150 QString envVariable = p.second.envVariable; 200 QString envVariable = p.second.envVariable;
151 std::string envVarStr = envVariable.toStdString(); 201 std::string envVarStr = envVariable.toStdString();
152 QString currentValue = qEnvironmentVariable(envVarStr.c_str()); 202 QString currentValue = qEnvironmentVariable(envVarStr.c_str());
203 m_originalEnvValues[envVariable] = currentValue;
153 if (currentValue != QString() && p.second.useEnvVariable) { 204 if (currentValue != QString() && p.second.useEnvVariable) {
154 // don't override 205 // don't override
155 continue; 206 continue;
156 } 207 }
157 QString separator = 208 QString separator =