From 6d0b38e38a3d476ec86166cf8eda1626171b29a2 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 11 May 2020 19:25:06 +0200 Subject: [PATCH] Added hex version checking to the project file to warn the user if opening a file 'from the future'. --- nw/__init__.py | 1 + nw/core/project.py | 18 ++++++++++++++++++ sample/sampleNovel/nwProject.nwx | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/nw/__init__.py b/nw/__init__.py index 85b5cab4..3330c6b6 100644 --- a/nw/__init__.py +++ b/nw/__init__.py @@ -41,6 +41,7 @@ __author__ = "Veronica Berglyd Olsen" __copyright__ = "Copyright 2018–2020, Veronica Berglyd Olsen" __license__ = "GPLv3" __version__ = "0.5" +__hexversion__ = "0x000500f0" __date__ = "2020-05-09" __maintainer__ = "Veronica Berglyd Olsen" __email__ = "code@vkbo.net" diff --git a/nw/core/project.py b/nw/core/project.py index ca1d7a55..32d0cfdd 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -39,6 +39,8 @@ from hashlib import sha256 from time import time from shutil import make_archive +from PyQt5.QtWidgets import QMessageBox + from nw.gui.tools import OptionState from nw.core.tools import projectMaintenance from nw.core.document import NWDoc @@ -285,12 +287,15 @@ class NWProject(): nwxRoot = xRoot.tag appVersion = "Unknown" + hexVersion = "0x0" fileVersion = "Unknown" self.saveCount = 0 self.autoCount = 0 if "appVersion" in xRoot.attrib: appVersion = xRoot.attrib["appVersion"] + if "hexVersion" in xRoot.attrib: + hexVersion = xRoot.attrib["hexVersion"] if "fileVersion" in xRoot.attrib: fileVersion = xRoot.attrib["fileVersion"] if "saveCount" in xRoot.attrib: @@ -308,6 +313,18 @@ class NWProject(): ) return False + if int(hexVersion, 16) > int(nw.__hexversion__, 16): + msgBox = QMessageBox() + msgRes = msgBox.question(self.theParent, "Version Conflict", ( + "This project was saved by a newer version of %s, version %s. This is version %s. " + "If you continue to open the project, some attributes and settings may not be " + "preserved. Continue opening the project?" + ) % ( + nw.__package__, appVersion, nw.__version__ + )) + if msgRes != QMessageBox.Yes: + return False + for xChild in xRoot: if xChild.tag == "project": logger.debug("Found project meta") @@ -397,6 +414,7 @@ class NWProject(): logger.debug("Writing project meta") nwXML = etree.Element("novelWriterXML",attrib={ "appVersion" : str(nw.__version__), + "hexVersion" : str(nw.__hexversion__), "fileVersion" : "1.0", "saveCount" : str(self.saveCount), "autoCount" : str(self.autoCount), diff --git a/sample/sampleNovel/nwProject.nwx b/sample/sampleNovel/nwProject.nwx index a452021d..ad764dec 100644 --- a/sample/sampleNovel/nwProject.nwx +++ b/sample/sampleNovel/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project