6 #include "pbd/filesystem.h"
7 #include "pbd/basename.h"
8 #include "pbd/pathscanner.h"
11 #include "ardour/template_utils.h"
12 #include "ardour/directory_names.h"
13 #include "ardour/filesystem_paths.h"
14 #include "ardour/filename_extensions.h"
15 #include "ardour/io.h"
23 system_template_directory ()
25 SearchPath spath(system_data_search_path());
26 spath.add_subdirectory_to_paths(templates_dir_name);
28 // just return the first directory in the search path that exists
29 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
31 if (i == spath.end()) return sys::path();
37 system_route_template_directory ()
39 SearchPath spath(system_data_search_path());
40 spath.add_subdirectory_to_paths(route_templates_dir_name);
42 // just return the first directory in the search path that exists
43 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
45 if (i == spath.end()) return sys::path();
51 user_template_directory ()
53 sys::path p(user_config_directory());
54 p /= templates_dir_name;
60 user_route_template_directory ()
62 sys::path p(user_config_directory());
63 p /= route_templates_dir_name;
69 template_filter (const string &str, void */*arg*/)
71 if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) {
79 route_template_filter (const string &str, void */*arg*/)
81 if (str.find (template_suffix) == str.length() - strlen (template_suffix)) {
89 session_template_dir_to_file (string const & dir)
91 sys::path dir_path = dir;
92 sys::path file_path = dir;
93 file_path /= dir_path.leaf() + template_suffix;
94 return file_path.to_string ();
99 find_session_templates (vector<TemplateInfo>& template_names)
101 vector<string *> *templates;
103 SearchPath spath (system_template_directory());
104 spath += user_template_directory ();
106 templates = scanner (spath.to_string(), template_filter, 0, true, true);
109 cerr << "Found nothing along " << spath.to_string() << endl;
113 cerr << "Found " << templates->size() << " along " << spath.to_string() << endl;
115 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
116 string file = session_template_dir_to_file (**i);
120 if (!tree.read (file.c_str())) {
126 rti.name = basename_nosuffix (**i);
129 template_names.push_back (rti);
136 find_route_templates (vector<TemplateInfo>& template_names)
138 vector<string *> *templates;
140 SearchPath spath (system_route_template_directory());
141 spath += user_route_template_directory ();
143 templates = scanner (spath.to_string(), route_template_filter, 0, false, true);
149 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
150 string fullpath = *(*i);
154 if (!tree.read (fullpath.c_str())) {
158 XMLNode* root = tree.root();
162 rti.name = IO::name_from_state (*root->children().front());
165 template_names.push_back (rti);