From 681b4fbffee11e18b10d17ebb87832d145c6ad52 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 29 Aug 2024 09:37:07 +0200 Subject: [PATCH] #11650 Cloud data configuration file search order 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. --- .../Application/RiaApplication.cpp | 49 ++++++++++++++----- .../Application/RiaPreferences.cpp | 2 + 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/ApplicationLibCode/Application/RiaApplication.cpp b/ApplicationLibCode/Application/RiaApplication.cpp index 3c6759a6da..f3c2e9166a 100644 --- a/ApplicationLibCode/Application/RiaApplication.cpp +++ b/ApplicationLibCode/Application/RiaApplication.cpp @@ -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; + } } } }; @@ -1577,7 +1602,7 @@ void RiaApplication::initialize() initializeDataLoadController(); - readConfigFiles( m_preferences.get() ); + readCloudConfigFiles( m_preferences.get() ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Application/RiaPreferences.cpp b/ApplicationLibCode/Application/RiaPreferences.cpp index 131551e6f1..ff64446bc2 100644 --- a/ApplicationLibCode/Application/RiaPreferences.cpp +++ b/ApplicationLibCode/Application/RiaPreferences.cpp @@ -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() )