44#include < string_view>
55#include " logging_utils.h"
66#include " services/download_service.h"
7+ #include " utils/config_yaml_utils.h"
78
89#if defined(__APPLE__) && defined(__MACH__)
910#include < mach-o/dyld.h>
@@ -84,23 +85,54 @@ inline std::filesystem::path GetConfigurationPath() {
8485 return configuration_path;
8586}
8687
87- inline std::filesystem::path GetCortexPath () {
88+ inline void CreateConfigFileIfNotExist () {
89+ auto config_path = file_manager_utils::GetConfigurationPath ();
90+ if (std::filesystem::exists (config_path)) {
91+ // already exists
92+ return ;
93+ }
94+ CLI_LOG (" Config file not found. Creating one at " + config_path.string ());
95+ auto defaultDataFolderPath =
96+ file_manager_utils::GetHomeDirectoryPath () / config_yaml_utils::kCortexFolderName ;
97+ auto config = config_yaml_utils::CortexConfig{
98+ .dataFolderPath = defaultDataFolderPath.string (),
99+ .host = config_yaml_utils::kDefaultHost ,
100+ .port = config_yaml_utils::kDefaultPort ,
101+ };
102+ std::cout << " config: " << config.dataFolderPath << " \n " ;
103+ DumpYamlConfig (config, config_path.string ());
104+ }
105+
106+ inline config_yaml_utils::CortexConfig GetCortexConfig () {
107+ auto config_path = GetConfigurationPath ();
108+ std::string variant = " " ; // TODO: empty for now
109+ return config_yaml_utils::FromYaml (config_path.string (), variant);
110+ }
111+
112+ inline std::filesystem::path GetCortexDataPath () {
88113 // TODO: We will need to support user to move the data folder to other place.
89114 // TODO: get the variant of cortex. As discussed, we will have: prod, beta, nightly
90- // currently we will store cortex data at ~/.cortex
115+ // currently we will store cortex data at ~/cortexcpp
116+ auto config = GetCortexConfig ();
117+ std::filesystem::path data_folder_path;
118+ if (!config.dataFolderPath .empty ()) {
119+ data_folder_path =
120+ std::filesystem::path (config.dataFolderPath );
121+ } else {
122+ auto home_path = GetHomeDirectoryPath ();
123+ data_folder_path = home_path / config_yaml_utils::kCortexFolderName ;
124+ }
91125
92- auto home_path = GetHomeDirectoryPath ();
93- auto cortex_path = home_path / " .cortex" ;
94- if (!std::filesystem::exists (cortex_path)) {
126+ if (!std::filesystem::exists (data_folder_path)) {
95127 CTL_INF (" Cortex home folder not found. Create one: " +
96- cortex_path .string ());
97- std::filesystem::create_directory (cortex_path );
128+ data_folder_path .string ());
129+ std::filesystem::create_directory (data_folder_path );
98130 }
99- return cortex_path ;
131+ return data_folder_path ;
100132}
101133
102134inline std::filesystem::path GetModelsContainerPath () {
103- auto cortex_path = GetCortexPath ();
135+ auto cortex_path = GetCortexDataPath ();
104136 auto models_container_path = cortex_path / " models" ;
105137
106138 if (!std::filesystem::exists (models_container_path)) {
@@ -113,7 +145,7 @@ inline std::filesystem::path GetModelsContainerPath() {
113145}
114146
115147inline std::filesystem::path GetEnginesContainerPath () {
116- auto cortex_path = GetCortexPath ();
148+ auto cortex_path = GetCortexDataPath ();
117149 auto engines_container_path = cortex_path / " engines" ;
118150
119151 if (!std::filesystem::exists (engines_container_path)) {
0 commit comments