X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Ftemplate_utils.cc;h=d355231115f13beebceeb44292f8435018bda47f;hb=62ce5465cadaa6cf7e315cb1dc2e61444bc19e01;hp=8efe3115366594cbebc75d0de974a13b1b07fc80;hpb=5399425f534e2d96d07cf29f427bfa0f39d904b7;p=ardour.git diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index 8efe311536..d355231115 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Paul Davis + Copyright (C) 2012 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,8 +22,8 @@ #include -#include "pbd/basename.h" -#include "pbd/pathscanner.h" +#include "pbd/file_utils.h" +#include "pbd/stl_delete.h" #include "pbd/xml++.h" #include "ardour/template_utils.h" @@ -56,7 +56,7 @@ template_filter (const string &str, void* /*arg*/) if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) { return false; } - + return true; } @@ -66,7 +66,7 @@ route_template_filter (const string &str, void* /*arg*/) if (str.find (template_suffix) == str.length() - strlen (template_suffix)) { return true; } - + return false; } @@ -78,56 +78,52 @@ session_template_dir_to_file (string const & dir) void -find_session_templates (vector& template_names) +find_session_templates (vector& template_names, bool read_xml) { - vector *templates; - PathScanner scanner; - Searchpath spath (template_search_path()); + vector templates; - templates = scanner (spath.to_string(), template_filter, 0, true, true); + find_paths_matching_filter (templates, template_search_path(), template_filter, 0, true, true); - if (!templates) { - cerr << "Found nothing along " << spath.to_string() << endl; + if (templates.empty()) { + cerr << "Found nothing along " << template_search_path().to_string() << endl; return; } - cerr << "Found " << templates->size() << " along " << spath.to_string() << endl; - - for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { - string file = session_template_dir_to_file (**i); + cerr << "Found " << templates.size() << " along " << template_search_path().to_string() << endl; - XMLTree tree; - - if (!tree.read (file.c_str())) { - continue; - } + for (vector::iterator i = templates.begin(); i != templates.end(); ++i) { + string file = session_template_dir_to_file (*i); TemplateInfo rti; - - rti.name = basename_nosuffix (**i); - rti.path = **i; + rti.name = Glib::path_get_basename (*i); + rti.path = *i; + + if (read_xml) { + XMLTree tree; + if (!tree.read (file.c_str())) { + continue; + } + // TODO extract description, + // compare to Session::get_info_from_path + } template_names.push_back (rti); } - - delete templates; } void find_route_templates (vector& template_names) { - vector *templates; - PathScanner scanner; - Searchpath spath (route_template_search_path()); + vector templates; - templates = scanner (spath.to_string(), route_template_filter, 0, false, true); + find_files_matching_filter (templates, route_template_search_path(), route_template_filter, 0, false, true); - if (!templates) { + if (templates.empty()) { return; } - for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { - string fullpath = *(*i); + for (vector::iterator i = templates.begin(); i != templates.end(); ++i) { + string fullpath = *i; XMLTree tree; @@ -144,8 +140,6 @@ find_route_templates (vector& template_names) template_names.push_back (rti); } - - delete templates; } }