settings.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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
  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. // Flags, meaning that database is fresh and needs to be installed
  29. {"DatabaseNeedInstall/text", false}, // TextsPatch
  30. {"DatabaseNeedInstall/font", false}, // TextsPatch
  31. {"DatabaseNeedInstall/image", false}, // GraphicsPatch
  32. {"DatabaseNeedInstall/loadscreen", false}, // GraphicsPatch
  33. {"DatabaseNeedInstall/texture", false}, // GraphicsPatch
  34. {"DatabaseNeedInstall/sound", false}, // SoundsPatch
  35. {"DatabaseNeedInstall/video", false}, // VideosPatch
  36. {"DatabaseNeedInstall/micro", false}, // MircoPatch
  37. // Localisation components, showed and edited by user in GUI
  38. {"Components/texts_main", false}, // TextsPatch
  39. {"Components/texts_items", false}, // TextsPatch
  40. {"Components/texts_emotes", false}, // TextsPatch
  41. {"Components/maps", false}, // ImagesPatch
  42. {"Components/loadscreens", false}, // ImagesPatch
  43. {"Components/textures", false}, // ImagesPatch
  44. {"Components/sounds", false}, // SoundsPatch
  45. {"Components/videos", false}, // VideosPatch
  46. {"Components/micropatch", false}, // PatchList
  47. // Network settings
  48. {"Network/site_url", "http://translate.lotros.ru/"},
  49. {"Network/forum_url", "http://lotros.ru/"},
  50. {"Network/discord_url", "https://discord.gg/j25MdKR"},
  51. {"Network/add_report_url", "http://translate.lotros.ru/bugs/add"},
  52. {"Network/donate_url", "http://translate.lotros.ru/donate"},
  53. {"Network/game_servers_status", "http://translate.lotros.ru/servers.txt"},
  54. {"Network/game_servers_message", "http://translate.lotros.ru/profmessage.txt"},
  55. {"Network/weekly_code_url", "http://translate.lotros.ru/coupon.txt"},
  56. {"Network/news_list_url", "http://translate.lotros.ru/groupware/launcher_news/30/1"},
  57. {"Network/patch_updates_url", "http://translate.lotros.ru/groupware/check_updates"}
  58. };
  59. void setDefaultSettings()
  60. {
  61. QSettings settings;
  62. foreach (QString key, defaults.keys()) {
  63. settings.setValue(key, defaults[key]);
  64. }
  65. }
  66. QVariant getValue(QString key) {
  67. QSettings settings;
  68. return settings.value(key, defaults.value(key, QVariant()));
  69. }
  70. void setValue(QString key, QVariant value) {
  71. QSettings settings;
  72. settings.setValue(key, value);
  73. }
  74. SettingsBackup createSettingsBackup() {
  75. QSettings settings;
  76. QMap<QString, QVariant> keysValuesPairs;
  77. QStringList keys = settings.allKeys();
  78. QStringListIterator it(keys);
  79. while (it.hasNext()) {
  80. QString currentKey = it.next();
  81. keysValuesPairs.insert(currentKey, settings.value(currentKey));
  82. }
  83. return keysValuesPairs;
  84. }
  85. void restoreFromSettingsBackup(const SettingsBackup& backup) {
  86. QSettings settings;
  87. settings.clear();
  88. for (auto i = backup.begin(); i != backup.end(); ++i) {
  89. settings.setValue(i.key(), i.value());
  90. }
  91. }
  92. void updatePatchComponentsDependencies() {
  93. QSettings settings;
  94. auto isComponentActive = [&settings](const QString& component) -> bool {
  95. return settings.value("Components/" + component).toBool();
  96. };
  97. if (isComponentActive("texts_main") || isComponentActive("texts_items")
  98. || isComponentActive("texts_emotes") || isComponentActive("videos")) {
  99. // Videos also need text database, because it contains videos path references
  100. settings.setValue("DatabaseDownload/text", true);
  101. } else {
  102. settings.setValue("DatabaseDownload/text", false);
  103. }
  104. if (isComponentActive("texts_main") || isComponentActive("texts_items")
  105. || isComponentActive("texts_emotes")) {
  106. settings.setValue("DatabaseDownload/font", true);
  107. } else {
  108. settings.setValue("DatabaseDownload/font", false);
  109. }
  110. settings.setValue("DatabaseDownload/image", isComponentActive("maps"));
  111. settings.setValue("DatabaseDownload/loadscreen", isComponentActive("loadscreens"));
  112. settings.setValue("DatabaseDownload/texture", isComponentActive("textures"));
  113. settings.setValue("DatabaseDownload/sound", isComponentActive("sounds"));
  114. settings.setValue("DatabaseDownload/video", isComponentActive("videos"));
  115. settings.setValue("DatabaseDownload/micro", isComponentActive("micropatch"));
  116. }
  117. } /* namespace Settings */