Remove unused header includes from ardour/session_directory.cc
[ardour.git] / libs / ardour / session_directory.cc
1 /*
2         Copyright (C) 2007 Tim Mayberry 
3
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.
8
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.
13
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.
17 */
18
19 #include <pbd/error.h>
20 #include <pbd/compose.h>
21 #include <pbd/filesystem.h>
22
23 #include <ardour/directory_names.h>
24 #include <ardour/session_directory.h>
25
26 #include "i18n.h"
27
28 namespace ARDOUR {
29
30 using namespace PBD::sys;
31
32 SessionDirectory::SessionDirectory (const path& session_path)
33         : m_root_path(session_path)
34 {
35
36 }
37
38 bool
39 SessionDirectory::create ()
40 {
41         bool is_new = false;
42
43         vector<path> sub_dirs = sub_directories ();
44         for (vector<path>::const_iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i)
45         {
46                 try
47                 {
48                         if(create_directories(*i)) {
49                                 PBD::info << string_compose(_("Created Session directory at path %1"), (*i).to_string()) << endmsg;
50                                 is_new = true;
51                         }
52                 }
53                 catch (PBD::sys::filesystem_error& ex)
54                 {
55                         // log the error
56                         PBD::error << string_compose(_("Cannot create Session directory at path %1 Error: %2"), (*i).to_string(), ex.what()) << endmsg;
57
58                         // and rethrow
59                         throw ex;
60                 }
61         }
62
63         return is_new;
64 }
65
66 bool
67 SessionDirectory::is_valid () const
68 {
69         if (!is_directory (m_root_path)) return false;
70
71         vector<path> sub_dirs = sub_directories ();
72
73         for (vector<path>::iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i) {
74                 if (!is_directory (*i)) {
75                         PBD::warning << string_compose(_("Session subdirectory does not exist at path %1"), (*i).to_string()) << endmsg;
76                         return false;
77                 }
78         }
79         return true;
80 }
81
82 const path
83 SessionDirectory::old_sound_path () const
84 {
85         return m_root_path / old_sound_dir_name;
86 }
87
88 const path
89 SessionDirectory::sound_path () const
90 {
91         if(is_directory (old_sound_path ())) return old_sound_path();
92
93         // the new style sound directory
94         return m_root_path / interchange_dir_name / m_root_path.leaf() / sound_dir_name;
95 }
96
97 const path
98 SessionDirectory::midi_path () const
99 {
100         // the new style sound directory
101         return m_root_path / interchange_dir_name / m_root_path.leaf() / midi_dir_name;
102 }
103
104 const path
105 SessionDirectory::peak_path () const
106 {
107         return m_root_path / peak_dir_name;
108 }
109
110 const path
111 SessionDirectory::dead_sound_path () const
112 {
113         return m_root_path / dead_sound_dir_name;
114 }
115
116 const path
117 SessionDirectory::dead_midi_path () const
118 {
119         return m_root_path / dead_midi_dir_name;
120 }
121
122 const path
123 SessionDirectory::export_path () const
124 {
125         return m_root_path / export_dir_name;
126 }
127
128 const vector<path>
129 SessionDirectory::sub_directories () const
130 {
131         vector<path> tmp_paths; 
132
133         tmp_paths.push_back ( sound_path () );
134         tmp_paths.push_back ( midi_path () );
135         tmp_paths.push_back ( peak_path () );
136         tmp_paths.push_back ( dead_sound_path () );
137         tmp_paths.push_back ( dead_midi_path () );
138         tmp_paths.push_back ( export_path () );
139
140         return tmp_paths;
141 }
142
143 } // namespace ARDOUR