From 54f810f90efd988c0f0f5f4f177c75bbe9c4ccf2 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 11 Jul 2024 19:04:05 -0600 Subject: [PATCH] throw WrongProgram exception if session was modified with incompatible app --- libs/ardour/ardour/wrong_program.h | 41 +++++++++++++++++++++++++ libs/ardour/session.cc | 48 ++++++++++++++++-------------- libs/ardour/session_state.cc | 7 +++++ 3 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 libs/ardour/ardour/wrong_program.h diff --git a/libs/ardour/ardour/wrong_program.h b/libs/ardour/ardour/wrong_program.h new file mode 100644 index 0000000000..9e3bedce35 --- /dev/null +++ b/libs/ardour/ardour/wrong_program.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 Paul Davis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __libardour_wrong_program_h__ +#define __libardour_wrong_program_h__ + +#include +#include + +#include "pbd/compose.h" + +#include "ardour/libardour_visibility.h" +#include "pbd/i18n.h" + +namespace ARDOUR { + +class LIBARDOUR_API WrongProgram : public std::exception { + public: + WrongProgram (std::string const & c) : creator (c) {} + virtual const char *what() const throw() { return "Created or modified by the wrong program"; } + std::string creator; +}; + +} /* namespace */ + +#endif /* __libardour_wrong_program_h__ */ diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index f6f4ed6c4d..75894610c9 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -111,6 +111,7 @@ #include "ardour/revision.h" #include "ardour/route_group.h" #include "ardour/rt_tasklist.h" +#include "ardour/wrong_program.h" #include "ardour/rt_safe_delete.h" #include "ardour/silentfilesource.h" @@ -459,28 +460,31 @@ Session::Session (AudioEngine &eng, if (err) { destroy (); switch (err) { - case -1: - throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Failed to create background threads."))); - break; - case -2: - case -3: - throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Invalid TempoMap in session-file."))); - break; - case -4: - throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Invalid or corrupt session state."))); - break; - case -5: - throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Port registration failed."))); - break; - case -6: - throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Audio/MIDI Engine is not running or sample-rate mismatches."))); - break; - case -8: - throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Required Plugin/Processor is missing."))); - break; - default: - throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Unexpected exception during session setup, possibly invalid audio/midi engine parameters. Please see stdout/stderr for details"))); - break; + case -1: + throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Failed to create background threads."))); + break; + case -2: + case -3: + throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Invalid TempoMap in session-file."))); + break; + case -4: + throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Invalid or corrupt session state."))); + break; + case -5: + throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Port registration failed."))); + break; + case -6: + throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Audio/MIDI Engine is not running or sample-rate mismatches."))); + break; + case -8: + throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Required Plugin/Processor is missing."))); + break; + case -9: + throw WrongProgram (modified_with); + break; + default: + throw SessionException (string_compose (_("Cannot initialize session/engine: %1"), _("Unexpected exception during session setup, possibly invalid audio/midi engine parameters. Please see stdout/stderr for details"))); + break; } } diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 3f642d78de..963e074c42 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -145,6 +145,7 @@ #include "ardour/user_bundle.h" #include "ardour/vca.h" #include "ardour/vca_manager.h" +#include "ardour/wrong_program.h" #include "control_protocol/control_protocol.h" @@ -383,6 +384,9 @@ Session::post_engine_init () } catch (ProcessorException const & e) { error << e.what() << endmsg; return -8; + } catch (WrongProgram const & wp) { + error << wp.what() << endmsg; + return -9; } catch (std::exception const & e) { error << _("Unexpected exception during session setup: ") << e.what() << endmsg; return -6; @@ -1782,6 +1786,9 @@ Session::set_state (const XMLNode& node, int version) child->get_property (X_("created-with"), created_with); child->get_property (X_("modified-with"), modified_with); + if (modified_with.rfind (PROGRAM_NAME, 0) != 0) { + throw WrongProgram (modified_with); + } } setup_raid_path(_session_dir->root_path());