Improve error detection when saving files

This commit is contained in:
Chocobo1 2021-09-03 22:56:19 +08:00
parent 6a6268c068
commit 81139c0098
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
5 changed files with 21 additions and 23 deletions

View file

@ -452,13 +452,12 @@ void AutomatedRssDownloader::on_exportBtn_clicked()
path += EXT_LEGACY;
}
const QByteArray rules {RSS::AutoDownloader::instance()->exportRules(format)};
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()));
if (!file.open(QFile::WriteOnly) || (file.write(rules) != rules.length()))
{
QMessageBox::critical(this, tr("I/O Error")
, tr("Failed to create the destination file. Reason: %1").arg(file.errorString()));
}
}