Commit 38f4aedb authored by Elizabeth's avatar Elizabeth
Browse files

Support for multiple paths in OPENMM_PLUGIN_DIR

parent 37d4b472
......@@ -35,6 +35,7 @@
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include "openmm/internal/windowsExport.h"
namespace OpenMM {
......
......@@ -261,31 +261,42 @@ void Platform::loadPluginLibrary(const string& file) {
vector<string> Platform::loadPluginsFromDirectory(const string& directory) {
vector<string> files;
char dirSeparator;
char pathSeparator;
stringstream sdirectory(directory);
#ifdef WIN32
dirSeparator = '\\';
pathSeparator = ';';
WIN32_FIND_DATA fileInfo;
string filePattern(directory + dirSeparator + "*.dll");
for (string path; std::getline(sdirectory, path, pathSeparator);) {
string filePattern(path + dirSeparator + "*.dll");
HANDLE findHandle = FindFirstFile(filePattern.c_str(), &fileInfo);
if (findHandle != INVALID_HANDLE_VALUE) {
do {
if (fileInfo.cFileName[0] != '.')
files.push_back(string(fileInfo.cFileName));
files.push_back(path+dirSeparator+string(fileInfo.cFileName));
} while (FindNextFile(findHandle, &fileInfo));
FindClose(findHandle);
}
}
vector<HMODULE> plugins;
#else
dirSeparator = '/';
DIR* dir;
dirSeparator = '/';
pathSeparator = ':';
struct dirent *entry;
dir = opendir(directory.c_str());
for (string path; std::getline(sdirectory, path, pathSeparator);) {
dir = opendir(path.c_str());
if (dir != NULL) {
while ((entry = readdir(dir)) != NULL) {
if (entry->d_name[0] != '.')
files.push_back(string(entry->d_name));
files.push_back(path+dirSeparator+string(entry->d_name));
}
closedir(dir);
}
}
vector<void*> plugins;
#endif
vector<string> loadedLibraries;
......@@ -294,7 +305,7 @@ vector<string> Platform::loadPluginsFromDirectory(const string& directory) {
for (unsigned int i = 0; i < files.size(); ++i) {
try {
plugins.push_back(loadOneLibrary(directory+dirSeparator+files[i]));
plugins.push_back(loadOneLibrary(files[i]));
loadedLibraries.push_back(files[i]);
} catch (OpenMMException& ex) {
pluginLoadFailures.push_back(ex.what());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment