#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

@@ -348,7 +348,7 @@ bool RiaApplication::loadProject(const QString& projectFileName, ProjectLoadActi
// Open the project file and read the serialized data.
// Will initialize itself.
if (!QFile::exists(projectFileName))
if (!caf::Utils::fileExists(projectFileName))
{
RiaLogging::info(QString("File does not exist : '%1'").arg(projectFileName));
return false;
@@ -714,7 +714,7 @@ bool RiaApplication::saveProject()
{
CVF_ASSERT(m_project.notNull());
if (!QFile::exists(m_project->fileName()))
if (!caf::Utils::fileExists(m_project->fileName()))
{
return saveProjectPromptForFileName();
}
@@ -940,7 +940,7 @@ QString RiaApplication::createAbsolutePathFromProjectRelativePath(QString projec
//--------------------------------------------------------------------------------------------------
bool RiaApplication::openEclipseCaseFromFile(const QString& fileName)
{
if (!QFile::exists(fileName)) return false;
if (!caf::Utils::fileExists(fileName)) return false;
QFileInfo gridFileName(fileName);
QString caseName = gridFileName.completeBaseName();
@@ -1113,7 +1113,7 @@ bool RiaApplication::openInputEclipseCaseFromFileNames(const QStringList& fileNa
//--------------------------------------------------------------------------------------------------
bool RiaApplication::openOdbCaseFromFile(const QString& fileName)
{
if (!QFile::exists(fileName)) return false;
if (!caf::Utils::fileExists(fileName)) return false;
QFileInfo gridFileName(fileName);
QString caseName = gridFileName.completeBaseName();
@@ -1479,14 +1479,14 @@ bool RiaApplication::parseArguments()
foreach (QString caseName, caseNames)
{
QString caseFileNameWithExt = caseName + ".EGRID";
if (QFile::exists(caseFileNameWithExt))
if (!caf::Utils::fileExists(caseFileNameWithExt))
{
openEclipseCaseFromFile(caseFileNameWithExt);
}
else
{
caseFileNameWithExt = caseName + ".GRID";
if (QFile::exists(caseFileNameWithExt))
if (!caf::Utils::fileExists(caseFileNameWithExt))
{
openEclipseCaseFromFile(caseFileNameWithExt);
}
@@ -2135,7 +2135,7 @@ void RiaApplication::setLastUsedDialogDirectory(const QString& dialogName, const
//--------------------------------------------------------------------------------------------------
bool RiaApplication::openFile(const QString& fileName)
{
if (!QFile::exists(fileName)) return false;
if (!caf::Utils::fileExists(fileName)) return false;
bool loadingSucceded = false;

View File

@@ -29,6 +29,8 @@
#include "RiuMainWindow.h"
#include "cafUtils.h"
#include <QAction>
#include <QFileInfo>
#include <QInputDialog>
@@ -76,7 +78,7 @@ void RicNewScriptFeature::onActionTriggered(bool isChecked)
fullPathFilenameNewScript = fullPathNewScript + "/untitled.m";
int num= 1;
while (QFileInfo(fullPathFilenameNewScript).exists())
while (caf::Utils::fileExists(fullPathFilenameNewScript))
{
fullPathFilenameNewScript = fullPathNewScript + "/untitled" + QString::number(num) + ".m";
num++;

View File

@@ -27,6 +27,8 @@
#include "RiuMainWindow.h"
#include "RiuWellImportWizard.h"
#include "cafUtils.h"
#include <QAction>
#include <QDir>
#include <QFile>
@@ -47,7 +49,7 @@ bool RicWellPathsImportSsihubFeature::isCommandEnabled()
return false;
}
if (!QFile::exists(app->project()->fileName()))
if (!caf::Utils::fileExists(app->project()->fileName()))
{
return false;
}
@@ -66,7 +68,7 @@ void RicWellPathsImportSsihubFeature::onActionTriggered(bool isChecked)
return;
}
if (!QFile::exists(app->project()->fileName()))
if (!caf::Utils::fileExists(app->project()->fileName()))
{
return;
}

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;
}

View File

@@ -25,6 +25,7 @@
#include "RimWellLogExtractionCurve.h"
#include "cafUtils.h"
#include "cvfAssert.h"
#include "laswell.hpp"
@@ -390,7 +391,7 @@ bool RigLasFileExporter::writeToFolder(const QString& exportFolder)
QDir dir(exportFolder);
QString fileName = dir.absoluteFilePath(QString::fromStdString(lasFileDescr.generateFilename()));
if (QFile::exists(fileName))
if (caf::Utils::fileExists(fileName))
{
QString txt = QString("File %1 exists.\n\nDo you want to overwrite the file?").arg(fileName);
int ret = QMessageBox::question(NULL, "LAS File Export",

View File

@@ -56,6 +56,7 @@
#include "cafPdmUiPropertyViewDialog.h"
#include "cafPdmUiTreeView.h"
#include "cafSelectionManager.h"
#include "cafUtils.h"
#include "cvfTimer.h"
@@ -637,7 +638,7 @@ void RiuMainWindow::slotRefreshFileActions()
{
RiaApplication* app = RiaApplication::instance();
bool projectFileExists = QFile::exists(app->project()->fileName());
bool projectFileExists = caf::Utils::fileExists(app->project()->fileName());
caf::CmdFeatureManager* cmdFeatureMgr = caf::CmdFeatureManager::instance();
CVF_ASSERT(cmdFeatureMgr);

View File

@@ -32,6 +32,7 @@
#include "cafPdmUiPropertyView.h"
#include "cafPdmUiTreeView.h"
#include "cafPdmUiTreeViewEditor.h"
#include "cafUtils.h"
#include <QObject>
#include <QtGui>
@@ -99,7 +100,7 @@ QString RiuWellImportWizard::jsonWellsFilePath()
void RiuWellImportWizard::downloadFields()
{
QString wellFileName = jsonWellsFilePath();
if (QFile::exists(wellFileName))
if (caf::Utils::fileExists(wellFileName))
{
QFile::remove(wellFileName);
}
@@ -355,7 +356,7 @@ void RiuWellImportWizard::updateFieldsModel()
{
QString fileName = jsonFieldsFilePath();
if (QFile::exists(fileName))
if (caf::Utils::fileExists(fileName))
{
ResInsightInternalJson::JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(fileName);
@@ -540,7 +541,7 @@ QStringList RiuWellImportWizard::absoluteFilePathsToWellPaths() const
for (size_t i = 0; i < downloadEntities.size(); i++)
{
if (QFile::exists(downloadEntities[i].responseFilename))
if (caf::Utils::fileExists(downloadEntities[i].responseFilename))
{
filePaths.push_back(downloadEntities[i].responseFilename);
}
@@ -582,7 +583,7 @@ void RiuWellImportWizard::parseWellsResponse(RimOilFieldEntry* oilFieldEntry)
QStringList surveyNames;
QStringList planNames;
if (QFile::exists(oilFieldEntry->wellsFilePath))
if (caf::Utils::fileExists(oilFieldEntry->wellsFilePath))
{
ResInsightInternalJson::JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(oilFieldEntry->wellsFilePath);
@@ -1056,7 +1057,7 @@ void WellSummaryPage::updateSummaryPage()
for (size_t i = 0; i < downloadEntities.size(); i++)
{
if (QFile::exists(downloadEntities[i].responseFilename))
if (caf::Utils::fileExists(downloadEntities[i].responseFilename))
{
wellPathCount++;
}