UI: FortSettings: Simplify .conf saving.

This commit is contained in:
Nodir Temirkhodjaev 2018-05-10 11:37:27 +05:00
parent 94347ef144
commit 272ecde7fe
4 changed files with 7 additions and 33 deletions

View File

@ -192,33 +192,18 @@ bool FortSettings::writeConf(const FirewallConf &conf)
return false;
}
if (!tryToWriteConf(conf, backupFilePath)) {
setErrorMessage(tr("Can't create backup .conf file"));
return false;
}
if (!FileUtil::removeFile(filePath)) {
setErrorMessage(tr("Can't remove .conf file"));
return false;
}
if (!FileUtil::copyFile(backupFilePath, filePath)) {
setErrorMessage(tr("Can't create .conf file"));
return false;
}
return true;
}
bool FortSettings::tryToWriteConf(const FirewallConf &conf, const QString &filePath)
{
const QJsonDocument jsonDoc = QJsonDocument::fromVariant(
conf.toVariant());
const QByteArray data = jsonDoc.toJson(QJsonDocument::Indented);
if (!FileUtil::writeFileData(backupFilePath, data)) {
setErrorMessage(tr("Can't create backup .conf file"));
return false;
}
if (!FileUtil::writeFileData(filePath, data)) {
setErrorMessage(tr("Can't write .conf file"));
setErrorMessage(tr("Can't create .conf file"));
return false;
}

View File

@ -111,7 +111,6 @@ private:
QString confBackupFilePath() const;
bool tryToReadConf(FirewallConf &conf, const QString &filePath);
bool tryToWriteConf(const FirewallConf &conf, const QString &filePath);
QVariant migrateConf(const QVariant &confVar);
void removeMigratedKeys();

Binary file not shown.

View File

@ -84,26 +84,16 @@
<source>Can&apos;t write .ini file</source>
<translation>Не удалось записать .ini файл</translation>
</message>
<message>
<location filename="../fortsettings.cpp" line="201"/>
<source>Can&apos;t remove .conf file</source>
<translation>Не удалось удалить .conf файл</translation>
</message>
<message>
<location filename="../fortsettings.cpp" line="206"/>
<source>Can&apos;t create .conf file</source>
<translation>Не удалось создать .conf файл</translation>
</message>
<message>
<location filename="../fortsettings.cpp" line="196"/>
<location filename="../fortsettings.cpp" line="201"/>
<source>Can&apos;t create backup .conf file</source>
<translation>Не удалось создать бэкап .conf файла</translation>
</message>
<message>
<location filename="../fortsettings.cpp" line="221"/>
<source>Can&apos;t write .conf file</source>
<translation>Не удалось записать .conf файл</translation>
</message>
</context>
<context>
<name>Ip4Range</name>