Config.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. FilterPublisher,
  23. FilterFeatures,
  24. // Sort
  25. SortGameList,
  26. SortGameListDirection,
  27. SortInstalledList,
  28. SortInstalledListDirection,
  29. // Update
  30. AutoUpdate,
  31. LastUpdatedTime,
  32. DownloadTitleKeys,
  33. KeyURLs,
  34. DownloadFromMultipleURLs,
  35. // Download
  36. DownloadTimeout,
  37. DownloadBufferSize,
  38. PlaySoundAfterDownload,
  39. PowerOffAfterDownload,
  40. PowerOffTime,
  41. // Music
  42. MusicMode,
  43. MusicFilename,
  44. MusicTurnOffSlider,
  45. // Locales
  46. Language,
  47. Keyboard,
  48. SystemKeyboard,
  49. // Notifiers
  50. LEDStartup,
  51. LEDDownloadFinished,
  52. LEDDownloadError,
  53. NEWSDownloadFinished,
  54. NEWSNoLED,
  55. // Inactivity
  56. SleepMode,
  57. SleepModeBottom,
  58. DimLEDs,
  59. SoundOnInactivity,
  60. MusicOnInactivity,
  61. InactivitySeconds,
  62. // Other
  63. TitleID,
  64. ShowBattery,
  65. ShowGameCounter,
  66. ShowGameDescription,
  67. DarkTheme,
  68. RestartFix,
  69. AP_FUSE,
  70. // Internals
  71. ResetEshopMusic,
  72. CleanExit,
  73. KEY_COUNT,
  74. };
  75. static Config& getInstance();
  76. void loadDefaults();
  77. public:
  78. static bool loadFromFile(const std::string& filename = FREESHOP_DIR "/config.json");
  79. static void saveToFile(const std::string& filename = FREESHOP_DIR "/config.json");
  80. static bool keyExists(const char *key);
  81. static const rapidjson::Value &get(Key key);
  82. static rapidjson::Document::AllocatorType &getAllocator();
  83. template <typename T>
  84. static void set(Key key, T val)
  85. {
  86. rapidjson::Value v(val);
  87. set(key, v);
  88. }
  89. static void set(Key key, const char *val);
  90. static void set(Key key, rapidjson::Value &val);
  91. private:
  92. Config();
  93. rapidjson::Document m_json;
  94. };
  95. } // namespace FreeShop
  96. #endif // FREESHOP_CONFIG_HPP