Replace QFile::exists by QFileInfo::exists

QFile::exists only calls QFileInfo::exists, so this saves one
function call per invocation.

Change-Id: I41cb407345654eeead14455a4955b8b9b015aedc
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-09-01 11:23:56 +02:00
parent 3d028125df
commit 9679412a23
40 changed files with 53 additions and 53 deletions

View File

@@ -1475,7 +1475,7 @@ public:
static std::optional<QString> lockedPluginName(PluginManagerPrivate *pm)
{
const QString lockFilePath = LockFile::filePath(pm);
if (QFile::exists(lockFilePath)) {
if (QFileInfo::exists(lockFilePath)) {
QFile f(lockFilePath);
if (f.open(QIODevice::ReadOnly)) {
const auto pluginName = QString::fromUtf8(f.readLine()).trimmed();

View File

@@ -259,7 +259,7 @@ void ContextPaneWidgetImage::setProperties(QmlJS::PropertyReader *propertyReader
if (propertyReader->hasProperty(QLatin1String("source"))) {
QString source = propertyReader->readProperty(QLatin1String("source")).toString();
m_fileWidget->setFileName(source);
if (QFile::exists(m_path + QLatin1Char('/') + source))
if (QFileInfo::exists(m_path + QLatin1Char('/') + source))
setPixmap(m_path + QLatin1Char('/') + source);
else
setPixmap(source);

View File

@@ -505,7 +505,7 @@ bool MimeBinaryProvider::loadMimeTypePrivate(MimeTypePrivate &data)
// shared-mime-info since 1.3 lowercases the xml files
QString mimeFile = m_directory + QLatin1Char('/') + data.name.toLower() + QLatin1String(".xml");
if (!QFile::exists(mimeFile))
if (!QFileInfo::exists(mimeFile))
mimeFile = m_directory + QLatin1Char('/') + data.name + QLatin1String(".xml"); // pre-1.3
QFile qfile(mimeFile);

View File

@@ -111,7 +111,7 @@ bool SaveFile::commit()
if (!result) {
DWORD replaceErrorCode = GetLastError();
QString errorStr;
if (!QFile::exists(finalFileName)) {
if (!QFileInfo::exists(finalFileName)) {
// Replace failed because finalFileName does not exist, try rename.
if (!(result = rename(finalFileName)))
errorStr = errorString();
@@ -148,7 +148,7 @@ bool SaveFile::commit()
// Back up current file.
// If it's opened by another application, the lock follows the move.
if (QFile::exists(finalFileName)) {
if (QFileInfo::exists(finalFileName)) {
// Kill old backup. Might be useful if creator crashed before removing backup.
QFile::remove(backupName);
QFile finalFile(finalFileName);

View File

@@ -847,7 +847,7 @@ QString StyleHelper::dpiSpecificImageFile(const QString &fileName)
if (qApp->devicePixelRatio() > 1.0) {
const QString atDprfileName =
imageFileWithResolution(fileName, qRound(qApp->devicePixelRatio()));
if (QFile::exists(atDprfileName))
if (QFileInfo::exists(atDprfileName))
return atDprfileName;
}
return fileName;
@@ -867,7 +867,7 @@ QList<int> StyleHelper::availableImageResolutions(const QString &fileName)
QList<int> result;
const int maxResolutions = qApp->devicePixelRatio();
for (int i = 1; i <= maxResolutions; ++i)
if (QFile::exists(imageFileWithResolution(fileName, i)))
if (QFileInfo::exists(imageFileWithResolution(fileName, i)))
result.append(i);
return result;
}

View File

@@ -48,10 +48,10 @@ static FilePath sdkFromUrl(const QUrl &url)
if (basename.isEmpty())
basename = "sdk-tools.zip";
if (QFile::exists(basename)) {
if (QFileInfo::exists(basename)) {
int i = 0;
basename += '.';
while (QFile::exists(basename + QString::number(i)))
while (QFileInfo::exists(basename + QString::number(i)))
++i;
basename += QString::number(i);
}

View File

@@ -828,7 +828,7 @@ QStringList ClearCasePluginPrivate::ccGetActiveVobs() const
// Snapshot views does not necessarily have all active VOBs loaded, so we'll have to
// check if the dirs exists as well. Else the command will work, but the output will
// complain about the element not being loaded.
if (QFile::exists(prefix + relativeDir))
if (QFileInfo::exists(prefix + relativeDir))
res.append(relativeDir);
}
return res;

View File

@@ -391,7 +391,7 @@ void CompilationDatabaseBuildSystem::buildTreeAndProjectParts()
root->addNode(std::make_unique<FileNode>(projectFilePath(), FileType::Project));
if (QFile::exists(dbContents.extraFileName))
if (QFileInfo::exists(dbContents.extraFileName))
root->addNode(std::make_unique<FileNode>(Utils::FilePath::fromString(dbContents.extraFileName),
FileType::Project));

View File

@@ -228,7 +228,7 @@ void SourceSettings::fillLanguageIdModel(StringSelectionAspect::ResultCallback c
auto *newItem = new QStandardItem(language.name);
newItem->setData(language.id);
if (QFile::exists(":/compilerexplorer/logos/" + language.logoUrl)) {
if (QFileInfo::exists(":/compilerexplorer/logos/" + language.logoUrl)) {
QIcon icon(":/compilerexplorer/logos/" + language.logoUrl);
newItem->setIcon(icon);
}

View File

@@ -957,7 +957,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
stream >> historyData;
view()->m_editorHistory = loadHistory(historyData);
if (!QFile::exists(fileName))
if (!QFileInfo::exists(fileName))
return;
IEditor *e = EditorManagerPrivate::openEditor(view(), FilePath::fromString(fileName), Id::fromString(id),
EditorManager::IgnoreNavigationHistory

View File

@@ -174,7 +174,7 @@ static bool hasQmFilesForLocale(const QString &locale, const QString &creatorTrP
static const QString qtTrPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
const QString trFile = QLatin1String("/qt_") + locale + QLatin1String(".qm");
return QFile::exists(qtTrPath + trFile) || QFile::exists(creatorTrPath + trFile);
return QFileInfo::exists(qtTrPath + trFile) || QFileInfo::exists(creatorTrPath + trFile);
}
void GeneralSettingsWidget::fillLanguageBox() const

View File

@@ -633,7 +633,7 @@ void MimeTypeSettingsPrivate::writeUserModifiedMimeTypes()
{
static Utils::FilePath modifiedMimeTypesFile = ICore::userResourcePath(kModifiedMimeTypesFile);
if (QFile::exists(modifiedMimeTypesFile.toString())
if (QFileInfo::exists(modifiedMimeTypesFile.toString())
|| QDir().mkpath(modifiedMimeTypesFile.parentDir().toString())) {
QFile file(modifiedMimeTypesFile.toString());
if (file.open(QFile::WriteOnly | QFile::Truncate)) {

View File

@@ -109,7 +109,7 @@ public:
bool isComplete() const final
{
const FilePath path = m_data->sourcePath;
if (!QFile::exists(path.toString())) {
if (!QFileInfo::exists(path.toString())) {
m_info->setText(Tr::tr("File does not exist."));
return false;
}

View File

@@ -376,7 +376,7 @@ void CompilerOptionsBuilder::addHeaderPathOptions()
void CompilerOptionsBuilder::addIncludeFile(const QString &file)
{
if (QFile::exists(file)) {
if (QFileInfo::exists(file)) {
add({isClStyle() ? QLatin1String(includeFileOptionCl)
: QLatin1String(includeFileOptionGcc),
QDir::toNativeSeparators(file)});

View File

@@ -120,7 +120,7 @@ GDB 32bit | Api | Api | NA | Win32
const QString executable = breakApi == UseWin32Interrupt
? QCoreApplication::applicationDirPath() + "/win32interrupt.exe"
: QCoreApplication::applicationDirPath() + "/win64interrupt.exe";
if (!QFile::exists(executable)) {
if (!QFileInfo::exists(executable)) {
*errorMessage = QString::fromLatin1(
"%1 does not exist. If you have built %2 "
"on your own, checkout "

View File

@@ -916,7 +916,7 @@ void setQtPluginPath(const QString &qtPluginPath)
*sQtPluginPath = Utils::trimBack(*sQtPluginPath, '/');
if (sQtPluginPath->endsWith(postfix))
sQtPluginPath->chop(postfix.size());
if (!QFile::exists(*sQtPluginPath + postfix)) {
if (!QFileInfo::exists(*sQtPluginPath + postfix)) {
qWarning() << qPrintable(
QLatin1String(
"Warning: The path \"%1\" passed to -designer-qt-pluginpath does not exist. "

View File

@@ -2529,7 +2529,7 @@ FilePath GitClient::gitBinDirectory() const
// Git for Windows uses Git/usr/bin. Prefer that if it exists.
QString usrBinPath = path;
usrBinPath.replace(usrBinPath.size() - 3, 3, "usr/bin");
if (QFile::exists(usrBinPath))
if (QFileInfo::exists(usrBinPath))
path = usrBinPath;
}
}

View File

@@ -372,7 +372,7 @@ void MacroManager::saveLastMacro()
QString MacroManager::macrosDirectory()
{
const QString path = Core::ICore::userResourcePath("macros").toString();
if (QFile::exists(path) || QDir().mkpath(path))
if (QFileInfo::exists(path) || QDir().mkpath(path))
return path;
return QString();
}

View File

@@ -24,7 +24,7 @@ namespace Internal {
template<typename File_t>
bool containsFiles(const QString &path, const File_t &file)
{
return QFile::exists(QString("%1/%2").arg(path).arg(file));
return QFileInfo::exists(QString("%1/%2").arg(path).arg(file));
}
template<typename File_t, typename... T>

View File

@@ -163,7 +163,7 @@ GDB 32bit | Api | Api | N/A | Win32
executable += si == Win32Interrupt
? QLatin1String("/win32interrupt.exe")
: QLatin1String("/win64interrupt.exe");
if (!QFile::exists(executable)) {
if (!QFileInfo::exists(executable)) {
appendMsgCannotInterrupt(pid,
Tr::tr("%1 does not exist. If you built %2 "
"yourself, check out https://code.qt.io/cgit/"

View File

@@ -1210,8 +1210,8 @@ void MsvcToolChain::rescanForCompiler()
env.searchInPath(QLatin1String("cl.exe"), {}, [](const Utils::FilePath &name) {
QDir dir(QDir::cleanPath(name.toFileInfo().absolutePath() + QStringLiteral("/..")));
do {
if (QFile::exists(dir.absoluteFilePath(QStringLiteral("vcvarsall.bat")))
|| QFile::exists(dir.absolutePath() + "/Auxiliary/Build/vcvarsall.bat"))
if (QFileInfo::exists(dir.absoluteFilePath(QStringLiteral("vcvarsall.bat")))
|| QFileInfo::exists(dir.absolutePath() + "/Auxiliary/Build/vcvarsall.bat"))
return true;
} while (dir.cdUp() && !dir.isRoot());
return false;

View File

@@ -1917,7 +1917,7 @@ FilePaths QmakeProFile::subDirsPaths(QtSupport::ProFileReader *reader,
else
realFile = realDir;
if (QFile::exists(realFile)) {
if (QFileInfo::exists(realFile)) {
realFile = QDir::cleanPath(realFile);
subProjectPaths << FilePath::fromString(realFile);
if (subProjectsNotToDeploy && !subProjectsNotToDeploy->contains(realFile)

View File

@@ -115,7 +115,7 @@ void AssetsLibraryModel::deleteFiles(const QStringList &filePaths, bool dontAskA
QmlDesignerPlugin::settings().insert(DesignerSettingsKey::ASK_BEFORE_DELETING_ASSET, false);
for (const QString &filePath : filePaths) {
if (QFile::exists(filePath) && !QFile::remove(filePath)) {
if (QFileInfo::exists(filePath) && !QFile::remove(filePath)) {
QMessageBox::warning(Core::ICore::dialogParent(),
tr("Failed to Delete File"),
tr("Could not delete \"%1\".").arg(filePath));

View File

@@ -86,7 +86,7 @@ bool fileComponentExists(const ModelNode &modelNode)
if (fileName.contains("qml/QtQuick"))
return false;
return QFile::exists(fileName);
return QFileInfo::exists(fileName);
}
bool selectionIsComponent(const SelectionContext &selectionState)

View File

@@ -291,7 +291,7 @@ void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
for (const QString &s : std::as_const(sharedFiles)) {
const QString fullSharedFilePath = matBundleDir.filePath(s);
if (!QFile::exists(fullSharedFilePath))
if (!QFileInfo::exists(fullSharedFilePath))
missingSharedFiles.push_back(s);
}

View File

@@ -165,7 +165,7 @@ void LocalQmlProfilerRunnerTest::testFindFreeSocket()
QUrl serverUrl = Utils::urlFromLocalSocket();
QString socket = serverUrl.path();
QVERIFY(!socket.isEmpty());
QVERIFY(!QFile::exists(socket));
QVERIFY(!QFileInfo::exists(socket));
QFile file(socket);
QVERIFY(file.open(QIODevice::WriteOnly));
file.close();

View File

@@ -822,7 +822,7 @@ static QString qtVersionsFile(const QString &baseDir)
static std::optional<FilePath> currentlyLinkedQtDir(bool *hasInstallSettings)
{
const QString installSettingsFilePath = settingsFile(Core::ICore::resourcePath().toString());
const bool installSettingsExist = QFile::exists(installSettingsFilePath);
const bool installSettingsExist = QFileInfo::exists(installSettingsFilePath);
if (hasInstallSettings)
*hasInstallSettings = installSettingsExist;
if (installSettingsExist) {
@@ -934,8 +934,8 @@ static std::optional<FilePath> settingsDirForQtDir(const FilePath &baseDirectory
return qtDir / dir;
});
const FilePath validDir = Utils::findOrDefault(dirsToCheck, [baseDirectory](const FilePath &dir) {
return QFile::exists(settingsFile(baseDirectory.resolvePath(dir).toString()))
|| QFile::exists(qtVersionsFile(baseDirectory.resolvePath(dir).toString()));
return QFileInfo::exists(settingsFile(baseDirectory.resolvePath(dir).toString()))
|| QFileInfo::exists(qtVersionsFile(baseDirectory.resolvePath(dir).toString()));
});
if (!validDir.isEmpty())
return validDir;

View File

@@ -229,7 +229,7 @@ QString ResolveLocationContext::execCopyFileDialog(QWidget *parent, const QDir &
// Helper to copy a file with message boxes
static inline bool copyFile(const QString &file, const QString &copyName, QWidget *parent)
{
if (QFile::exists(copyName)) {
if (QFileInfo::exists(copyName)) {
if (!QFile::remove(copyName)) {
QMessageBox::critical(parent, Tr::tr("Overwriting Failed"),
Tr::tr("Could not overwrite file %1.")

View File

@@ -50,7 +50,7 @@ void File::checkExistence()
bool File::exists()
{
if (!m_checked) {
m_exists = QFile::exists(name);
m_exists = QFileInfo::exists(name);
m_checked = true;
}
@@ -363,7 +363,7 @@ bool ResourceFile::renameFile(const QString &fileName, const QString &newFileNam
}
if (success) {
const bool exists = QFile::exists(newFileName);
const bool exists = QFileInfo::exists(newFileName);
for (File *file : std::as_const(entries)) {
file->name = newFileName;
file->setExists(exists);
@@ -1230,7 +1230,7 @@ EntryBackup * RelativeResourceModel::removeEntry(const QModelIndex &index)
} else {
const QString fileNameBackup = file(index);
const QString aliasBackup = alias(index);
if (!QFile::exists(fileNameBackup)) {
if (!QFileInfo::exists(fileNameBackup)) {
deleteItem(index);
return new FileEntryBackup(*this, prefixIndex.row(), index.row(), fileNameBackup, aliasBackup);
}

View File

@@ -349,7 +349,7 @@ bool ScxmlDocument::pasteData(const QByteArray &data, const QPointF &minPos, con
void ScxmlDocument::load(const QString &fileName)
{
if (QFile::exists(fileName)) {
if (QFileInfo::exists(fileName)) {
QFile file(fileName);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
if (load(&file)) {

View File

@@ -778,7 +778,7 @@ void MemcheckToolPrivate::heobAction()
// heob executable
const QString heob = QString("heob%1.exe").arg(abi.wordWidth());
const QString heobPath = dialog.path() + '/' + heob;
if (!QFile::exists(heobPath)) {
if (!QFileInfo::exists(heobPath)) {
QMessageBox::critical(
Core::ICore::dialogParent(),
Tr::tr("Heob"),
@@ -791,7 +791,7 @@ void MemcheckToolPrivate::heobAction()
if (abi.osFlavor() == Abi::WindowsMSysFlavor) {
const QString dwarfstack = QString("dwarfstack%1.dll").arg(abi.wordWidth());
const QString dwarfstackPath = dialog.path() + '/' + dwarfstack;
if (!QFile::exists(dwarfstackPath)
if (!QFileInfo::exists(dwarfstackPath)
&& CheckableMessageBox::information(
Core::ICore::dialogParent(),
Tr::tr("Heob"),

View File

@@ -91,7 +91,7 @@ static QString makeFrameName(const Frame &frame, bool withLocation)
else
path = frame.object();
if (QFile::exists(path))
if (QFileInfo::exists(path))
path = QFileInfo(path).canonicalFilePath();
if (frame.line() != -1)

View File

@@ -1156,7 +1156,7 @@ void VcsBaseEditorWidget::jumpToChangeFromDiff(QTextCursor cursor)
return;
const QString fileName = findDiffFile(fileNameFromDiffSpecification(block));
const bool exists = fileName.isEmpty() ? false : QFile::exists(fileName);
const bool exists = fileName.isEmpty() ? false : QFileInfo::exists(fileName);
if (!exists)
return;

View File

@@ -79,7 +79,7 @@ QString QMakeGlobals::cleanSpec(QMakeCmdLineParserState &state, const QString &s
QString ret = QDir::cleanPath(spec);
if (ret.contains(QLatin1Char('/'))) {
QString absRet = IoUtils::resolvePath(device_root, state.pwd, ret);
if (QFile::exists(absRet))
if (QFileInfo::exists(absRet))
ret = absRet;
}
return ret;

View File

@@ -554,7 +554,7 @@ int main(int argc, char *argv[])
// Process files
const QStringList files = args;
for (const QString &fileName : files) {
if (! QFile::exists(fileName)) {
if (! QFileInfo::exists(fileName)) {
std::cerr << "Error: File \"" << qPrintable(fileName) << "\" does not exist."
<< std::endl;
exit(EXIT_FAILURE);

View File

@@ -76,7 +76,7 @@ SystemPreprocessor::SystemPreprocessor(bool verbose)
void SystemPreprocessor::check() const
{
QTextStream out(stderr);
if (!QFile::exists(QLatin1String(PATH_PREPROCESSOR_CONFIG))) {
if (!QFileInfo::exists(QLatin1String(PATH_PREPROCESSOR_CONFIG))) {
out << QString::fromLatin1("Error: File \"%1\" does not exist.")
.arg(QLatin1String(PATH_PREPROCESSOR_CONFIG))
<< Qt::endl;
@@ -94,7 +94,7 @@ void SystemPreprocessor::check() const
void SystemPreprocessor::preprocessFile(const QString &inputFile, const QString &outputFile) const
{
check();
if (!QFile::exists(inputFile)) {
if (!QFileInfo::exists(inputFile)) {
QTextStream out(stderr);
out << QString::fromLatin1("Error: File \"%1\" does not exist.").arg(inputFile) << Qt::endl;
exit(EXIT_FAILURE);

View File

@@ -1606,7 +1606,7 @@ int main(int argc, char *argv[])
}
QDir cplusplusDir(pathCppFrontend);
if (!QFile::exists(pathCppFrontend)) {
if (!QFileInfo::exists(pathCppFrontend)) {
std::cerr << "Error: Directory \"" << qPrintable(cplusplusDir.absolutePath())
<< "\" does not exist." << std::endl;
return EXIT_FAILURE;
@@ -1616,7 +1616,7 @@ int main(int argc, char *argv[])
<< "\"." << std::endl;
return EXIT_FAILURE;
}
if (!QFile::exists(pathDumpersFile)) {
if (!QFileInfo::exists(pathDumpersFile)) {
std::cerr << "Error: File \"" << qPrintable(pathDumpersFile)
<< "\" does not exist." << std::endl;
return EXIT_FAILURE;

View File

@@ -108,14 +108,14 @@ void QmlPuppet::initQmlRunner()
if (m_argParser.isSet("readcapturedstream") && m_coreApp->arguments().count() > 2) {
QString fileName = m_argParser.value("readcapturedstream");
if (!QFile::exists(fileName)) {
if (!QFileInfo::exists(fileName)) {
qDebug() << "Input stream does not exist:" << fileName;
exit(-1);
}
if (m_coreApp->arguments().count() > 3) {
fileName = m_coreApp->arguments().at(3);
if (!QFile::exists(fileName)) {
if (!QFileInfo::exists(fileName)) {
qDebug() << "Output stream does not exist:" << fileName;
exit(-1);
}

View File

@@ -173,7 +173,7 @@ bool SdkSaveFile::commit()
if (!result) {
DWORD replaceErrorCode = GetLastError();
QString errorStr;
if (!QFile::exists(finalFileName)) {
if (!QFileInfo::exists(finalFileName)) {
// Replace failed because finalFileName does not exist, try rename.
if (!(result = rename(finalFileName)))
errorStr = errorString();
@@ -210,7 +210,7 @@ bool SdkSaveFile::commit()
// Back up current file.
// If it's opened by another application, the lock follows the move.
if (QFile::exists(finalFileName)) {
if (QFileInfo::exists(finalFileName)) {
// Kill old backup. Might be useful if creator crashed before removing backup.
QFile::remove(backupName);
QFile finalFile(finalFileName);

View File

@@ -1252,7 +1252,7 @@ void tst_Dumpers::initTestCase()
QString cdbextPath = qEnvironmentVariable("QTC_CDBEXT_PATH");
if (cdbextPath.isEmpty())
cdbextPath = QString(CDBEXT_PATH "\\qtcreatorcdbext64");
QVERIFY(QFile::exists(cdbextPath + "\\qtcreatorcdbext.dll"));
QVERIFY(QFileInfo::exists(cdbextPath + "\\qtcreatorcdbext.dll"));
env.set("_NT_DEBUGGER_EXTENSION_PATH", cdbextPath);
env.prependOrSetPath(Utils::FilePath::fromString(m_qmakeBinary).parentDir());
m_makeBinary = env.searchInPath("nmake.exe").toString();