Mercurial > hg > tony
diff src/main.cpp @ 541:fea109b93831
Fixes to plugin path handling: use application path (even if not default); support wide-char APIs on Windows
author | Chris Cannam |
---|---|
date | Wed, 13 Feb 2019 10:33:44 +0000 |
parents | 25aa28a27252 |
children | 702a70e48ca9 |
line wrap: on
line diff
--- a/src/main.cpp Tue Feb 12 15:02:50 2019 +0000 +++ b/src/main.cpp Wed Feb 13 10:33:44 2019 +0000 @@ -121,47 +121,72 @@ } }; +static QString +getEnvQStr(QString variable) +{ +#ifdef Q_OS_WIN32 + std::wstring wvar = variable.toStdWString(); + wchar_t *value = _wgetenv(wvar.c_str()); + if (!value) return QString(); + else return QString::fromUtf16(value); +#else + std::string var = variable.toStdString(); + return QString::fromUtf8(qgetenv(var.c_str())); +#endif +} + +static void +putEnvQStr(QString assignment) +{ +#ifdef Q_OS_WIN32 + std::wstring wassignment = assignment.toStdWString(); + _wputenv(wstrdup(wassignment)); +#else + putenv(strdup(assignment.toUtf8().data())); +#endif +} + static void setupTonyVampPath() { + QString tonyVampPath = getEnvQStr("TONY_VAMP_PATH"); + #ifdef Q_OS_WIN32 QChar sep(';'); - QString programFiles = getenv("ProgramFiles"); - if (programFiles == "") programFiles = "C:\\Program Files"; - QString defaultTonyPath(programFiles + "\\Tony"); #else QChar sep(':'); -#ifdef Q_OS_MAC - QString defaultTonyPath; -#else - QString defaultTonyPath("/usr/local/lib/tony:/usr/lib/tony"); #endif + + if (tonyVampPath == "") { + tonyVampPath = QApplication::applicationDirPath(); + +#ifdef Q_OS_WIN32 + QString programFiles = getEnvQStr("ProgramFiles"); + if (programFiles == "") programFiles = "C:\\Program Files"; + QString defaultTonyPath(programFiles + "\\Tony"); + tonyVampPath = tonyVampPath + sep + defaultTonyPath; #endif - - QString tonyVampPath = getenv("TONY_VAMP_PATH"); - if (tonyVampPath == "") { - tonyVampPath = defaultTonyPath; - } - if (tonyVampPath == "") { - // just use the default Vamp path or VAMP_PATH environment - // variable -- leave it up to the Vamp SDK - return; + +#ifndef Q_OS_MAC + QString defaultTonyPath("/usr/local/lib/tony:/usr/lib/tony"); + tonyVampPath = tonyVampPath + sep + defaultTonyPath; +#endif } std::vector<std::string> vampPathList = Vamp::PluginHostAdapter::getPluginPath(); - QStringList qVampPathList; - for (auto p: vampPathList) qVampPathList.push_back(p.c_str()); - QString vampPath = qVampPathList.join(sep); - QString newPath = tonyVampPath + sep + vampPath; + for (auto p: vampPathList) { + tonyVampPath = tonyVampPath + sep + QString::fromUtf8(p.c_str()); + } - cerr << "Setting VAMP_PATH to " << newPath << " for Tony plugins" << endl; + SVCERR << "Setting VAMP_PATH to " << tonyVampPath + << " for Tony plugins" << endl; - QString env = "VAMP_PATH=" + newPath; + QString env = "VAMP_PATH=" + tonyVampPath; // Windows lacks setenv, must use putenv (different arg convention) - putenv(strdup(env.toLocal8Bit().data())); + putEnvQStr(env); } int @@ -176,10 +201,10 @@ } #endif + TonyApplication application(argc, argv); + setupTonyVampPath(); - TonyApplication application(argc, argv); - QStringList args = application.arguments(); signal(SIGINT, signalHandler);