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"
21 system_template_directory ()
23 SearchPath spath(system_data_search_path());
24 spath.add_subdirectory_to_paths(templates_dir_name);
26 // just return the first directory in the search path that exists
27 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
29 if (i == spath.end()) return sys::path();
35 system_route_template_directory ()
37 SearchPath spath(system_data_search_path());
38 spath.add_subdirectory_to_paths(route_templates_dir_name);
40 // just return the first directory in the search path that exists
41 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
43 if (i == spath.end()) return sys::path();
49 user_template_directory ()
51 sys::path p(user_config_directory());
52 p /= templates_dir_name;
58 user_route_template_directory ()
60 sys::path p(user_config_directory());
61 p /= route_templates_dir_name;
67 template_filter (const string &str, void *arg)
69 cerr << "Checking into " << str << " using " << template_suffix << endl;
70 return (str.length() > strlen(template_suffix) &&
71 str.find (template_suffix) == (str.length() - strlen (template_suffix)));
75 find_session_templates (vector<TemplateInfo>& template_names)
77 vector<string *> *templates;
79 SearchPath spath (system_template_directory());
80 spath += user_template_directory ();
82 templates = scanner (spath.to_string(), template_filter, 0, false, true);
85 cerr << "Found nothing along " << spath.to_string() << endl;
89 cerr << "Found " << templates->size() << " along " << spath.to_string() << endl;
91 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
92 string fullpath = *(*i);
96 if (!tree.read (fullpath.c_str())) {
102 rti.name = basename_nosuffix (fullpath);
105 template_names.push_back (rti);
112 find_route_templates (vector<TemplateInfo>& template_names)
114 vector<string *> *templates;
116 SearchPath spath (system_route_template_directory());
117 spath += user_route_template_directory ();
119 templates = scanner (spath.to_string(), template_filter, 0, false, true);
125 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
126 string fullpath = *(*i);
130 if (!tree.read (fullpath.c_str())) {
134 XMLNode* root = tree.root();
138 rti.name = IO::name_from_state (*root->children().front());
141 template_names.push_back (rti);