config.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #include "app.h"
  2. AConfig::AConfig() {
  3. conffile = QApplication::applicationDirPath() + "/settings.ini";
  4. }
  5. AConfig::AConfig(const AConfig&) {
  6. throw QException(); // Выкидываем QException, в случае если
  7. // вообще попытались скопировать объект
  8. }
  9. AConfig& AConfig::operator=(AConfig&) {
  10. throw QException(); // Выкидываем QException, в случае если
  11. // вообще попытались скопировать объект
  12. }
  13. void AConfig::saveConfig(){
  14. QSettings settings( conffile, QSettings::IniFormat );
  15. //Global
  16. settings.setValue("Global/current_theme", "lotro");
  17. settings.setValue("Global/default_theme", "lotro");
  18. //Editor
  19. settings.setValue("Editor/texts", true);
  20. settings.setValue("Editor/fonts", true);
  21. settings.setValue("Editor/images", true);
  22. settings.setValue("Editor/sounds", true);
  23. settings.setValue("Editor/videos", false);
  24. settings.setValue("Editor/screens", true);
  25. settings.setValue("Editor/textures", true);
  26. //Network
  27. settings.setValue("Network/server", "http://translate.lotros.ru");
  28. settings.setValue("Network/coupon", "http://translate.lotros.ru/coupon");
  29. settings.setValue("Network/servers", "http://translate.lotros.ru/servers");
  30. settings.setValue("Network/foot", "http://translate.lotros.ru/profmessage");
  31. settings.setValue("Network/news", "http://translate.lotros.ru/groupware/launcher_news");
  32. settings.setValue("Network/launcher", "http://translate.lotros.ru/upload/launcher");
  33. settings.setValue("Network/releases", "http://translate.lotros.ru/groupware/check_updates");
  34. settings.setValue("Network/info", "http://translate.lotros.ru/paths");
  35. settings.setValue("Network/update", "http://translate.lotros.ru/groupware/update");
  36. // Values
  37. settings.setValue("Values/coupon", "");
  38. settings.setValue("Values/servers", "");
  39. // Local
  40. settings.setValue("Local/file", "client_local_English.dat");
  41. //Datetime
  42. settings.setValue("Datetime/texts", true);
  43. settings.setValue("Datetime/fonts", true);
  44. settings.setValue("Datetime/images", true);
  45. settings.setValue("Datetime/sounds", true);
  46. settings.setValue("Datetime/videos", false);
  47. settings.setValue("Datetime/loadscreens", true);
  48. settings.setValue("Datetime/textures", true);
  49. //Updates
  50. settings.setValue("Updates/update", false);
  51. settings.setValue("Updates/micro", false);
  52. settings.sync();
  53. }
  54. void AConfig::loadConfig(){
  55. App *app = &App::getInstance();
  56. app->logSectionStart("Загрузка конфигурации");
  57. qInfo("%s:%i: %s", __FILE__, __LINE__, "Находим каталог с игрой");
  58. app->window->ui->lotropathLabel->setText(app->config->getValue("Local", "folder") != "-1" ? app->config->getValue("Local", "folder") : "Выберите папку с игрой");
  59. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Шрифты\"");
  60. app->window->ui->checkFonts->setChecked(app->config->getValue("Editor", "fonts") == "true" ? true : false);
  61. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Тексты\"");
  62. app->window->ui->checkTexts->setChecked(app->config->getValue("Editor", "texts")== "true" ? true : false);
  63. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Карты\"");
  64. app->window->ui->checkMaps->setChecked(app->config->getValue("Editor", "images") == "true" ? true : false);
  65. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Звуки\"");
  66. app->window->ui->checkSounds->setChecked(app->config->getValue("Editor", "sounds")== "true" ? true : false);
  67. app->window->ui->checkVideos->setChecked(app->config->getValue("Editor", "videos") == "true" ? true : false);
  68. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Заставки\"");
  69. app->window->ui->checkScreens->setChecked(app->config->getValue("Editor", "screens")== "true" ? true : false);
  70. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность микрообновлений");
  71. app->window->ui->checkMicro->setChecked(app->config->getValue("Updates", "micro")== "true" ? true : false);
  72. qInfo("%s:%i: %s", __FILE__, __LINE__, "Выполнено.");
  73. app->logSectionEnd();
  74. }
  75. QString AConfig::getSkinFile(){
  76. App *app = &App::getInstance();
  77. QString current_theme = QApplication::applicationDirPath() + "/styles/" + app->config->getValue("Global", "current_theme") + "/skin.ini";
  78. QString default_theme = QApplication::applicationDirPath() + "/styles/" + app->config->getValue("Global", "default_theme") + "/skin.ini";
  79. QString skinfile = app->helper->fileExists(current_theme) ? current_theme : default_theme;
  80. return skinfile;
  81. }
  82. QString AConfig::getSkinName(){
  83. App *app = &App::getInstance();
  84. QString current_theme = app->config->getValue("Global", "current_theme");
  85. QString default_theme = app->config->getValue("Global", "default_theme");
  86. QString path = QApplication::applicationDirPath() + "/styles/" + current_theme + "/skin.ini";
  87. QString skinname = app->helper->fileExists(path) ? current_theme : default_theme;
  88. return skinname;
  89. }
  90. void AConfig::loadSkin(){
  91. App *app = &App::getInstance();
  92. app->logSectionStart("Загружаем скин лаунчера");
  93. qInfo("%s:%i: %s", __FILE__, __LINE__, "Определяем активную тему оформления");
  94. QSettings settings( getSkinFile(), QSettings::IniFormat );
  95. QStringList items = settings.childGroups();
  96. QVariant k;
  97. QPushButton butt;
  98. QLabel lab;
  99. qInfo("%s:%i: %s", __FILE__, __LINE__, "Начинаем настройку элементов");
  100. foreach (QString item, items){
  101. qInfo("%s:%i: %s%s", __FILE__, __LINE__, "Устанавливаем настройки для ", app->helper->stringToChar(item));
  102. QWidget* obj = app->window->findChild<QWidget*>(item);
  103. if (obj != nullptr){
  104. obj->installEventFilter(app->window);
  105. settings.beginGroup(item);
  106. if(settings.value("left").toString() != "-1"){
  107. obj->setGeometry(QRect(
  108. settings.value("left").toInt(),
  109. settings.value("top").toInt(),
  110. settings.value("width").toInt(),
  111. settings.value("height").toInt()
  112. ));
  113. }
  114. qInfo("%s:%i: %s%s", __FILE__, __LINE__, app->helper->stringToChar(item), ": настройка геометрии завершена");
  115. if(settings.value("shadow") != k){
  116. QString color = settings.value("shcolor") != k ? settings.value("shcolor").toString() : "#222";
  117. int blur = settings.value("shblur") != k ? settings.value("shblur").toInt() : 2;
  118. int offset_x = settings.value("shx") != k ? settings.value("shx").toInt() : 1;
  119. int offset_y = settings.value("shy") != k ? settings.value("shy").toInt() : 1;
  120. app->helper->applyShadow(obj, color, blur, offset_x, offset_y);
  121. }
  122. qInfo("%s:%i: %s%s", __FILE__, __LINE__, app->helper->stringToChar(item), ": настройка теней завершена");
  123. if(settings.value("text") != k){
  124. QString text = settings.value("text").toString();
  125. if(text == "del") text = "";
  126. if(obj->metaObject()->className() == butt.metaObject()->className()){
  127. QPushButton * b = dynamic_cast<QPushButton* >(obj);
  128. b->setText(text);
  129. }
  130. if(obj->metaObject()->className() == lab.metaObject()->className()){
  131. QLabel * l = dynamic_cast<QLabel* >(obj);
  132. l->setText(settings.value("text").toString());
  133. }
  134. qInfo("%s:%i: %s%s", __FILE__, __LINE__, app->helper->stringToChar(item), ": текст установлен");
  135. }
  136. if(settings.value("align") != k){
  137. QLabel * lab = dynamic_cast<QLabel* >(obj);
  138. if(settings.value("align") == "left") lab->setAlignment(Qt::AlignLeft);
  139. if(settings.value("align") == "center") lab->setAlignment(Qt::AlignCenter);
  140. if(settings.value("align") == "right") lab->setAlignment(Qt::AlignRight);
  141. }
  142. qInfo("%s:%i: %s%s", __FILE__, __LINE__, app->helper->stringToChar(item), ": настройки позиционирования применены");
  143. settings.endGroup();
  144. } else {
  145. if(item == "mainWindow") {
  146. settings.beginGroup(item);
  147. qInfo("%s:%i: %s%s", __FILE__, __LINE__, app->helper->stringToChar(item), ": обработка параметров главного окна");
  148. int w = settings.value("width").toInt();
  149. int h = settings.value("height").toInt();
  150. QDesktopWidget desktop;
  151. QRect rect = desktop.availableGeometry(desktop.primaryScreen()); // прямоугольник с размерами экрана
  152. QPoint center = rect.center(); //координаты центра экрана
  153. int x = center.x() - (w/2); // учитываем половину ширины окна
  154. int y = center.y() - (h/2); // .. половину высоты
  155. center.setX(x);
  156. center.setY(y);
  157. app->window->move(center);
  158. settings.endGroup();
  159. }
  160. qInfo("%s:%i: %s%s", __FILE__, __LINE__, app->helper->stringToChar(item), ": закончен просчет геометрии");
  161. if(item == "htmlColors") {
  162. settings.beginGroup(item);
  163. foreach(QString key, settings.allKeys()){
  164. app->helper->htmlColors.insert(key, settings.value(key).toString());
  165. }
  166. settings.endGroup();
  167. }
  168. qInfo("%s:%i: %s%s", __FILE__, __LINE__, app->helper->stringToChar(item), ": загружены HTML-цвета");
  169. }
  170. }
  171. qInfo("%s:%i: %s", __FILE__, __LINE__, "Выполнено.");
  172. app->logSectionEnd();
  173. }
  174. QString AConfig::getValue(QString section, QString key){
  175. QSettings settings( conffile, QSettings::IniFormat );
  176. settings.beginGroup(section);
  177. key = settings.value(key, -1).toString();
  178. settings.endGroup();
  179. return key;
  180. }
  181. void AConfig::setValue(QString section, QString key, QString value){
  182. QSettings settings( conffile, QSettings::IniFormat );
  183. settings.beginGroup(section);
  184. settings.setValue(key, value);
  185. settings.sync();
  186. }
  187. void AConfig::deleteKey(QString section, QString key){
  188. QSettings settings( conffile, QSettings::IniFormat );
  189. QStringList keys = settings.childKeys();
  190. settings.beginGroup(section);
  191. if (keys.contains(key)){ settings.remove(key); }
  192. settings.endGroup();
  193. }
  194. void AConfig::deleteSection(QString section){
  195. QSettings settings( conffile, QSettings::IniFormat );
  196. settings.beginGroup(section);
  197. settings.remove("");
  198. settings.endGroup();
  199. }
  200. QStringList AConfig::getLotroPath(){
  201. App *app = &App::getInstance();
  202. QStringList paths;
  203. //#if defined(Q_WS_WIN)
  204. // Windows 7
  205. QSettings m("HKEY_CLASSES_ROOT\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache", QSettings::NativeFormat);
  206. foreach (QString key, m.allKeys()) {
  207. if(key.contains("TurbineLauncher.exe") && app->helper->fileExists(key)){
  208. paths.append(key.replace("/TurbineLauncher.exe", ""));
  209. }
  210. }
  211. // Windows 8, 10
  212. QSettings n("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\12bbe590-c890-11d9-9669-0800200c9a66_is1", QSettings::NativeFormat);
  213. foreach (QString key, n.allKeys()) {
  214. qDebug() << key;
  215. if(key.contains("InstallLocation") || key.contains("installlocation")){
  216. QString folder = n.value(key).toString().replace("\\", "/").replace("/TurbineLauncher.exe", "").replace("\"", "");
  217. if(app->helper->fileExists(folder + "/TurbineLauncher.exe")) paths.append(folder);
  218. }
  219. }
  220. //#else
  221. // Реализация под Linux
  222. //#endif
  223. return paths;
  224. }
  225. void AConfig::saveAllDatFiles(){
  226. App *app = &App::getInstance();
  227. for(int i = 0; i < 5; i++){
  228. //app->datfiles[i].CommitChanges();
  229. app->datfiles[i].CloseDatFile();
  230. }
  231. }
  232. const char * AConfig::getDatPath(int id){
  233. App *app = &App::getInstance();
  234. QStringList dats;
  235. dats << app->config->getValue("Local", "file") << "client_general.dat" << "client_sound.dat" << "client_surface.dat" << "client_highres.dat";
  236. //std::string file = (app->config->getValue("Local", "folder") + "/" + dats.at(id)).toStdString();
  237. return app->helper->stringToChar(app->config->getValue("Local", "folder") + "/" + dats.at(id));
  238. }