4 #include "pbd/filesystem.h"
5 #include "pbd/pathscanner.h"
8 #include "ardour/template_utils.h"
9 #include "ardour/directory_names.h"
10 #include "ardour/filesystem_paths.h"
11 #include "ardour/filename_extensions.h"
12 #include "ardour/io.h"
17 system_template_directory ()
19 SearchPath spath(system_data_search_path());
20 spath.add_subdirectory_to_paths(templates_dir_name);
22 // just return the first directory in the search path that exists
23 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
25 if (i == spath.end()) return sys::path();
31 system_route_template_directory ()
33 SearchPath spath(system_data_search_path());
34 spath.add_subdirectory_to_paths(route_templates_dir_name);
36 // just return the first directory in the search path that exists
37 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
39 if (i == spath.end()) return sys::path();
45 user_template_directory ()
47 sys::path p(user_config_directory());
48 p /= templates_dir_name;
54 user_route_template_directory ()
56 sys::path p(user_config_directory());
57 p /= route_templates_dir_name;
63 template_filter (const string &str, void *arg)
65 return (str.length() > strlen(temp_suffix) &&
66 str.find (temp_suffix) == (str.length() - strlen (temp_suffix)));
70 find_route_templates (vector<RouteTemplateInfo>& template_names)
72 vector<string *> *templates;
74 SearchPath spath (system_data_search_path());
76 spath += user_config_directory();
77 spath.add_subdirectory_to_paths(route_templates_dir_name);
79 templates = scanner (spath.to_string(), template_filter, 0, false, true);
85 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
86 string fullpath = *(*i);
90 if (!tree.read (fullpath.c_str())) {
94 XMLNode* root = tree.root();
96 RouteTemplateInfo rti;
98 rti.name = IO::name_from_state (*root->children().front());
101 template_names.push_back (rti);
107 } // namespace ARDOUR