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
This commit is contained in:
wmayer
2025-03-10 18:05:52 +01:00
committed by Ladislav Michl
parent cafd4a4fc3
commit 0efd60b654

View File

@@ -49,6 +49,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/ProjectFile.h>
#include <Base/Exception.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
@@ -164,6 +165,7 @@ public:
QList<Info> 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;