X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Ftemplate_utils.cc;h=825a24d3e10a39406414899186f9ecc9a81dbd36;hb=d345d446883c0425f8312149d04abc62076e36fc;hp=6dac270a501425ce7077dc2b4ee2b80d26600918;hpb=c287ebec9b92d7abb48a92daf11bac0152cc6789;p=ardour.git diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index 6dac270a50..825a24d3e1 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -1,6 +1,8 @@ #include #include +#include + #include "pbd/filesystem.h" #include "pbd/basename.h" #include "pbd/pathscanner.h" @@ -12,6 +14,9 @@ #include "ardour/filename_extensions.h" #include "ardour/io.h" +using namespace std; +using namespace PBD; + namespace ARDOUR { sys::path @@ -61,13 +66,25 @@ user_route_template_directory () } static bool -template_filter (const string &str, void *arg) +template_filter (const string &str, void */*arg*/) { - cerr << "Checking into " << str << " using " << template_suffix << endl; - return (str.length() > strlen(template_suffix) && - str.find (template_suffix) == (str.length() - strlen (template_suffix))); + if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) { + return false; + } + + return true; } +string +session_template_dir_to_file (string const & dir) +{ + sys::path dir_path = dir; + sys::path file_path = dir; + file_path /= dir_path.leaf() + template_suffix; + return file_path.to_string (); +} + + void find_session_templates (vector& template_names) { @@ -76,35 +93,33 @@ find_session_templates (vector& template_names) SearchPath spath (system_template_directory()); spath += user_template_directory (); - templates = scanner (spath.to_string(), template_filter, 0, false, true); - + templates = scanner (spath.to_string(), template_filter, 0, true, true); + if (!templates) { cerr << "Found nothing along " << spath.to_string() << endl; return; } cerr << "Found " << templates->size() << " along " << spath.to_string() << endl; - + for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { - string fullpath = *(*i); + string file = session_template_dir_to_file (**i); XMLTree tree; - if (!tree.read (fullpath.c_str())) { + if (!tree.read (file.c_str())) { continue; } - XMLNode* root = tree.root(); - TemplateInfo rti; - rti.name = basename_nosuffix (fullpath); - rti.path = fullpath; + rti.name = basename_nosuffix (**i); + rti.path = **i; template_names.push_back (rti); } - free (templates); + delete templates; } void @@ -116,11 +131,11 @@ find_route_templates (vector& template_names) spath += user_route_template_directory (); templates = scanner (spath.to_string(), template_filter, 0, false, true); - + if (!templates) { return; } - + for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { string fullpath = *(*i); @@ -131,7 +146,7 @@ find_route_templates (vector& template_names) } XMLNode* root = tree.root(); - + TemplateInfo rti; rti.name = IO::name_from_state (*root->children().front()); @@ -140,7 +155,7 @@ find_route_templates (vector& template_names) template_names.push_back (rti); } - free (templates); + delete templates; } }