Skip to content

Commit

Permalink
#11650 Cloud data configuration file search order
Browse files Browse the repository at this point in the history
Check multiple locations for configuration files. The first valid configuration file is used. Currently, using Qt5 the ResInsight binary file is stored at the root of the installation folder. When moving to Qt6, we will probably use sub folders /bin /lib and others. Support both one and two search levels to support Qt6.
  • Loading branch information
magnesj committed Aug 29, 2024
1 parent c3d8f13 commit 6e8fccc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
49 changes: 37 additions & 12 deletions ApplicationLibCode/Application/RiaApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,27 +1533,52 @@ cvf::Font* RiaApplication::defaultWellLabelFont()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
auto readConfigFiles = []( RiaPreferences* preferences )
auto readCloudConfigFiles = []( RiaPreferences* preferences )
{
if ( preferences == nullptr ) return;

// Check multiple locations for configuration files. The first valid configuration file is used. Currently, using Qt5 the ResInsight
// binary file is stored at the root of the installation folder. When moving to Qt6, we will probably use sub folders /bin /lib and
// others. Support both one and two search levels to support Qt6.
//
// home_folder/.resinsight/*_config.json
// location_of_resinsight_executable/../share/cloud_services/*_config.json
// location_of_resinsight_executable/../../share/cloud_services/*_config.json
//

{
QString osduConfigPath = QDir::homePath() + "/.resinsight/osdu_config.json";
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( osduConfigPath );
if ( !keyValuePairs.empty() )
QStringList osduFilePathCandidates;
osduFilePathCandidates << QDir::homePath() + "/.resinsight/osdu_config.json";
osduFilePathCandidates << QCoreApplication::applicationDirPath() + "/../share/cloud_services/osdu_config.json";
osduFilePathCandidates << QCoreApplication::applicationDirPath() + "/../../share/cloud_services/osdu_config.json";

for ( const auto& osduFileCandidate : osduFilePathCandidates )
{
preferences->osduPreferences()->setData( keyValuePairs );
preferences->osduPreferences()->setFieldsReadOnly();
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( osduFileCandidate );
if ( !keyValuePairs.empty() )
{
preferences->osduPreferences()->setData( keyValuePairs );
preferences->osduPreferences()->setFieldsReadOnly();
break;
}
}
}

{
QString sumoConfigPath = QDir::homePath() + "/.resinsight/sumo_config.json";
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( sumoConfigPath );
if ( !keyValuePairs.empty() )
QStringList sumoFilePathCandidates;
sumoFilePathCandidates << QDir::homePath() + "/.resinsight/sumo_config.json";
sumoFilePathCandidates << QCoreApplication::applicationDirPath() + "/../share/cloud_services/sumo_config.json";
sumoFilePathCandidates << QCoreApplication::applicationDirPath() + "/../../share/cloud_services/sumo_config.json";

for ( const auto& sumoFileCandidate : sumoFilePathCandidates )
{
preferences->sumoPreferences()->setData( keyValuePairs );
preferences->sumoPreferences()->setFieldsReadOnly();
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( sumoFileCandidate );
if ( !keyValuePairs.empty() )
{
preferences->sumoPreferences()->setData( keyValuePairs );
preferences->sumoPreferences()->setFieldsReadOnly();
break;
}
}
}
};
Expand All @@ -1577,7 +1602,7 @@ void RiaApplication::initialize()

initializeDataLoadController();

readConfigFiles( m_preferences.get() );
readCloudConfigFiles( m_preferences.get() );
}

//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/Application/RiaPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,11 @@ void RiaPreferences::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
otherGroup->add( &m_summaryCalculationExpressionFolder );

caf::PdmUiGroup* osduGroup = uiOrdering.addNewGroup( "OSDU" );
osduGroup->setCollapsedByDefault();
m_osduPreferences()->uiOrdering( uiConfigName, *osduGroup );

caf::PdmUiGroup* sumoGroup = uiOrdering.addNewGroup( "SUMO" );
sumoGroup->setCollapsedByDefault();
m_sumoPreferences()->uiOrdering( uiConfigName, *sumoGroup );
}
else if ( RiaApplication::enableDevelopmentFeatures() && uiConfigName == RiaPreferences::tabNameSystem() )
Expand Down

0 comments on commit 6e8fccc

Please sign in to comment.