Use sys::path and SessionDirectory in Session::create_session_file_from_template...
[ardour.git] / libs / ardour / session_directory.cc
index e871b84244eb51c512f96b5f9b7900ad025bb64e..99a252ecb502be34d1abc960b1df93240d15b3b2 100644 (file)
@@ -43,23 +43,29 @@ SessionDirectory::SessionDirectory (const string& session_path)
 bool
 SessionDirectory::create ()
 {
-       if (is_directory (m_root_path))
-       {
-               PBD::error << string_compose(_("Cannot create Session directory at path %1 as it already exists"), m_root_path.to_string()) << endmsg;
-               return false;
-       }
+       bool is_new = false;
 
        vector<path> sub_dirs = sub_directories ();
        for (vector<path>::const_iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i)
        {
-               if (!create_directories(*i))
+               try
                {
-                       PBD::error << string_compose(_("Cannot create Session directory at path %1 Error: %2"), (*i).to_string(), g_strerror (errno)) << endmsg;
-                       return false;
+                       if(create_directories(*i)) {
+                               PBD::info << string_compose(_("Created Session directory at path %1"), (*i).to_string()) << endmsg;
+                               is_new = true;
+                       }
+               }
+               catch (PBD::sys::filesystem_error& ex)
+               {
+                       // log the error
+                       PBD::error << string_compose(_("Cannot create Session directory at path %1 Error: %2"), (*i).to_string(), ex.what()) << endmsg;
+
+                       // and rethrow
+                       throw ex;
                }
        }
 
-       return true;
+       return is_new;
 }
 
 bool
@@ -99,6 +105,19 @@ SessionDirectory::sound_path () const
        return l_sound_path;
 }
 
+const path
+SessionDirectory::midi_path () const
+{
+       // the new style sound directory
+       path l_midi_path(m_root_path);
+
+       l_midi_path /= interchange_dir_name;
+       l_midi_path /= basename(m_root_path);
+       l_midi_path /= midi_dir_name;
+
+       return l_midi_path;
+}
+
 const path
 SessionDirectory::peak_path () const
 {
@@ -111,6 +130,12 @@ SessionDirectory::dead_sound_path () const
        return path(m_root_path) /= dead_sound_dir_name;
 }
 
+const path
+SessionDirectory::dead_midi_path () const
+{
+       return path(m_root_path) /= dead_midi_dir_name;
+}
+
 const path
 SessionDirectory::export_path () const
 {
@@ -123,8 +148,10 @@ SessionDirectory::sub_directories () const
        vector<path> tmp_paths; 
 
        tmp_paths.push_back ( sound_path () );
+       tmp_paths.push_back ( midi_path () );
        tmp_paths.push_back ( peak_path () );
        tmp_paths.push_back ( dead_sound_path () );
+       tmp_paths.push_back ( dead_midi_path () );
        tmp_paths.push_back ( export_path () );
 
        return tmp_paths;