summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ingen/runtime_paths.hpp3
-rw-r--r--src/World.cpp39
-rw-r--r--src/runtime_paths.cpp36
3 files changed, 31 insertions, 47 deletions
diff --git a/ingen/runtime_paths.hpp b/ingen/runtime_paths.hpp
index fb697b14..a83a81fd 100644
--- a/ingen/runtime_paths.hpp
+++ b/ingen/runtime_paths.hpp
@@ -36,7 +36,7 @@ find_in_search_path(const std::string& name,
INGEN_API FilePath bundle_file_path(const std::string& name);
INGEN_API FilePath data_file_path(const std::string& name);
-INGEN_API FilePath ingen_module_path(const std::string& name, FilePath dir={});
+INGEN_API FilePath ingen_module_path(const std::string& name);
INGEN_API FilePath user_config_dir();
INGEN_API FilePath user_data_dir();
@@ -44,6 +44,7 @@ INGEN_API std::vector<FilePath> system_config_dirs();
INGEN_API std::vector<FilePath> system_data_dirs();
INGEN_API std::vector<FilePath> config_dirs();
INGEN_API std::vector<FilePath> data_dirs();
+INGEN_API std::vector<FilePath> ingen_module_dirs();
} // namespace ingen
diff --git a/src/World.cpp b/src/World.cpp
index b967de2f..693f9427 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -66,40 +66,21 @@ class Store;
static std::unique_ptr<Library>
ingen_load_library(Log& log, const string& name)
{
- std::unique_ptr<Library> library;
-
- // Search INGEN_MODULE_PATH first
- const char* const module_path = getenv("INGEN_MODULE_PATH");
- if (module_path) {
- string dir;
- std::istringstream iss(module_path);
- while (getline(iss, dir, search_path_separator)) {
- FilePath filename = ingen::ingen_module_path(name, FilePath(dir));
- if (filesystem::exists(filename)) {
- library = std::unique_ptr<Library>(new Library(filename));
- if (*library) {
- return library;
- } else {
- log.error(Library::get_last_error());
- }
- }
- }
+ const auto path = ingen_module_path(name);
+ if (path.empty()) {
+ log.error("Failed to find %1% (%2%)\n",
+ name, Library::get_last_error());
+ return nullptr;
}
- // Try default directory if not found
- library = std::unique_ptr<Library>(new Library(ingen::ingen_module_path(name)));
-
+ UPtr<Library> library = make_unique<Library>(path);
if (*library) {
return library;
- } else if (!module_path) {
- log.error("Unable to find %1% (%2%)\n",
- name, Library::get_last_error());
- return nullptr;
- } else {
- log.error("Unable to load %1% from %2% (%3%)\n",
- name, module_path, Library::get_last_error());
- return nullptr;
}
+
+ log.error("Unable to load %1% from %2% (%3%)\n",
+ name, path, Library::get_last_error());
+ return nullptr;
}
class World::Impl {
diff --git a/src/runtime_paths.cpp b/src/runtime_paths.cpp
index 471e2ba2..c4ee7c2b 100644
--- a/src/runtime_paths.cpp
+++ b/src/runtime_paths.cpp
@@ -108,34 +108,30 @@ bundle_file_path(const std::string& name)
return bundle_path / name;
}
-/** Return the absolute path of a 'resource' file.
- */
FilePath
data_file_path(const std::string& name)
{
-#ifdef BUNDLE
- return bundle_path / INGEN_DATA_DIR / name;
-#else
return find_in_search_path(name, data_dirs());
-#endif
}
-/** Return the absolute path of a module (dynamically loaded shared library).
- */
-FilePath
-ingen_module_path(const std::string& name, FilePath dir)
+std::vector<FilePath>
+ingen_module_dirs()
{
- FilePath ret;
- if (dir.empty()) {
#ifdef BUNDLE
- dir = FilePath(bundle_path) / INGEN_MODULE_DIR;
+ const FilePath default_dir = FilePath(bundle_path) / INGEN_MODULE_DIR;
#else
- dir = FilePath(INGEN_MODULE_DIR);
+ const FilePath default_dir = INGEN_MODULE_DIR;
#endif
- }
- return dir /
- (std::string(library_prefix) + "ingen_" + name + library_suffix);
+ return parse_search_path(getenv("INGEN_MODULE_PATH"), {default_dir});
+}
+
+FilePath
+ingen_module_path(const std::string& name)
+{
+ return find_in_search_path(
+ std::string(library_prefix) + "ingen_" + name + library_suffix,
+ ingen_module_dirs());
}
FilePath
@@ -189,9 +185,15 @@ data_dirs()
{
std::vector<FilePath> paths = system_data_dirs();
const FilePath user_dir = user_data_dir();
+
+#ifdef BUNDLE
+ paths.insert(paths.begin(), bundle_path / INGEN_DATA_DIR);
+#endif
+
if (!user_dir.empty()) {
paths.insert(paths.begin(), user_dir);
}
+
return paths;
}