From b097a89f1dd01eb57e605ab2e3002fff127787af Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 24 Mar 2026 12:14:57 +0100 Subject: Do more env handling --- lib/core/c++/environment.hpp | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'lib/core') diff --git a/lib/core/c++/environment.hpp b/lib/core/c++/environment.hpp index 9e587d0..f9bac48 100644 --- a/lib/core/c++/environment.hpp +++ b/lib/core/c++/environment.hpp @@ -7,18 +7,70 @@ namespace kel { namespace lbm { +struct environment { + std::filesystem::path lbm_dir; + std::filesystem::path data_dir; +}; + +saw::error_or lbm_directory(){ + namespace fs = std::filesystem; + + const char* home_dir = std::getenv("HOME"); + if(not home_dir){ + return saw::make_error("Couldn't find home dir"); + } + + environment env; + + env.lbm_dir = std::filesystem::path{home_dir} / ".lbm"; + + { + env.data_dir = env.lbm_dir / "data"; + // LBM + auto lbm_dir_config = lbm_dir / "data_dir_location.txt"; + if( fs::exists(lbm_dir_config) && fs::is_regular_file(lbm_dir_config) ){ + std::ifstream file{lbm_dir_config}; + + if(file.is_open()){ + std::stringstream buffer; + buffer < output_directory(){ + namespace fs = std::filesystem; + const char* home_dir = std::getenv("HOME"); if(not home_dir){ return saw::make_error("Couldn't find home dir"); } - return std::filesystem::path{home_dir} / ".lbm"; + auto lbm_dir = std::filesystem::path{home_dir} / ".lbm"; + + { + auto lbm_dir_config = lbm_dir / "data_dir_location.txt"; + if( fs::exists(lbm_dir_config) && fs::is_regular_file(lbm_dir_config) ){ + std::ifstream file{lbm_dir_config}; + + if(file.is_open()){ + std::stringstream buffer; + buffer <