@brief get_models_directory gets the models directory from environment variable or defaults to user/.flm/models on Windows or ~/.config/flm on Linux @return the models directory path
| 185 | ///@brief get_models_directory gets the models directory from environment variable or defaults to user/.flm/models on Windows or ~/.config/flm on Linux |
| 186 | ///@return the models directory path |
| 187 | std::string get_models_directory() { |
| 188 | #ifdef _WIN32 |
| 189 | char* model_path_env = nullptr; |
| 190 | size_t len = 0; |
| 191 | if (_dupenv_s(&model_path_env, &len, "FLM_MODEL_PATH") == 0 && model_path_env != nullptr) { |
| 192 | std::string custom_path(model_path_env); |
| 193 | free(model_path_env); |
| 194 | if (!custom_path.empty()) { |
| 195 | return custom_path; |
| 196 | } |
| 197 | } |
| 198 | #else |
| 199 | const char* model_path_env = std::getenv("FLM_MODEL_PATH"); |
| 200 | if (model_path_env && *model_path_env) { |
| 201 | return std::string(model_path_env); |
| 202 | } |
| 203 | #endif |
| 204 | // Fallback to user/.flm/ on Windows or ~/.config/flm on Linux if environment variable is not set |
| 205 | std::string user_dir = get_user_directory(); |
| 206 | #ifdef _WIN32 |
| 207 | return user_dir + "\\.flm"; |
| 208 | #else |
| 209 | return user_dir + "/flm"; |
| 210 | #endif |
| 211 | } |
| 212 | |
| 213 | } // end of namespace utils |