Mercurial > hg > orthanc
changeset 7059:0822a5109ae1
integrating advanced options into default configuration
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Wed, 12 Aug 2026 08:56:32 +0200 |
| parents | 1a4929bdd068 |
| children | 4199096fe8c5 |
| files | OrthancServer/CMakeLists.txt OrthancServer/Sources/OrthancConfiguration.cpp OrthancServer/Sources/main.cpp |
| diffstat | 3 files changed, 109 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/CMakeLists.txt Wed Aug 12 08:37:33 2026 +0200 +++ b/OrthancServer/CMakeLists.txt Wed Aug 12 08:56:32 2026 +0200 @@ -261,8 +261,6 @@ ##################################################################### set(ORTHANC_EMBEDDED_FILES - CONFIGURATION_SAMPLE ${CMAKE_SOURCE_DIR}/Resources/Configuration.json - ADVANCED_CONFIGURATION_SAMPLE ${CMAKE_SOURCE_DIR}/Resources/AdvancedConfiguration.json DICOM_CONFORMANCE_STATEMENT ${CMAKE_SOURCE_DIR}/Resources/DicomConformanceStatement.txt FONT_UBUNTU_MONO_BOLD_16 ${CMAKE_SOURCE_DIR}/Resources/Fonts/UbuntuMonoBold-16.json LUA_TOOLBOX ${CMAKE_SOURCE_DIR}/Resources/Toolbox.lua @@ -285,7 +283,9 @@ ) list(APPEND ORTHANC_EMBEDDED_FILES - ORTHANC_EXPLORER ${CMAKE_SOURCE_DIR}/OrthancExplorer + ORTHANC_EXPLORER ${CMAKE_SOURCE_DIR}/OrthancExplorer + CONFIGURATION_SAMPLE ${CMAKE_SOURCE_DIR}/Resources/Configuration.json + ADVANCED_CONFIGURATION_SAMPLE ${CMAKE_SOURCE_DIR}/Resources/AdvancedConfiguration.json ) else() add_definitions(
--- a/OrthancServer/Sources/OrthancConfiguration.cpp Wed Aug 12 08:37:33 2026 +0200 +++ b/OrthancServer/Sources/OrthancConfiguration.cpp Wed Aug 12 08:56:32 2026 +0200 @@ -83,26 +83,6 @@ } - static void ReadDefaultConfiguration(Json::Value& target) - { -#if ORTHANC_STANDALONE == 1 - std::string content; - GetFileResource(content, ServerResources::CONFIGURATION_SAMPLE); - - ReadConfigurationFromString(target, content); -#else - // In a non-standalone build, we use the - // "Resources/Configuration.json" from the Orthanc source code - - boost::filesystem::path p = ORTHANC_PATH; - p /= "Resources"; - p /= "Configuration.json"; - - ReadConfigurationFromFile(target, p); -#endif - } - - static void MergeConfigurations(Json::Value& target, const Json::Value& source) { @@ -131,6 +111,53 @@ } + static void ReadDefaultConfiguration(Json::Value& target) + { +#if ORTHANC_STANDALONE == 1 + { + std::string content; + GetFileResource(content, ServerResources::CONFIGURATION_SAMPLE); + ReadConfigurationFromString(target, content); + } + + { + // Merge with the content of the advanced configuration + std::string content; + GetFileResource(content, ServerResources::ADVANCED_CONFIGURATION_SAMPLE); + + Json::Value advanced; + ReadConfigurationFromString(advanced, content); + + MergeConfigurations(target, advanced); + } + +#else + // In a non-standalone build, we use the + // "Resources/Configuration.json" from the Orthanc source code + + { + boost::filesystem::path p = ORTHANC_PATH; + p /= "Resources"; + p /= "Configuration.json"; + + ReadConfigurationFromFile(target, p); + } + + { + // Merge with the content of the advanced configuration + boost::filesystem::path p = ORTHANC_PATH; + p /= "Resources"; + p /= "AdvancedConfiguration.json"; + + Json::Value advanced; + ReadConfigurationFromFile(advanced, p); + + MergeConfigurations(target, advanced); + } +#endif + } + + static void ReadConfigurationsFromFolder(Json::Value& target, const boost::filesystem::path& folder) {
--- a/OrthancServer/Sources/main.cpp Wed Aug 12 08:37:33 2026 +0200 +++ b/OrthancServer/Sources/main.cpp Wed Aug 12 08:56:32 2026 +0200 @@ -1977,6 +1977,30 @@ } +static int ExportFile(const std::string& target, + const std::string& content) +{ + try + { + if (target == "-") + { + std::cout << content; // Print to stdout + } + else + { + SystemToolbox::WriteFile(content, SystemToolbox::PathFromUtf8(target)); + } + + return 0; + } + catch (OrthancException&) + { + LOG(ERROR) << "Cannot export to file \"" << target << "\""; + return -1; + } +} + + static int ExportOpenApi(const std::string& target) { Json::Value openapi; @@ -2008,24 +2032,7 @@ std::string s; Toolbox::WriteStyledJson(s, openapi); - try - { - if (target == "-") - { - std::cout << s; // Print to stdout - } - else - { - SystemToolbox::WriteFile(s, SystemToolbox::PathFromUtf8(target)); - } - - return 0; - } - catch (OrthancException&) - { - LOG(ERROR) << "Cannot export OpenAPI documentation as file \"" << target << "\""; - return -1; - } + return ExportFile(target, s); } @@ -2043,58 +2050,42 @@ context.Stop(); } - try - { - if (target == "-") - { - std::cout << cheatsheet; // Print to stdout - } - else - { - SystemToolbox::WriteFile(cheatsheet, SystemToolbox::PathFromUtf8(target)); - } - - return 0; - } - catch (OrthancException&) - { - LOG(ERROR) << "Cannot export REST cheat sheet as file \"" << target << "\""; - return -1; - } + return ExportFile(target, cheatsheet); } +#if ORTHANC_STANDALONE == 1 static int ExportResource(const std::string& target, Orthanc::ServerResources::FileResourceId resource) { - try - { - std::string content; - GetFileResource(content, resource); + std::string content; + GetFileResource(content, resource); #if defined(_WIN32) - // Replace UNIX newlines with DOS newlines - boost::replace_all(content, "\n", "\r\n"); + // Replace UNIX newlines with DOS newlines + boost::replace_all(content, "\n", "\r\n"); +#endif + + return ExportFile(target, content); +} #endif - if (target == "-") - { - // New in 1.5.8: Print to stdout - std::cout << content; - } - else - { - SystemToolbox::WriteFile(content, SystemToolbox::PathFromUtf8(target)); - } + +#if ORTHANC_STANDALONE == 0 +static int ExportResource(const std::string& target, + const boost::filesystem::path& path) +{ + std::string content; + Orthanc::SystemToolbox::ReadFile(content, path); - return 0; - } - catch (OrthancException&) - { - LOG(ERROR) << "Cannot write to file " << SystemToolbox::PathFromUtf8(target) << ", aborting."; - return -1; - } +#if defined(_WIN32) + // Replace UNIX newlines with DOS newlines + boost::replace_all(content, "\n", "\r\n"); +#endif + + return ExportFile(target, content); } +#endif #if defined(_WIN32) && !defined(__MINGW32__) @@ -2366,13 +2357,23 @@ if (options.count(OPTION_CONFIG) == 1) { const std::string file = options[OPTION_CONFIG].as<std::string>(); + +#if ORTHANC_STANDALONE == 1 return ExportResource(file, Orthanc::ServerResources::CONFIGURATION_SAMPLE); +#else + return ExportResource(file, boost::filesystem::path(ORTHANC_PATH) / "Resources" / "Configuration.json"); +#endif } if (options.count(OPTION_ADVANCED_CONFIG) == 1) { const std::string file = options[OPTION_ADVANCED_CONFIG].as<std::string>(); + +#if ORTHANC_STANDALONE == 1 return ExportResource(file, Orthanc::ServerResources::ADVANCED_CONFIGURATION_SAMPLE); +#else + return ExportResource(file, boost::filesystem::path(ORTHANC_PATH) / "Resources" / "AdvancedConfiguration.json"); +#endif } if (options.count(OPTION_ERRORS) == 1)
