settings.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include <QSettings>
  2. #include "settings.h"
  3. namespace Settings {
  4. QMap<QString, QVariant> defaults = {
  5. // General info
  6. {"General/UI_scale", 100},
  7. {"General/CurrentInitStage", "0"},
  8. {"General/MicroUpdates", false},
  9. {"General/PatchDownloadDir", "data"},
  10. // Lotro Manager
  11. {"Lotro/game_path", "none"},
  12. {"Lotro/original_locale", "English"},
  13. {"Lotro/skip_raw_download", true},
  14. {"Lotro/no_splash_screen", false},
  15. // Backup
  16. {"Backup/installed", false},
  17. {"Backup/path", "/backup/"},
  18. {"Backup/creation_time", "none"},
  19. // Databases download settings (true means component is enabled)
  20. {"DatabaseDownload/text", false}, // TextsPatch
  21. {"DatabaseDownload/font", false}, // TextsPatch
  22. {"DatabaseDownload/image", false}, // GraphicsPatch
  23. {"DatabaseDownload/loadscreen", false}, // GraphicsPatch
  24. {"DatabaseDownload/texture", false}, // GraphicsPatch
  25. {"DatabaseDownload/sound", false}, // SoundsPatch
  26. {"DatabaseDownload/video", false}, // VideosPatch
  27. {"DatabaseDownload/micro", false}, // MicroPatch
  28. // Network settings
  29. {"Network/site_url", "http://translate.lotros.ru/"},
  30. {"Network/forum_url", "http://lotros.ru/"},
  31. {"Network/discord_url", "https://discord.gg/j25MdKR"},
  32. {"Network/add_report_url", "http://translate.lotros.ru/bugs/add"},
  33. {"Network/donate_url", "http://translate.lotros.ru/donate"},
  34. {"Network/game_servers_status", "http://translate.lotros.ru/servers.txt"},
  35. {"Network/game_servers_message", "http://translate.lotros.ru/profmessage.txt"},
  36. {"Network/weekly_code_url", "http://translate.lotros.ru/coupon.txt"},
  37. {"Network/news_list_url", "http://translate.lotros.ru/groupware/launcher_news/30/1"},
  38. {"Network/patch_updates_url", "http://translate.lotros.ru/groupware/check_updates"}
  39. };
  40. void setDefaultSettings()
  41. {
  42. QSettings settings;
  43. foreach (QString key, defaults.keys()) {
  44. settings.setValue(key, defaults[key]);
  45. }
  46. }
  47. QVariant getValue(QString key) {
  48. QSettings settings;
  49. return settings.value(key, defaults.value(key, QVariant()));
  50. }
  51. void setValue(QString key, QVariant value) {
  52. QSettings settings;
  53. settings.setValue(key, value);
  54. }
  55. SettingsBackup createSettingsBackup() {
  56. QSettings settings;
  57. QMap<QString, QVariant> keysValuesPairs;
  58. QStringList keys = settings.allKeys();
  59. QStringListIterator it(keys);
  60. while (it.hasNext()) {
  61. QString currentKey = it.next();
  62. keysValuesPairs.insert(currentKey, settings.value(currentKey));
  63. }
  64. return keysValuesPairs;
  65. }
  66. void restoreFromSettingsBackup(const SettingsBackup& backup) {
  67. QSettings settings;
  68. settings.clear();
  69. for (auto i = backup.begin(); i != backup.end(); ++i) {
  70. settings.setValue(i.key(), i.value());
  71. }
  72. }
  73. void updatePatchComponentsDependencies() {
  74. QSettings settings;
  75. auto isComponentActive = [&settings](const QString& component) -> bool {
  76. return settings.value("Components/" + component).toBool();
  77. };
  78. if (isComponentActive("texts_main") || isComponentActive("texts_items")
  79. || isComponentActive("texts_emotes") || isComponentActive("videos")) {
  80. // Videos also need text database, because it contains videos path references
  81. settings.setValue("DatabaseDownload/text", true);
  82. } else {
  83. settings.setValue("DatabaseDownload/text", false);
  84. }
  85. if (isComponentActive("texts_main") || isComponentActive("texts_items")
  86. || isComponentActive("texts_emotes")) {
  87. settings.setValue("DatabaseDownload/font", true);
  88. } else {
  89. settings.setValue("DatabaseDownload/font", false);
  90. }
  91. settings.setValue("DatabaseDownload/image", isComponentActive("maps"));
  92. settings.setValue("DatabaseDownload/loadscreen", isComponentActive("loadscreens"));
  93. settings.setValue("DatabaseDownload/texture", isComponentActive("textures"));
  94. settings.setValue("DatabaseDownload/sound", isComponentActive("sounds"));
  95. settings.setValue("DatabaseDownload/video", isComponentActive("videos"));
  96. settings.setValue("DatabaseDownload/micro", isComponentActive("micropatch"));
  97. }
  98. } /* namespace Settings */