From 1f6c54a2f053caa8afec70f2acffdb7f7d73f09f Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Wed, 30 Aug 2017 10:20:29 -0500 Subject: [PATCH] Gracefully handle templates that lack contents in their description or created_with node. --- libs/ardour/template_utils.cc | 60 +++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index 80baf47f54..5c6fd9c833 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -101,26 +101,32 @@ find_session_templates (vector& template_names, bool read_xml) rti.path = *i; if (read_xml) { + XMLTree tree; if (!tree.read (file.c_str())) { + cerr << "Failed to parse Route-template XML file: " << file; continue; } - string created_with = _("(unknown)"); - XMLNode *pv = tree.root()->child("ProgramVersion"); - if (pv != 0) { - pv->get_property (X_("created-with"), created_with); - } - - string description = _("No Description"); - XMLNode *desc = tree.root()->child("description"); - if (desc != 0) { - description = desc->attribute_value(); - } - - rti.created_with = created_with; - rti.description = description; + XMLNode* root = tree.root(); + + rti.created_with = _("(unknown)"); + try { + XMLNode *pv = root->child("ProgramVersion"); + string created_with; + if (pv != 0) { + pv->get_property (X_("created-with"), created_with); + } + rti.created_with = created_with; + } catch ( LIBPBD_API::XMLException &e) {} + rti.description = _("No Description"); + try { + XMLNode *desc = root->child("description"); + if (desc != 0) { + rti.description = desc->attribute_value(); + } + } catch ( LIBPBD_API::XMLException &e) {} } template_names.push_back (rti); @@ -144,22 +150,34 @@ find_route_templates (vector& template_names) XMLTree tree; if (!tree.read (fullpath.c_str())) { + cerr << "Failed to parse Route-template XML file: " << fullpath; continue; } XMLNode* root = tree.root(); - string description = _("No Description"); - XMLNode* desc = tree.root()->child ("description"); - if (desc) { - description = desc->attribute_value (); - } - TemplateInfo rti; + rti.created_with = _("(unknown)"); + try { + XMLNode *pv = root->child("ProgramVersion"); + string created_with; + if (pv != 0) { + pv->get_property (X_("created-with"), created_with); + } + rti.created_with = created_with; + } catch ( LIBPBD_API::XMLException &e) {} + + rti.description = _("No Description"); + try { + XMLNode *desc = root->child("description"); + if (desc != 0) { + rti.description = desc->attribute_value(); + } + } catch ( LIBPBD_API::XMLException &e) {} + rti.name = IO::name_from_state (*root->children().front()); rti.path = fullpath; - rti.description = description; template_names.push_back (rti); }