<commit_before>#include "brick/helper.h"
#include "app_settings.h"
#include "third-party/json/json.h"

AppSettings::AppSettings()
: app_token(""),
  profile_path(""),
  cache_path(""),
  log_file(""),
  proxy_server(""),
  resource_dir(""),
  ignore_certificate_errors(false),
  log_severity(LOGSEVERITY_DEFAULT),
#ifndef NDEBUG
  start_minimized(true),
#else
  start_minimized(false),
#endif
  auto_away(true),
  external_api(true),
  hide_on_delete(false)
{

}

AppSettings::~AppSettings() {

}

AppSettings
AppSettings::InitByJson(std::string json) {
  AppSettings settings;
  Json::Value root;   // will contains the root value after parsing.
  Json::Reader reader;

  bool parsingSuccessful = reader.parse(json, root);
  if (!parsingSuccessful) {
#if 0 // Turn off error message while we haven't any configuration file by default
      fprintf(stderr, "Failed to parse configuration: %s", reader.getFormattedErrorMessages().c_str());
#endif
      return settings;
  }

  settings.UpdateByJson(json);

  return settings;
}

void
AppSettings::UpdateByJson(std::string json) {
  Json::Value root;   // will contains the root value after parsing.
  Json::Reader reader;

  bool parsingSuccessful = reader.parse(json, root);
  if (!parsingSuccessful) {
#if 0 // Turn off error message while we haven't any configuration file by default
      fprintf(stderr, "Failed to parse configuration: %s", reader.getFormattedErrorMessages().c_str());
#endif
    return;
  }

  if (root.isMember("app_token")
     && root["app_token"].isString()) {
    this->profile_path = root["app_token"].asString();
  }

  if (root.isMember("profile_path")
     && root["profile_path"].isString()) {
    this->profile_path = root["profile_path"].asString();
  }<commit_msg>Выпилил лишний код в инициализации настроек<commit_after>#include "brick/helper.h"
#include "app_settings.h"
#include "third-party/json/json.h"

AppSettings::AppSettings()
: app_token(""),
  profile_path(""),
  cache_path(""),
  log_file(""),
  proxy_server(""),
  resource_dir(""),
  ignore_certificate_errors(false),
  log_severity(LOGSEVERITY_DEFAULT),
#ifndef NDEBUG
  start_minimized(true),
#else
  start_minimized(false),
#endif
  auto_away(true),
  external_api(true),
  hide_on_delete(false)
{

}

AppSettings::~AppSettings() {

}

AppSettings
AppSettings::InitByJson(std::string json) {
  AppSettings settings;
  settings.UpdateByJson(json);

  return settings;
}

void
AppSettings::UpdateByJson(std::string json) {
  Json::Value root;   // will contains the root value after parsing.
  Json::Reader reader;

  bool parsingSuccessful = reader.parse(json, root);
  if (!parsingSuccessful) {
#if 0 // Turn off error message while we haven't any configuration file by default
      fprintf(stderr, "Failed to parse configuration: %s", reader.getFormattedErrorMessages().c_str());
#endif
    return;
  }

  if (root.isMember("app_token")
     && root["app_token"].isString()) {
    this->profile_path = root["app_token"].asString();
  }

  if (root.isMember("profile_path")
     && root["profile_path"].isString()) {
    this->profile_path = root["profile_path"].asString();
  }
{'fraction_non_alphanumeric': 0.1446360153256705, 'fraction_numerical': 0.0009578544061302681, 'mean_word_length': 5.001915708812261, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7194328', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1022, 'n_words': 218}