summaryrefslogtreecommitdiff
path: root/libs/ardour/session_state.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-08-17 18:32:49 +0200
committerRobin Gareus <robin@gareus.org>2017-08-17 18:32:49 +0200
commit22055a07c075b5fba546f0453ba93867747519c1 (patch)
tree8b01af864a58b5de3745c5219b9b75afef83e6b3 /libs/ardour/session_state.cc
parente62e040502ac35213ce11353c9c1e7a487eb941f (diff)
Check major session file format version.
Don't allow to load sessions created with a newer version of Ardour with an old one (no forward compatibility).
Diffstat (limited to 'libs/ardour/session_state.cc')
-rw-r--r--libs/ardour/session_state.cc53
1 files changed, 37 insertions, 16 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index 051eca4b68..ecd8071215 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -954,20 +954,12 @@ Session::load_state (string snapshot_name)
}
std::string version;
- if (root.get_property ("version", version)) {
- if (version.find ('.') != string::npos) {
- /* old school version format */
- if (version[0] == '2') {
- Stateful::loading_state_version = 2000;
- } else {
- Stateful::loading_state_version = 3000;
- }
- } else {
- Stateful::loading_state_version = string_to<int32_t>(version);
- }
- } else {
- /* no version implies very old version of Ardour */
- Stateful::loading_state_version = 1000;
+ root.get_property ("version", version);
+ Stateful::loading_state_version = parse_stateful_loading_version (version);
+
+ if ((Stateful::loading_state_version / 1000L) > (CURRENT_SESSION_FILE_VERSION / 1000L)) {
+ cerr << "Session-version: " << Stateful::loading_state_version << " is not supported. Current: " << CURRENT_SESSION_FILE_VERSION << "\n";
+ throw SessionException (string_compose (_("Incomatible Session Version. That session was created with a newer version of %1"), PROGRAM_NAME));
}
if (Stateful::loading_state_version < CURRENT_SESSION_FILE_VERSION && _writable) {
@@ -4488,10 +4480,31 @@ Session::rename (const std::string& new_name)
}
int
+Session::parse_stateful_loading_version (const std::string& version)
+{
+ if (version.empty ()) {
+ /* no version implies very old version of Ardour */
+ return 1000;
+ }
+
+ if (version.find ('.') != string::npos) {
+ /* old school version format */
+ if (version[0] == '2') {
+ return 2000;
+ } else {
+ return 3000;
+ }
+ } else {
+ return string_to<int32_t>(version);
+ }
+}
+
+int
Session::get_info_from_path (const string& xmlpath, float& sample_rate, SampleFormat& data_format, std::string& program_version)
{
bool found_sr = false;
bool found_data_format = false;
+ std::string version;
program_version = "";
if (!Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) {
@@ -4517,16 +4530,24 @@ Session::get_info_from_path (const string& xmlpath, float& sample_rate, SampleFo
return -1;
}
- /* sample rate */
+ /* sample rate & version*/
xmlAttrPtr attr;
for (attr = node->properties; attr; attr = attr->next) {
+ if (!strcmp ((const char*)attr->name, "version") && attr->children) {
+ version = std::string ((char*)attr->children->content);
+ }
if (!strcmp ((const char*)attr->name, "sample-rate") && attr->children) {
sample_rate = atoi ((char*)attr->children->content);
found_sr = true;
}
}
+ if ((parse_stateful_loading_version(version) / 1000L) > (CURRENT_SESSION_FILE_VERSION / 1000L)) {
+ return -1;
+ }
+
+
node = node->children;
while (node != NULL) {
if (!strcmp((const char*) node->name, "ProgramVersion")) {
@@ -4565,7 +4586,7 @@ Session::get_info_from_path (const string& xmlpath, float& sample_rate, SampleFo
xmlFreeParserCtxt(ctxt);
xmlFreeDoc (doc);
- return !(found_sr && found_data_format); // zero if they are both found
+ return (found_sr && found_data_format) ? 0 : 1;
}
std::string