Check return value of 'virtual bool QFile::open(QIODeviceBase::OpenMode)'
Signed-off-by: Dylan Schooner <dschooner05@gmail.com>
This commit is contained in:
@@ -1968,7 +1968,9 @@ bool Application::handleDataMigration(const QString& currentData,
|
||||
|
||||
auto setDoNotMigrate = [&nomigratePath] {
|
||||
QFile file(nomigratePath);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
qWarning() << "setDoNotMigrate failed; Failed to open file '" << file.fileName() << "' for writing!";
|
||||
}
|
||||
};
|
||||
|
||||
// create no-migrate file if user doesn't want to migrate
|
||||
|
||||
@@ -1002,7 +1002,10 @@ QString createShortcut(QString destination, QString target, QStringList args, QS
|
||||
if (!destination.endsWith(".desktop")) // in case of isFlatpak destination is already populated
|
||||
destination += ".desktop";
|
||||
QFile f(destination);
|
||||
f.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qWarning() << "Failed to open file '" << f.fileName() << "' for writing!";
|
||||
return QString();
|
||||
}
|
||||
QTextStream stream(&f);
|
||||
|
||||
auto argstring = quoteArgs(args, "'", "'\\''");
|
||||
|
||||
@@ -15,7 +15,10 @@ void createOverrides(const QString& name, const QString& parent_folder, const QS
|
||||
FS::ensureFilePathExists(file_path);
|
||||
|
||||
QFile file(file_path);
|
||||
file.open(QFile::WriteOnly);
|
||||
if (!file.open(QFile::WriteOnly)) {
|
||||
qWarning() << "Failed to open file '" << file.fileName() << "' for writing!";
|
||||
return;
|
||||
}
|
||||
|
||||
QDirIterator override_iterator(override_path, QDirIterator::Subdirectories);
|
||||
while (override_iterator.hasNext()) {
|
||||
@@ -43,7 +46,10 @@ QStringList readOverrides(const QString& name, const QString& parent_folder)
|
||||
|
||||
QStringList previous_overrides;
|
||||
|
||||
file.open(QFile::ReadOnly);
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
qWarning() << "Failed to open file '" << file.fileName() << "' for reading!";
|
||||
return previous_overrides;
|
||||
}
|
||||
|
||||
QString entry;
|
||||
do {
|
||||
|
||||
@@ -153,25 +153,29 @@ void PackInstallTask::install()
|
||||
QFile packJson(m_stagingPath + "/minecraft/pack.json");
|
||||
QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods");
|
||||
if (packJson.exists()) {
|
||||
packJson.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
|
||||
packJson.close();
|
||||
if (packJson.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
|
||||
packJson.close();
|
||||
|
||||
// we only care about the libs
|
||||
QJsonArray libs = doc.object().value("libraries").toArray();
|
||||
// we only care about the libs
|
||||
QJsonArray libs = doc.object().value("libraries").toArray();
|
||||
|
||||
for (const auto& value : libs) {
|
||||
QString nameValue = value.toObject().value("name").toString();
|
||||
if (!nameValue.startsWith("net.minecraftforge")) {
|
||||
continue;
|
||||
for (const auto& value : libs) {
|
||||
QString nameValue = value.toObject().value("name").toString();
|
||||
if (!nameValue.startsWith("net.minecraftforge")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
GradleSpecifier forgeVersion(nameValue);
|
||||
|
||||
components->setComponentVersion("net.minecraftforge",
|
||||
forgeVersion.version().replace(m_pack.mcVersion, "").replace("-", ""));
|
||||
packJson.remove();
|
||||
fallback = false;
|
||||
break;
|
||||
}
|
||||
|
||||
GradleSpecifier forgeVersion(nameValue);
|
||||
|
||||
components->setComponentVersion("net.minecraftforge", forgeVersion.version().replace(m_pack.mcVersion, "").replace("-", ""));
|
||||
packJson.remove();
|
||||
fallback = false;
|
||||
break;
|
||||
} else {
|
||||
qWarning() << "Failed to open file '" << packJson.fileName() << "' for reading!";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,10 @@ auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString ex
|
||||
qint64 file_last_changed = finfo.lastModified().toUTC().toMSecsSinceEpoch();
|
||||
if (file_last_changed != entry->m_local_changed_timestamp) {
|
||||
QFile input(real_path);
|
||||
input.open(QIODevice::ReadOnly);
|
||||
if (!input.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Failed to open file '" << input.fileName() << "' for reading!";
|
||||
return staleEntry(base, resource_path);
|
||||
}
|
||||
QString md5sum = QCryptographicHash::hash(input.readAll(), QCryptographicHash::Md5).toHex().constData();
|
||||
if (entry->m_md5sum != md5sum) {
|
||||
selected_base.entry_list.remove(resource_path);
|
||||
|
||||
@@ -124,9 +124,14 @@ QString getCreditsHtml()
|
||||
QString getLicenseHtml()
|
||||
{
|
||||
QFile dataFile(":/documents/COPYING.md");
|
||||
dataFile.open(QIODevice::ReadOnly);
|
||||
QString output = markdownToHTML(dataFile.readAll());
|
||||
return output;
|
||||
if (dataFile.open(QIODevice::ReadOnly)) {
|
||||
QString output = markdownToHTML(dataFile.readAll());
|
||||
dataFile.close();
|
||||
return output;
|
||||
} else {
|
||||
qWarning() << "Failed to open file '" << dataFile.fileName() << "' for reading!";
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -48,7 +48,10 @@ class LibraryTest : public QObject {
|
||||
LibraryPtr readMojangJson(const QString path)
|
||||
{
|
||||
QFile jsonFile(path);
|
||||
jsonFile.open(QIODevice::ReadOnly);
|
||||
if (!jsonFile.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open file '" << jsonFile.fileName() << "' for reading!";
|
||||
return LibraryPtr();
|
||||
}
|
||||
auto data = jsonFile.readAll();
|
||||
jsonFile.close();
|
||||
ProblemContainer problems;
|
||||
|
||||
@@ -9,7 +9,10 @@ class MojangVersionFormatTest : public QObject {
|
||||
static QJsonDocument readJson(const QString path)
|
||||
{
|
||||
QFile jsonFile(path);
|
||||
jsonFile.open(QIODevice::ReadOnly);
|
||||
if (!jsonFile.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Failed to open file '" << jsonFile.fileName() << "' for reading!";
|
||||
return QJsonDocument();
|
||||
}
|
||||
auto data = jsonFile.readAll();
|
||||
jsonFile.close();
|
||||
return QJsonDocument::fromJson(data);
|
||||
@@ -17,7 +20,10 @@ class MojangVersionFormatTest : public QObject {
|
||||
static void writeJson(const char* file, QJsonDocument doc)
|
||||
{
|
||||
QFile jsonFile(file);
|
||||
jsonFile.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
if (!jsonFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qCritical() << "Failed to open file '" << jsonFile.fileName() << "' for writing!";
|
||||
return;
|
||||
}
|
||||
auto data = doc.toJson(QJsonDocument::Indented);
|
||||
qDebug() << QString::fromUtf8(data);
|
||||
jsonFile.write(data);
|
||||
|
||||
@@ -106,7 +106,10 @@ class VersionTest : public QObject {
|
||||
|
||||
QFile vector_file{ test_vector_dir.absoluteFilePath("test_vectors.txt") };
|
||||
|
||||
vector_file.open(QFile::OpenModeFlag::ReadOnly);
|
||||
if (!vector_file.open(QFile::OpenModeFlag::ReadOnly)) {
|
||||
qCritical() << "Failed to open file '" << vector_file.fileName() << "' for reading!";
|
||||
return;
|
||||
}
|
||||
|
||||
int test_number = 0;
|
||||
const QString test_name_template{ "FlexVer test #%1 (%2)" };
|
||||
|
||||
Reference in New Issue
Block a user