From 119dc86f6fb8d5100ed49930fa9ff73c6322fa34 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 4 Jan 2007 19:12:55 +0000 Subject: [PATCH] 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 --- SConstruct | 12 +++--- gtk2_ardour/SConscript | 11 +++++- gtk2_ardour/ardev | 2 +- gtk2_ardour/ardev.in | 3 ++ gtk2_ardour/ardour.sh.in | 2 +- libs/ardour/session_state.cc | 74 ++++++++++++++++++++++-------------- libs/pbd/SConscript | 3 +- libs/pbd/copyfile.cc | 38 ++++++++++++++++++ libs/pbd/pbd/copyfile.h | 6 +++ svn_revision.h | 2 +- 10 files changed, 112 insertions(+), 41 deletions(-) create mode 100644 gtk2_ardour/ardev.in create mode 100644 libs/pbd/copyfile.cc create mode 100644 libs/pbd/pbd/copyfile.h diff --git a/SConstruct b/SConstruct index b9079e34e7..1b04306efb 100644 --- a/SConstruct +++ b/SConstruct @@ -16,7 +16,7 @@ import SCons.Node.FS SConsignFile() EnsureSConsVersion(0, 96) -version = '2.0beta10' +ardour_version = '2.0beta10' subst_dict = { } @@ -76,11 +76,11 @@ class LibraryInfo(Environment): env = LibraryInfo (options = opts, CPPPATH = [ '.' ], - VERSION = version, - TARBALL='ardour-' + version + '.tar.bz2', + VERSION = ardour_version, + TARBALL='ardour-' + ardour_version + '.tar.bz2', DISTFILES = [ ], - DISTTREE = '#ardour-' + version, - DISTCHECKDIR = '#ardour-' + version + '/check' + DISTTREE = '#ardour-' + ardour_version, + DISTCHECKDIR = '#ardour-' + ardour_version + '/check' ) env.ENV_update(os.environ) @@ -1034,7 +1034,7 @@ env = conf.Finish() if env['NLS'] == 1: env.Append(CCFLAGS="-DENABLE_NLS") -Export('env install_prefix final_prefix config_prefix final_config_prefix libraries i18n version subst_dict') +Export('env install_prefix final_prefix config_prefix final_config_prefix libraries i18n ardour_version subst_dict') # # the configuration file may be system dependent diff --git a/gtk2_ardour/SConscript b/gtk2_ardour/SConscript index f2c51e18a0..375dba278b 100644 --- a/gtk2_ardour/SConscript +++ b/gtk2_ardour/SConscript @@ -4,7 +4,7 @@ import os import os.path import glob -Import('env install_prefix final_prefix config_prefix libraries i18n version') +Import('env install_prefix final_prefix config_prefix libraries i18n ardour_version') gtkardour = env.Copy() gtkmmtests = env.Copy() @@ -260,7 +260,7 @@ versionflag = '-DVERSIONSTRING=\\\"' + env['VERSION'] + '\\\"' gtkardour.Append(CXXFLAGS=versionflag) -executable = 'ardour.bin' +executable = 'ardour-' + ardour_version ardour = gtkardour.Program(target = executable, source = gtkardour_files + extra_sources) ardourlib = gtkardour.SharedLibrary(target = 'ardourgtk', source = gtkardour_files + extra_sources) @@ -273,10 +273,17 @@ tt = gtkmmtests.Program(target = 'tt', source = tt_files) my_subst_dict = { } my_subst_dict['%INSTALL_PREFIX%'] = final_prefix my_subst_dict['%LIBDIR%'] = env['LIBDIR'] +my_subst_dict['%VERSION%'] = ardour_version ardoursh = env.SubstInFile ('ardour.sh','ardour.sh.in', SUBST_DICT = my_subst_dict); env.AddPostAction (ardoursh, Chmod ('$TARGET', 0755)) +ardourdev = env.SubstInFile ('ardev','ardev.in', SUBST_DICT = my_subst_dict); +env.AddPostAction (ardourdev, Chmod ('$TARGET', 0755)) + +Default(ardourdev) +Default(ardoursh) + if env['VST']: Default(ardourlib) # the library - into the library dir diff --git a/gtk2_ardour/ardev b/gtk2_ardour/ardev index 04719908b4..73f6573228 100755 --- a/gtk2_ardour/ardev +++ b/gtk2_ardour/ardev @@ -1,3 +1,3 @@ #!/bin/sh . `dirname "$0"`/ardev_common.sh -exec gtk2_ardour/ardour.bin --novst $* +exec gtk2_ardour/ardour-2.0beta10 $* diff --git a/gtk2_ardour/ardev.in b/gtk2_ardour/ardev.in new file mode 100644 index 0000000000..d9ba8330bb --- /dev/null +++ b/gtk2_ardour/ardev.in @@ -0,0 +1,3 @@ +#!/bin/sh +. `dirname "$0"`/ardev_common.sh +exec gtk2_ardour/ardour-%VERSION% $* diff --git a/gtk2_ardour/ardour.sh.in b/gtk2_ardour/ardour.sh.in index 835cbd4582..1bf1ffa94b 100644 --- a/gtk2_ardour/ardour.sh.in +++ b/gtk2_ardour/ardour.sh.in @@ -6,6 +6,6 @@ export LD_LIBRARY_PATH=%INSTALL_PREFIX%/%LIBDIR%/ardour2:$LD_LIBRARY_PATH # DYLD_LIBRARY_PATH is for Darwin export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH -exec %INSTALL_PREFIX%/%LIBDIR%/ardour2/ardour.bin $* +exec %INSTALL_PREFIX%/%LIBDIR%/ardour2/ardour-%VERSION% $* 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 #include #include +#include #include #include @@ -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 +#include + +#include +#include +#include + +#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 + +namespace PBD { + + int copy_file (Glib::ustring from, Glib::ustring to); +} diff --git a/svn_revision.h b/svn_revision.h index 4e065cd919..cddf78e774 100644 --- a/svn_revision.h +++ b/svn_revision.h @@ -1,4 +1,4 @@ #ifndef __ardour_svn_revision_h__ #define __ardour_svn_revision_h__ -static const char* ardour_svn_revision = "1239"; +static const char* ardour_svn_revision = "1266"; #endif