From 0efd60b65462e576b6df3ac372bd936e760e3c4c Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 10 Mar 2025 18:05:52 +0100 Subject: [PATCH] Gui: Improve document recovery When checking for recovery files also check for validity of the actual project file. In case it's broken but has a never date then still process the recovery file. This is done to reduce the chance of data loss as described in issue 18044 --- src/Gui/DocumentRecovery.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index 539cddecbe..642f730332 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -164,6 +165,7 @@ public: QList recoveryInfo; Info getRecoveryInfo(const QFileInfo&) const; + bool isValidProject(const QFileInfo&) const; void writeRecoveryInfo(const Info&) const; XmlConfig readXmlFile(const QString& fn) const; }; @@ -433,7 +435,7 @@ DocumentRecoveryPrivate::Info DocumentRecoveryPrivate::getRecoveryInfo(const QFi if (info.status == DocumentRecoveryPrivate::Created) { // compare the modification dates QFileInfo fileInfo(info.fileName); - if (!info.fileName.isEmpty() && fileInfo.exists()) { + if (!info.fileName.isEmpty() && isValidProject(fileInfo)) { QDateTime dateRecv = QFileInfo(file).lastModified(); QDateTime dateProj = fileInfo.lastModified(); if (dateRecv < dateProj) { @@ -449,6 +451,16 @@ DocumentRecoveryPrivate::Info DocumentRecoveryPrivate::getRecoveryInfo(const QFi return info; } +bool DocumentRecoveryPrivate::isValidProject(const QFileInfo& fi) const +{ + if (!fi.exists()) { + return false; + } + + App::ProjectFile project(fi.absoluteFilePath().toStdString()); + return project.loadDocument(); +} + DocumentRecoveryPrivate::XmlConfig DocumentRecoveryPrivate::readXmlFile(const QString& fn) const { DocumentRecoveryPrivate::XmlConfig cfg;