From 78992ee762feb62fa822afa335825c9ef9d56933 Mon Sep 17 00:00:00 2001 From: Claveau Joshua Date: Sun, 2 Aug 2020 22:24:46 +0200 Subject: [PATCH] Fix backup file on windows For unknown reason KautoSaveFile don't write the file on Windows if file is open in another part of the code. No error is returned and use the method : qint64 QIODevice::write(const QByteArray &byteArray) return the good number of bytes written but the real file stay empty. Probably the problem don't come from KautoSaveFile but QFileDevice or QIODevice on windows. The fix consist to open the file just before write on it and close it just after. --- sources/qetproject.cpp | 22 +++++----------------- sources/qetproject.h | 4 +++- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index e30f1ac9f..a423e0c05 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2020 The QElectroTech Team This file is part of QElectroTech. @@ -33,7 +33,6 @@ #include #include #include -#include static int BACKUP_INTERVAL = 120000; //interval in ms of backup = 2min @@ -263,17 +262,11 @@ void QETProject::setFilePath(const QString &filepath) return; } - if (m_backup_file) - { - delete m_backup_file; - m_backup_file = nullptr; + if (m_backup_file.isOpen()) { + m_backup_file.close(); } + m_backup_file.setManagedFile(QUrl::fromLocalFile(filepath)); - m_backup_file = new KAutoSaveFile(QUrl::fromLocalFile(filepath), this); - if (!m_backup_file->open(QIODevice::WriteOnly)) { - delete m_backup_file; - m_backup_file = nullptr; - } m_file_path = filepath; QFileInfo fi(m_file_path); @@ -1613,13 +1606,8 @@ NamesList QETProject::namesListForIntegrationCategory() { */ void QETProject::writeBackup() { - if (!m_backup_file || - (!m_backup_file->isOpen() && !m_backup_file->open(QIODevice::ReadWrite))) { - return; - } - QDomDocument xml_project(toXml()); - QET::writeToFile(xml_project, m_backup_file); + QET::writeToFile(xml_project, &m_backup_file); } /** diff --git a/sources/qetproject.h b/sources/qetproject.h index af1f8b687..00e39ec58 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -28,6 +28,8 @@ #include "projectdatabase.h" #include "reportproperties.h" +#include + class Diagram; class ElementsLocation; class QETResult; @@ -264,7 +266,7 @@ class QETProject : public QObject bool m_freeze_new_conductors = false; QTimer m_save_backup_timer, m_autosave_timer; - KAutoSaveFile *m_backup_file = nullptr; + KAutoSaveFile m_backup_file; QUuid m_uuid = QUuid::createUuid(); projectDataBase m_data_base; };