summaryrefslogtreecommitdiff
path: root/lib/core/c++/environment.hpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-03-24 17:42:17 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-03-24 17:42:17 +0100
commit5235f13226b9a40a1d95d1d61a48cb2e8b4986a0 (patch)
tree45d1e7842b2f9866053824e9fb6ddf088723e973 /lib/core/c++/environment.hpp
parent889710232771ce78be5e815d5e12dc42a57ffcb0 (diff)
parent3af0e20773b21b519ea474e34e7c1df73d04a307 (diff)
downloadlibs-lbm-5235f13226b9a40a1d95d1d61a48cb2e8b4986a0.tar.gz
Merge branch 'dev'
Diffstat (limited to 'lib/core/c++/environment.hpp')
-rw-r--r--lib/core/c++/environment.hpp54
1 files changed, 53 insertions, 1 deletions
diff --git a/lib/core/c++/environment.hpp b/lib/core/c++/environment.hpp
index 9e587d0..27d8f3a 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<environment> lbm_directory(){
+ namespace fs = std::filesystem;
+
+ const char* home_dir = std::getenv("HOME");
+ if(not home_dir){
+ return saw::make_error<saw::err::not_found>("Couldn't find home dir");
+ }
+
+ environment env;
+
+ env.lbm_dir = std::filesystem::path{home_dir} / ".lbm";
+
+ {
+ env.data_dir = env.lbm_dir / "data";
+ // LBM Data Location
+ auto lbm_dir_config = env.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 <<file.rdbuf();
+ env.data_dir = fs::path{buffer.str()};
+ }
+ }
+ }
+
+ return env;
+}
+
/**
* Returns the default output directory.
* Located outside the project dir because dispatching build jobs with output data in the git directory
* also copies simulated data which takes a long time.
*/
saw::error_or<std::filesystem::path> output_directory(){
+ namespace fs = std::filesystem;
+
const char* home_dir = std::getenv("HOME");
if(not home_dir){
return saw::make_error<saw::err::not_found>("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 <<file.rdbuf();
+ return fs::path{buffer.str()};
+ }
+ }
+ }
+
+ return lbm_dir / "data";
}
}