Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

HostsConfig.cpp 920B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // Created by robin on 8/8/15.
  3. //
  4. #include <json/json.h>
  5. #include <fstream>
  6. #include "HostsConfig.h"
  7. HostsConfig::HostsConfig(const std::string &filePath)
  8. : _filePath(filePath)
  9. {
  10. }
  11. bool HostsConfig::readConfig()
  12. {
  13. std::ifstream file(_filePath);
  14. if (!file)
  15. return false;
  16. Json::Value root;
  17. try
  18. {
  19. file >> root;
  20. file.close();
  21. }
  22. catch (...)
  23. {
  24. file.close();
  25. return false;
  26. }
  27. auto defaults = root["defaults"];
  28. auto actions = root["actions"];
  29. for (Json::ArrayIndex i = 0; i < actions.size(); ++i)
  30. {
  31. auto action = actions[i];
  32. auto action_type = readValue(action, defaults, "action");
  33. }
  34. return true;
  35. }
  36. Json::Value HostsConfig::readValue(const Json::Value &value, const Json::Value &defaults, const std::string &name)
  37. {
  38. auto v = value[name];
  39. if (!v)
  40. return defaults[name];
  41. return v;
  42. }