diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2006-12-15 19:40:10 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2006-12-15 19:40:10 +0000 |
commit | 7e845c53ab95f4fd33c8327bf3dff9bdb82a7a18 (patch) | |
tree | 21948926eb794efa7bb48111deccb64291899883 /libs/ardour/session_state.cc | |
parent | e80214b71d9e38be55290cb594616a42d1e8c5e7 (diff) |
write session file to alternate name before, then rename; auditioner defaults to first 2 physical outputs; engine started before loading session, always; clean up handling off input connections and so forth during startup (faster! a bitcd ..); notice new locates while doing older ones; stop engine at shutdown first, not later
git-svn-id: svn://localhost/ardour2/trunk@1214 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/session_state.cc')
-rw-r--r-- | libs/ardour/session_state.cc | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 2ae8a833e1..a34b3ec52b 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -54,6 +54,7 @@ #include <pbd/pathscanner.h> #include <pbd/pthread_utils.h> #include <pbd/strsplit.h> +#include <pbd/stacktrace.h> #include <ardour/audioengine.h> #include <ardour/configuration.h> @@ -306,11 +307,7 @@ Session::second_stage_init (bool new_session) _engine.Halted.connect (mem_fun (*this, &Session::engine_halted)); _engine.Xrun.connect (mem_fun (*this, &Session::xrun_recovery)); - if (_engine.running()) { - when_engine_running(); - } else { - first_time_running = _engine.Running.connect (mem_fun (*this, &Session::when_engine_running)); - } + when_engine_running(); send_full_time_code (); _engine.transport_locate (0); @@ -586,15 +583,34 @@ Session::save_state (string snapshot_name, bool pending) xml_path = _path; xml_path += snapshot_name; xml_path += _statefile_suffix; + bak_path = xml_path; bak_path += ".bak"; - // Make backup of state file + if (g_file_test (xml_path.c_str(), G_FILE_TEST_EXISTS)) { + + // Make backup of state file - if ((access (xml_path.c_str(), F_OK) == 0) && - (rename(xml_path.c_str(), bak_path.c_str()))) { - error << _("could not backup old state file, current state not saved.") << endmsg; - return -1; + ifstream in (xml_path.c_str()); + ofstream out (bak_path.c_str()); + + if (!in) { + error << string_compose (_("Could not open existing session file %1 for backup"), xml_path) << endmsg; + return -1; + } + + if (!out) { + error << string_compose (_("Could not open backup session file %1"), bak_path) << endmsg; + return -1; + } + + out << in.rdbuf(); + + if (!in || !out) { + error << string_compose (_("Could not copy existing session file %1 to %2 for backup"), xml_path, bak_path) << endmsg; + unlink (bak_path.c_str()); + return -1; + } } } else { @@ -605,30 +621,31 @@ Session::save_state (string snapshot_name, bool pending) } + string tmp_path; + + tmp_path = _path; + tmp_path += snapshot_name; + tmp_path += ".tmp"; + cerr << "actually writing state\n"; - if (!tree.write (xml_path)) { - error << string_compose (_("state could not be saved to %1"), xml_path) << endmsg; + if (!tree.write (tmp_path)) { + error << string_compose (_("state could not be saved to %1"), tmp_path) << endmsg; + unlink (tmp_path.c_str()); + return -1; - /* don't leave a corrupt file lying around if it is - possible to fix. - */ + } else { - if (unlink (xml_path.c_str())) { - error << string_compose (_("could not remove corrupt state file %1"), xml_path) << endmsg; - } else { - if (!pending) { - if (rename (bak_path.c_str(), xml_path.c_str())) { - error << string_compose (_("could not restore state file from backup %1"), bak_path) << endmsg; - } - } + 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; + unlink (tmp_path.c_str()); + return -1; } - - return -1; } if (!pending) { - save_history(snapshot_name); + + save_history (snapshot_name); bool was_dirty = dirty(); |