summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2007-01-04 19:12:55 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2007-01-04 19:12:55 +0000
commit119dc86f6fb8d5100ed49930fa9ff73c6322fa34 (patch)
tree352ce436c0daa19daeeb147540faaca9a6412e3b /libs
parent588910d8d7ff7698eaa02421775ee4b358cc13c1 (diff)
copy older versions of the session file, fix up ardev to work again using %VERSION%
git-svn-id: svn://localhost/ardour2/trunk@1268 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/session_state.cc74
-rw-r--r--libs/pbd/SConscript3
-rw-r--r--libs/pbd/copyfile.cc38
-rw-r--r--libs/pbd/pbd/copyfile.h6
4 files changed, 91 insertions, 30 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index b58d414ffd..9d5733b122 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -55,6 +55,7 @@
#include <pbd/pthread_utils.h>
#include <pbd/strsplit.h>
#include <pbd/stacktrace.h>
+#include <pbd/copyfile.h>
#include <ardour/audioengine.h>
#include <ardour/configuration.h>
@@ -604,29 +605,7 @@ Session::save_state (string snapshot_name, bool pending)
bak_path += ".bak";
if (g_file_test (xml_path.c_str(), G_FILE_TEST_EXISTS)) {
-
- // Make backup of state file
-
- 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;
- }
+ copy_file (xml_path, bak_path);
}
} else {
@@ -730,15 +709,52 @@ Session::load_state (string snapshot_name)
set_dirty();
- if (state_tree->read (xmlpath)) {
- return 0;
- } else {
+ if (!state_tree->read (xmlpath)) {
error << string_compose(_("Could not understand ardour file %1"), xmlpath) << endmsg;
+ delete state_tree;
+ state_tree = 0;
+ return -1;
}
- delete state_tree;
- state_tree = 0;
- return -1;
+ XMLNode& root (*state_tree->root());
+
+ if (root.name() != X_("Session")) {
+ error << string_compose (_("Session file %1 is not an Ardour session"), xmlpath) << endmsg;
+ delete state_tree;
+ state_tree = 0;
+ return -1;
+ }
+
+ const XMLProperty* prop;
+ bool is_old = false;
+
+ if ((prop = root.property ("version")) == 0) {
+ /* no version implies very old version of Ardour */
+ is_old = true;
+ } else {
+ int major_version;
+ major_version = atoi (prop->value()); // grab just the first number before the period
+ if (major_version < 2) {
+ is_old = true;
+ }
+ }
+
+ if (is_old) {
+ string backup_path;
+
+ backup_path = xmlpath;
+ backup_path += ".1";
+
+ info << string_compose (_("Copying old session file %1 to %2\nUse %2 with Ardour versions before 2.0 from now on"),
+ xmlpath, backup_path)
+ << endmsg;
+
+ copy_file (xmlpath, backup_path);
+
+ /* if it fails, don't worry. right? */
+ }
+
+ return 0;
}
int
diff --git a/libs/pbd/SConscript b/libs/pbd/SConscript
index f5c65c3b2c..afb24a4311 100644
--- a/libs/pbd/SConscript
+++ b/libs/pbd/SConscript
@@ -20,8 +20,9 @@ pbd.Append(POTFILE=domain + '.pot')
pbd_files = Split("""
basename.cc
base_ui.cc
-convert.cc
command.cc
+convert.cc
+copyfile.cc
controllable.cc
enumwriter.cc
dmalloc.cc
diff --git a/libs/pbd/copyfile.cc b/libs/pbd/copyfile.cc
new file mode 100644
index 0000000000..d36ecef58a
--- /dev/null
+++ b/libs/pbd/copyfile.cc
@@ -0,0 +1,38 @@
+#include <fstream>
+#include <unistd.h>
+
+#include <pbd/copyfile.h>
+#include <pbd/error.h>
+#include <pbd/compose.h>
+
+#include "i18n.h"
+
+using namespace PBD;
+using namespace std;
+
+int
+PBD::copy_file (Glib::ustring from, Glib::ustring to)
+{
+ ifstream in (from.c_str());
+ ofstream out (to.c_str());
+
+ if (!in) {
+ error << string_compose (_("Could not open %1 for copy"), from) << endmsg;
+ return -1;
+ }
+
+ if (!out) {
+ error << string_compose (_("Could not open %1 as copy"), to) << endmsg;
+ return -1;
+ }
+
+ out << in.rdbuf();
+
+ if (!in || !out) {
+ error << string_compose (_("Could not copy existing file %1 to %2"), from, to) << endmsg;
+ unlink (to.c_str());
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/libs/pbd/pbd/copyfile.h b/libs/pbd/pbd/copyfile.h
new file mode 100644
index 0000000000..8a1bf242bb
--- /dev/null
+++ b/libs/pbd/pbd/copyfile.h
@@ -0,0 +1,6 @@
+#include <glibmm/ustring.h>
+
+namespace PBD {
+
+ int copy_file (Glib::ustring from, Glib::ustring to);
+}