auto-backup: libardour part. (from mixbus)
[ardour.git] / libs / ardour / session_directory.cc
index 491a593398378a5bae8bea419ce0d4406a98919f..1f6b991f8282b8fe0945b8a3cc7af8cfa0a0dc86 100644 (file)
 #include "pbd/error.h"
 #include "pbd/compose.h"
 #include "pbd/file_utils.h"
+#include "pbd/openuri.h"
 
 #include "ardour/directory_names.h"
 #include "ardour/session_directory.h"
 #include "ardour/utils.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 namespace ARDOUR {
 
@@ -140,7 +141,20 @@ SessionDirectory::sources_root () const
        try {
                Glib::Dir dir(sources_root_path);
 
-               std::list<std::string> entries (dir.begin(), dir.end());
+               std::list<std::string> entries;
+
+               for (Glib::DirIterator di = dir.begin(); di != dir.end(); di++) {
+                       // ignore hidden files (eg. OS X ".DS_Store")
+                       if ((*di).at(0) == '.') {
+                               continue;
+                       }
+                       // and skip regular files (eg. Win Thumbs.db)
+                       string fullpath = Glib::build_filename (sources_root_path, *di);
+                       if (!Glib::file_test (fullpath, Glib::FILE_TEST_IS_DIR)) {
+                               continue;
+                       }
+                       entries.push_back(*di);
+               }
 
                if (entries.size() == 1) {
                        if (entries.front() != legalized_root) {
@@ -149,6 +163,7 @@ SessionDirectory::sources_root () const
                        root_cache[m_root_path] = Glib::build_filename (sources_root_path, entries.front());
                }
                else if (entries.size() > 1) {
+                       PBD::open_folder (sources_root_path);
                        PBD::fatal << string_compose (_("The session's interchange dir is tainted.\nThere is more than one folder in '%1'.\nPlease remove extra subdirs to reduce possible filename ambiguties."), sources_root_path) << endmsg;
                        assert (0); // not reached
                }
@@ -230,6 +245,12 @@ SessionDirectory::export_path () const
        return Glib::build_filename (m_root_path, export_dir_name);
 }
 
+const std::string
+SessionDirectory::backup_path () const
+{
+       return Glib::build_filename (m_root_path, backup_dir_name);
+}
+
 const vector<std::string>
 SessionDirectory::sub_directories () const
 {
@@ -241,6 +262,7 @@ SessionDirectory::sub_directories () const
        tmp_paths.push_back (peak_path ());
        tmp_paths.push_back (dead_path ());
        tmp_paths.push_back (export_path ());
+       tmp_paths.push_back (backup_path ());
 
        return tmp_paths;
 }