From ca639a6913d6f979255261c3355ec000c6b4bf97 Mon Sep 17 00:00:00 2001 From: siliconninja Date: Mon, 5 Aug 2019 13:27:43 -0400 Subject: [PATCH] Issue #1397: File contents are now kept if load fails, add "no pages" loading error The "Rephrase error message (thanks to Technius!)" commit on the issue_1397_archive branch is included in this PR. Because that change is minor, I squashed everything into 1 commit. --- src/control/Control.cpp | 4 ++-- src/control/xojfile/LoadHandler.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/control/Control.cpp b/src/control/Control.cpp index ba073d7e..f953dad8 100644 --- a/src/control/Control.cpp +++ b/src/control/Control.cpp @@ -2316,8 +2316,6 @@ bool Control::openFile(Path filename, int scrollToPage, bool forceOpen) } } - this->closeDocument(); - // Read template file if (filename.hasExtension(".xopt")) { @@ -2381,6 +2379,8 @@ bool Control::openFile(Path filename, int scrollToPage, bool forceOpen) } else { + this->closeDocument(); + this->doc->lock(); this->doc->clearDocument(); *this->doc = *loadedDocument; diff --git a/src/control/xojfile/LoadHandler.cpp b/src/control/xojfile/LoadHandler.cpp index de3ef8e7..782ac6e2 100644 --- a/src/control/xojfile/LoadHandler.cpp +++ b/src/control/xojfile/LoadHandler.cpp @@ -298,6 +298,11 @@ bool LoadHandler::parseXml() lastError = _("Document is not complete (maybe the end is cut off?)"); return false; } + else if (this->pos == PASER_POS_FINISHED && this->doc.getPageCount() == 0) + { + lastError = _("Document is corrupted (no pages found in file)"); + return false; + } doc.setCreateBackupOnSave(this->fileVersion >= 3);