project: detect project version and show errors on incompatibility

This commit is contained in:
itsmattkc
2020-10-03 23:44:32 +10:00
parent b9359ce50d
commit de9c67a0f8
4 changed files with 24 additions and 2 deletions
+1
View File
@@ -68,6 +68,7 @@
OLIVE_NAMESPACE_ENTER
Core* Core::instance_ = nullptr;
const uint Core::kProjectVersion = 201003;
Core::Core(const CoreParams& params) :
main_window_(nullptr),
+2
View File
@@ -268,6 +268,8 @@ public:
*/
void CacheActiveSequence(bool in_out_only);
static const uint kProjectVersion;
public slots:
/**
* @brief Starts an open file dialog to load a project from file
+17 -1
View File
@@ -25,6 +25,7 @@
#include <QXmlStreamReader>
#include "common/xmlutils.h"
#include "core.h"
OLIVE_NAMESPACE_ENTER
@@ -45,7 +46,17 @@ bool ProjectLoadTask::Run()
if (reader.name() == QStringLiteral("olive")) {
while(XMLReadNextStartElement(&reader)) {
if (reader.name() == QStringLiteral("version")) {
qDebug() << "Project version:" << reader.readElementText();
uint project_version = reader.readElementText().toUInt();
if (project_version > Core::kProjectVersion) {
// Project is newer than we support
SetError(tr("This project is newer than this version of Olive and cannot be opened."));
return false;
} else if (project_version < 201003) { // Change this if we drop support for a project version
// Project is older than we support
SetError(tr("This project is from a version of Olive that is no longer supported in this version."));
return false;
}
} else if (reader.name() == QStringLiteral("project")) {
ProjectPtr project = std::make_shared<Project>();
@@ -66,6 +77,11 @@ bool ProjectLoadTask::Run()
reader.skipCurrentElement();
}
}
} else if (reader.name() == QStringLiteral("project")) {
// 0.1 projects use "project" as the root instead of Olive. We don't currently support
// these projects
SetError(tr("This project is from a version of Olive that is no longer supported in this version."));
return false;
} else {
reader.skipCurrentElement();
}
+4 -1
View File
@@ -25,6 +25,7 @@
#include <QXmlStreamWriter>
#include "common/filefunctions.h"
#include "core.h"
OLIVE_NAMESPACE_ENTER
@@ -49,7 +50,9 @@ bool ProjectSaveTask::Run()
writer.writeStartElement("olive");
writer.writeTextElement("version", "0.2.0");
// Version is stored in YYMMDD from whenever the project format was last changed
// Allows easy integer math for checking project versions.
writer.writeTextElement("version", QString::number(Core::kProjectVersion));
project_->Save(&writer);