Mercurial > hg > vamp-plugin-load-checker
changeset 34:6905d8b146f6 plugin-path-config
Toward supporting separate environment variables for 32-bit plugins on a 64-bit system (otherwise we try to load both from the same helpers)
author | Chris Cannam |
---|---|
date | Wed, 06 Jun 2018 13:49:23 +0100 |
parents | cf18645ff411 |
children | 4154894d638c |
files | checker/knownplugins.h src/knownplugins.cpp |
diffstat | 2 files changed, 71 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/checker/knownplugins.h Sun Mar 05 17:15:22 2017 +0000 +++ b/checker/knownplugins.h Wed Jun 06 13:49:23 2018 +0100 @@ -59,9 +59,7 @@ KnownPlugins(std::string helperExecutableName, PluginCandidates::LogCallback *cb = 0); - std::vector<PluginType> getKnownPluginTypes() const { - return { VampPlugin, LADSPAPlugin, DSSIPlugin }; - }; + std::vector<PluginType> getKnownPluginTypes() const; std::string getTagFor(PluginType type) const { return m_known.at(type).tag; @@ -71,6 +69,14 @@ return m_candidates.getCandidateLibrariesFor(getTagFor(type)); } + std::string getPathEnvironmentVariableFor(PluginType type) const { + return m_known.at(type).variable; + } + + stringlist getPathFor(PluginType type) const { + return m_known.at(type).path; + } + std::string getHelperExecutableName() const { return m_helperExecutableName; } @@ -80,10 +86,12 @@ private: struct TypeRec { std::string tag; + std::string variable; stringlist path; std::string descriptor; }; - std::map<PluginType, TypeRec> m_known; + typedef std::map<PluginType, TypeRec> Known; + Known m_known; stringlist expandConventionalPath(PluginType type, std::string var); std::string getDefaultPath(PluginType type); @@ -91,7 +99,14 @@ PluginCandidates m_candidates; std::string m_helperExecutableName; - bool is32bit() const; // true if helper looks to be 32-bit on 64-bit system + /** This returns true if the helper has a name ending in "-32". By + * our convention, this means that it is a 32-bit helper found on + * a 64-bit system, so (depending on the OS) we may need to look + * in 32-bit-specific paths. Note that is32bit() is *not* usually + * true on 32-bit systems; it's used specifically to indicate a + * "non-native" 32-bit helper. + */ + bool is32bit() const; }; #endif
--- a/src/knownplugins.cpp Sun Mar 05 17:15:22 2017 +0000 +++ b/src/knownplugins.cpp Wed Jun 06 13:49:23 2018 +0100 @@ -45,30 +45,31 @@ m_helperExecutableName(helperExecutableName) { m_candidates.setLogCallback(cb); + + std::string variableSuffix = ""; + if (is32bit()) { + variableSuffix = "_32"; + } - m_known = { - { - VampPlugin, - { - "vamp", - expandConventionalPath(VampPlugin, "VAMP_PATH"), - "vampGetPluginDescriptor" - }, - }, { - LADSPAPlugin, - { - "ladspa", - expandConventionalPath(LADSPAPlugin, "LADSPA_PATH"), - "ladspa_descriptor" - }, - }, { - DSSIPlugin, - { - "dssi", - expandConventionalPath(DSSIPlugin, "DSSI_PATH"), - "dssi_descriptor" - } - } + m_known[VampPlugin] = { + "vamp", + "VAMP_PATH" + variableSuffix, + expandConventionalPath(VampPlugin, "VAMP_PATH" + variableSuffix), + "vampGetPluginDescriptor" + }; + + m_known[LADSPAPlugin] = { + "ladspa", + "LADSPA_PATH" + variableSuffix, + expandConventionalPath(LADSPAPlugin, "LADSPA_PATH" + variableSuffix), + "ladspa_descriptor" + }; + + m_known[DSSIPlugin] = { + "dssi", + "DSSI_PATH" + variableSuffix, + expandConventionalPath(DSSIPlugin, "DSSI_PATH" + variableSuffix), + "dssi_descriptor" }; for (const auto &k: m_known) { @@ -76,6 +77,18 @@ } } +std::vector<KnownPlugins::PluginType> +KnownPlugins::getKnownPluginTypes() const +{ + std::vector<PluginType> kt; + + for (const auto &k: m_known) { + kt.push_back(k.first); + } + + return kt; +} + bool KnownPlugins::is32bit() const { @@ -128,10 +141,6 @@ char *cpath = getenv(var.c_str()); if (cpath) path = cpath; -#ifdef _WIN32 - bool is32 = is32bit(); -#endif - if (path == "") { path = getDefaultPath(type); @@ -149,23 +158,26 @@ #ifdef _WIN32 const char *pfiles = 0; - if (is32) { - pfiles = getenv("ProgramFiles(x86)"); + const char *pfiles32 = 0; + + pfiles = getenv("ProgramFiles"); + if (!pfiles) { + pfiles = "C:\\Program Files"; } - if (!pfiles) { - pfiles = getenv("ProgramFiles"); + + pfiles32 = getenv("ProgramFiles(x86)"); + if (!pfiles32) { + pfiles32 = "C:\\Program Files (x86)"; } - if (!pfiles) { - if (is32) { - pfiles = "C:\\Program Files (x86)"; - } else { - pfiles = "C:\\Program Files"; - } - } + string::size_type f; while ((f = path.find("%ProgramFiles%")) != string::npos && f < path.length()) { - path.replace(f, 14, pfiles); + if (is32bit()) { + path.replace(f, 14, pfiles32); + } else { + path.replace(f, 14, pfiles); + } } #endif }