Commit 9477ed0a authored by hjk's avatar hjk

Introduce and use FileName::exists()

This can use the faster route through QFileInfo::exist now.

Change-Id: Idb41b5d5185d7f02eacba498fb01f483d95e8d57
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 36f94d36
......@@ -144,7 +144,7 @@ bool FileUtils::copyRecursively(const FileName &srcFilePath, const FileName &tgt
{
QFileInfo srcFileInfo = srcFilePath.toFileInfo();
if (srcFileInfo.isDir()) {
if (!tgtFilePath.toFileInfo().exists()) {
if (!tgtFilePath.exists()) {
QDir targetDir(tgtFilePath.toString());
targetDir.cdUp();
if (!targetDir.mkdir(tgtFilePath.toFileInfo().fileName())) {
......@@ -551,6 +551,13 @@ QString FileName::toUserOutput() const
return QDir::toNativeSeparators(toString());
}
/// \returns a bool indicating whether a file with this
/// FileName exists.
bool FileName::exists() const
{
return QFileInfo::exists(*this);
}
/// Find the parent directory of a given directory.
/// Returns an empty FileName if the current directory is already
......
......@@ -72,6 +72,7 @@ public:
static FileName fromUserInput(const QString &filename);
QString toString() const;
QString toUserOutput() const;
bool exists() const;
FileName parentDir() const;
......
......@@ -384,7 +384,7 @@ FileName AndroidConfig::androidToolPath() const
// Java and I've made some progress on it. So if android.exe exists, return that instead.
FileName path = m_sdkLocation;
path.appendPath(QLatin1String("tools/android" QTC_HOST_EXE_SUFFIX));
if (path.toFileInfo().exists())
if (path.exists())
return path;
path = m_sdkLocation;
return path.appendPath(QLatin1String("tools/android" ANDROID_BAT_SUFFIX));
......@@ -1299,7 +1299,7 @@ void AndroidConfigurations::load()
void AndroidConfigurations::updateAndroidDevice()
{
DeviceManager * const devMgr = DeviceManager::instance();
if (m_instance->m_config.adbToolPath().toFileInfo().exists())
if (m_instance->m_config.adbToolPath().exists())
devMgr->addDevice(IDevice::Ptr(new Internal::AndroidDevice));
else if (devMgr->find(Constants::ANDROID_DEVICE_ID))
devMgr->removeDevice(Core::Id(Constants::ANDROID_DEVICE_ID));
......
......@@ -587,7 +587,7 @@ bool AndroidManager::checkCertificatePassword(const QString &keystorePath, const
bool AndroidManager::checkForQt51Files(Utils::FileName fileName)
{
fileName.appendPath(QLatin1String("android")).appendPath(QLatin1String("version.xml"));
if (!fileName.toFileInfo().exists())
if (!fileName.exists())
return false;
QDomDocument dstVersionDoc;
if (!openXmlFile(dstVersionDoc, fileName))
......@@ -684,7 +684,7 @@ bool AndroidManager::updateGradleProperties(ProjectExplorer::Target *target)
AndroidBuildApkStep *buildApkStep
= AndroidGlobal::buildStep<AndroidBuildApkStep>(target->activeBuildConfiguration());
if (!buildApkStep || !buildApkStep->androidPackageSourceDir().appendPath(QLatin1String("gradlew")).toFileInfo().exists())
if (!buildApkStep || !buildApkStep->androidPackageSourceDir().appendPath(QLatin1String("gradlew")).exists())
return false;
GradleProperties localProperties;
......
......@@ -256,9 +256,9 @@ void AndroidSettingsWidget::check(AndroidSettingsWidget::Mode mode)
m_ui->gdbWarningLabel->setVisible(false);
if (m_androidConfig.ndkLocation().isEmpty()) {
m_ndkState = NotSet;
} else if (!platformPath.appendPath(QLatin1String("platforms")).toFileInfo().exists()
|| !toolChainPath.appendPath(QLatin1String("toolchains")).toFileInfo().exists()
|| !sourcesPath.appendPath(QLatin1String("sources/cxx-stl")).toFileInfo().exists()) {
} else if (!platformPath.appendPath(QLatin1String("platforms")).exists()
|| !toolChainPath.appendPath(QLatin1String("toolchains")).exists()
|| !sourcesPath.appendPath(QLatin1String("sources/cxx-stl")).exists()) {
m_ndkState = Error;
m_ndkErrorMessage = tr("\"%1\" does not seem to be an Android NDK top folder.")
.arg(m_androidConfig.ndkLocation().toUserOutput());
......@@ -277,7 +277,7 @@ void AndroidSettingsWidget::check(AndroidSettingsWidget::Mode mode)
if (ati.architecture != ProjectExplorer::Abi::ArmArchitecture)
continue;
Utils::FileName gdbPath = m_androidConfig.gdbPath(ati.architecture, ati.version);
if (gdbPath.toFileInfo().exists())
if (gdbPath.exists())
gdbPaths << gdbPath.toString();
}
......@@ -325,8 +325,7 @@ void AndroidSettingsWidget::check(AndroidSettingsWidget::Mode mode)
} else {
Utils::FileName bin = m_androidConfig.openJDKLocation();
bin.appendPath(QLatin1String("bin/javac" QTC_HOST_EXE_SUFFIX));
if (!m_androidConfig.openJDKLocation().toFileInfo().exists()
|| !bin.toFileInfo().exists())
if (!m_androidConfig.openJDKLocation().exists() || !bin.exists())
m_javaState = Error;
}
}
......@@ -407,15 +406,15 @@ bool AndroidSettingsWidget::sdkLocationIsValid() const
Utils::FileName androidExe = m_androidConfig.sdkLocation();
Utils::FileName androidBat = m_androidConfig.sdkLocation();
Utils::FileName emulator = m_androidConfig.sdkLocation();
return (androidExe.appendPath(QLatin1String("/tools/android" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists()
|| androidBat.appendPath(QLatin1String("/tools/android" ANDROID_BAT_SUFFIX)).toFileInfo().exists())
&& emulator.appendPath(QLatin1String("/tools/emulator" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists();
return (androidExe.appendPath(QLatin1String("/tools/android" QTC_HOST_EXE_SUFFIX)).exists()
|| androidBat.appendPath(QLatin1String("/tools/android" ANDROID_BAT_SUFFIX)).exists())
&& emulator.appendPath(QLatin1String("/tools/emulator" QTC_HOST_EXE_SUFFIX)).exists();
}
bool AndroidSettingsWidget::sdkPlatformToolsInstalled() const
{
Utils::FileName adb = m_androidConfig.sdkLocation();
return adb.appendPath(QLatin1String("platform-tools/adb" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists();
return adb.appendPath(QLatin1String("platform-tools/adb" QTC_HOST_EXE_SUFFIX)).exists();
}
void AndroidSettingsWidget::saveSettings()
......@@ -477,7 +476,7 @@ void AndroidSettingsWidget::searchForAnt(const Utils::FileName &location)
ant.appendPath(QLatin1String("ant.bat"));
else
ant.appendPath(QLatin1String("ant"));
if (ant.toFileInfo().exists()) {
if (ant.exists()) {
m_androidConfig.setAntLocation(ant);
m_ui->AntLocationPathChooser->setFileName(ant);
}
......
......@@ -151,13 +151,13 @@ FileName AndroidToolChain::suggestedGdbServer() const
Utils::FileName path = AndroidConfigurations::currentConfig().ndkLocation();
path.appendPath(QString::fromLatin1("prebuilt/android-%1/gdbserver/gdbserver")
.arg(Abi::toString(targetAbi().architecture())));
if (path.toFileInfo().exists())
if (path.exists())
return path;
path = AndroidConfigurations::currentConfig().ndkLocation();
path.appendPath(QString::fromLatin1("toolchains/%1-%2/prebuilt/gdbserver")
.arg(AndroidConfig::toolchainPrefix(targetAbi().architecture()))
.arg(m_ndkToolChainVersion));
if (path.toFileInfo().exists())
if (path.exists())
return path;
return Utils::FileName();
......
......@@ -586,7 +586,7 @@ QString CMakeProject::uiHeaderFile(const QString &uiFile)
while (baseDirectory.isChildOf(project)) {
Utils::FileName cmakeListsTxt = baseDirectory;
cmakeListsTxt.appendPath(QLatin1String("CMakeLists.txt"));
if (cmakeListsTxt.toFileInfo().exists())
if (cmakeListsTxt.exists())
break;
QDir dir(baseDirectory.toString());
dir.cdUp();
......
......@@ -298,7 +298,7 @@ void DebuggerItemManager::readLegacyDebuggers(const FileName &file)
if (fn == QLatin1String("auto"))
continue;
FileName command = FileName::fromUserInput(fn);
if (!command.toFileInfo().exists())
if (!command.exists())
continue;
if (findByCommand(command))
continue;
......
......@@ -136,7 +136,7 @@ RunControl *IosDebugSupport::createDebugRunControl(IosRunConfiguration *runConfi
Utils::FileName xcodeInfo = IosConfigurations::developerPath().parentDir()
.appendPath(QLatin1String("Info.plist"));
bool buggyLldb = false;
if (xcodeInfo.toFileInfo().exists()) {
if (xcodeInfo.exists()) {
QSettings settings(xcodeInfo.toString(), QSettings::NativeFormat);
QStringList version = settings.value(QLatin1String("CFBundleShortVersionString")).toString()
.split(QLatin1Char('.'));
......@@ -147,7 +147,7 @@ RunControl *IosDebugSupport::createDebugRunControl(IosRunConfiguration *runConfi
bundlePath.chop(4);
Utils::FileName dsymPath = Utils::FileName::fromString(
bundlePath.append(QLatin1String(".dSYM")));
if (!dsymPath.toFileInfo().exists()) {
if (!dsymPath.exists()) {
if (buggyLldb)
TaskHub::addTask(Task::Warning,
tr("Debugging with Xcode 5.0.x can be unreliable without a dSYM. "
......
......@@ -272,7 +272,7 @@ void IosDeployStep::checkProvisioningProfile()
// the file is a signed plist stored in DER format
// we simply search for start and end of the plist instead of decoding the DER payload
if (!provisioningFilePath.toFileInfo().exists())
if (!provisioningFilePath.exists())
return;
QFile provisionFile(provisioningFilePath.toString());
if (!provisionFile.open(QIODevice::ReadOnly))
......
......@@ -450,7 +450,7 @@ QStringList IosDsymBuildStep::defaultCmdList() const
QString dsymutilCmd = QLatin1String("dsymutil");
Utils::FileName dsymUtilPath = IosConfigurations::developerPath()
.appendPath(QLatin1String("Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil"));
if (dsymUtilPath.toFileInfo().exists())
if (dsymUtilPath.exists())
dsymutilCmd = dsymUtilPath.toUserOutput();
IosRunConfiguration *runConf =
qobject_cast<IosRunConfiguration *>(target()->activeRunConfiguration());
......
......@@ -738,7 +738,7 @@ QString IosToolHandler::iosSimulatorToolPath()
Utils::FileName devPath = Internal::IosConfigurations::developerPath();
bool version182 = devPath.appendPath(QLatin1String(
"Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/iPhoneSimulatorRemoteClient.framework"))
.toFileInfo().exists();
.exists();
QString res = Core::ICore::libexecPath() + QLatin1String("/ios/iossim");
if (version182)
res = res.append(QLatin1String("_1_8_2"));
......
......@@ -159,7 +159,7 @@ void KitManager::restoreKits()
// read all kits from user file
KitList userKits;
FileName userSettingsFile(settingsFileName());
if (userSettingsFile.toFileInfo().exists())
if (userSettingsFile.exists())
userKits = restoreKits(userSettingsFile);
foreach (Kit *k, userKits.kits) {
if (k->isSdkProvided())
......
......@@ -883,7 +883,7 @@ bool SessionManager::loadSession(const QString &session)
// Try loading the file
FileName fileName = sessionNameToFileName(session);
PersistentSettingsReader reader;
if (fileName.toFileInfo().exists()) {
if (fileName.exists()) {
if (!reader.load(fileName)) {
QMessageBox::warning(ICore::dialogParent(), tr("Error while restoring session"),
tr("Could not restore session %1").arg(fileName.toUserOutput()));
......@@ -919,7 +919,7 @@ bool SessionManager::loadSession(const QString &session)
d->m_sessionName = session;
EditorManager::updateWindowTitles();
if (fileName.toFileInfo().exists()) {
if (fileName.exists()) {
d->m_virginSession = false;
ProgressManager::addTask(d->m_future.future(), tr("Loading Session"),
......@@ -1021,7 +1021,7 @@ QStringList SessionManager::projectsForSessionName(const QString &session)
{
const FileName fileName = sessionNameToFileName(session);
PersistentSettingsReader reader;
if (fileName.toFileInfo().exists()) {
if (fileName.exists()) {
if (!reader.load(fileName)) {
qWarning() << "Could not restore session" << fileName.toUserOutput();
return QStringList();
......
......@@ -752,7 +752,7 @@ SettingsAccessor::IssueInfo SettingsAccessor::findIssues(const QVariantMap &data
defaultSettingsPath.appendString(m_userSuffix);
int version = versionFromMap(data);
if (!path.toFileInfo().exists()) {
if (!path.exists()) {
return result;
} else if (data.isEmpty() || version < firstSupportedVersion() || version > currentVersion()) {
result.title = QApplication::translate("Utils::SettingsAccessor", "No Valid Settings Found");
......
......@@ -475,7 +475,7 @@ void TaskWindow::triggerDefaultHandler(const QModelIndex &index)
if (d->m_defaultHandler->canHandle(task)) {
d->m_defaultHandler->handle(task);
} else {
if (!task.file.toFileInfo().exists())
if (!task.file.exists())
d->m_model->setFileNotFound(index, true);
}
}
......
......@@ -192,7 +192,7 @@ void ToolChainManager::restoreToolChains()
// read all tool chains from user file.
// Read legacy settings once and keep them around...
FileName fileName = settingsFileName(QLatin1String(TOOLCHAIN_FILENAME));
if (!fileName.toFileInfo().exists())
if (!fileName.exists())
fileName = settingsFileName(QLatin1String(LEGACY_TOOLCHAIN_FILENAME));
readTcs = restoreFromFile(fileName);
......
......@@ -104,7 +104,7 @@ void AndroidPackageInstallationStep::run(QFutureInterface<bool> &fi)
QString error;
foreach (const QString &dir, m_androidDirsToClean) {
Utils::FileName androidDir = Utils::FileName::fromString(dir);
if (!dir.isEmpty() && androidDir.toFileInfo().exists()) {
if (!dir.isEmpty() && androidDir.exists()) {
emit addOutput(tr("Removing directory %1").arg(dir), MessageOutput);
if (!Utils::FileUtils::removeRecursively(androidDir, &error)) {
emit addOutput(error, ErrorOutput);
......
......@@ -241,7 +241,7 @@ bool BarDescriptorFileNodeManager::createBarDescriptor(ProjectExplorer::Project
content.replace(QLatin1String("TARGETNAME"), targetName);
content.replace(QLatin1String("ID"), QLatin1String("com.example.") + projectName);
if (project->projectDirectory().appendPath(QLatin1String("qml")).toFileInfo().exists())
if (project->projectDirectory().appendPath(QLatin1String("qml")).exists())
content.replace(QLatin1String("</qnx>"),
QLatin1String(" <asset path=\"qml\">qml</asset>\n</qnx>"));
......
......@@ -130,10 +130,10 @@ void BlackBerryApiLevelConfiguration::ctor()
QString host = qnxHost().toString();
FileName qmake4Path = FileName::fromString(Utils::HostOsInfo::withExecutableSuffix(host + QLatin1String("/usr/bin/qmake")));
FileName qmake5Path = FileName::fromString(Utils::HostOsInfo::withExecutableSuffix(host + QLatin1String("/usr/bin/qt5/qmake")));
if (qmake4Path.toFileInfo().exists())
if (qmake4Path.exists())
m_qmake4BinaryFile = qmake4Path;
if (qmake5Path.toFileInfo().exists())
if (qmake5Path.exists())
m_qmake5BinaryFile = qmake5Path;
}
......@@ -183,8 +183,8 @@ bool BlackBerryApiLevelConfiguration::isValid() const
return QnxBaseConfiguration::isValid() &&
((!m_qmake4BinaryFile.isEmpty() || !m_qmake5BinaryFile.isEmpty())
&& (m_autoDetectionSource.isEmpty() ||
m_autoDetectionSource.toFileInfo().exists())
&& (!m_sysRoot.isEmpty() && m_sysRoot.toFileInfo().exists()));
m_autoDetectionSource.exists())
&& (!m_sysRoot.isEmpty() && m_sysRoot.exists()));
}
......@@ -276,10 +276,10 @@ QStringList BlackBerryApiLevelConfiguration::validationErrors() const
if (m_qmake4BinaryFile.isEmpty() && m_qmake5BinaryFile.isEmpty())
errorStrings << tr("- No Qt version found.");
if (!m_autoDetectionSource.isEmpty() && !m_autoDetectionSource.toFileInfo().exists())
if (!m_autoDetectionSource.isEmpty() && !m_autoDetectionSource.exists())
errorStrings << tr("- No auto detection source found.");
if (m_sysRoot.isEmpty() && m_sysRoot.toFileInfo().exists())
if (m_sysRoot.isEmpty() && m_sysRoot.exists())
errorStrings << tr("- No sysroot found.");
......
......@@ -391,7 +391,7 @@ bool BlackBerryDeviceConfigurationWizardConfigPage::isComplete() const
bool configurationNameComplete = !m_ui->configurationNameField->text().isEmpty();
Utils::FileName fileName = Utils::FileName::fromString(m_ui->debugTokenCombo->currentText());
bool debugTokenComplete = m_holder.isSimulator || !m_holder.isProductionDevice
|| (!fileName.isEmpty() && fileName.toFileInfo().exists());
|| (!fileName.isEmpty() && fileName.exists());
return configurationNameComplete && debugTokenComplete;
}
......
......@@ -188,10 +188,10 @@ void BlackBerryNDKSettingsWidget::updateConfigurationList()
// TODO: Do the same if qmake, qcc, debugger are no longer detected...
if (!config->isValid()) {
QString toolTip = tr("Invalid target %1:").arg(config->targetName());
if (config->isAutoDetected() && !config->autoDetectionSource().toFileInfo().exists())
if (config->isAutoDetected() && !config->autoDetectionSource().exists())
toolTip += QLatin1Char('\n') + tr("- Target no longer installed.");
if (!config->envFile().toFileInfo().exists())
if (!config->envFile().exists())
toolTip += QLatin1Char('\n') + tr("- No NDK environment file found.");
if (config->qmake4BinaryFile().isEmpty()
......
......@@ -136,7 +136,7 @@ bool QnxBaseConfiguration::isValid() const
void QnxBaseConfiguration::ctor(const FileName &envScript)
{
QTC_ASSERT(!envScript.isEmpty() && envScript.toFileInfo().exists(), return);
QTC_ASSERT(!envScript.isEmpty() && envScript.exists(), return);
m_envFile = envScript;
m_qnxEnv = QnxUtils::qnxEnvironmentFromEnvFile(m_envFile.toString());
foreach (const Utils::EnvironmentItem &item, m_qnxEnv) {
......@@ -151,7 +151,7 @@ void QnxBaseConfiguration::ctor(const FileName &envScript)
m_qnxHost.toString() + QLatin1String("/usr/bin/qcc")));
FileName armlev7GdbPath = FileName::fromString(Utils::HostOsInfo::withExecutableSuffix(
m_qnxHost.toString() + QLatin1String("/usr/bin/ntoarm-gdb")));
if (!armlev7GdbPath.toFileInfo().exists()) {
if (!armlev7GdbPath.exists()) {
armlev7GdbPath = FileName::fromString(Utils::HostOsInfo::withExecutableSuffix(
m_qnxHost.toString() + QLatin1String("/usr/bin/ntoarmv7-gdb")));
}
......@@ -159,13 +159,13 @@ void QnxBaseConfiguration::ctor(const FileName &envScript)
FileName x86GdbPath = FileName::fromString(Utils::HostOsInfo::withExecutableSuffix(
m_qnxHost.toString() + QLatin1String("/usr/bin/ntox86-gdb")));
if (qccPath.toFileInfo().exists())
if (qccPath.exists())
m_qccCompiler = qccPath;
if (armlev7GdbPath.toFileInfo().exists())
if (armlev7GdbPath.exists())
m_armlev7Debugger = armlev7GdbPath;
if (x86GdbPath.toFileInfo().exists())
if (x86GdbPath.exists())
m_x86Debugger = x86GdbPath;
}
......
......@@ -181,7 +181,7 @@ void QtVersionManager::triggerQtVersionRestore()
saveQtVersions();
const FileName configFileName = globalSettingsFileName();
if (configFileName.toFileInfo().exists()) {
if (configFileName.exists()) {
m_configFileWatcher = new FileSystemWatcher(m_instance);
connect(m_configFileWatcher, SIGNAL(fileChanged(QString)),
m_fileWatcherTimer, SLOT(start()));
......@@ -231,7 +231,7 @@ static bool restoreQtVersions()
FileName filename = settingsFileName(QLatin1String(QTVERSION_FILENAME));
// Read Qt Creator 2.5 qtversions.xml once:
if (!filename.toFileInfo().exists())
if (!filename.exists())
filename = settingsFileName(QLatin1String(QTVERSION_LEGACY_FILENAME));
if (!reader.load(filename))
return false;
......
......@@ -102,7 +102,7 @@ QVariantMap Operation::load(const QString &file)
// Read values from original file:
Utils::FileName path = Settings::instance()->getPath(file);
if (path.toFileInfo().exists()) {
if (path.exists()) {
Utils::PersistentSettingsReader reader;
if (!reader.load(path))
return QVariantMap();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment