#1476 Include isFile() when checking if a file exists

This commit is contained in:
Magne Sjaastad
2017-05-11 09:23:13 +02:00
parent e1e75a4fad
commit 84b922ba82
12 changed files with 45 additions and 31 deletions

View File

@@ -41,6 +41,7 @@
#include "cafPdmSettings.h"
#include "cafPdmUiPropertyViewDialog.h"
#include "cafProgressInfo.h"
#include "cafUtils.h"
#include <QDir>
#include <QFile>
@@ -100,7 +101,7 @@ bool RimEclipseResultCase::openEclipseGridFile()
}
else
{
if (!QFile::exists(caseFileName()))
if (!caf::Utils::fileExists(caseFileName()))
{
return false;
}
@@ -174,7 +175,7 @@ bool RimEclipseResultCase::openAndReadActiveCellData(RigEclipseCaseData* mainEcl
}
else
{
if (!QFile::exists(caseFileName()))
if (!caf::Utils::fileExists(caseFileName()))
{
return false;
}

View File

@@ -40,6 +40,8 @@
#include "RimGeoMechResultDefinition.h"
#include "RimGeoMechPropertyFilter.h"
#include "cafUtils.h"
#include <QFile>
CAF_PDM_SOURCE_INIT(RimGeoMechCase, "ResInsightGeoMechCase");
@@ -110,7 +112,7 @@ bool RimGeoMechCase::openGeoMechCase(std::string* errorMessage)
// If read already, return
if (this->m_geoMechCaseData.notNull()) return true;
if (!QFile::exists(m_caseFileName()))
if (!caf::Utils::fileExists(m_caseFileName()))
{
return false;
}

View File

@@ -29,6 +29,7 @@
#include "RimTools.h"
#include "cafProgressInfo.h"
#include "cafUtils.h"
#include "cvfGeometryTools.h"
@@ -1394,16 +1395,15 @@ void RimReservoirCellResultsStorage::setCellResults(RigCaseCellResultsData* cell
// Get the name of the cache name relative to the current project file position
QString newValidCacheFileName = getValidCacheFileName();
QFile storageFile(newValidCacheFileName);
// Warn if we thought we were to find some data on the storage file
if (!storageFile.exists() && m_resultCacheMetaData.size())
if (!caf::Utils::fileExists(newValidCacheFileName) && m_resultCacheMetaData.size())
{
qWarning() << "Reading stored results: Missing the storage file : " + newValidCacheFileName;
return;
}
QFile storageFile(newValidCacheFileName);
if (!storageFile.open(QIODevice::ReadOnly))
{
qWarning() << "Reading stored results: Can't open the file : " + newValidCacheFileName;

View File

@@ -87,11 +87,12 @@ void RimScriptCollection::readContentFromDisc()
{
QString fileName = fileList.at(i);
QFileInfo fi(fileName);
if (fi.exists())
if (caf::Utils::fileExists(fileName))
{
RimCalcScript* calcScript = new RimCalcScript;
calcScript->absolutePath = fileName;
QFileInfo fi(fileName);
calcScript->setUiName(fi.baseName());
calcScripts.push_back(calcScript);

View File

@@ -30,6 +30,7 @@
#include "RimWellPathCollection.h"
#include "cafPdmUiItem.h"
#include "cafUtils.h"
#include <QFileInfo>
#include <QDir>
@@ -81,7 +82,7 @@ QString RimTools::relocateFile(const QString& orgFileName, const QString& orgNew
bool isWindowsPath = false;
if (orgFileName.count("/")) isWindowsPath = false; // "/" are not allowed in a windows path
else if (orgFileName.count("\\")
&& !QFile::exists(orgFileName)) // To make sure we do not convert single linux files containing "\"
&& !caf::Utils::fileExists(orgFileName)) // To make sure we do not convert single linux files containing "\"
{
isWindowsPath = true;
}
@@ -93,7 +94,7 @@ QString RimTools::relocateFile(const QString& orgFileName, const QString& orgNew
}
if (searchedPaths) searchedPaths->push_back(fileName);
if (QFile::exists(fileName))
if (caf::Utils::fileExists(fileName))
{
return fileName;
}
@@ -104,7 +105,7 @@ QString RimTools::relocateFile(const QString& orgFileName, const QString& orgNew
QString candidate = QDir::fromNativeSeparators(newProjectPath + QDir::separator() + fileNameWithoutPath);
if (searchedPaths) searchedPaths->push_back(candidate);
if (QFile::exists(candidate))
if (caf::Utils::fileExists(candidate))
{
return candidate;
}
@@ -199,7 +200,7 @@ QString RimTools::relocateFile(const QString& orgFileName, const QString& orgNew
if (searchedPaths) searchedPaths->push_back(relocatedFileName);
if (QFile::exists(relocatedFileName))
if (caf::Utils::fileExists(relocatedFileName))
{
return relocatedFileName;
}

View File

@@ -36,6 +36,8 @@
#include "RivWellPathPartMgr.h"
#include "cafUtils.h"
#include <QDateTime>
#include <QDir>
#include <QFileInfo>
@@ -202,7 +204,7 @@ bool RimWellPath::readWellPathFile(QString* errorMessage, RifWellPathAsciiFileRe
{
QFileInfo fileInf(filepath());
if (fileInf.isFile() && fileInf.exists())
if (caf::Utils::fileExists(filepath()))
{
if (fileInf.suffix().compare("json") == 0)
{
@@ -410,7 +412,7 @@ void RimWellPath::updateFilePathsFromProjectPath(const QString& newProjectPath,
{
QString newCacheFileName = getCacheFileName();
if (QFile::exists(newCacheFileName))
if (caf::Utils::fileExists(newCacheFileName))
{
filepath = newCacheFileName;
}