From 86ac8536d2a0d09347e622c2df43aebeba4e4150 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 9 Dec 2011 03:06:58 +0000 Subject: [PATCH] centralize legal-session-name-checkng and include : and ; in characters that we disallow, because they conflict with search path conventions on *nix and windows git-svn-id: svn://localhost/ardour2/branches/3.0@10943 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour_ui.cc | 30 ++++++++++-------------------- libs/ardour/ardour/session.h | 1 + libs/ardour/session.cc | 13 +++++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 382d8b7ca4..54a74884f9 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -2280,15 +2280,11 @@ ARDOUR_UI::rename_session () bool do_rename = (name.length() != 0); if (do_rename) { - if (name.find ('/') != string::npos) { - MessageDialog msg (_("To ensure compatibility with various systems\n" - "session names may not contain a '/' character")); - msg.run (); - goto again; - } - if (name.find ('\\') != string::npos) { - MessageDialog msg (_("To ensure compatibility with various systems\n" - "session names may not contain a '\\' character")); + char illegal = Session::session_name_is_legal (name); + + if (illegal) { + MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n" + "session names may not contain a '%1' character"), illegal)); msg.run (); goto again; } @@ -2666,19 +2662,13 @@ ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, stri session_path = _startup->session_folder(); - if (session_name.find ('/') != string::npos) { - MessageDialog msg (*_startup, - _("To ensure compatibility with various systems\n" - "session names may not contain a '/' character")); - msg.run (); - ARDOUR_COMMAND_LINE::session_name = ""; // cancel that - continue; - } + char illegal = Session::session_name_is_legal (session_name); - if (session_name.find ('\\') != string::npos) { + if (illegal) { MessageDialog msg (*_startup, - _("To ensure compatibility with various systems\n" - "session names may not contain a '\\' character")); + string_compose (_("To ensure compatibility with various systems\n" + "session names may not contain a '%1' character"), + illegal)); msg.run (); ARDOUR_COMMAND_LINE::session_name = ""; // cancel that continue; diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 5b87b5bc9b..3c1c9b564b 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -238,6 +238,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi template void foreach_route (T *obj, void (T::*func)(boost::shared_ptr)); template void foreach_route (T *obj, void (T::*func)(Route&, A), A arg); + static char session_name_is_legal (const std::string&); bool io_name_is_legal (const std::string&); boost::shared_ptr route_by_name (std::string); boost::shared_ptr route_by_id (PBD::ID); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index d0ca765754..4f5e8093bb 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -4543,3 +4543,16 @@ Session::update_latency_compensation (bool force_whole_graph) } } +char +Session::session_name_is_legal (const string& path) +{ + char illegal_chars[] = { '/', '\\', ':', ';', '\0' }; + + for (int i = 0; illegal_chars[i]; ++i) { + if (path.find (illegal_chars[i]) != string::npos) { + return illegal_chars[i]; + } + } + + return 0; +}