#include #include #include #include #include #include "json.hpp" #include "bottles.hpp" using namespace std; using namespace cellar::bottles; namespace fs = boost::filesystem; using json = nlohmann::json; bool Bottle::load_config() { string jsonpath = this->canonical_path + "/cellar.json"; if (fs::exists(jsonpath)) { json config; ifstream configstream(jsonpath); stringstream sstr_config; sstr_config << configstream.rdbuf(); config = json::parse(sstr_config.str()); this->config = config; return true; } else { return false; } } bool Bottle::save_config() { string jsonpath = this->canonical_path + "/cellar.json"; // backup the old config in case something bad happens if (fs::exists(jsonpath)) { fs::copy_file(jsonpath, jsonpath + ".old"); // now make room for the new one fs::remove(jsonpath); } ofstream configstream(jsonpath); configstream << this->config.dump(4); return true; } string Bottle::get_config(string key) { if (this->config.find(key) != this->config.end()) { return this->config[key]; } else { return ""; } } bool Bottle::set_config(string key, string value) { this->config[key] = value; return true; }