Mercurial > hg > svcore
comparison plugin/PluginPathSetter.cpp @ 1480:5ac102155409 plugin-path-config
Environment variable lookup fixes, & use this implementation throughout
author | Chris Cannam |
---|---|
date | Fri, 08 Jun 2018 11:27:40 +0100 |
parents | f52bf66b9096 |
children | 75fe1c1e003f |
comparison
equal
deleted
inserted
replaced
1479:ba27edcd6102 | 1480:5ac102155409 |
---|---|
21 #include "DSSIPluginFactory.h" | 21 #include "DSSIPluginFactory.h" |
22 | 22 |
23 #include <QSettings> | 23 #include <QSettings> |
24 #include <QMutexLocker> | 24 #include <QMutexLocker> |
25 | 25 |
26 #include "system/System.h" | |
27 | |
26 QMutex | 28 QMutex |
27 PluginPathSetter::m_mutex; | 29 PluginPathSetter::m_mutex; |
28 | 30 |
29 PluginPathSetter::Paths | 31 PluginPathSetter::Paths |
30 PluginPathSetter::m_defaultPaths; | 32 PluginPathSetter::m_defaultPaths; |
32 PluginPathSetter::Paths | 34 PluginPathSetter::Paths |
33 PluginPathSetter::m_environmentPaths; | 35 PluginPathSetter::m_environmentPaths; |
34 | 36 |
35 std::map<QString, QString> | 37 std::map<QString, QString> |
36 PluginPathSetter::m_originalEnvValues; | 38 PluginPathSetter::m_originalEnvValues; |
39 | |
40 using std::string; | |
37 | 41 |
38 PluginPathSetter::Paths | 42 PluginPathSetter::Paths |
39 PluginPathSetter::getEnvironmentPathsUncached() | 43 PluginPathSetter::getEnvironmentPathsUncached() |
40 { | 44 { |
41 Paths paths; | 45 Paths paths; |
73 QMutexLocker locker(&m_mutex); | 77 QMutexLocker locker(&m_mutex); |
74 | 78 |
75 if (!m_defaultPaths.empty()) { | 79 if (!m_defaultPaths.empty()) { |
76 return m_defaultPaths; | 80 return m_defaultPaths; |
77 } | 81 } |
78 | 82 |
79 QString savedPathVamp = qEnvironmentVariable("VAMP_PATH"); | 83 string savedPathVamp, savedPathDssi, savedPathLadspa; |
80 QString savedPathDssi = qEnvironmentVariable("DSSI_PATH"); | 84 (void)getEnvUtf8("VAMP_PATH", savedPathVamp); |
81 QString savedPathLadspa = qEnvironmentVariable("LADSPA_PATH"); | 85 (void)getEnvUtf8("DSSI_PATH", savedPathDssi); |
82 | 86 (void)getEnvUtf8("LADSPA_PATH", savedPathLadspa); |
83 qunsetenv("VAMP_PATH"); | 87 |
84 qunsetenv("DSSI_PATH"); | 88 putEnvUtf8("VAMP_PATH", ""); |
85 qunsetenv("LADSPA_PATH"); | 89 putEnvUtf8("DSSI_PATH", ""); |
90 putEnvUtf8("LADSPA_PATH", ""); | |
86 | 91 |
87 Paths paths = getEnvironmentPathsUncached(); | 92 Paths paths = getEnvironmentPathsUncached(); |
88 | 93 |
89 qputenv("VAMP_PATH", savedPathVamp.toUtf8()); | 94 putEnvUtf8("VAMP_PATH", savedPathVamp); |
90 qputenv("DSSI_PATH", savedPathDssi.toUtf8()); | 95 putEnvUtf8("DSSI_PATH", savedPathDssi); |
91 qputenv("LADSPA_PATH", savedPathLadspa.toUtf8()); | 96 putEnvUtf8("LADSPA_PATH", savedPathLadspa); |
92 | 97 |
93 m_defaultPaths = paths; | 98 m_defaultPaths = paths; |
94 return m_defaultPaths; | 99 return m_defaultPaths; |
95 } | 100 } |
96 | 101 |
129 .toString(); | 134 .toString(); |
130 bool useEnvVariable = | 135 bool useEnvVariable = |
131 settings.value(QString("use-env-variable-%1").arg(tag), | 136 settings.value(QString("use-env-variable-%1").arg(tag), |
132 p.second.useEnvVariable) | 137 p.second.useEnvVariable) |
133 .toBool(); | 138 .toBool(); |
134 std::string envVarStr = envVariable.toStdString(); | 139 |
135 | 140 string envVarStr = envVariable.toStdString(); |
136 QString currentValue = qEnvironmentVariable(envVarStr.c_str()); | 141 string currentValue; |
137 if (currentValue != QString() && useEnvVariable) { | 142 (void)getEnvUtf8(envVarStr, currentValue); |
138 directories = currentValue.split( | 143 |
144 if (currentValue != "" && useEnvVariable) { | |
145 directories = QString::fromStdString(currentValue).split( | |
139 #ifdef Q_OS_WIN | 146 #ifdef Q_OS_WIN |
140 ";" | 147 ";" |
141 #else | 148 #else |
142 ":" | 149 ":" |
143 #endif | 150 #endif |
196 | 203 |
197 Paths paths = getPaths(); | 204 Paths paths = getPaths(); |
198 | 205 |
199 for (auto p: paths) { | 206 for (auto p: paths) { |
200 QString envVariable = p.second.envVariable; | 207 QString envVariable = p.second.envVariable; |
201 std::string envVarStr = envVariable.toStdString(); | 208 string envVarStr = envVariable.toStdString(); |
202 QString currentValue = qEnvironmentVariable(envVarStr.c_str()); | 209 QString currentValue = qEnvironmentVariable(envVarStr.c_str()); |
203 m_originalEnvValues[envVariable] = currentValue; | 210 m_originalEnvValues[envVariable] = currentValue; |
204 if (currentValue != QString() && p.second.useEnvVariable) { | 211 if (currentValue != QString() && p.second.useEnvVariable) { |
205 // don't override | 212 // don't override |
206 continue; | 213 continue; |
211 #else | 218 #else |
212 ":" | 219 ":" |
213 #endif | 220 #endif |
214 ; | 221 ; |
215 QString proposedValue = p.second.directories.join(separator); | 222 QString proposedValue = p.second.directories.join(separator); |
216 qputenv(envVarStr.c_str(), proposedValue.toUtf8()); | 223 putEnvUtf8(envVarStr, proposedValue.toStdString()); |
217 } | 224 } |
218 } | 225 } |
219 | 226 |