Mercurial > hg > vamp-plugin-sdk
comparison src/vamp-hostsdk/PluginHostAdapter.cpp @ 512:54277cb679ff
Wide-char environment variable lookup
author | Chris Cannam |
---|---|
date | Fri, 08 Jun 2018 11:25:19 +0100 |
parents | abdf03252c8a |
children | 4b619c5871ee |
comparison
equal
deleted
inserted
replaced
511:328cb056da44 | 512:54277cb679ff |
---|---|
35 */ | 35 */ |
36 | 36 |
37 #include <vamp-hostsdk/PluginHostAdapter.h> | 37 #include <vamp-hostsdk/PluginHostAdapter.h> |
38 #include <cstdlib> | 38 #include <cstdlib> |
39 | 39 |
40 #include "Files.h" | |
41 | |
40 #if ( VAMP_SDK_MAJOR_VERSION != 2 || VAMP_SDK_MINOR_VERSION != 7 ) | 42 #if ( VAMP_SDK_MAJOR_VERSION != 2 || VAMP_SDK_MINOR_VERSION != 7 ) |
41 #error Unexpected version of Vamp SDK header included | 43 #error Unexpected version of Vamp SDK header included |
42 #endif | 44 #endif |
43 | 45 |
44 _VAMP_SDK_HOSTSPACE_BEGIN(PluginHostAdapter.cpp) | 46 _VAMP_SDK_HOSTSPACE_BEGIN(PluginHostAdapter.cpp) |
68 PluginHostAdapter::getPluginPath() | 70 PluginHostAdapter::getPluginPath() |
69 { | 71 { |
70 std::vector<std::string> path; | 72 std::vector<std::string> path; |
71 std::string envPath; | 73 std::string envPath; |
72 | 74 |
73 char *cpath = getenv("VAMP_PATH"); | 75 (void)Files::getEnvUtf8("VAMP_PATH", envPath); |
74 if (cpath) envPath = cpath; | |
75 | 76 |
76 #ifdef _WIN32 | 77 #ifdef _WIN32 |
77 #define PATH_SEPARATOR ';' | 78 #define PATH_SEPARATOR ';' |
78 #define DEFAULT_VAMP_PATH "%ProgramFiles%\\Vamp Plugins" | 79 #define DEFAULT_VAMP_PATH "%ProgramFiles%\\Vamp Plugins" |
79 #else | 80 #else |
85 #endif | 86 #endif |
86 #endif | 87 #endif |
87 | 88 |
88 if (envPath == "") { | 89 if (envPath == "") { |
89 envPath = DEFAULT_VAMP_PATH; | 90 envPath = DEFAULT_VAMP_PATH; |
90 char *chome = getenv("HOME"); | 91 std::string home; |
91 if (chome) { | 92 if (Files::getEnvUtf8("HOME", home)) { |
92 std::string home(chome); | |
93 std::string::size_type f; | 93 std::string::size_type f; |
94 while ((f = envPath.find("$HOME")) != std::string::npos && | 94 while ((f = envPath.find("$HOME")) != std::string::npos && |
95 f < envPath.length()) { | 95 f < envPath.length()) { |
96 envPath.replace(f, 5, home); | 96 envPath.replace(f, 5, home); |
97 } | 97 } |
98 } | 98 } |
99 #ifdef _WIN32 | 99 #ifdef _WIN32 |
100 char *cpfiles = getenv("ProgramFiles"); | 100 std::string pfiles; |
101 if (!cpfiles) cpfiles = (char *)"C:\\Program Files"; | 101 if (!Files::getEnvUtf8("ProgramFiles", pfiles)) { |
102 std::string pfiles(cpfiles); | 102 pfiles = "C:\\Program Files"; |
103 } | |
103 std::string::size_type f; | 104 std::string::size_type f; |
104 while ((f = envPath.find("%ProgramFiles%")) != std::string::npos && | 105 while ((f = envPath.find("%ProgramFiles%")) != std::string::npos && |
105 f < envPath.length()) { | 106 f < envPath.length()) { |
106 envPath.replace(f, 14, pfiles); | 107 envPath.replace(f, 14, pfiles); |
107 } | 108 } |