34 if (accountId.empty())
35 return rootPath /
"data" /
"preferences.json";
37 return rootPath /
"data" /
"accountpreferences.json";
43 if (accountId.empty() || accountId ==
"default")
44 return rootPath /
"preferences.msgpack";
47 dhtnet::fileutils::check_dir(
dir);
48 return dir /
"preferences.msgpack";
80std::map<std::string, std::string>
86 for (
const auto&
member : members) {
88 if (value.isString()) {
90 }
else if (value.isArray()) {
97std::vector<std::map<std::string, std::string>>
104 Json::CharReaderBuilder rbuilder;
105 rbuilder[
"collectComments"] =
false;
107 std::set<std::string>
keys;
108 std::vector<std::map<std::string, std::string>> preferences;
116 if (
ok &&
root.isArray()) {
118 for (
unsigned i = 0;
i <
root.size();
i++) {
123 if (type !=
"None" && key !=
"None") {
149 JAMI_ERR() <<
"PluginPreferencesParser:: Failed to parse preferences.json for plugin: "
157std::map<std::string, std::string>
163 std::map<std::string, std::string>
rmap;
169 file.seekg(0, std::ios::end);
174 str.reserve(
static_cast<size_t>(
file.tellg()));
175 file.seekg(0, std::ios::beg);
176 str.assign((std::istreambuf_iterator<char>(
file)), std::istreambuf_iterator<char>());
180 msgpack::object_handle
oh = msgpack::unpack(
str.data(),
str.size());
184 }
catch (
const std::exception&
e) {
192std::map<std::string, std::string>
195 std::map<std::string, std::string>
rmap;
201 preferences.push_back(
item);
212 if (!accountId.empty()) {
236 }
catch (
const std::exception&
e) {
248 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
255 }
catch (
const std::exception&
e) {
264 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
271 file.seekg(0, std::ios::end);
276 str.reserve(
static_cast<size_t>(
file.tellg()));
277 file.seekg(0, std::ios::beg);
278 str.assign((std::istreambuf_iterator<char>(
file)), std::istreambuf_iterator<char>());
282 msgpack::object_handle
oh = msgpack::unpack(
str.data(),
str.size());
286 }
catch (
const std::exception&
e) {
300 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
302 Json::CharReaderBuilder rbuilder;
304 rbuilder[
"collectComments"] =
false;
308 if (
ok &&
root.isArray()) {
320 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
322 Json::CharReaderBuilder rbuilder;
324 rbuilder[
"collectComments"] =
false;
328 if (
ok &&
root.isArray()) {
344 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
356 const std::string& accountId)
361 preferences.push_back(
item);
static std::map< std::string, std::string > getPreferencesValuesMap(const std::filesystem::path &rootPath, const std::string &accountId="")
Reads preferences values.
static void getAllowDenyListPreferences(ChatHandlerList &list)
Reads ChantHandlers status from allowdeny.msgpack file.
static std::map< std::string, std::string > parsePreferenceConfig(const Json::Value &jsonPreference)
Parses a single preference from json::Value to a Map<string, string>.
static std::filesystem::path getPreferencesConfigFilePath(const std::filesystem::path &rootPath, const std::string &accountId="")
Given a plugin installation path, returns the path to the preference.json of this plugin.
static std::vector< std::map< std::string, std::string > > getPreferences(const std::filesystem::path &rootPath, const std::string &accountId="")
Reads a preference.json file from the plugin installed in rootPath.
static bool getAlwaysPreference(const std::string &rootPath, const std::string &handlerName, const std::string &accountId)
Read plugin's preferences and returns wheter a specific handler "always" preference is True or False.
static std::filesystem::path getAllowDenyListsPath()
Returns the path to allowdeny.msgpack file.
static std::filesystem::path valuesFilePath(const std::filesystem::path &rootPath, const std::string &accountId="")
Given a plugin installation path, returns the path to the preference.msgpack file.
static void setAllowDenyListPreferences(const ChatHandlerList &list)
Saves ChantHandlers status provided by list.
static bool resetPreferencesValuesMap(const std::string &rootPath, const std::string &accountId)
Resets all preferences values to their defaultValues by erasing all data saved in preferences....
static std::map< std::string, std::string > getUserPreferencesValuesMap(const std::filesystem::path &rootPath, const std::string &accountId="")
Reads preferences values which were modified from defaultValue.
static void addAlwaysHandlerPreference(const std::string &handlerName, const std::string &rootPath)
Creates a "always" preference for a handler if this preference doesn't exist yet.
static std::string convertArrayToString(const Json::Value &jsonArray)
Returns a colon separated string with values from a json::Value containing an array.
std::string getLanguage()
Returns the language of the current locale.
std::map< std::string, std::string > getLocales(const std::string &rootPath, const std::string &lang)
Returns the available keys and translations for a given plugin.
const std::filesystem::path & get_data_dir()
void emitSignal(Args... args)
std::string_view string_remove_suffix(std::string_view str, char separator)
std::map< std::pair< std::string, std::string >, std::map< std::string, bool > > ChatHandlerList
void string_replace(std::string &str, const std::string &from, const std::string &to)