merged with trunk revs 2605-2627
[ardour.git] / libs / ardour / template_utils.cc
1 #include <algorithm>
2
3 #include <pbd/filesystem.h>
4 #include <pbd/error.h>
5
6 #include <ardour/template_utils.h>
7 #include <ardour/directory_names.h>
8 #include <ardour/filesystem_paths.h>
9
10 namespace ARDOUR {
11
12 sys::path
13 system_template_directory ()
14 {
15         SearchPath spath(system_data_search_path());
16         spath.add_subdirectory_to_paths(templates_dir_name);
17
18         // just return the first directory in the search path that exists
19         SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
20
21         if (i == spath.end())
22         {
23                 warning << "System template directory does not exist" << endmsg;
24                 return sys::path("");
25         }
26
27         return *i;
28 }
29
30 sys::path
31 user_template_directory ()
32 {
33         sys::path p(user_config_directory());
34         p /= templates_dir_name;
35
36         return p;
37 }
38
39 } // namespace ARDOUR