Config.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef FREESHOP_CONFIG_HPP
  2. #define FREESHOP_CONFIG_HPP
  3. #include <string>
  4. #include <rapidjson/document.h>
  5. #ifndef FREESHOP_VERSION
  6. #error "No version defined"
  7. #endif
  8. namespace FreeShop {
  9. class Config {
  10. public:
  11. // See string deifnitions in Config.coo
  12. enum Key {
  13. Version,
  14. CacheVersion,
  15. TriggerUpdateFlag,
  16. ShowNews,
  17. // Filter
  18. FilterRegion,
  19. FilterGenre,
  20. FilterLanguage,
  21. FilterPlatform,
  22. // Sort
  23. // Update
  24. AutoUpdate,
  25. LastUpdatedTime,
  26. DownloadTitleKeys,
  27. KeyURLs,
  28. // Download
  29. DownloadTimeout,
  30. DownloadBufferSize,
  31. PlaySoundAfterDownload,
  32. PowerOffAfterDownload,
  33. PowerOffTime,
  34. // Music
  35. MusicMode,
  36. MusicFilename,
  37. // Other
  38. SleepMode,
  39. Language,
  40. KEY_COUNT,
  41. };
  42. static Config& getInstance();
  43. void loadDefaults();
  44. public:
  45. static bool loadFromFile(const std::string& filename = FREESHOP_DIR "/config.json");
  46. static void saveToFile(const std::string& filename = FREESHOP_DIR "/config.json");
  47. static bool keyExists(const char *key);
  48. static const rapidjson::Value &get(Key key);
  49. static rapidjson::Document::AllocatorType &getAllocator();
  50. template <typename T>
  51. static void set(Key key, T val)
  52. {
  53. rapidjson::Value v(val);
  54. set(key, v);
  55. }
  56. static void set(Key key, const char *val);
  57. static void set(Key key, rapidjson::Value &val);
  58. private:
  59. Config();
  60. rapidjson::Document m_json;
  61. };
  62. } // namespace FreeShop
  63. #endif // FREESHOP_CONFIG_HPP