From 56a27e873485b17e35bf458a3d94aa2338c5fa33 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Sun, 17 Jun 2007 00:52:57 +0000 Subject: [PATCH] Modify Session::save_template for portablity git-svn-id: svn://localhost/ardour2/trunk@2017 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/session_state.cc | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 9b1c934a8b..291443efd4 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -101,6 +101,8 @@ #include #include #include +#include + #include #include "i18n.h" @@ -1584,34 +1586,32 @@ Session::save_template (string template_name) return -1; } - DIR* dp; - string dir = template_dir(); + sys::path user_template_dir(user_template_directory()); - if ((dp = opendir (dir.c_str()))) { - closedir (dp); - } else { - if (g_mkdir_with_parents (dir.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { - error << string_compose(_("Could not create mix templates directory \"%1\" (%2)"), dir, strerror (errno)) << endmsg; - return -1; - } + try + { + sys::create_directories (user_template_dir); + } + catch(sys::filesystem_error& ex) + { + error << string_compose(_("Could not create mix templates directory \"%1\" (%2)"), + user_template_dir.to_string(), ex.what()) << endmsg; + return -1; } tree.set_root (&get_template()); - xml_path = dir; - xml_path += template_name; - xml_path += template_suffix; + sys::path template_file_path(user_template_dir); + template_file_path /= template_name + template_suffix; - ifstream in(xml_path.c_str()); - - if (in) { - warning << string_compose(_("Template \"%1\" already exists - new version not created"), template_name) << endmsg; + if (sys::exists (template_file_path)) + { + warning << string_compose(_("Template \"%1\" already exists - new version not created"), + template_file_path.to_string()) << endmsg; return -1; - } else { - in.close(); } - if (!tree.write (xml_path)) { + if (!tree.write (template_file_path.to_string())) { error << _("mix template not saved") << endmsg; return -1; }