Merge pull request #15419 from Chocobo1/file

Improve error detection when saving files
This commit is contained in:
Chocobo1
2021-09-19 13:28:47 +08:00
committed by GitHub
17 changed files with 2610 additions and 104 deletions

View File

@@ -49,6 +49,7 @@
#include "base/rss/rss_session.h"
#include "base/utils/compare.h"
#include "base/utils/fs.h"
#include "base/utils/io.h"
#include "base/utils/string.h"
#include "gui/autoexpandabledialog.h"
#include "gui/torrentcategorydialog.h"
@@ -452,13 +453,12 @@ void AutomatedRssDownloader::on_exportBtn_clicked()
path += EXT_LEGACY;
}
QFile file {path};
if (!file.open(QFile::WriteOnly)
|| (file.write(RSS::AutoDownloader::instance()->exportRules(format)) == -1))
{
QMessageBox::critical(
this, tr("I/O Error")
, tr("Failed to create the destination file. Reason: %1").arg(file.errorString()));
const QByteArray rules = RSS::AutoDownloader::instance()->exportRules(format);
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(path, rules);
if (!result)
{
QMessageBox::critical(this, tr("I/O Error")
, tr("Failed to create the destination file. Reason: %1").arg(result.error()));
}
}