Handle return value of QFile::open

This commit is contained in:
2026-04-12 10:19:40 +02:00
parent ef8b3d7668
commit 63149745ed
3 changed files with 21 additions and 15 deletions
+9 -7
View File
@@ -15,11 +15,13 @@ About::About(QWidget *parent) : QDialog(parent)
QLabel *label = new QLabel(this); QLabel *label = new QLabel(this);
QFile tenmonText(":/about/tenmon"); QFile tenmonText(":/about/tenmon");
tenmonText.open(QIODevice::ReadOnly); if(tenmonText.open(QIODevice::ReadOnly))
QByteArray text = tenmonText.readAll(); {
text.replace("@GITVERSION@", GITVERSION); QByteArray text = tenmonText.readAll();
label->setText(text); text.replace("@GITVERSION@", GITVERSION);
label->setOpenExternalLinks(true); label->setText(text);
label->setOpenExternalLinks(true);
}
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
@@ -41,8 +43,8 @@ HelpDialog::HelpDialog(QWidget *parent) : QDialog(parent)
layout->addWidget(helpText); layout->addWidget(helpText);
QFile tenmonText(":/help"); QFile tenmonText(":/help");
tenmonText.open(QIODevice::ReadOnly); if(tenmonText.open(QIODevice::ReadOnly))
helpText->setHtml(tenmonText.readAll()); helpText->setHtml(tenmonText.readAll());
} }
QString getVersion() QString getVersion()
+10 -6
View File
@@ -345,18 +345,22 @@ Download::Download(QNetworkReply *reply, const QString indexPath, QObject *paren
filename.remove(QRegularExpression("\\.zst$")); filename.remove(QRegularExpression("\\.zst$"));
_fw.setFileName(indexPath + "/" + filename); _fw.setFileName(indexPath + "/" + filename);
_fw.open(QIODevice::WriteOnly | QIODevice::Truncate); if(_fw.open(QIODevice::WriteOnly | QIODevice::Truncate))
if(_fw.isOpen())
{ {
qDebug() << "open file" << _fw.fileName(); qDebug() << "open file" << _fw.fileName();
_dstream = ZSTD_createDStream();
}
else
{
qWarning() << "Failed to open file" << _fw.fileName();
abort();
} }
_dstream = ZSTD_createDStream();
} }
Download::~Download() Download::~Download()
{ {
ZSTD_freeDStream(_dstream); if(_dstream)
ZSTD_freeDStream(_dstream);
} }
void Download::abort() void Download::abort()
@@ -402,7 +406,7 @@ void Download::finished()
void Download::decompress(QByteArray &data) void Download::decompress(QByteArray &data)
{ {
if(data.isEmpty())return; if(data.isEmpty() || _dstream == nullptr)return;
_hash.addData(data); _hash.addData(data);
+2 -2
View File
@@ -11,8 +11,8 @@
class Download : public QObject class Download : public QObject
{ {
Q_OBJECT Q_OBJECT
QNetworkReply *_reply; QNetworkReply *_reply = nullptr;
ZSTD_DStream *_dstream; ZSTD_DStream *_dstream = nullptr;
QFile _fw; QFile _fw;
QCryptographicHash _hash; QCryptographicHash _hash;
public: public: