#include "app.h" #include "filesystem.h" AConfig::AConfig() { conffile = QApplication::applicationDirPath() + "/settings.ini"; //conffile = "../settings.ini"; } AConfig::AConfig(const AConfig&) { throw QException(); // Выкидываем QException, в случае если // вообще попытались скопировать объект } AConfig& AConfig::operator=(AConfig&) { throw QException(); // Выкидываем QException, в случае если // вообще попытались скопировать объект } void AConfig::saveConfig(){ QSettings settings( conffile, QSettings::IniFormat ); //Global settings.setValue("Global/current_theme", "lotro"); settings.setValue("Global/default_theme", "lotro"); //Editor settings.setValue("Editor/texts", true); settings.setValue("Editor/fonts", true); settings.setValue("Editor/images", true); settings.setValue("Editor/sounds", true); settings.setValue("Editor/videos", false); settings.setValue("Editor/loadscreens", true); settings.setValue("Editor/textures", true); //Network settings.setValue("Network/server", "http://translate.lotros.ru"); settings.setValue("Network/coupon", "http://translate.lotros.ru/coupon"); settings.setValue("Network/servers", "http://translate.lotros.ru/servers"); settings.setValue("Network/foot", "http://translate.lotros.ru/profmessage"); settings.setValue("Network/news", "http://translate.lotros.ru/groupware/launcher_news"); settings.setValue("Network/launcher", "http://translate.lotros.ru/upload/launcher"); settings.setValue("Network/releases", "http://translate.lotros.ru/groupware/check_updates"); settings.setValue("Network/info", "http://translate.lotros.ru/paths"); settings.setValue("Network/update", "http://translate.lotros.ru/groupware/update"); // Values settings.setValue("Values/coupon", ""); settings.setValue("Values/servers", ""); // Local settings.setValue("Local/file", "client_local_English.dat"); settings.setValue("Local/lang", "en"); //Datetime settings.setValue("Datetime/texts", "-1"); settings.setValue("Datetime/fonts", "-1"); settings.setValue("Datetime/images", "-1"); settings.setValue("Datetime/sounds", "-1"); settings.setValue("Datetime/videos", "-1"); settings.setValue("Datetime/loadscreens", "-1"); settings.setValue("Datetime/textures", "-1"); //Updates settings.setValue("Updates/update", false); settings.setValue("Updates/micro", false); settings.sync(); } void AConfig::loadConfig(){ App *app = &App::getInstance(); app->logSectionStart("Загрузка конфигурации"); qInfo("%s:%i: %s", __FILE__, __LINE__, "Находим каталог с игрой"); app->window->ui->lotropathLabel->setText(app->config->getValue("Local", "folder") != "-1" ? app->config->getValue("Local", "folder") : "Выберите папку с игрой"); qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Шрифты\""); app->window->ui->checkFonts->setChecked(app->config->getValue("Editor", "fonts") == "true" ? true : false); qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Тексты\""); app->window->ui->checkTexts->setChecked(app->config->getValue("Editor", "texts")== "true" ? true : false); qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Карты\""); app->window->ui->checkMaps->setChecked(app->config->getValue("Editor", "images") == "true" ? true : false); qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Звуки\""); app->window->ui->checkSounds->setChecked(app->config->getValue("Editor", "sounds")== "true" ? true : false); app->window->ui->checkVideos->setChecked(app->config->getValue("Editor", "videos") == "true" ? true : false); qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Заставки\""); app->window->ui->checkScreens->setChecked(app->config->getValue("Editor", "screens")== "true" ? true : false); qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность микрообновлений"); app->window->ui->checkMicro->setChecked(app->config->getValue("Updates", "micro")== "true" ? true : false); qInfo("%s:%i: %s", __FILE__, __LINE__, "Выполнено."); app->logSectionEnd(); } QString AConfig::getSkinFile(){ App *app = &App::getInstance(); QString current_theme = QApplication::applicationDirPath() + "/styles/" + app->config->getValue("Global", "current_theme") + "/skin.ini"; QString default_theme = QApplication::applicationDirPath() + "/styles/" + app->config->getValue("Global", "default_theme") + "/skin.ini"; QString skinfile = FileSystem::fileExists(current_theme) ? current_theme : default_theme; return skinfile; } QString AConfig::getSkinName(){ App *app = &App::getInstance(); QString current_theme = app->config->getValue("Global", "current_theme"); QString default_theme = app->config->getValue("Global", "default_theme"); QString path = QApplication::applicationDirPath() + "/styles/" + current_theme + "/skin.ini"; QString skinname = FileSystem::fileExists(path) ? current_theme : default_theme; return skinname; } void AConfig::loadSkin(){ App *app = &App::getInstance(); app->logSectionStart("Загружаем скин лаунчера"); qInfo("%s:%i: %s", __FILE__, __LINE__, "Определяем активную тему оформления"); QSettings settings( getSkinFile(), QSettings::IniFormat ); QStringList items = settings.childGroups(); QVariant k; QPushButton butt; QLabel lab; qInfo("%s:%i: %s", __FILE__, __LINE__, "Начинаем настройку элементов"); foreach (QString item, items){ qInfo("%s:%i: %s%s", __FILE__, __LINE__, "Устанавливаем настройки для ", item.toUtf8().data()); QWidget* obj = app->window->findChild(item); if (obj != nullptr){ obj->installEventFilter(app->window); settings.beginGroup(item); if(settings.value("left").toString() != "-1"){ obj->setGeometry(QRect( settings.value("left").toInt(), settings.value("top").toInt(), settings.value("width").toInt(), settings.value("height").toInt() )); } qInfo("%s:%i: %s%s", __FILE__, __LINE__, item.toUtf8().data(), ": настройка геометрии завершена"); if(settings.value("shadow") != k){ QString color = settings.value("shcolor") != k ? settings.value("shcolor").toString() : "#222"; int blur = settings.value("shblur") != k ? settings.value("shblur").toInt() : 2; int offset_x = settings.value("shx") != k ? settings.value("shx").toInt() : 1; int offset_y = settings.value("shy") != k ? settings.value("shy").toInt() : 1; app->helper->applyShadow(obj, color, blur, offset_x, offset_y); } qInfo("%s:%i: %s%s", __FILE__, __LINE__, item.toUtf8().data(), ": настройка теней завершена"); if(settings.value("text") != k){ QString text = settings.value("text").toString(); if(text == "del") text = ""; if(obj->metaObject()->className() == butt.metaObject()->className()){ QPushButton * b = dynamic_cast(obj); b->setText(text); } if(obj->metaObject()->className() == lab.metaObject()->className()){ QLabel * l = dynamic_cast(obj); l->setText(settings.value("text").toString()); } qInfo("%s:%i: %s%s", __FILE__, __LINE__, item.toUtf8().data(), ": текст установлен"); } if(settings.value("align") != k){ QLabel * lab = dynamic_cast(obj); if(settings.value("align") == "left") lab->setAlignment(Qt::AlignLeft); if(settings.value("align") == "center") lab->setAlignment(Qt::AlignCenter); if(settings.value("align") == "right") lab->setAlignment(Qt::AlignRight); } qInfo("%s:%i: %s%s", __FILE__, __LINE__, item.toUtf8().data(), ": настройки позиционирования применены"); settings.endGroup(); } else { if(item == "mainWindow") { settings.beginGroup(item); qInfo("%s:%i: %s%s", __FILE__, __LINE__, item.toUtf8().data(), ": обработка параметров главного окна"); int w = settings.value("width").toInt(); int h = settings.value("height").toInt(); QDesktopWidget desktop; QRect rect = desktop.availableGeometry(desktop.primaryScreen()); // прямоугольник с размерами экрана QPoint center = rect.center(); //координаты центра экрана int x = center.x() - (w/2); // учитываем половину ширины окна int y = center.y() - (h/2); // .. половину высоты center.setX(x); center.setY(y); app->window->move(center); settings.endGroup(); } qInfo("%s:%i: %s%s", __FILE__, __LINE__, item.toUtf8().data(), ": закончен просчет геометрии"); if(item == "htmlColors") { settings.beginGroup(item); foreach(QString key, settings.allKeys()){ app->helper->htmlColors.insert(key, settings.value(key).toString()); } settings.endGroup(); } qInfo("%s:%i: %s%s", __FILE__, __LINE__, item.toUtf8().data(), ": загружены HTML-цвета"); } } qInfo("%s:%i: %s", __FILE__, __LINE__, "Выполнено."); app->logSectionEnd(); } QString AConfig::getValue(QString section, QString key){ QSettings settings( conffile, QSettings::IniFormat ); settings.beginGroup(section); key = settings.value(key, -1).toString(); settings.endGroup(); return key; } void AConfig::setValue(QString section, QString key, QString value){ QSettings settings( conffile, QSettings::IniFormat ); settings.beginGroup(section); settings.setValue(key, value); settings.sync(); } void AConfig::deleteKey(QString section, QString key){ QSettings settings( conffile, QSettings::IniFormat ); QStringList keys = settings.childKeys(); settings.beginGroup(section); if (keys.contains(key)){ settings.remove(key); } settings.endGroup(); } void AConfig::deleteSection(QString section){ QSettings settings( conffile, QSettings::IniFormat ); settings.beginGroup(section); settings.remove(""); settings.endGroup(); } QStringList AConfig::getLotroPath(){ QStringList paths; //#if defined(Q_WS_WIN) // Windows 7 QSettings m("HKEY_CLASSES_ROOT\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache", QSettings::NativeFormat); foreach (QString key, m.allKeys()) { if(key.contains("TurbineLauncher.exe") && FileSystem::fileExists(key)){ paths.append(key.replace("/TurbineLauncher.exe", "")); } } // Windows 8, 10 QSettings n("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\12bbe590-c890-11d9-9669-0800200c9a66_is1", QSettings::NativeFormat); foreach (QString key, n.allKeys()) { qDebug() << key; if(key.contains("InstallLocation") || key.contains("installlocation")){ QString folder = n.value(key).toString().replace("\\", "/").replace("/TurbineLauncher.exe", "").replace("\"", ""); if(FileSystem::fileExists(folder + "/TurbineLauncher.exe")) paths.append(folder); } } //#else // Реализация под Linux //#endif return paths; } const char * AConfig::getDatPath(int id){ App *app = &App::getInstance(); QStringList dats; dats << app->config->getValue("Local", "file") << "client_general.dat" << "client_sound.dat" << "client_surface.dat" << "client_highres.dat"; //std::string file = (app->config->getValue("Local", "folder") + "/" + dats.at(id)).toStdString(); return (app->config->getValue("Local", "folder") + "/" + dats.at(id)).toUtf8().data(); }