2 Copyright (C) 2007 Tim Mayberry
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <glibmm/fileutils.h>
22 #include <glibmm/miscutils.h>
24 #include <pbd/error.h>
25 #include <pbd/compose.h>
26 #include <pbd/filesystem.h>
28 #include <ardour/directory_names.h>
29 #include <ardour/session_directory.h>
35 using namespace PBD::sys;
37 SessionDirectory::SessionDirectory (const string& session_path)
38 : m_root_path(session_path)
44 SessionDirectory::create ()
46 if (is_directory (m_root_path))
48 PBD::error << string_compose(_("Cannot create Session directory at path %1 as it already exists"), m_root_path.to_string()) << endmsg;
52 vector<path> sub_dirs = sub_directories ();
53 for (vector<path>::const_iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i)
55 if (!create_directories(*i))
57 PBD::error << string_compose(_("Cannot create Session directory at path %1 Error: %2"), (*i).to_string(), g_strerror (errno)) << endmsg;
66 SessionDirectory::is_valid () const
68 if (!is_directory (m_root_path)) return false;
70 vector<path> sub_dirs = sub_directories ();
72 for (vector<path>::iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i) {
73 if (!is_directory (*i)) {
74 PBD::warning << string_compose(_("Session subdirectory does not exist at path %1"), (*i).to_string()) << endmsg;
82 SessionDirectory::old_sound_path () const
84 return path(m_root_path) /= old_sound_dir_name;
88 SessionDirectory::sound_path () const
90 if(is_directory (old_sound_path ())) return old_sound_path();
92 // the new style sound directory
93 path l_sound_path(m_root_path);
95 l_sound_path /= interchange_dir_name;
96 l_sound_path /= basename(m_root_path);
97 l_sound_path /= sound_dir_name;
103 SessionDirectory::peak_path () const
105 return path(m_root_path) /= peak_dir_name;
109 SessionDirectory::dead_sound_path () const
111 return path(m_root_path) /= dead_sound_dir_name;
115 SessionDirectory::sub_directories () const
117 vector<path> tmp_paths;
119 tmp_paths.push_back ( sound_path () );
120 tmp_paths.push_back ( peak_path () );
121 tmp_paths.push_back ( dead_sound_path () );
126 } // namespace ARDOUR