diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2019-07-18 12:27:00 -0600 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2019-07-18 12:27:16 -0600 |
commit | ce7add1481f54eb12b32e5f46af4ea36140eb932 (patch) | |
tree | 43e80ce1b73442c4ee8f741dbb618c281eae6638 /libs | |
parent | 4679439af92fb03e6099644452e802790c5e5703 (diff) |
fix use of session-creation via template, when just template name is given
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/session_state.cc | 103 |
1 files changed, 55 insertions, 48 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index e02fefc3b6..f51b85b797 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -580,7 +580,7 @@ Session::ensure_subdirs () * Caller must not hold process lock. */ int -Session::create (const string& session_template, BusProfile* bus_profile) +Session::create (const string& st, BusProfile* bus_profile) { if (g_mkdir_with_parents (_path.c_str(), 0755) < 0) { error << string_compose(_("Session: cannot create session folder \"%1\" (%2)"), _path, strerror (errno)) << endmsg; @@ -593,71 +593,78 @@ Session::create (const string& session_template, BusProfile* bus_profile) _writable = exists_and_writable (_path); + string session_template (st); + if (!session_template.empty()) { - string in_path = (ARDOUR::Profile->get_trx () ? session_template : session_template_dir_to_file (session_template)); - FILE* in = g_fopen (in_path.c_str(), "rb"); + if (session_template.find (G_DIR_SEPARATOR) == string::npos) { + /* not a path */ + session_template = Glib::build_filename (user_template_directory(), session_template); + } - if (in) { - /* no need to call legalize_for_path() since the string - * in session_template is already a legal path name - */ - string out_path = Glib::build_filename (_session_dir->root_path(), _name + statefile_suffix); + cerr << "Using session template " << session_template << endl; - FILE* out = g_fopen (out_path.c_str(), "wb"); + string in_path = (ARDOUR::Profile->get_trx () ? session_template : session_template_dir_to_file (session_template)); - if (out) { - char buf[1024]; - stringstream new_session; + FILE* in = g_fopen (in_path.c_str(), "rb"); - while (!feof (in)) { - size_t charsRead = fread (buf, sizeof(char), 1024, in); + if (!in) { + error << string_compose (_("Could not open session template %1 for reading"), in_path) + << endmsg; + return -1; + } - if (ferror (in)) { - error << string_compose (_("Error reading session template file %1 (%2)"), in_path, strerror (errno)) << endmsg; - fclose (in); - fclose (out); - return -1; - } - if (charsRead == 0) { - break; - } - new_session.write (buf, charsRead); - } - fclose (in); + /* no need to call legalize_for_path() since the string + * in session_template is already a legal path name + */ + string out_path = Glib::build_filename (_session_dir->root_path(), _name + statefile_suffix); - string file_contents = new_session.str(); - size_t writeSize = file_contents.length(); - if (fwrite (file_contents.c_str(), sizeof(char), writeSize, out) != writeSize) { - error << string_compose (_("Error writing session template file %1 (%2)"), out_path, strerror (errno)) << endmsg; - fclose (out); - return -1; - } - fclose (out); + FILE* out = g_fopen (out_path.c_str(), "wb"); - _is_new = false; + if (!out) { + error << string_compose (_("Could not open %1 for writing session template"), out_path) + << endmsg; + fclose(in); + return -1; + } - if (!ARDOUR::Profile->get_trx()) { - /* Copy plugin state files from template to new session */ - std::string template_plugins = Glib::build_filename (session_template, X_("plugins")); - copy_recurse (template_plugins, plugins_dir ()); - } + char buf[1024]; + stringstream new_session; - return 0; + while (!feof (in)) { + size_t charsRead = fread (buf, sizeof(char), 1024, in); - } else { - error << string_compose (_("Could not open %1 for writing session template"), out_path) - << endmsg; - fclose(in); + if (ferror (in)) { + error << string_compose (_("Error reading session template file %1 (%2)"), in_path, strerror (errno)) << endmsg; + fclose (in); + fclose (out); return -1; } + if (charsRead == 0) { + break; + } + new_session.write (buf, charsRead); + } + fclose (in); - } else { - error << string_compose (_("Could not open session template %1 for reading"), in_path) - << endmsg; + string file_contents = new_session.str(); + size_t writeSize = file_contents.length(); + if (fwrite (file_contents.c_str(), sizeof(char), writeSize, out) != writeSize) { + error << string_compose (_("Error writing session template file %1 (%2)"), out_path, strerror (errno)) << endmsg; + fclose (out); return -1; } + fclose (out); + _is_new = false; + + if (!ARDOUR::Profile->get_trx()) { + /* Copy plugin state files from template to new session */ + std::string template_plugins = Glib::build_filename (session_template, X_("plugins")); + copy_recurse (template_plugins, plugins_dir ()); + } + + return 0; } if (Profile->get_trx()) { |