throw WrongProgram exception if session was modified with incompatible app

This commit is contained in:
Paul Davis 2024-07-11 19:04:05 -06:00
parent 4212e23e77
commit 54f810f90e
3 changed files with 74 additions and 22 deletions

View file

@ -0,0 +1,41 @@
/*
* Copyright (C) 2024 Paul Davis <paul@linuxaudiosystems.com>
*
* 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 <exception>
#include <string>
#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__ */

View file

@ -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;
}
}

View file

@ -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());