diff 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
line wrap: on
line diff
--- a/plugin/PluginPathSetter.cpp	Thu Jun 07 16:49:09 2018 +0100
+++ b/plugin/PluginPathSetter.cpp	Fri Jun 08 11:27:40 2018 +0100
@@ -23,6 +23,8 @@
 #include <QSettings>
 #include <QMutexLocker>
 
+#include "system/System.h"
+
 QMutex
 PluginPathSetter::m_mutex;
 
@@ -35,6 +37,8 @@
 std::map<QString, QString>
 PluginPathSetter::m_originalEnvValues;
 
+using std::string;
+
 PluginPathSetter::Paths
 PluginPathSetter::getEnvironmentPathsUncached()
 {
@@ -75,20 +79,21 @@
     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");
+    string savedPathVamp, savedPathDssi, savedPathLadspa;
+    (void)getEnvUtf8("VAMP_PATH", savedPathVamp);
+    (void)getEnvUtf8("DSSI_PATH", savedPathDssi);
+    (void)getEnvUtf8("LADSPA_PATH", savedPathLadspa);
+
+    putEnvUtf8("VAMP_PATH", "");
+    putEnvUtf8("DSSI_PATH", "");
+    putEnvUtf8("LADSPA_PATH", "");
 
     Paths paths = getEnvironmentPathsUncached();
 
-    qputenv("VAMP_PATH", savedPathVamp.toUtf8());
-    qputenv("DSSI_PATH", savedPathDssi.toUtf8());
-    qputenv("LADSPA_PATH", savedPathLadspa.toUtf8());
+    putEnvUtf8("VAMP_PATH", savedPathVamp);
+    putEnvUtf8("DSSI_PATH", savedPathDssi);
+    putEnvUtf8("LADSPA_PATH", savedPathLadspa);
 
     m_defaultPaths = paths;
     return m_defaultPaths;
@@ -131,11 +136,13 @@
             settings.value(QString("use-env-variable-%1").arg(tag),
                            p.second.useEnvVariable)
             .toBool();
-        std::string envVarStr = envVariable.toStdString();
-        
-        QString currentValue = qEnvironmentVariable(envVarStr.c_str());
-        if (currentValue != QString() && useEnvVariable) {
-            directories = currentValue.split(
+
+        string envVarStr = envVariable.toStdString();
+        string currentValue;
+        (void)getEnvUtf8(envVarStr, currentValue);
+
+        if (currentValue != "" && useEnvVariable) {
+            directories = QString::fromStdString(currentValue).split(
 #ifdef Q_OS_WIN
                ";"
 #else
@@ -198,7 +205,7 @@
 
     for (auto p: paths) {
         QString envVariable = p.second.envVariable;
-        std::string envVarStr = envVariable.toStdString();
+        string envVarStr = envVariable.toStdString();
         QString currentValue = qEnvironmentVariable(envVarStr.c_str());
         m_originalEnvValues[envVariable] = currentValue;
         if (currentValue != QString() && p.second.useEnvVariable) {
@@ -213,7 +220,7 @@
 #endif
             ;
         QString proposedValue = p.second.directories.join(separator);
-        qputenv(envVarStr.c_str(), proposedValue.toUtf8());
+        putEnvUtf8(envVarStr, proposedValue.toStdString());
     }
 }