mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
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.
This commit is contained in:
parent
7a04788d54
commit
78992ee762
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@ -33,7 +33,6 @@
|
||||
#include <QTimer>
|
||||
#include <QStandardPaths>
|
||||
#include <utility>
|
||||
#include <KAutoSaveFile>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "projectdatabase.h"
|
||||
#include "reportproperties.h"
|
||||
|
||||
#include <KAutoSaveFile>
|
||||
|
||||
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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user