Settings::Settings() { auto lk = getLocker(); set(ZMKW_LOGPORT, ZCSTR("59000"), lk); set(ZMKW_LOGSERVER, ZCSTR("127.0.0.1"), lk); set(ZMKW_LOGPROTO, ZCSTR("ZMG_PUB"), lk); ZConstString home_str((const char*)secure_getenv("HOME")); set(ZMB::ZMKW_USER_HOME, home_str, lk); char* temp = (char*)alloca(ZMB::max<unsigned>(1024u, (unsigned)(4 * home_str.len))); ZUnsafeBuf buf(temp, 1024); buf.fill(0); buf.read(0, home_str, 0); char* origin = buf.begin(); buf.str += home_str.len;//advance to point after the user home location buf.len -= home_str.len; auto __set_value = [&](ZConstString str, ZConstString key) mutable { char* end = 0; buf.read(&end, str, 0); *end = '\0'; set(key, ZConstString(origin, end), lk); }; __set_value(ZCSTR("/zmbaq_config.json"), ZMKW_CFG_LOCATION); /** TODO: platform-dependent temporary storage. **/ __set_value(ZCSTR("/tmp/video_temp"), ZMKW_FS_TEMP_LOCATION); __set_value(ZCSTR("/tmp/video_perm"), ZMKW_FS_PERM_LOCATION); __set_value(ZCSTR("/tmp/test_db"), ZMKW_TESTDB_LOCATION); __set_value(ZCSTR("/tmp/test_blob_db"), ZMKW_TESTDBBLOB_LOCATION); }
const std::string compact_path_home(const std::string &str) { const char *home = get_home(); if (home) { std::string home_str(home); if (str == home_str || boost::algorithm::starts_with(str, home_str + "/")) return "~" + str.substr(home_str.size()); } return str; }