4 #include "pbd/filesystem.h"
5 #include "pbd/basename.h"
6 #include "pbd/pathscanner.h"
9 #include "ardour/template_utils.h"
10 #include "ardour/directory_names.h"
11 #include "ardour/filesystem_paths.h"
12 #include "ardour/filename_extensions.h"
13 #include "ardour/io.h"
18 system_template_directory ()
20 SearchPath spath(system_data_search_path());
21 spath.add_subdirectory_to_paths(templates_dir_name);
23 // just return the first directory in the search path that exists
24 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
26 if (i == spath.end()) return sys::path();
32 system_route_template_directory ()
34 SearchPath spath(system_data_search_path());
35 spath.add_subdirectory_to_paths(route_templates_dir_name);
37 // just return the first directory in the search path that exists
38 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
40 if (i == spath.end()) return sys::path();
46 user_template_directory ()
48 sys::path p(user_config_directory());
49 p /= templates_dir_name;
55 user_route_template_directory ()
57 sys::path p(user_config_directory());
58 p /= route_templates_dir_name;
64 template_filter (const string &str, void *arg)
66 cerr << "Checking into " << str << " using " << template_suffix << endl;
67 return (str.length() > strlen(template_suffix) &&
68 str.find (template_suffix) == (str.length() - strlen (template_suffix)));
72 find_session_templates (vector<TemplateInfo>& template_names)
74 vector<string *> *templates;
76 SearchPath spath (system_template_directory());
77 spath += user_template_directory ();
79 templates = scanner (spath.to_string(), template_filter, 0, false, true);
82 cerr << "Found nothing along " << spath.to_string() << endl;
86 cerr << "Found " << templates->size() << " along " << spath.to_string() << endl;
88 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
89 string fullpath = *(*i);
93 if (!tree.read (fullpath.c_str())) {
97 XMLNode* root = tree.root();
101 rti.name = basename_nosuffix (fullpath);
104 template_names.push_back (rti);
111 find_route_templates (vector<TemplateInfo>& template_names)
113 vector<string *> *templates;
115 SearchPath spath (system_route_template_directory());
116 spath += user_route_template_directory ();
118 templates = scanner (spath.to_string(), template_filter, 0, false, true);
124 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
125 string fullpath = *(*i);
129 if (!tree.read (fullpath.c_str())) {
133 XMLNode* root = tree.root();
137 rti.name = IO::name_from_state (*root->children().front());
140 template_names.push_back (rti);