X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fardour%2Fsession_state.cc;h=07f10e9bc10236538e2207dd3532d2b9b9c9a3ef;hb=e36f74e071d4c14862d23da5ff0d49df0940d536;hp=6d535b8e59b75a82c7f2cd7199ce256b7726d0cf;hpb=60a9213035d3c9b8e17686778c70d91aa6acd356;p=ardour.git diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 6d535b8e59..07f10e9bc1 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -33,15 +33,14 @@ #include #include #include -#include -#include #include -#include #include #ifdef HAVE_SYS_VFS_H #include -#else +#endif + +#ifdef __APPLE__ #include #include #endif @@ -69,11 +68,13 @@ #include "pbd/enumwriter.h" #include "pbd/error.h" #include "pbd/file_utils.h" +#include "pbd/pathexpand.h" #include "pbd/pathscanner.h" #include "pbd/pthread_utils.h" #include "pbd/stacktrace.h" #include "pbd/convert.h" #include "pbd/clear_dir.h" +#include "pbd/localtime_r.h" #include "ardour/amp.h" #include "ardour/audio_diskstream.h" @@ -135,23 +136,8 @@ Session::pre_engine_init (string fullpath) /* discover canonical fullpath */ - char buf[PATH_MAX+1]; + _path = canonical_path(fullpath); - if (!realpath (fullpath.c_str(), buf)) { - if (errno == ENOENT) { - /* fullpath does not exist yet, so realpath() returned - * ENOENT. Just use it as-is - */ - _path = fullpath; - } else { - error << string_compose(_("Could not use path %1 (%2)"), buf, strerror(errno)) << endmsg; - destroy (); - throw failed_constructor(); - } - } else { - _path = string(buf); - } - /* we require _path to end with a dir separator */ if (_path[_path.length()-1] != G_DIR_SEPARATOR) { @@ -363,7 +349,7 @@ Session::post_engine_init () string Session::raid_path () const { - SearchPath raid_search_path; + Searchpath raid_search_path; for (vector::const_iterator i = session_dirs.begin(); i != session_dirs.end(); ++i) { raid_search_path += (*i).path; @@ -384,11 +370,11 @@ Session::setup_raid_path (string path) session_dirs.clear (); - SearchPath search_path(path); - SearchPath sound_search_path; - SearchPath midi_search_path; + Searchpath search_path(path); + Searchpath sound_search_path; + Searchpath midi_search_path; - for (SearchPath::const_iterator i = search_path.begin(); i != search_path.end(); ++i) { + for (Searchpath::const_iterator i = search_path.begin(); i != search_path.end(); ++i) { sp.path = *i; sp.blocks = 0; // not needed session_dirs.push_back (sp); @@ -734,9 +720,9 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot } else { - if (::rename (tmp_path.c_str(), xml_path.c_str()) != 0) { - error << string_compose (_("could not rename temporary session file %1 to %2"), - tmp_path, xml_path) << endmsg; + if (::g_rename (tmp_path.c_str(), xml_path.c_str()) != 0) { + error << string_compose (_("could not rename temporary session file %1 to %2 (%3)"), + tmp_path, xml_path, g_strerror(errno)) << endmsg; if (g_remove (tmp_path.c_str()) != 0) { error << string_compose(_("Could not remove temporary session file at path \"%1\" (%2)"), tmp_path, g_strerror (errno)) << endmsg; @@ -812,7 +798,7 @@ Session::load_state (string snapshot_name) set_dirty(); - _writable = exists_and_writable (xmlpath); + _writable = exists_and_writable (xmlpath) && exists_and_writable(Glib::path_get_dirname(xmlpath)); if (!state_tree->read (xmlpath)) { error << string_compose(_("Could not understand session file %1"), xmlpath) << endmsg; @@ -930,7 +916,7 @@ Session::state (bool full_state) p += (*i).path; if (next != session_dirs.end()) { - p += ':'; + p += G_SEARCHPATH_SEPARATOR; } else { break; } @@ -987,19 +973,9 @@ Session::state (bool full_state) if (!fs->destructive()) { if (fs->empty() && !fs->used()) { -#ifndef NDEBUG - cerr << "DEBUG: source '" - << fs->name() << "' id: " - << fs->id() << " is marked as empty and unused and is not saved.\n"; -#endif continue; } } -#ifndef NDEBUG - cerr << "DEBUG: saving source '" - << fs->name() << "' id: " - << fs->id() << ".\n"; -#endif child->add_child_nocopy (siter->second->get_state()); } @@ -2059,6 +2035,54 @@ Session::refresh_disk_space () _total_free_4k_blocks_uncertain = true; } } +#elif defined (COMPILER_MSVC) + vector scanned_volumes; + vector::iterator j; + vector::iterator i; + DWORD nSectorsPerCluster, nBytesPerSector, + nFreeClusters, nTotalClusters; + char disk_drive[4]; + bool volume_found; + + _total_free_4k_blocks = 0; + + for (i = session_dirs.begin(); i != session_dirs.end(); i++) { + strncpy (disk_drive, (*i).path.c_str(), 3); + disk_drive[3] = 0; + strupr(disk_drive); + + volume_found = false; + if (0 != (GetDiskFreeSpace(disk_drive, &nSectorsPerCluster, &nBytesPerSector, &nFreeClusters, &nTotalClusters))) + { + int64_t nBytesPerCluster = nBytesPerSector * nSectorsPerCluster; + int64_t nFreeBytes = nBytesPerCluster * (int64_t)nFreeClusters; + i->blocks = (uint32_t)(nFreeBytes / 4096); + + for (j = scanned_volumes.begin(); j != scanned_volumes.end(); j++) { + if (0 == j->compare(disk_drive)) { + volume_found = true; + break; + } + } + + if (!volume_found) { + scanned_volumes.push_back(disk_drive); + _total_free_4k_blocks += i->blocks; + } + } + } + + if (0 == _total_free_4k_blocks) { + strncpy (disk_drive, path().c_str(), 3); + disk_drive[3] = 0; + + if (0 != (GetDiskFreeSpace(disk_drive, &nSectorsPerCluster, &nBytesPerSector, &nFreeClusters, &nTotalClusters))) + { + int64_t nBytesPerCluster = nBytesPerSector * nSectorsPerCluster; + int64_t nFreeBytes = nBytesPerCluster * (int64_t)nFreeClusters; + _total_free_4k_blocks = (uint32_t)(nFreeBytes / 4096); + } + } #endif } @@ -2245,7 +2269,7 @@ Session::auto_save() } static bool -state_file_filter (const string &str, void */*arg*/) +state_file_filter (const string &str, void* /*arg*/) { return (str.length() > strlen(statefile_suffix) && str.find (statefile_suffix) == (str.length() - strlen (statefile_suffix))); @@ -2422,7 +2446,7 @@ Session::commit_reversible_command (Command *cmd) } static bool -accept_all_audio_files (const string& path, void */*arg*/) +accept_all_audio_files (const string& path, void* /*arg*/) { if (!Glib::file_test (path, Glib::FILE_TEST_IS_REGULAR)) { return false; @@ -2436,7 +2460,7 @@ accept_all_audio_files (const string& path, void */*arg*/) } static bool -accept_all_midi_files (const string& path, void */*arg*/) +accept_all_midi_files (const string& path, void* /*arg*/) { if (!Glib::file_test (path, Glib::FILE_TEST_IS_REGULAR)) { return false; @@ -2448,7 +2472,7 @@ accept_all_midi_files (const string& path, void */*arg*/) } static bool -accept_all_state_files (const string& path, void */*arg*/) +accept_all_state_files (const string& path, void* /*arg*/) { if (!Glib::file_test (path, Glib::FILE_TEST_IS_REGULAR)) { return false; @@ -2604,6 +2628,8 @@ Session::cleanup_sources (CleanupReport& rep) bool used; string spath; int ret = -1; + string tmppath1; + string tmppath2; _state_of_the_state = (StateOfTheState) (_state_of_the_state | InCleanup); @@ -2654,7 +2680,7 @@ Session::cleanup_sources (CleanupReport& rep) audio_path += sdir.sound_path(); if (nexti != session_dirs.end()) { - audio_path += ':'; + audio_path += G_SEARCHPATH_SEPARATOR; } i = nexti; @@ -2672,7 +2698,7 @@ Session::cleanup_sources (CleanupReport& rep) midi_path += sdir.midi_path(); if (nexti != session_dirs.end()) { - midi_path += ':'; + midi_path += G_SEARCHPATH_SEPARATOR; } i = nexti; @@ -2710,27 +2736,28 @@ Session::cleanup_sources (CleanupReport& rep) ++tmp; if ((fs = boost::dynamic_pointer_cast (i->second)) != 0) { - if (playlists->source_use_count (fs) != 0) { - all_sources.insert (fs->path()); - } else { - /* we might not remove this source from disk, because it may be used - by other snapshots, but its not being used in this version - so lets get rid of it now, along with any representative regions - in the region list. - */ + if (!fs->is_stub()) { - RegionFactory::remove_regions_using_source (i->second); - sources.erase (i); - } + if (playlists->source_use_count (fs) != 0) { + all_sources.insert (fs->path()); + } else { + + /* we might not remove this source from disk, because it may be used + by other snapshots, but its not being used in this version + so lets get rid of it now, along with any representative regions + in the region list. + */ + + RegionFactory::remove_regions_using_source (i->second); + sources.erase (i); + } + } } i = tmp; } - char tmppath1[PATH_MAX+1]; - char tmppath2[PATH_MAX+1]; - if (candidates) { for (vector::iterator x = candidates->begin(); x != candidates->end(); ++x) { @@ -2739,19 +2766,10 @@ Session::cleanup_sources (CleanupReport& rep) for (set::iterator i = all_sources.begin(); i != all_sources.end(); ++i) { - if (realpath(spath.c_str(), tmppath1) == 0) { - error << string_compose (_("Cannot expand path %1 (%2)"), - spath, strerror (errno)) << endmsg; - continue; - } - - if (realpath((*i).c_str(), tmppath2) == 0) { - error << string_compose (_("Cannot expand path %1 (%2)"), - (*i), strerror (errno)) << endmsg; - continue; - } + tmppath1 = canonical_path (spath); + tmppath2 = canonical_path ((*i)); - if (strcmp(tmppath1, tmppath2) == 0) { + if (tmppath1 == tmppath2) { used = true; break; } @@ -2855,7 +2873,7 @@ Session::cleanup_sources (CleanupReport& rep) string peakpath = peak_path (base); if (Glib::file_test (peakpath.c_str(), Glib::FILE_TEST_EXISTS)) { - if (::unlink (peakpath.c_str()) != 0) { + if (::g_unlink (peakpath.c_str()) != 0) { error << string_compose (_("cannot remove peakfile %1 for %2 (%3)"), peakpath, _path, strerror (errno)) << endmsg; @@ -3584,8 +3602,6 @@ Session::rename (const std::string& new_name) string const old_sources_root = _session_dir->sources_root(); -#define RENAME ::rename - /* Rename: * session directory @@ -3647,7 +3663,8 @@ Session::rename (const std::string& new_name) cerr << "Rename " << oldstr << " => " << newstr << endl; - if (RENAME (oldstr.c_str(), newstr.c_str()) != 0) { + if (::g_rename (oldstr.c_str(), newstr.c_str()) != 0) { + error << string_compose (_("renaming %s as %2 failed (%3)"), oldstr, newstr, g_strerror (errno)) << endmsg; return 1; } @@ -3674,7 +3691,8 @@ Session::rename (const std::string& new_name) cerr << "Rename " << oldstr << " => " << newstr << endl; - if (RENAME (oldstr.c_str(), newstr.c_str()) != 0) { + if (::g_rename (oldstr.c_str(), newstr.c_str()) != 0) { + error << string_compose (_("renaming %s as %2 failed (%3)"), oldstr, newstr, g_strerror (errno)) << endmsg; return 1; } } @@ -3686,7 +3704,8 @@ Session::rename (const std::string& new_name) cerr << "Rename " << oldstr << " => " << newstr << endl; - if (RENAME (oldstr.c_str(), newstr.c_str()) != 0) { + if (::g_rename (oldstr.c_str(), newstr.c_str()) != 0) { + error << string_compose (_("renaming %s as %2 failed (%3)"), oldstr, newstr, g_strerror (errno)) << endmsg; return 1; } @@ -3700,7 +3719,8 @@ Session::rename (const std::string& new_name) cerr << "Rename " << oldstr << " => " << newstr << endl; - if (RENAME (oldstr.c_str(), newstr.c_str()) != 0) { + if (::g_rename (oldstr.c_str(), newstr.c_str()) != 0) { + error << string_compose (_("renaming %s as %2 failed (%3)"), oldstr, newstr, g_strerror (errno)) << endmsg; return 1; } } @@ -3724,6 +3744,11 @@ Session::rename (const std::string& new_name) _current_snapshot_name = new_name; _name = new_name; + /* re-add directory separator - reverse hack to oldstr above */ + if (_path[_path.length()-1] != G_DIR_SEPARATOR) { + _path += G_DIR_SEPARATOR; + } + set_dirty (); /* save state again to get everything just right */ @@ -3736,8 +3761,6 @@ Session::rename (const std::string& new_name) store_recent_sessions (new_name, _path); return 0; - -#undef RENAME } int