Config.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. CacheVersion,
  14. TriggerUpdateFlag,
  15. ShowNews,
  16. // Filter
  17. FilterRegion,
  18. FilterGenre,
  19. FilterLanguage,
  20. FilterPlatform,
  21. // Sort
  22. // Update
  23. AutoUpdate,
  24. LastUpdatedTime,
  25. DownloadTitleKeys,
  26. KeyURLs,
  27. // Download
  28. DownloadTimeout,
  29. DownloadBufferSize,
  30. PlaySoundAfterDownload,
  31. PowerOffAfterDownload,
  32. PowerOffTime,
  33. // Other
  34. SleepMode,
  35. Language,
  36. KEY_COUNT,
  37. };
  38. static Config& getInstance();
  39. void loadDefaults();
  40. public:
  41. static bool loadFromFile(const std::string& filename = FREESHOP_DIR "/config.json");
  42. static void saveToFile(const std::string& filename = FREESHOP_DIR "/config.json");
  43. static bool keyExists(const char *key);
  44. static const rapidjson::Value &get(Key key);
  45. static rapidjson::Document::AllocatorType &getAllocator();
  46. template <typename T>
  47. static void set(Key key, T val)
  48. {
  49. rapidjson::Value v(val);
  50. set(key, v);
  51. }
  52. static void set(Key key, const char *val);
  53. static void set(Key key, rapidjson::Value &val);
  54. private:
  55. Config();
  56. rapidjson::Document m_json;
  57. };
  58. } // namespace FreeShop
  59. #endif // FREESHOP_CONFIG_HPP