mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1768 Add flag in preferences to control use of Result Index File
This commit is contained in:
parent
56312a4883
commit
6629447fa1
@ -19,9 +19,13 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RifEclipseUnifiedRestartFileAccess.h"
|
||||
#include "RifEclipseOutputFileTools.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "RifEclipseOutputFileTools.h"
|
||||
#include "RifReaderSettings.h"
|
||||
|
||||
#include "ert/ecl/ecl_file.h"
|
||||
#include "ert/ecl/ecl_kw_magic.h"
|
||||
@ -68,18 +72,26 @@ bool RifEclipseUnifiedRestartFileAccess::openFile()
|
||||
if (!m_ecl_file)
|
||||
{
|
||||
QString indexFileName = RifEclipseOutputFileTools::createIndexFileName(m_filename);
|
||||
if (caf::Utils::fileExists(indexFileName))
|
||||
{
|
||||
QFileInfo indexFileInfo(indexFileName);
|
||||
QFileInfo resultFileInfo(m_filename);
|
||||
|
||||
if (resultFileInfo.lastModified() < indexFileInfo.lastModified())
|
||||
if (useResultIndexFile())
|
||||
{
|
||||
if (caf::Utils::fileExists(indexFileName))
|
||||
{
|
||||
m_ecl_file = ecl_file_fast_open(m_filename.toAscii().data(), indexFileName.toAscii().data(), ECL_FILE_CLOSE_STREAM);
|
||||
if (!m_ecl_file)
|
||||
QFileInfo indexFileInfo(indexFileName);
|
||||
QFileInfo resultFileInfo(m_filename);
|
||||
|
||||
if (resultFileInfo.lastModified() < indexFileInfo.lastModified())
|
||||
{
|
||||
RiaLogging::error(QString("Failed to open file %1 using index file.").arg(m_filename));
|
||||
RiaLogging::info(QString("Will try to open file without index file."));
|
||||
m_ecl_file = ecl_file_fast_open(m_filename.toAscii().data(), indexFileName.toAscii().data(), ECL_FILE_CLOSE_STREAM);
|
||||
if (!m_ecl_file)
|
||||
{
|
||||
RiaLogging::error(QString("Failed to open file %1 using index file.").arg(m_filename));
|
||||
RiaLogging::info(QString("Will try to open file without index file."));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::info(QString("Imported file %1 using index file.").arg(m_filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,18 +99,30 @@ bool RifEclipseUnifiedRestartFileAccess::openFile()
|
||||
if (!m_ecl_file)
|
||||
{
|
||||
m_ecl_file = ecl_file_open(m_filename.toAscii().data(), ECL_FILE_CLOSE_STREAM);
|
||||
if (m_ecl_file)
|
||||
if (!m_ecl_file)
|
||||
{
|
||||
QFileInfo fi(indexFileName);
|
||||
QString resultPath = fi.absolutePath();
|
||||
if (caf::Utils::isFolderWritable(resultPath))
|
||||
{
|
||||
ecl_file_write_index(m_ecl_file, indexFileName.toAscii().data());
|
||||
}
|
||||
RiaLogging::error(QString("Failed to open file %1").arg(m_filename));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error(QString("Failed to open file %1").arg(m_filename));
|
||||
if (useResultIndexFile())
|
||||
{
|
||||
QFileInfo fi(indexFileName);
|
||||
QString resultPath = fi.absolutePath();
|
||||
if (caf::Utils::isFolderWritable(resultPath))
|
||||
{
|
||||
bool success = ecl_file_write_index(m_ecl_file, indexFileName.toAscii().data());
|
||||
|
||||
if (success)
|
||||
{
|
||||
RiaLogging::info(QString("Exported index file to %1 ").arg(indexFileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::info(QString("Failed to exported index file to %1 ").arg(indexFileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -108,6 +132,17 @@ bool RifEclipseUnifiedRestartFileAccess::openFile()
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseUnifiedRestartFileAccess::useResultIndexFile() const
|
||||
{
|
||||
RiaPreferences* prefs = RiaApplication::instance()->preferences();
|
||||
const RifReaderSettings* readerSettings = prefs->readerSettings();
|
||||
|
||||
return readerSettings->useResultIndexFile();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Close file
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
|
||||
private:
|
||||
bool openFile();
|
||||
bool useResultIndexFile() const;
|
||||
|
||||
private:
|
||||
QString m_filename;
|
||||
|
@ -40,6 +40,9 @@ RifReaderSettings::RifReaderSettings()
|
||||
CAF_PDM_InitField(&importAdvancedMswData, "importAdvancedMswData", false, "Import Advanced MSW Data", "", "", "");
|
||||
importAdvancedMswData.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
|
||||
|
||||
CAF_PDM_InitField(&useResultIndexFile, "useResultIndexFile", false, "Use Result Index File", "", "", "");
|
||||
useResultIndexFile.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
|
||||
|
||||
CAF_PDM_InitField(&faultIncludeFileAbsolutePathPrefix, "faultIncludeFileAbsolutePathPrefix", QString(), "Fault Include File Absolute Path Prefix", "", "Path used to prefix absolute UNIX paths in fault include statements on Windows", "");
|
||||
}
|
||||
|
||||
@ -50,7 +53,8 @@ void RifReaderSettings::defineEditorAttribute(const caf::PdmFieldHandle* field,
|
||||
{
|
||||
if (field == &importFaults ||
|
||||
field == &importAdvancedMswData ||
|
||||
field == &importNNCs)
|
||||
field == &importNNCs ||
|
||||
field == &useResultIndexFile)
|
||||
{
|
||||
caf::PdmUiCheckBoxEditorAttribute* myAttr = dynamic_cast<caf::PdmUiCheckBoxEditorAttribute*>(attribute);
|
||||
if (myAttr)
|
||||
@ -65,6 +69,7 @@ void RifReaderSettings::defineUiOrdering(QString uiConfigName, caf::PdmUiOrderin
|
||||
uiOrdering.add(&importFaults);
|
||||
uiOrdering.add(&importNNCs);
|
||||
uiOrdering.add(&importAdvancedMswData);
|
||||
uiOrdering.add(&useResultIndexFile);
|
||||
#ifdef WIN32
|
||||
uiOrdering.add(&faultIncludeFileAbsolutePathPrefix);
|
||||
#endif
|
||||
|
@ -40,6 +40,7 @@ public:
|
||||
caf::PdmField<bool> importNNCs;
|
||||
caf::PdmField<bool> importAdvancedMswData;
|
||||
caf::PdmField<QString> faultIncludeFileAbsolutePathPrefix;
|
||||
caf::PdmField<bool> useResultIndexFile;
|
||||
|
||||
protected:
|
||||
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute);
|
||||
|
Loading…
Reference in New Issue
Block a user