1 #include "pool_info.hpp" 2 #include "util/util.hpp" 3 #include <glibmm/miscutils.h> 4 #include "nlohmann/json.hpp" 5 6 namespace horizon { 7 8 const UUID PoolInfo::project_pool_uuid = UUID("466088f9-3f15-420d-af8a-fff902537aed"); 9 PoolInfo(const std::string & bp)10PoolInfo::PoolInfo(const std::string &bp) : base_path(bp) 11 { 12 auto pool_json = Glib::build_filename(base_path, "pool.json"); 13 auto j = load_json_from_file(pool_json); 14 from_json(j); 15 } 16 from_json(const json & j)17void PoolInfo::from_json(const json &j) 18 { 19 uuid = j.at("uuid").get<std::string>(); 20 default_via = j.at("default_via").get<std::string>(); 21 name = j.at("name"); 22 if (j.count("pools_included")) { 23 auto &o = j.at("pools_included"); 24 for (auto &it : o) { 25 pools_included.emplace_back(it.get<std::string>()); 26 } 27 } 28 } 29 PoolInfo()30PoolInfo::PoolInfo() 31 { 32 } 33 is_project_pool() const34bool PoolInfo::is_project_pool() const 35 { 36 return uuid == project_pool_uuid; 37 } 38 save() const39void PoolInfo::save() const 40 { 41 json j; 42 j["uuid"] = (std::string)uuid; 43 j["default_via"] = (std::string)default_via; 44 j["name"] = name; 45 j["type"] = "pool"; 46 json o = json::array(); 47 for (const auto &it : pools_included) { 48 o.push_back((std::string)it); 49 } 50 j["pools_included"] = o; 51 save_json_to_file(Glib::build_filename(base_path, "pool.json"), j); 52 } 53 54 } // namespace horizon 55