From c1a8273c44df7863d15d5c326efcc9106bea3a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Thu, 15 Aug 2024 00:53:29 +0200 Subject: [PATCH] Save: ask if project format changes Ask before save if the project file format differs (breaking compatibility with older versions of Friction. Also disable auto save if project version differs, requires you to save the file before auto save will work again. This is needed to avoid accidental breakage of the project format version. --- src/app/GUI/mainwindow.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/app/GUI/mainwindow.cpp b/src/app/GUI/mainwindow.cpp index 230658cd4..b3e408ccf 100644 --- a/src/app/GUI/mainwindow.cpp +++ b/src/app/GUI/mainwindow.cpp @@ -1371,7 +1371,21 @@ void MainWindow::checkAutoSaveTimer() if (mAutoSave && mChangedSinceSaving && !mDocument.fEvFile.isEmpty()) - { saveFile(mDocument.fEvFile); } + { + const int projectVersion = AppSupport::getProjectVersion(mDocument.fEvFile); + const int newProjectVersion = AppSupport::getProjectVersion(); + if (newProjectVersion > projectVersion && projectVersion > 0) { + QMessageBox::warning(this, + tr("Auto Save canceled"), + tr("Auto Save is not allowed to break" + " project format compatibility (%1 vs. %2)." + " Please save the project to confirm" + " project format changes.").arg(QString::number(newProjectVersion), + QString::number(projectVersion))); + return; + } + saveFile(mDocument.fEvFile); + } } void MainWindow::openAboutWindow() @@ -2000,7 +2014,22 @@ void MainWindow::openFile(const QString& openPath) void MainWindow::saveFile() { if (mDocument.fEvFile.isEmpty()) { saveFileAs(true); } - else { saveFile(mDocument.fEvFile); } + else { + const int projectVersion = AppSupport::getProjectVersion(mDocument.fEvFile); + const int newProjectVersion = AppSupport::getProjectVersion(); + if (newProjectVersion > projectVersion && projectVersion > 0) { + const auto result = QMessageBox::question(this, + tr("Project version"), + tr("Saving this project file will change the project" + " format from version %1 to version %2." + " This breaks compatibility with older versions of Friction." + "\n\nAre you sure you want" + " to save this project file?").arg(QString::number(projectVersion), + QString::number(newProjectVersion))); + if (result != QMessageBox::Yes) { return; } + } + saveFile(mDocument.fEvFile); + } } void MainWindow::saveFile(const QString& path,