Make _profile in Config public and rename to profile.
This commit is contained in:
parent
61d591e925
commit
a692e00128
|
@ -74,8 +74,8 @@ std::ostream &operator <<(std::ostream &out, const ProfileData &data)
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::Config(string profile)
|
Config::Config(string profile_name)
|
||||||
:_profile{move(profile)}
|
: profile{move(profile)}
|
||||||
{
|
{
|
||||||
const fs::path filename = get_filename();
|
const fs::path filename = get_filename();
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Config filename is: " << filename;
|
BOOST_LOG_TRIVIAL(debug) << "Config filename is: " << filename;
|
||||||
|
@ -127,7 +127,7 @@ fs::path Config::get_config_dir() const
|
||||||
|
|
||||||
fs::path Config::get_filename() const
|
fs::path Config::get_filename() const
|
||||||
{
|
{
|
||||||
return get_config_dir() /= "config-" + _profile + ".json";
|
return get_config_dir() /= "config-" + profile+ ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::generate()
|
void Config::generate()
|
||||||
|
@ -225,48 +225,48 @@ string Config::get_access_token(const string &instance) const
|
||||||
|
|
||||||
void Config::parse()
|
void Config::parse()
|
||||||
{
|
{
|
||||||
profiledata.access_token = _json[_profile]["access_token"].asString();
|
profiledata.access_token = _json[profile]["access_token"].asString();
|
||||||
profiledata.append = _json[_profile]["append"].asString();
|
profiledata.append = _json[profile]["append"].asString();
|
||||||
profiledata.feedurl = _json[_profile]["feedurl"].asString();
|
profiledata.feedurl = _json[profile]["feedurl"].asString();
|
||||||
for (const auto &fix : _json[_profile]["fixes"])
|
for (const auto &fix : _json[profile]["fixes"])
|
||||||
{
|
{
|
||||||
profiledata.fixes.push_back(fix.asString());
|
profiledata.fixes.push_back(fix.asString());
|
||||||
}
|
}
|
||||||
profiledata.instance = _json[_profile]["instance"].asString();
|
profiledata.instance = _json[profile]["instance"].asString();
|
||||||
if (!_json[_profile]["interval"].isNull())
|
if (!_json[profile]["interval"].isNull())
|
||||||
{
|
{
|
||||||
profiledata.interval =
|
profiledata.interval =
|
||||||
static_cast<uint32_t>(_json[_profile]["interval"].asUInt64());
|
static_cast<uint32_t>(_json[profile]["interval"].asUInt64());
|
||||||
}
|
}
|
||||||
profiledata.last_guid = _json[_profile]["last_guid"].asString();
|
profiledata.last_guid = _json[profile]["last_guid"].asString();
|
||||||
if (!_json[_profile]["max_size"].isNull())
|
if (!_json[profile]["max_size"].isNull())
|
||||||
{
|
{
|
||||||
profiledata.max_size = _json[_profile]["max_size"].asUInt64();
|
profiledata.max_size = _json[profile]["max_size"].asUInt64();
|
||||||
}
|
}
|
||||||
for (const auto &skip : _json[_profile]["skip"])
|
for (const auto &skip : _json[profile]["skip"])
|
||||||
{
|
{
|
||||||
profiledata.skip.push_back(skip.asString());
|
profiledata.skip.push_back(skip.asString());
|
||||||
}
|
}
|
||||||
profiledata.titles_as_cw = _json[_profile]["titles_as_cw"].asBool();
|
profiledata.titles_as_cw = _json[profile]["titles_as_cw"].asBool();
|
||||||
profiledata.titles_only = _json[_profile]["titles_only"].asBool();
|
profiledata.titles_only = _json[profile]["titles_only"].asBool();
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Read config: " << profiledata;
|
BOOST_LOG_TRIVIAL(debug) << "Read config: " << profiledata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::write()
|
void Config::write()
|
||||||
{
|
{
|
||||||
_json[_profile]["access_token"] = profiledata.access_token;
|
_json[profile]["access_token"] = profiledata.access_token;
|
||||||
_json[_profile]["append"] = profiledata.append;
|
_json[profile]["append"] = profiledata.append;
|
||||||
_json[_profile]["feedurl"] = profiledata.feedurl;
|
_json[profile]["feedurl"] = profiledata.feedurl;
|
||||||
// Leave fixes.
|
// Leave fixes.
|
||||||
_json[_profile]["instance"] = profiledata.instance;
|
_json[profile]["instance"] = profiledata.instance;
|
||||||
_json[_profile]["interval"] = profiledata.interval;
|
_json[profile]["interval"] = profiledata.interval;
|
||||||
_json[_profile]["last_guid"] = profiledata.last_guid;
|
_json[profile]["last_guid"] = profiledata.last_guid;
|
||||||
_json[_profile]["max_size"]
|
_json[profile]["max_size"]
|
||||||
= static_cast<Json::Value::UInt64>(profiledata.max_size);
|
= static_cast<Json::Value::UInt64>(profiledata.max_size);
|
||||||
// Leave skip.
|
// Leave skip.
|
||||||
_json[_profile]["titles_as_cw"] = profiledata.titles_as_cw;
|
_json[profile]["titles_as_cw"] = profiledata.titles_as_cw;
|
||||||
_json[_profile]["titles_only"] = profiledata.titles_only;
|
_json[profile]["titles_only"] = profiledata.titles_only;
|
||||||
|
|
||||||
ofstream file{get_filename().c_str()};
|
ofstream file{get_filename().c_str()};
|
||||||
if (file.good())
|
if (file.good())
|
||||||
|
|
|
@ -64,8 +64,9 @@ struct ProfileData
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Config(string profile);
|
explicit Config(string profile_name);
|
||||||
|
|
||||||
|
const string profile;
|
||||||
ProfileData profiledata;
|
ProfileData profiledata;
|
||||||
|
|
||||||
void write();
|
void write();
|
||||||
|
@ -73,7 +74,6 @@ public:
|
||||||
fs::path get_config_dir() const;
|
fs::path get_config_dir() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const string _profile;
|
|
||||||
Json::Value _json;
|
Json::Value _json;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user