diff options
Diffstat (limited to 'libs/ardour/globals.cc')
-rw-r--r-- | libs/ardour/globals.cc | 74 |
1 files changed, 55 insertions, 19 deletions
diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index ad7f5c0cc8..9c3cadafe2 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -32,6 +32,7 @@ #include <lrdf.h> #include <pbd/error.h> +#include <pbd/strsplit.h> #include <midi++/port.h> #include <midi++/port_request.h> @@ -298,37 +299,72 @@ ARDOUR::new_change () return c; } -static string -find_file (string name, string dir, string subdir = "") +string +ARDOUR::get_user_ardour_path () { string path; + char* envvar; + + if ((envvar = getenv ("HOME")) == 0 || strlen (envvar) == 0) { + return "/"; + } + + path = envvar; + path += "/.ardour/"; + + return path; +} - /* stop A: ~/.ardour/... */ - - path = getenv ("HOME"); +string +ARDOUR::get_system_ardour_path () +{ + string path; - if (path.length()) { - - path += "/.ardour/"; + path += DATA_DIR; + path += "/ardour/"; + + return path; +} - /* try to ensure that the directory exists. - failure doesn't mean much here. - */ +static string +find_file (string name, string dir, string subdir = "") +{ + string path; + char* envvar = getenv("ARDOUR_PATH"); - mkdir (path.c_str(), 0755); + /* stop A: any directory in ARDOUR_PATH */ + + if (envvar != 0) { - if (subdir.length()) { - path += subdir + "/"; - } + vector<string> split_path; + + split (envvar, split_path, ':'); - path += name; - if (access (path.c_str(), R_OK) == 0) { - return path; + for (vector<string>::iterator i = split_path.begin(); i != split_path.end(); ++i) { + path = *i; + path += "/" + name; + if (access (path.c_str(), R_OK) == 0) { + cerr << "Using file " << path << " found in ARDOUR_PATH." << endl; + return path; + } } } - /* stop B: dir/... */ + /* stop B: ~/.ardour/ */ + path = get_user_ardour_path(); + + if (subdir.length()) { + path += subdir + "/"; + } + + path += name; + if (access (path.c_str(), R_OK) == 0) { + return path; + } + + /* C: dir/... */ + path = dir; path += "/ardour/"; |