Config.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 definitions in Config.cpp
  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. // Locales
  38. Language,
  39. Keyboard,
  40. SystemKeyboard,
  41. // Other
  42. SleepMode,
  43. TitleID,
  44. Skiddo,
  45. ShowBattery,
  46. ShowGameCounter,
  47. KEY_COUNT,
  48. };
  49. static Config& getInstance();
  50. void loadDefaults();
  51. public:
  52. static bool loadFromFile(const std::string& filename = FREESHOP_DIR "/config.json");
  53. static void saveToFile(const std::string& filename = FREESHOP_DIR "/config.json");
  54. static bool keyExists(const char *key);
  55. static const rapidjson::Value &get(Key key);
  56. static rapidjson::Document::AllocatorType &getAllocator();
  57. template <typename T>
  58. static void set(Key key, T val)
  59. {
  60. rapidjson::Value v(val);
  61. set(key, v);
  62. }
  63. static void set(Key key, const char *val);
  64. static void set(Key key, rapidjson::Value &val);
  65. private:
  66. Config();
  67. rapidjson::Document m_json;
  68. };
  69. } // namespace FreeShop
  70. #endif // FREESHOP_CONFIG_HPP