(#542) Fixed several project-open crashes related to missing files.

Added errormessage on missing wellpath file
This commit is contained in:
Jacob Støren
2015-10-12 12:41:02 +02:00
parent 6b8e51ca87
commit 36d2bb224c
5 changed files with 60 additions and 25 deletions
@@ -158,21 +158,31 @@ caf::PdmFieldHandle* RimWellPath::objectToggleField()
//--------------------------------------------------------------------------------------------------
/// Read JSON file containing well path data
/// Read JSON or ascii file containing well path data
//--------------------------------------------------------------------------------------------------
void RimWellPath::readWellPathFile()
bool RimWellPath::readWellPathFile(QString* errorMessage)
{
QFileInfo fi(filepath());
QFileInfo fileInf(filepath());
if (fi.suffix().compare("json") == 0)
if (fileInf.isFile() && fileInf.exists())
{
this->readJsonWellPathFile();
if (fileInf.suffix().compare("json") == 0)
{
this->readJsonWellPathFile();
}
else
{
this->readAsciiWellPathFile();
}
return true;
}
else
{
this->readAsciiWellPathFile();
}
if (errorMessage) (*errorMessage) = "Could not find the well path file: " + filepath();
return false;
}
}
//--------------------------------------------------------------------------------------------------
@@ -273,12 +283,18 @@ QString RimWellPath::getCacheDirectoryPath()
//--------------------------------------------------------------------------------------------------
QString RimWellPath::getCacheFileName()
{
if (filepath().isEmpty())
{
return "";
}
QString cacheFileName;
// Make the path correct related to the possibly new project filename
QString newCacheDirPath = getCacheDirectoryPath();
QFileInfo oldCacheFile(filepath);
cacheFileName = newCacheDirPath + "/" + oldCacheFile.fileName();
return cacheFileName;
@@ -295,6 +311,11 @@ void RimWellPath::setupBeforeSave()
return;
}
if (filepath().isEmpty())
{
return;
}
QDir::root().mkpath(getCacheDirectoryPath());
QString newCacheFileName = getCacheFileName();