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] {
|
auto setDoNotMigrate = [&nomigratePath] {
|
||||||
QFile file(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
|
// 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
|
if (!destination.endsWith(".desktop")) // in case of isFlatpak destination is already populated
|
||||||
destination += ".desktop";
|
destination += ".desktop";
|
||||||
QFile f(destination);
|
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);
|
QTextStream stream(&f);
|
||||||
|
|
||||||
auto argstring = quoteArgs(args, "'", "'\\''");
|
auto argstring = quoteArgs(args, "'", "'\\''");
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ void createOverrides(const QString& name, const QString& parent_folder, const QS
|
|||||||
FS::ensureFilePathExists(file_path);
|
FS::ensureFilePathExists(file_path);
|
||||||
|
|
||||||
QFile file(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);
|
QDirIterator override_iterator(override_path, QDirIterator::Subdirectories);
|
||||||
while (override_iterator.hasNext()) {
|
while (override_iterator.hasNext()) {
|
||||||
@@ -43,7 +46,10 @@ QStringList readOverrides(const QString& name, const QString& parent_folder)
|
|||||||
|
|
||||||
QStringList previous_overrides;
|
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;
|
QString entry;
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ void PackInstallTask::install()
|
|||||||
QFile packJson(m_stagingPath + "/minecraft/pack.json");
|
QFile packJson(m_stagingPath + "/minecraft/pack.json");
|
||||||
QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods");
|
QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods");
|
||||||
if (packJson.exists()) {
|
if (packJson.exists()) {
|
||||||
packJson.open(QIODevice::ReadOnly | QIODevice::Text);
|
if (packJson.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
|
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
|
||||||
packJson.close();
|
packJson.close();
|
||||||
|
|
||||||
@@ -168,11 +168,15 @@ void PackInstallTask::install()
|
|||||||
|
|
||||||
GradleSpecifier forgeVersion(nameValue);
|
GradleSpecifier forgeVersion(nameValue);
|
||||||
|
|
||||||
components->setComponentVersion("net.minecraftforge", forgeVersion.version().replace(m_pack.mcVersion, "").replace("-", ""));
|
components->setComponentVersion("net.minecraftforge",
|
||||||
|
forgeVersion.version().replace(m_pack.mcVersion, "").replace("-", ""));
|
||||||
packJson.remove();
|
packJson.remove();
|
||||||
fallback = false;
|
fallback = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
qWarning() << "Failed to open file '" << packJson.fileName() << "' for reading!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jarmodDir.exists()) {
|
if (jarmodDir.exists()) {
|
||||||
|
|||||||
@@ -112,7 +112,10 @@ auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString ex
|
|||||||
qint64 file_last_changed = finfo.lastModified().toUTC().toMSecsSinceEpoch();
|
qint64 file_last_changed = finfo.lastModified().toUTC().toMSecsSinceEpoch();
|
||||||
if (file_last_changed != entry->m_local_changed_timestamp) {
|
if (file_last_changed != entry->m_local_changed_timestamp) {
|
||||||
QFile input(real_path);
|
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();
|
QString md5sum = QCryptographicHash::hash(input.readAll(), QCryptographicHash::Md5).toHex().constData();
|
||||||
if (entry->m_md5sum != md5sum) {
|
if (entry->m_md5sum != md5sum) {
|
||||||
selected_base.entry_list.remove(resource_path);
|
selected_base.entry_list.remove(resource_path);
|
||||||
|
|||||||
@@ -124,9 +124,14 @@ QString getCreditsHtml()
|
|||||||
QString getLicenseHtml()
|
QString getLicenseHtml()
|
||||||
{
|
{
|
||||||
QFile dataFile(":/documents/COPYING.md");
|
QFile dataFile(":/documents/COPYING.md");
|
||||||
dataFile.open(QIODevice::ReadOnly);
|
if (dataFile.open(QIODevice::ReadOnly)) {
|
||||||
QString output = markdownToHTML(dataFile.readAll());
|
QString output = markdownToHTML(dataFile.readAll());
|
||||||
|
dataFile.close();
|
||||||
return output;
|
return output;
|
||||||
|
} else {
|
||||||
|
qWarning() << "Failed to open file '" << dataFile.fileName() << "' for reading!";
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -48,7 +48,10 @@ class LibraryTest : public QObject {
|
|||||||
LibraryPtr readMojangJson(const QString path)
|
LibraryPtr readMojangJson(const QString path)
|
||||||
{
|
{
|
||||||
QFile jsonFile(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();
|
auto data = jsonFile.readAll();
|
||||||
jsonFile.close();
|
jsonFile.close();
|
||||||
ProblemContainer problems;
|
ProblemContainer problems;
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ class MojangVersionFormatTest : public QObject {
|
|||||||
static QJsonDocument readJson(const QString path)
|
static QJsonDocument readJson(const QString path)
|
||||||
{
|
{
|
||||||
QFile jsonFile(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();
|
auto data = jsonFile.readAll();
|
||||||
jsonFile.close();
|
jsonFile.close();
|
||||||
return QJsonDocument::fromJson(data);
|
return QJsonDocument::fromJson(data);
|
||||||
@@ -17,7 +20,10 @@ class MojangVersionFormatTest : public QObject {
|
|||||||
static void writeJson(const char* file, QJsonDocument doc)
|
static void writeJson(const char* file, QJsonDocument doc)
|
||||||
{
|
{
|
||||||
QFile jsonFile(file);
|
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);
|
auto data = doc.toJson(QJsonDocument::Indented);
|
||||||
qDebug() << QString::fromUtf8(data);
|
qDebug() << QString::fromUtf8(data);
|
||||||
jsonFile.write(data);
|
jsonFile.write(data);
|
||||||
|
|||||||
@@ -106,7 +106,10 @@ class VersionTest : public QObject {
|
|||||||
|
|
||||||
QFile vector_file{ test_vector_dir.absoluteFilePath("test_vectors.txt") };
|
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;
|
int test_number = 0;
|
||||||
const QString test_name_template{ "FlexVer test #%1 (%2)" };
|
const QString test_name_template{ "FlexVer test #%1 (%2)" };
|
||||||
|
|||||||
Reference in New Issue
Block a user