Parcourir la source

Implemented minimal LotroDatManager funtionality

Ivan Arkhipov il y a 5 ans
Parent
commit
f573505ee2

+ 0 - 2
src/Legacy/Legacy.pro

@@ -22,7 +22,6 @@ SOURCES += \
     widgets/helpwidget.cpp \
     widgets/mainwindow.cpp \
     widgets/menuentry.cpp \
-    widgets/rusificationtreeitem.cpp \
     widgets/rusificationwidget.cpp \
     widgets/settingswidget.cpp \
     widgets/statuswidget.cpp \
@@ -42,7 +41,6 @@ HEADERS += \
     widgets/helpwidget.h \
     widgets/mainwindow.h \
     widgets/menuentry.h \
-    widgets/rusificationtreeitem.h \
     widgets/rusificationwidget.h \
     widgets/settingswidget.h \
     widgets/statuswidget.h \

+ 8 - 8
src/Legacy/models/downloader.cpp

@@ -64,7 +64,7 @@ quint64 Downloader::getSpeed()
 
 QString Downloader::getSpeedFormatted(quint64 speed_bytes_per_sec)
 {
-    quint64 speed = speed_bytes_per_sec;
+    float speed = speed_bytes_per_sec;
 
     QString unit;
     if (speed < 1024) {
@@ -76,23 +76,23 @@ QString Downloader::getSpeedFormatted(quint64 speed_bytes_per_sec)
         speed /= 1024*1024;
         unit = "MB/s";
     }
-    return QString::number(speed) + " " + unit;
+    return QString::number(speed, 'g', 1) + " " + unit;
 }
 
 QString Downloader::getSizeFormatted(quint64 bytes)
 {
-
+    float size = bytes;
     QString unit;
-    if (bytes < 1024) {
+    if (size < 1024) {
         unit = "байт";
-    } else if (bytes < 1024*1024) {
-        bytes /= 1024;
+    } else if (size < 1024*1024) {
+        size /= 1024;
         unit = "kB";
     } else {
-        bytes /= 1024*1024;
+        size /= 1024*1024;
         unit = "MB";
     }
-    return QString::number(bytes) + " " + unit;
+    return QString::number(size, 'g', 1) + " " + unit;
 }
 
 

+ 1 - 1
src/Legacy/models/filesystem.h

@@ -15,7 +15,7 @@ private:
 
 public:
     static bool fileExists(QString path);
-    static QString fileHash(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm);
+    static QString fileHash(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm = QCryptographicHash::Md5);
     static void clearFolder(QDir &dir);
     static QStringList recognizeRegistryLotroPath();
 signals:

+ 239 - 397
src/Legacy/models/lotrodatmanager.cpp

@@ -1,6 +1,7 @@
 #include "lotrodatmanager.h"
 #include "filesystem.h"
 #include "LotroDat/Subfiles/TextSubFile.h"
+#include "models/patchdownloader.h"
 
 #include <QtConcurrent/QtConcurrent>
 #include <QFontDatabase>
@@ -14,406 +15,339 @@
 Q_DECLARE_METATYPE(LOTRO_DAT::FILE_TYPE)
 Q_DECLARE_METATYPE(LOTRO_DAT::SubfileData)
 
-LotroDatManager::LotroDatManager(QSettings* app_settings_, QObject *parent) :
-    QObject(parent), app_settings(app_settings_) {
+LotroDatManager::LotroDatManager(QSettings* settings, PatchDownloader* downloader, QObject *parent) :
+    QObject(parent), app_settings(settings), patch_downloader(downloader) {
 
     qRegisterMetaType<LOTRO_DAT::FILE_TYPE>();
     qRegisterMetaType<LOTRO_DAT::SubfileData>();
 }
 
-void LotroDatManager::initialiseDatFile(QString file_path) {
-    emit processStarted("initialiseDatFile", {file_path});
-
-    qDebug() << "Initialising file " << file_path;
-
-    if (!FileSystem::fileExists(file_path)) {
-        emit caughtError(QString("initialiseDatFile"), {QString("Ошибка инициализации"), QString("Файл " + file_path + " несуществует! Невозможно инициализировать файл ресурсов.")});
-        emit processFinished("initialiseDatFile", {QString("Error"), file_path});
-        return;
-    }
-
-    file.Initialise((file_path).toStdString(), 0);
-    emit processFinished("initialiseDatFile", {QString("Success"), file_path});
-}
-
-void LotroDatManager::deinitialiseDatFile()
+bool LotroDatManager::Initialised()
 {
-    emit processStarted("deintialiseDatFile", {});
-    qDebug() << "Deinitialising file...";
-    file.Deinitialize();
-    emit processFinished("deinitialiseDatFile", {});
+    return client_local_file.Initialized() && client_general_file.Initialized();
 }
 
-void LotroDatManager::changeLocale() {
-    qDebug() << "Changing locale of dat file...";
-    // Setting locale, opposite to current
-    auto current_locale = file.GetLocaleManager().GetCurrentLocale();
-    auto new_locale = current_locale == LOTRO_DAT::DatLocaleManager::PATCHED ?
-                LOTRO_DAT::DatLocaleManager::ORIGINAL :
-                LOTRO_DAT::DatLocaleManager::PATCHED;
-
-    QString old_locale_name = (current_locale == LOTRO_DAT::DatLocaleManager::PATCHED ? "Русифицированная" : "Оригинальная");
-    QString new_locale_name = (new_locale == LOTRO_DAT::DatLocaleManager::PATCHED ? "Русифицированная" : "Оригинальная");
-    emit processStarted("changeLocale", {old_locale_name, new_locale_name});
-
-
-    auto operation = file.GetLocaleManager().SetLocale(new_locale);
-
-    auto new_current_locale = file.GetLocaleManager().GetCurrentLocale();
-    QString new_current_locale_name = (new_current_locale == LOTRO_DAT::DatLocaleManager::PATCHED ? "Русифицированная" : "Оригинальная");
-
-    if (operation.result == LOTRO_DAT::SUCCESS) {
-        emit processFinished("changeLocale", {"Success", new_current_locale_name});
-    } else {
-        emit caughtError("changeLocale", {"Ошибка смены локали!", QString("Не удалось сменить локаль игры! Текущая локаль: ") + new_current_locale_name});
-        emit processFinished("changeLocale", {"Error", new_current_locale_name});
-    }
+bool LotroDatManager::NotPatched()
+{
+    return !client_local_file.GetStatusModule().CheckIfNotPatched() && !client_local_file.GetStatusModule().CheckIfNotPatched();
 }
 
-void LotroDatManager::getLocaleFileContents(long long file_id, int locale) {
-    emit processStarted("getLocaleFileContents", {file_id, locale});
-
-    auto getfile_op = file.GetLocaleManager().GetLocaleFile(file_id, (LOTRO_DAT::DatLocaleManager::LOCALE)locale);
-    if (!getfile_op.result) {
-        emit caughtError("getLocaleFileContents", {"Файл не найден!", QString("Не удаётся найти файл с id ") + QString::number(file_id)});
-        emit processFinished("getLocaleFileContents", {"Error"});
+void LotroDatManager::InitialiseManager()
+{
+    emit processStarted();
+    QString game_folder = app_settings->value("General/game_folder_path", QString()).toString();
+    QString locale_prefix = app_settings->value("General/original_locale", "English").toString();
+    if (game_folder.isEmpty() || !FileSystem::fileExists(game_folder + "client_local_" + locale_prefix + ".dat")
+            || !FileSystem::fileExists(game_folder + "client_general.dat")) {
+
+        emit caughtError(QString("InitialiseManager"), {"FileNotFound"});
+        emit processFinished();
         return;
     }
 
-    LOTRO_DAT::SubFile subfile = getfile_op.value;
+    auto client_local_init_res = client_local_file.Initialise((game_folder + "/client_local_" + locale_prefix + ".dat").toStdString(), 0);
+    auto client_general_init_res = client_general_file.Initialise((game_folder + "/client_general.dat").toStdString(), 1);
 
-    auto getrealfile_op = file.GetFileSystem().GetFile(file_id);
-    if (!getfile_op.result) {
-        emit caughtError("getLocaleFileContents", {"Файл не найден!", QString("Не удаётся найти в словаре файл с id ") + QString::number(file_id)});
-        emit processFinished("getLocaleFileContents", {"Error"});
-        return;
-    }
+    if (client_local_init_res.result != LOTRO_DAT::SUCCESS
+            || client_general_init_res.result != LOTRO_DAT::SUCCESS) {
+        client_local_file.Deinitialize();
+        client_general_file.Deinitialize();
 
-    if (getrealfile_op.value->FileType() != LOTRO_DAT::TEXT) {
-        emit caughtError("getLocaleFileContents", {"Некорректный формат!", QString("Получение данных локали доступно только для текстовых файлов!")});
-        emit processFinished("getLocaleFileContents", {"Error"});
+        emit caughtError(QString("InitialiseManager"), {"InitialisationError"});
+        emit processFinished();
         return;
     }
 
-    LOTRO_DAT::TextSubFile text_subfile(subfile);
+    emit processFinished();
+}
 
-    auto getfiledata_op = file.GetFileSystem().GetFileData(subfile, 8);
+void LotroDatManager::DeinitialiseManager()
+{
+    emit processStarted();
+    client_local_file.Deinitialize();
+    client_general_file.Deinitialize();
+    emit processFinished();
+}
 
-    if (getfile_op.result == LOTRO_DAT::ERROR) {
-        emit caughtError("getLocaleFileContents", {"Ошибка извлечения!", QString("Обнаружены некорректные данные файла в словаре! Файл ресурсов мог быть повреждён!\nid = ") + QString::number(file_id) + ", locale_id = " + QString::number(locale)});
-        emit processFinished("getLocaleFileContents", {"Error"});
-        return;
-    }
+void LotroDatManager::StartGame(LOTRO_DAT::DatLocaleManager::LOCALE locale)
+{
+    emit processStarted();
 
-    LOTRO_DAT::SubfileData result = text_subfile.PrepareForExport(getfiledata_op.value);
-    emit localeFileContentsReceived(locale, result);
-    emit processFinished("getLocaleFileContents", {"Success", file_id, locale});
-}
+    client_general_file.GetLocaleManager().SetLocale(locale);
+    client_local_file.GetLocaleManager().SetLocale(locale);
 
-void LotroDatManager::importFilesFromDatabase(QString database_path) {
-    emit processStarted("importFilesFromDatabase", {database_path});
+    QString game_folder = app_settings->value("General/game_folder_path", QString()).toString();
 
-    if (!FileSystem::fileExists(database_path)) {
-        emit caughtError(QString("importFilesFromDatabase"), {QString("Ошибка импорта!"), QString("Файл " + database_path + " не существует! Невозможно инициализировать базу данных!")});
-        emit processFinished("importFilesFromDatabase", {QString("Error")});
+    if (!FileSystem::fileExists(QApplication::applicationDirPath() + "/GameLauncher.exe")) {
+        emit caughtError("StartGame", {"NoGameLauncherInLegacyDir"});
+        emit processFinished();
         return;
     }
 
-    LOTRO_DAT::Database db;
-    if (!db.InitDatabase(database_path.toStdString())) {
-        emit caughtError("importFilesFromDatabase", {QString("Ошибка импорта!"), QString("Внутренняя ошибка инициализации базы данных!")});
-        emit processFinished("importFilesFromDatabase", {QString("Error")});
+    if (!QFile::remove(game_folder + "/LotroLauncher.exe")) {
+        emit caughtError("StartGame", {"NoAccessToLotroLauncher"});
+        emit processFinished();
         return;
     }
 
-    auto patch_operation = file.GetPatcher().PatchAllDatabase(&db);
-
-    if (patch_operation.result == LOTRO_DAT::SUCCESS) {
-        file.GetFileSystem().CommitDirectories();
-        file.GetLocaleManager().CommitLocales();
-        emit processFinished("importFilesFromDatabase", {QString("Success"), patch_operation.value});
-    } else {
-        emit processFinished("importFilesFromDatabase", {QString("Error"), 0});
-    }
-}
-
-void LotroDatManager::importFile(long long file_id, QString file_path) {
-    emit processStarted("importFile", {file_id, file_path});
-
-    if (!FileSystem::fileExists(file_path)) {
-        emit caughtError("importFile", {QString("Ошибка импорта!"), QString("Файл ") + file_path + QString(" не существует!")});
-        emit processFinished("importFile", {QString("Error")});
+    if (!QFile::copy(QApplication::applicationDirPath() + "/GameLauncher.exe", game_folder + "/LotroLauncher.exe")) {
+        emit caughtError("StartGame", {"NoAccessToGameLauncher"});
+        emit processFinished();
         return;
     }
 
-    LOTRO_DAT::SubfileData data;
-
-    data.options["fid"] = file_id;
-
-    auto getfile_op = file.GetFileSystem().GetFile(file_id);
-    if (getfile_op.result == LOTRO_DAT::ERROR) {
-        emit caughtError("importFile", {QString("Ошибка импорта!"), QString("Файл с id ") + QString::number(file_id) + QString(" не существует в ресурсах игры! Невозможно импортировать :/")});
-        emit processFinished("importFile", {QString("Error")});
-        return;
-    }
-
-    std::shared_ptr<LOTRO_DAT::SubFile> subfile = getfile_op.value;
-    data.options["ext"] = subfile->Extension();
-    data.options["cat"] = subfile->category;
-
-    if (subfile->FileType() == LOTRO_DAT::TEXT) {
-        std::basic_ifstream<char16_t> input_stream(file_path.toStdString(), std::ios::in);
-        if (!input_stream.is_open()) {
-            emit caughtError("importFile", {QString("Ошибка импорта!"), QString("Текстовый файл ") + file_path + QString(" не удаётся открыть!")});
-            emit processFinished("importFile", {QString("Error")});
-            return;
-        }
+    startLotroLauncherWithParameters(locale);
+    emit processFinished();
+}
 
-        std::basic_stringstream<char16_t>  strStream;
-        strStream << input_stream.rdbuf();//read the file
-        data.text_data = strStream.str();//str holds the content of the file
+void LotroDatManager::ChangeTranslationLanguage()
+{
+    DeinitialiseManager();
+    InitialiseManager();
+}
 
-        input_stream.close();
-    } else {
-        QFile data_file(file_path);
-        data_file.open(QIODevice::ReadOnly);
+void LotroDatManager::InstallActivePatches()
+{
+    InstallPatches();
+    ApplyTexts();
+    ApplyImages();
+    ApplySounds();
+    InstallLoadscreens();
+    InstallVideos();
+}
 
-        if (!data_file.isOpen()) {
-            emit caughtError("importFile", {QString("Ошибка импорта!"), QString("Файл ") + file_path + QString(" не удаётся открыть!")});
-            emit processFinished("importFile", {QString("Error")});
-            return;
+void LotroDatManager::InstallPatches()
+{
+    const QStringList all_patch_names = {"sound", "text", "image", "texture"};
+    foreach (QString patch_name, all_patch_names) {
+        if (app_settings->value("patch_databases/" + patch_name, "Disabled").toString() == "Disabled")
+            continue;
+
+        QString database_path = patch_downloader->getDatabasePathByPatchName(patch_name);
+        LOTRO_DAT::Database db;
+        if (!db.InitDatabase(database_path.toStdString())) {
+            emit caughtError("InstallPatches", {"ErrorInitDatabase"});
+            continue;
         }
 
-        QByteArray contents = data_file.readAll();
-        data.binary_data = LOTRO_DAT::BinaryData(contents.constData(), contents.size());
-    }
-
+        if (client_local_file.GetPatcher().PatchAllDatabase(&db).result != LOTRO_DAT::SUCCESS)
+            emit caughtError("InstallPatches", {"ErrorCannotPatch", "client_local"});
 
-    auto patchfile_op = file.GetPatcher().PatchFile(data);
+        if (client_general_file.GetPatcher().PatchAllDatabase(&db).result != LOTRO_DAT::SUCCESS)
+            emit caughtError("InstallPatches", {"ErrorCannotPatch", "client_general"});
 
-    if (patchfile_op.result == LOTRO_DAT::SUCCESS) {
-        file.GetFileSystem().CommitDirectories();
-        file.GetLocaleManager().CommitLocales();
-        emit processFinished("importFile", {QString("Success")});
-    } else {
-        emit caughtError("importFile", {QString("Ошибка импорта!"), QString("Возникла внутренняя ошибка применения патча. Импорт завершился с ошибкой")});
-        emit processFinished("importFile", {QString("Error")});
+        db.CloseDatabase();
     }
-    return;
 }
 
-void LotroDatManager::importTextFragment(long long file_id, long long fragment_id,
-                               QString fragment_contents, QString arguments) {
-    emit processStarted("importTextFragment", {file_id, fragment_id});
+void LotroDatManager::InstallLoadscreens()
+{
+    emit processStarted();
 
-    if (fragment_contents.contains("DO_NOT_TOUCH-1!")) {
-        emit caughtError("importTextFragment", {"Ошибка формата!", QString("Текстовые данные содержат указатели на аргументы DO_NOT_TOUCH! с встроенным указанием порядка аргументов (как на сайте) Такого быть не должно! Пользуйтесь порядком перечисления аргументов внизу")});
-        emit processFinished("importTextFragment", {"Error"});
+    if (app_settings->value("patch_databases/loadscreen", "Disabled").toString() == "Disabled")
         return;
-    }
 
-    auto getfile_op = file.GetFileSystem().GetFile(file_id);
-    if (!getfile_op.result) {
-        emit caughtError("importTextFragment", {"Файл не найден!", QString("Не удаётся найти в ресурсах файл с id ") + QString::number(file_id)});
-        emit processFinished("importTextFragment", {"Error"});
+    QString game_folder = app_settings->value("General/game_folder_path", QString()).toString();
+    QString locale_prefix = app_settings->value("General/original_locale", "English").toString();
+
+    QString raw_folder;
+    if (locale_prefix == "English")
+        raw_folder = "en";
+    if (locale_prefix == "DE")
+        raw_folder = "de";
+    if (locale_prefix == "FR")
+        raw_folder = "fr";
+
+    QString folder = game_folder + "/raw/" + raw_folder + "/logo/";
+
+    QString mainscreen =
+            game_folder == "en"
+            ? "lotro_ad_pregame.jpg"
+            : "lotro_ad_pregame_" + game_folder + ".jpg";
+
+    QStringList filenames;
+    filenames << mainscreen
+              << "lotro_generic_teleport_screen_01.jpg"
+              << "lotro_generic_teleport_screen_02.jpg"
+              << "lotro_generic_teleport_screen_03.jpg"
+              << "lotro_generic_teleport_screen_04.jpg"
+              << "lotro_generic_teleport_screen_05.jpg"
+              << "lotro_generic_teleport_screen_06.jpg"
+              << "lotro_generic_teleport_screen_07.jpg"
+              << "lotro_generic_teleport_screen_08.jpg"
+              << "lotro_generic_teleport_screen_09.jpg"
+              << "lotro_generic_teleport_screen_10.jpg";
+
+
+    QString database_path = patch_downloader->getDatabasePathByPatchName("loadscreen");
+    LOTRO_DAT::Database db;
+    if (!db.InitDatabase(database_path.toStdString())) {
+        emit caughtError("InstallLoadscreens", {"ErrorInitDatabase"});
         return;
     }
 
-    auto subfile = getfile_op.value;
+    for (size_t i = 0; i < qMin(db.CountRows(), size_t(filenames.size())); i++) {
+        LOTRO_DAT::SubfileData subfile = db.GetNextFile();
 
-    auto getfiledata_op = file.GetFileSystem().GetFileData(*subfile, 8);
+        if (subfile.binary_data.Empty())
+            continue;
 
-    if (getfile_op.result == LOTRO_DAT::ERROR) {
-        emit caughtError("importTextFragment", {"Ошибка импорта!", QString("Обнаружены некорректные данные файла в словаре! Файл ресурсов мог быть повреждён!\nid = ") + QString::number(file_id)});
-        emit processFinished("importTextFragment", {"Error"});
-        return;
+        QFile::remove(folder + filenames[i]);
+        subfile.binary_data.WriteToFile((folder + filenames[i]).toStdString());
     }
+    db.CloseDatabase();
 
-    LOTRO_DAT::SubfileData data = subfile->PrepareForExport(getfiledata_op.value);
-    if (data.Empty()) {
-        emit caughtError("importTextFragment", {"Ошибка импорта!", QString("Не удалось подготовить файл к изменению фрагмента!\nid = ") + QString::number(file_id)});
-        emit processFinished("importTextFragment", {"Error"});
-        return;
-    }
-
-    unsigned beginning = data.text_data.find(QString::number(fragment_id).toStdU16String(), 0);
-    if (beginning == std::u16string::npos) {
-        emit caughtError("importTextFragment", {"Ошибка импорта!", QString("Не удалось найти фрагмент в файле!\nid = ") + QString::number(file_id) + "\nfragment_id = " + QString::number(fragment_id)});
-        emit processFinished("importTextFragment", {"Error"});
-        return;
-    }
-
-    unsigned ending = data.text_data.find(QString("|||").toStdU16String(), beginning);
-
-    QString new_fragment = QString::number(fragment_id) + ":::" + arguments + ":::" + fragment_contents;
-    std::u16string new_text =  data.text_data.substr(0, beginning) + new_fragment.toStdU16String() + data.text_data.substr(ending);
-    data.text_data = new_text;
-
-    auto patchfile_op = file.GetPatcher().PatchFile(data);
-
-    if (patchfile_op.result == LOTRO_DAT::SUCCESS) {
-        file.GetFileSystem().CommitDirectories();
-        file.GetLocaleManager().CommitLocales();
-        emit processFinished("importTextFragment", {QString("Success")});
-    } else {
-        emit caughtError("importTextFragment", {QString("Ошибка импорта!"), QString("Возникла внутренняя ошибка применения патча. Импорт завершился с ошибкой")});
-        emit processFinished("importTextFragment", {QString("Error")});
-    }
+    emit processFinished();
 }
 
-void LotroDatManager::getTextFragment(long long file_id, long long fragment_id) {
-    emit processStarted("getTextFragment", {file_id, fragment_id});
-
-    auto getfile_op = file.GetFileSystem().GetFile(file_id);
-    if (!getfile_op.result) {
-        emit caughtError("getTextFragment", {"Файл не найден!", QString("Не удаётся найти в ресурсах файл с id ") + QString::number(file_id)});
-        emit processFinished("getTextFragment", {"Error"});
+void LotroDatManager::InstallVideos()
+{
+    emit processStarted();
+    if (app_settings->value("patch_databases/video", "Disabled").toString() == "Disabled")
         return;
-    }
 
-    auto subfile = getfile_op.value;
+    QString game_folder = app_settings->value("General/game_folder_path", QString()).toString();
 
-    auto getfiledata_op = file.GetFileSystem().GetFileData(*subfile, 8);
+    QString database_path = patch_downloader->getDatabasePathByPatchName("loadscreen");
 
-    if (getfile_op.result == LOTRO_DAT::ERROR) {
-        emit caughtError("getTextFragment", {"Ошибка импорта!", QString("Обнаружены некорректные данные файла в словаре! Файл ресурсов мог быть повреждён!\nid = ") + QString::number(file_id)});
-        emit processFinished("getTextFragment", {"Error"});
+    LOTRO_DAT::Database db;
+    if (!db.InitDatabase(database_path.toStdString())) {
+        emit caughtError("InstallVideos", {"ErrorInitDatabase"});
         return;
     }
 
-    LOTRO_DAT::SubfileData data = subfile->PrepareForExport(getfiledata_op.value);
-    if (data.Empty()) {
-        emit caughtError("getTextFragment", {"Ошибка импорта!", QString("Не удалось подготовить файл к изменению фрагмента!\nid = ") + QString::number(file_id)});
-        emit processFinished("getTextFragment", {"Error"});
-        return;
-    }
+    for(size_t i = 0; i < db.CountRows(); i++) {
+        LOTRO_DAT::SubfileData subfile = db.GetNextFile();
 
-    unsigned beginning = data.text_data.find(QString::number(fragment_id).toStdU16String(), 0);
-    if (beginning == std::u16string::npos) {
-        emit caughtError("getTextFragment", {"Ошибка импорта!", QString("Не удалось найти фрагмент в файле!\nid = ") + QString::number(file_id) + "\nfragment_id = " + QString::number(fragment_id)});
-        emit processFinished("getTextFragment", {"Error"});
-        return;
-    }
+        if (subfile.Empty())
+            continue;
 
-    unsigned ending = data.text_data.find(QString("|||").toStdU16String(), beginning);
+        QString filename = QString::fromStdString(subfile.options["name"].as<std::string>());
+        QUrl url = QString::fromStdString(subfile.options["url"].as<std::string>());
+        QString hash = QString::fromStdString(subfile.options["hash"].as<std::string>());
+        QString target_folder = game_folder + "/" + QString::fromStdString(subfile.options["folder"].as<std::string>()) + "/";
 
-    unsigned size = std::u16string::npos;
+        if (!QDir(target_folder).exists())
+            QDir(target_folder).mkpath(target_folder);
 
-    if (ending != std::u16string::npos)
-        size = ending - beginning;
+        if (FileSystem::fileExists(target_folder + filename))
+            QFile::remove(target_folder + filename);
 
-    std::u16string str = data.text_data.substr(beginning, size);
+        Downloader video_downloader;
+        video_downloader.setUrl(url);
+        video_downloader.targetFile = new QFile(target_folder + filename);
+        video_downloader.targetFile->open(QIODevice::ReadWrite);
+        video_downloader.start();
+        video_downloader.waitForDownloaded();
+        video_downloader.targetFile->close();
+        video_downloader.targetFile->deleteLater();
 
-    QStringList splitted_fragment = QString::fromStdU16String(str).split(":::");
-    if (splitted_fragment.size() != 3) {
-        emit caughtError("getTextFragment", {"Ошибка импорта!", QString("Получены некорректные данные фрагмента!\nДанные:") + QString::fromStdU16String(str)});
-        emit processFinished("getTextFragment", {"Error"});
-        return;
+        if (FileSystem::fileHash(target_folder + filename) != hash) {
+            emit caughtError("InstallVideos", {"IncorrectHash", hash, FileSystem::fileHash(target_folder + filename), target_folder, filename, url});
+        }
     }
+    db.CloseDatabase();
 
-    emit textFragmentReceived(splitted_fragment.at(1), splitted_fragment.at(2));
-    emit processFinished("getTextFragment", {"Success"});
+    emit processFinished();
 }
 
-void LotroDatManager::createCoreStatusFile(QString output_filename) {
-    emit processStarted("createCoreStatusFile", {output_filename});
-    auto gatherinfo_op = file.GatherInformation(output_filename.toStdString());
+void LotroDatManager::InstallUpdates()
+{
+    // TODO
+}
 
-    if (gatherinfo_op.result == LOTRO_DAT::SUCCESS) {
-        emit processFinished("createCoreStatusFile", {"Success", output_filename});
-    } else {
-        emit caughtError("createCoreStatusFile", {"Ошибка сбора информации!", QString("Не удаётся создать файл информации ядра")});
-        emit processFinished("createCoreStatusFile", {"Error", output_filename});
-    }
+void LotroDatManager::InstallMicroPatch()
+{
+    // TODO
 }
 
-void LotroDatManager::extractSingleFile(QString output_filename, long long file_id) {
-    emit processStarted("extractSingleFile", {output_filename, file_id});
-    auto extractfile_op = file.GetExporter().ExtractFileById(file_id, output_filename.toStdString());
-    if (extractfile_op.result == LOTRO_DAT::SUCCESS) {
-        emit processFinished("extractSingleFile", {"Success", output_filename, file_id});
-    } else {
-        emit caughtError("extractSingleFile", {"Ошибка экспорта!", QString("Не удаётся экспортировать файл " + QString::number(file_id) + " в файл " + output_filename)});
-        emit processFinished("extractSingleFile", {"Error", output_filename});
-    }
+void LotroDatManager::CreateBackup()
+{
+    emit processStarted();
+    QString locale_prefix = app_settings->value("General/original_locale", "English").toString();
+    client_local_file.GetBackupManager().CreateBackup((QApplication::applicationDirPath() + "/backup/client_local_" + locale_prefix + ".dat").toStdString());
+    client_general_file.GetBackupManager().CreateBackup((QApplication::applicationDirPath() + "/backup/client_general.dat").toStdString());
+    emit processFinished();
 }
 
-void LotroDatManager::extractSingleFileToDatabase(QString database_path, long long file_id) {
-    emit processStarted("extractSingleFileToDatabase", {database_path, file_id});
-    LOTRO_DAT::Database db;
-    if (!db.InitDatabase(database_path.toStdString())) {
-        emit caughtError("extractSingleFileToDatabase", {"Ошибка экспорта!", QString("Не удаётся создать/открыть базу данных " + database_path)});
-        emit processFinished("extractSingleFileToDatabase", {"Error", database_path});
-        return;
-    }
+void LotroDatManager::RestoreFromBackup()
+{
+    emit processStarted();
+    QString locale_prefix = app_settings->value("General/original_locale", "English").toString();
+    client_local_file.GetBackupManager().RestoreFromBackup((QApplication::applicationDirPath() + "/backup/client_local_" + locale_prefix + ".dat").toStdString());
+    client_general_file.GetBackupManager().RestoreFromBackup((QApplication::applicationDirPath() + "/backup/client_general.dat").toStdString());
+    emit processFinished();
+}
 
-    auto extractfile_op = file.GetExporter().ExtractFileById(file_id, &db);
+void LotroDatManager::RemoveBackup()
+{
+    emit processStarted();
+    QString locale_prefix = app_settings->value("General/original_locale", "English").toString();
+    client_local_file.GetBackupManager().RemoveBackup((QApplication::applicationDirPath() + "/backup/client_local_" + locale_prefix + ".dat").toStdString());
+    client_general_file.GetBackupManager().RemoveBackup((QApplication::applicationDirPath() + "/backup/client_general.dat").toStdString());
+    emit processFinished();
+}
 
-    if (extractfile_op.result == LOTRO_DAT::SUCCESS) {
-        emit processFinished("extractSingleFileToDatabase", {"Success", database_path, file_id});
+void LotroDatManager::ApplyTexts()
+{
+    if (app_settings->value("patch_options/texts_general", "Disabled").toString() == "Enabled") {
+        client_local_file.GetLocaleManager().EnableCategory(100);
     } else {
-        emit caughtError("extractSingleFileToDatabase", {"Ошибка экспорта!", QString("Не удаётся экспортировать файл " + QString::number(file_id) + " в базу данных " + database_path)});
-        emit processFinished("extractSingleFileToDatabase", {"Error", database_path});
+        client_local_file.GetLocaleManager().DisableCategory(100);
     }
-}
 
-void LotroDatManager::extractGrouppedFiles(QString output_foldername, LOTRO_DAT::FILE_TYPE type) {
-    emit processStarted("extractGrouppedFiles", {output_foldername, type});
-    auto extractfile_op = file.GetExporter().ExtractAllFilesByType(type, output_foldername.toStdString());
-    if (extractfile_op.result == LOTRO_DAT::SUCCESS) {
-        emit processFinished("extractGrouppedFiles", {"Success", output_foldername, type, extractfile_op.value});
+    if (app_settings->value("patch_options/texts_emotes", "Disabled").toString() == "Enabled") {
+        client_local_file.GetLocaleManager().EnableCategory(101);
     } else {
-        emit caughtError("extractGrouppedFiles", {"Ошибка экспорта!", QString("Не удаётся экспортировать файлы с типом " + QString::number(type) + " в папку " + output_foldername)});
-        emit processFinished("extractGrouppedFiles", {"Error", output_foldername, type, extractfile_op.value});
+        client_local_file.GetLocaleManager().DisableCategory(101);
     }
-}
 
-void LotroDatManager::extractGrouppedFilesToDatabase(QString database_path, LOTRO_DAT::FILE_TYPE type) {
-    emit processStarted(QString("extractGrouppedFilesToDatabase"), {database_path, type});
-    LOTRO_DAT::Database db;
-    if (!db.InitDatabase(database_path.toStdString())) {
-        emit caughtError("extractGrouppedFilesToDatabase", {"Ошибка экспорта!", QString("Не удаётся создать/открыть базу данных " + database_path)});
-        emit processFinished("extractGrouppedFilesToDatabase", {"Error", database_path});
-        return;
+    if (app_settings->value("patch_options/texts_items", "Disabled").toString() == "Enabled") {
+        client_local_file.GetLocaleManager().EnableCategory(102);
+    } else {
+        client_local_file.GetLocaleManager().DisableCategory(102);
     }
+    emit processFinished();
+}
 
-    auto extractfile_op = file.GetExporter().ExtractAllFilesByType(type, &db);
-    if (extractfile_op.result == LOTRO_DAT::SUCCESS) {
-        emit processFinished("extractGrouppedFilesToDatabase", {"Success", database_path, type, extractfile_op.value});
+void LotroDatManager::ApplyImages() {
+    emit processStarted();
+    if (app_settings->value("patch_options/maps", "Disabled").toString() == "Enabled") {
+        client_local_file.GetLocaleManager().EnableCategory(200);
     } else {
-        emit caughtError("extractGrouppedFilesToDatabase", {"Ошибка экспорта!", QString("Не удаётся экспортировать файлы с типом " + QString::number(type) + " в базу данных " + database_path)});
-        emit processFinished("extractGrouppedFilesToDatabase", {"Error", database_path, extractfile_op.value});
+        client_local_file.GetLocaleManager().DisableCategory(200);
     }
+    emit processFinished();
 }
 
-void LotroDatManager::getUnactiveCategories() {
-    emit processStarted("getUnactiveCategories", {});
-
-    const std::set<long long>& categories = file.GetLocaleManager().GetInactiveCategories();
-
-    QStringList result;
-    for (long long category : categories) {
-        result.append(QString::number(category));
+void LotroDatManager::ApplySounds() {
+    emit processStarted();
+    if (app_settings->value("patch_options/sounds", "Disabled").toString() == "Enabled") {
+        client_local_file.GetLocaleManager().EnableCategory(300);
+    } else {
+        client_local_file.GetLocaleManager().DisableCategory(300);
     }
 
-    qDebug() << "Received category set: " << result;
-
-    emit unactiveCategoriesReceived(result);
-    emit processFinished("getUnactiveCategories", {"Success"});
+    if (app_settings->value("patch_options/video", "Disabled").toString() == "Enabled") {
+        client_local_file.GetLocaleManager().EnableCategory(103);
+    } else {
+        client_local_file.GetLocaleManager().DisableCategory(103);
+    }
+    emit processFinished();
 }
 
-void LotroDatManager::startGame() {
-    emit processStarted("startGame", {});
-
+bool LotroDatManager::startLotroLauncherWithParameters(LOTRO_DAT::DatLocaleManager::LOCALE locale)
+{
     QStringList args;
-    args << "-skiprawdownload" << "-nosplash";
-    if (file.GetLocaleManager().GetCurrentLocale() == LOTRO_DAT::DatLocaleManager::PATCHED)
+    args << "-skiprawdownload";
+    if (locale == LOTRO_DAT::DatLocaleManager::PATCHED)
         args << "-disablePatch";
 
-    file.Deinitialize();
+    client_general_file.Deinitialize();
+    client_local_file.Deinitialize();
 
     if(FileSystem::fileExists(QApplication::applicationDirPath() + "/user.ini")){
-        QSettings login(QApplication::applicationDirPath() + "/user.ini", QSettings::IniFormat );
+        QSettings login(QApplication::applicationDirPath() + "/user.ini", QSettings::IniFormat);
         login.beginGroup("Account");
         QString username = login.value("username", "").toString();
         QString password = login.value("password", "").toString();
@@ -423,108 +357,16 @@ void LotroDatManager::startGame() {
 
     qDebug() << "Запускаем игру со следующими аргументами: " << args;
 
-    QFile f(app_settings->value("Local", "folder").toString() + "/LotroLauncher.exe");
+    QFile f(app_settings->value("General/game_folder_path", "none").toString() + "/LotroLauncher.exe");
     QProcess process;
 
     if (FileSystem::fileExists(f.fileName())) {
         if(f.fileName().contains(" ")) f.setFileName("\"" + f.fileName() + "\"");
         process.startDetached(f.fileName(), args);
         process.waitForFinished(-1);
-        emit processFinished("startGame", {});
+        return true;
     } else {
-        emit caughtError("startGame", {"Ошибка запуска игры!", QString("Не удалось найти файл LotroLauncher в папке: ") + app_settings->value("Local", "folder").toString()});
-        emit processFinished("startGame", {"Error"});
-    }
-}
-
-void LotroDatManager::getLocaleFileInfo(long long file_id, int locale) {
-    emit processStarted("getLocaleFileInfo", {file_id, locale});
-
-    auto getfile_op = file.GetLocaleManager().GetLocaleFile(file_id, (LOTRO_DAT::DatLocaleManager::LOCALE)locale);
-    if (!getfile_op.result) {
-        emit caughtError("getLocaleFileInfo", {"Файл не найден!", QString("Не удаётся найти в ресурсах файл с id ") + QString::number(file_id)});
-        emit processFinished("getLocaleFileInfo", {"Error"});
-        return;
-    }
-
-    LOTRO_DAT::SubFile subfile = getfile_op.value;
-
-    QString result = "Locale file info:\n "
-                     "dictionary_offset: " + QString::number(subfile.dictionary_offset()) + "\n"
-                     "unknown1: " + QString::number(subfile.unknown1()) + "\n"
-                     "file_id: " + QString::number(subfile.file_id()) + "\n"
-                     "file_offset: " + QString::number(subfile.file_offset()) + "\n"
-                     "file_size: " + QString::number(subfile.file_size()) + "\n"
-                     "timestamp: " + QString::number(subfile.timestamp()) + "\n"
-                     "version: " + QString::number(subfile.version()) + "\n"
-                     "block_size: " + QString::number(subfile.block_size()) + "\n"
-                     "unknown2: " + QString::number(subfile.file_id()) + "\n"
-                     "category: " + QString::number(subfile.category) + "\n";
-
-    emit localeFileInfoReceived(locale, result);
-    emit processFinished("getLocaleFileInfo", {"Success"});
-}
-
-void LotroDatManager::getFileInfo(long long file_id) {
-    emit processStarted(QString("getFileInfo"), {file_id});
-
-    auto getfile_op = file.GetFileSystem().GetFile(file_id);
-    if (!getfile_op.result) {
-        emit caughtError("getFileInfo", {"Файл не найден!", QString("Не удаётся найти файл с id ") + QString::number(file_id)});
-        emit processFinished("getFileInfo", {"Error"});
-        return;
+        emit caughtError("startLotroLauncherWithParameters", {"LotroLauncherNotFound"});
+        return false;
     }
-
-    LOTRO_DAT::SubFile subfile = *getfile_op.value;
-
-    QString result = "Locale file info:\n "
-                     "dictionary_offset: " + QString::number(subfile.dictionary_offset()) + "\n"
-                     "unknown1: " + QString::number(subfile.unknown1()) + "\n"
-                     "file_id: " + QString::number(subfile.file_id()) + "\n"
-                     "file_offset: " + QString::number(subfile.file_offset()) + "\n"
-                     "file_size: " + QString::number(subfile.file_size()) + "\n"
-                     "timestamp: " + QString::number(subfile.timestamp()) + "\n"
-                     "version: " + QString::number(subfile.version()) + "\n"
-                     "block_size: " + QString::number(subfile.block_size()) + "\n"
-                     "unknown2: " + QString::number(subfile.file_id()) + "\n";
-
-    emit fileInfoReceived(result);
-    emit processFinished("getFileInfo", {"Success"});
-}
-
-void LotroDatManager::disableCategory(long long category_id)
-{
-    emit processStarted(QString("disableCategory"), {category_id});
-    file.GetLocaleManager().DisableCategory(category_id);
-    file.GetLocaleManager().CommitLocales();
-    file.GetFileSystem().CommitDirectories();
-    getUnactiveCategories();
-    emit processFinished("disableCategory", {"Success"});
-}
-
-void LotroDatManager::enableCategory(long long category_id)
-{
-    emit processStarted(QString("enableCategory"), {category_id});
-    file.GetLocaleManager().EnableCategory(category_id);
-    file.GetLocaleManager().CommitLocales();
-    file.GetFileSystem().CommitDirectories();
-    getUnactiveCategories();
-    emit processFinished("enableCategory", {"Success"});
-}
-
-LOTRO_DAT::DatStatus *LotroDatManager::getStatusModule()
-{
-    return &file.GetStatusModule();
-}
-
-bool LotroDatManager::initialised() {
-    return file.Initialized();
-}
-
-int LotroDatManager::currentLocale() {
-    return file.GetLocaleManager().GetCurrentLocale();
-}
-
-bool LotroDatManager::notPatched() {
-    return file.GetStatusModule().CheckIfNotPatched();
 }

+ 34 - 37
src/Legacy/models/lotrodatmanager.h

@@ -7,75 +7,72 @@
 
 #include <LotroDat/LotroDat.h>
 
+class PatchDownloader;
+
 class LotroDatManager : public QObject
 {
     Q_OBJECT
 
 public:
-    explicit LotroDatManager(QSettings* app_settings_, QObject *parent = nullptr);
+    explicit LotroDatManager(QSettings* settings, PatchDownloader* downloader, QObject *parent = nullptr);
 
-    bool initialised();
+    bool Initialised();
 
-    int currentLocale();
+    bool NotPatched();
 
-    bool notPatched();
+    bool IsRusificationActive();
 
 public slots:
-    void initialiseDatFile(QString file_path);
-
-    void deinitialiseDatFile();
-
-    void changeLocale();
-
-    void getLocaleFileContents(long long file_id, int locale);
+    void InitialiseManager();
 
-    void importFilesFromDatabase(QString database_path);
+    void DeinitialiseManager();
 
-    void importFile(long long file_id, QString file_path);
+    void StartGame(LOTRO_DAT::DatLocaleManager::LOCALE locale);
 
-    void importTextFragment(long long file_id, long long fragment_id, QString fragment_contents, QString arguments);
+    void ChangeTranslationLanguage();
 
-    void getTextFragment(long long file_id, long long fragment_id);
+    void InstallActivePatches();
 
-    void createCoreStatusFile(QString output_filename);
+    void InstallPatches();
 
-    void extractSingleFile(QString output_filename, long long file_id);
+    void InstallLoadscreens();
 
-    void extractSingleFileToDatabase(QString database_path, long long file_id);
+    void InstallVideos();
 
-    void extractGrouppedFiles(QString output_foldername, LOTRO_DAT::FILE_TYPE type);
+    void InstallUpdates();
 
-    void extractGrouppedFilesToDatabase(QString database_path, LOTRO_DAT::FILE_TYPE type);
+    void InstallMicroPatch();
 
-    void getUnactiveCategories();
+    void CreateBackup();
 
-    void startGame();
+    void RestoreFromBackup();
 
-    void getLocaleFileInfo(long long file_id, int locale);
+    void RemoveBackup();
 
-    void getFileInfo(long long file_id);
-
-    void disableCategory(long long category_id);
+private:
+    bool startLotroLauncherWithParameters(LOTRO_DAT::DatLocaleManager::LOCALE locale);
+    void ApplyTexts();
+    void ApplyImages();
+    void ApplySounds();
 
-    void enableCategory(long long category_id);
+signals:
+    void textStatusChanged();
+    void imagesStatusChanged();
+    void soundsStatusChanged();
 
-    LOTRO_DAT::DatStatus *getStatusModule();
+    void generalStatusChanged();
 
-signals:
     // general signals. First argument is process_name, second - processed values
-    void processStarted(QString, QVector<QVariant>);
-    void processFinished(QString, QVector<QVariant>);
+    void processStarted();
+    void processFinished();
     void processUpdated(QString, QVector<QVariant>);
     void caughtError(QString, QVector<QVariant>);
 
-    void textFragmentReceived(QString, QString);
-    void unactiveCategoriesReceived(QStringList);
-    void localeFileContentsReceived(int, LOTRO_DAT::SubfileData); // extention, contents
-    void localeFileInfoReceived(int, QString);
-    void fileInfoReceived(QString);
 private:
-    LOTRO_DAT::DatFile file;
+    LOTRO_DAT::DatFile client_local_file;
+    LOTRO_DAT::DatFile client_general_file;
     QSettings* app_settings;
+    PatchDownloader* patch_downloader;
 };
 
 #endif // LEGACYAPP_H

+ 42 - 2
src/Legacy/models/patchdownloader.cpp

@@ -25,6 +25,46 @@ PatchDownloader::~PatchDownloader()
     }
 }
 
+QString PatchDownloader::getPredictedDownloadSizeFormatted()
+{
+    double mbytes = 0;
+
+    if (app_settings->value("patch_database/sound", "Disabled").toString() == "Enabled") {
+        mbytes += 650;
+    }
+    if (app_settings->value("patch_database/text", "Disabled").toString() == "Enabled") {
+        mbytes += 80;
+    }
+    if (app_settings->value("patch_database/image", "Disabled").toString() == "Enabled") {
+        mbytes += 120;
+    }
+    if (app_settings->value("patch_database/loadscreen", "Disabled").toString() == "Enabled") {
+        mbytes += 3;
+    }
+    if (app_settings->value("patch_database/texture", "Disabled").toString() == "Enabled") {
+        mbytes += 4;
+    }
+    if (app_settings->value("patch_database/font", "Disabled").toString() == "Enabled") {
+        mbytes += 1;
+    }
+    if (app_settings->value("patch_database/video", "Disabled").toString() == "Enabled") {
+        mbytes += 2100;
+    }
+
+    QString unit = "Мб";
+    if (mbytes > 1024) {
+        mbytes /= 1024;
+        unit = "Гб";
+    }
+
+    return QString::number(mbytes, 'g', 1) + " " + unit;
+}
+
+QString PatchDownloader::getDatabasePathByPatchName(QString name)
+{
+    return patch_download_dir.absolutePath() + "/" + patch_data[name].url.fileName();
+}
+
 void PatchDownloader::checkForUpdates()
 {
     foreach (QString patch_name, all_patch_names) {
@@ -177,8 +217,8 @@ bool PatchDownloader::addMissingPatchesToDownloadList()
     foreach (Patch patch, patch_data) {
         QString patch_filepath = patch_download_dir.absolutePath() + "/" + patch.url.fileName();
 
-        qDebug() << "Patch" << patch.name << "is marked as" << app_settings->value("patches/" + patch.name, "Disabled");
-        if (app_settings->value("patches/" + patch.name, "Disabled").toString() != "Enabled")
+        qDebug() << "Patch" << patch.name << "is marked as" << app_settings->value("patch_databases/" + patch.name, "Disabled");
+        if (app_settings->value("patch_databases/" + patch.name, "Disabled").toString() != "Enabled")
             continue;
 
         if (FileSystem::fileExists(patch_filepath)) {

+ 2 - 0
src/Legacy/models/patchdownloader.h

@@ -26,6 +26,8 @@ public:
     void disableAutoUpdate();
     void stopAllDownloads();
     void startAllDownloads();
+    QString getPredictedDownloadSizeFormatted();
+    QString getDatabasePathByPatchName(QString name);
 
 public slots:
     void checkForUpdates();

+ 0 - 1
src/Legacy/object_script.Legacy.Debug

@@ -9,7 +9,6 @@ INPUT(
 ./..\..\build\debug\Legacy\obj\helpwidget.o
 ./..\..\build\debug\Legacy\obj\mainwindow.o
 ./..\..\build\debug\Legacy\obj\menuentry.o
-./..\..\build\debug\Legacy\obj\rusificationtreeitem.o
 ./..\..\build\debug\Legacy\obj\rusificationwidget.o
 ./..\..\build\debug\Legacy\obj\settingswidget.o
 ./..\..\build\debug\Legacy\obj\statuswidget.o

+ 0 - 1
src/Legacy/object_script.Legacy.Release

@@ -7,7 +7,6 @@ INPUT(
 ./..\..\build\release\Legacy\obj\helpwidget.o
 ./..\..\build\release\Legacy\obj\mainwindow.o
 ./..\..\build\release\Legacy\obj\menuentry.o
-./..\..\build\release\Legacy\obj\rusificationtreeitem.o
 ./..\..\build\release\Legacy\obj\rusificationwidget.o
 ./..\..\build\release\Legacy\obj\settingswidget.o
 ./..\..\build\release\Legacy\obj\statuswidget.o

+ 1 - 1
src/Legacy/widgets/helpwidget.cpp

@@ -1,7 +1,7 @@
 #include "widgets\helpwidget.h"
 #include "ui_helpwidget.h"
 
-HelpWidget::HelpWidget(QWidget *parent) :
+HelpWidget::HelpWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) :
     QWidget(parent),
     ui(new Ui::HelpWidget)
 {

+ 9 - 1
src/Legacy/widgets/helpwidget.h

@@ -2,6 +2,10 @@
 #define HELPWIDGET_H
 
 #include <QWidget>
+#include <QSettings>
+
+class PatchDownloader;
+class LotroDatManager;
 
 namespace Ui {
 class HelpWidget;
@@ -12,10 +16,14 @@ class HelpWidget : public QWidget
     Q_OBJECT
 
 public:
-    explicit HelpWidget(QWidget *parent = 0);
+    explicit HelpWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent = 0);
     ~HelpWidget();
 
 private:
+    QSettings* app_settings;
+    PatchDownloader* patch_updater;
+    LotroDatManager* lotro_manager;
+
     Ui::HelpWidget *ui;
 };
 

+ 26 - 13
src/Legacy/widgets/mainwindow.cpp

@@ -2,6 +2,7 @@
 #include "ui_mainwindow.h"
 
 #include "models/patchdownloader.h"
+#include "models/lotrodatmanager.h"
 
 #include <QBitmap>
 #include <QPainter>
@@ -23,19 +24,27 @@ MainWindow::MainWindow(QWidget *parent) :
     QSettings *settings = new QSettings(qApp->applicationDirPath() + "/legacy_v2.ini", QSettings::IniFormat);
 
     qDebug() << "Creating patch downloader instance & thread";
-    patch_updater_thread = new QThread();
+    lotro_functions_thread = new QThread();
     patch_updater = new PatchDownloader(settings);
-    QObject::connect(patch_updater_thread, &QThread::finished, patch_updater, &QObject::deleteLater, Qt::QueuedConnection);
-    patch_updater->moveToThread(patch_updater_thread);
-    patch_updater_thread->start();
+    lotro_manager = new LotroDatManager(settings, patch_updater);
 
+    QObject::connect(lotro_functions_thread, &QThread::finished, patch_updater, &QObject::deleteLater, Qt::QueuedConnection);
+    QObject::connect(lotro_functions_thread, &QThread::finished, lotro_manager, &QObject::deleteLater, Qt::QueuedConnection);
+    patch_updater->moveToThread(lotro_functions_thread);
+    lotro_manager->moveToThread(lotro_functions_thread);
+    lotro_functions_thread->start();
+
+    qDebug() << "Initialising lotro manager...";
+    QMetaObject::invokeMethod(lotro_manager, "InitialiseManager", Qt::QueuedConnection);
     qDebug() << "Starting check for patch updates...";
     QMetaObject::invokeMethod(patch_updater, "checkForUpdates", Qt::QueuedConnection);
+    qDebug() << "Starting installation for patch updates...";
+    QMetaObject::invokeMethod(lotro_manager, "installUpdates", Qt::QueuedConnection);
 
-    status_widget = new StatusWidget(patch_updater, this);
-    rusification_widget = new RusificationWidget(this);
-    settings_widget = new SettingsWidget(settings, this);
-    help_widget = new HelpWidget(this);
+    status_widget = new StatusWidget(settings, patch_updater, lotro_manager, this);
+    rusification_widget = new RusificationWidget(settings, patch_updater, lotro_manager, this);
+    settings_widget = new SettingsWidget(settings, patch_updater, lotro_manager, this);
+    help_widget = new HelpWidget(settings, patch_updater, lotro_manager, this);
 
     ui->content_layout->addWidget(status_widget);
     ui->content_layout->addWidget(rusification_widget);
@@ -64,6 +73,7 @@ MainWindow::MainWindow(QWidget *parent) :
     background_update_timer.setInterval(30 * 1000);
     connect(&background_update_timer, &QTimer::timeout, this, &MainWindow::randomChangeBackground);
     background_update_timer.start();
+    randomChangeBackground();
 
     qDebug() << "Initialising main window connections";
     makeConnections();
@@ -118,8 +128,8 @@ void MainWindow::randomChangeBackground()
     }
     qDebug() << "Next background id = " << next_pixmap_id;
 
-    QPixmap *cur_bg = new QPixmap(current_bg.scaled(size()));
-    QPixmap *new_bg= new QPixmap(QPixmap(":/backgrounds/bg" + QString::number(next_pixmap_id) + ".png").scaled(size()));
+    QPixmap *cur_bg = new QPixmap(current_bg);
+    QPixmap *new_bg= new QPixmap(":/backgrounds/bg" + QString::number(next_pixmap_id) + ".png");
     current_bg_id = next_pixmap_id;
 
     QtConcurrent::run([cur_bg, new_bg, this](){
@@ -180,12 +190,13 @@ void MainWindow::setupWindowBackgroundAndMask(QPixmap background)
 {
     if (!qApp)
         return;
-    current_bg = background.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-    current_mask = current_bg.mask();
+    current_bg = background;
+    QPixmap scaled_bg = current_bg.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+    current_mask = scaled_bg.mask();
     setMask(current_mask);
 
     QPalette palette;
-    palette.setBrush(QPalette::Window, current_bg);
+    palette.setBrush(QPalette::Window, scaled_bg);
     setPalette(palette);
 }
 
@@ -259,6 +270,8 @@ void MainWindow::changeFontSizeRecursive(size_t percent, QWidget *widget)
     QFont widget_font = widget->font();
     QString widget_name = widget->objectName();
 
+    if (widget_name.contains("menuentry"))
+        widget_font.setPixelSize(small_font_size * percent / 100);
     if (widget_name.contains("_small"))
         widget_font.setPixelSize(small_font_size * percent / 100);
     if (widget_name.contains("_common"))

+ 4 - 3
src/Legacy/widgets/mainwindow.h

@@ -17,7 +17,7 @@ class MainWindow;
 }
 
 class MenuEntry;
-// class LotroManager;
+class LotroDatManager;
 // class NetworkUpdater;
 class PatchDownloader;
 
@@ -70,8 +70,9 @@ private:
 
     void setEventFilterRecursive(QObject* widget);
 private:    
-    PatchDownloader* patch_updater;
-    QThread *patch_updater_thread;
+    PatchDownloader *patch_updater;
+    LotroDatManager *lotro_manager;
+    QThread *lotro_functions_thread;
 
     Ui::MainWindow *ui;
 

+ 0 - 4
src/Legacy/widgets/mainwindow.ui

@@ -144,7 +144,6 @@
        <property name="font">
         <font>
          <family>Constantia</family>
-         <pointsize>8</pointsize>
          <weight>50</weight>
          <bold>false</bold>
         </font>
@@ -189,7 +188,6 @@
        <property name="font">
         <font>
          <family>Constantia</family>
-         <pointsize>8</pointsize>
         </font>
        </property>
        <property name="mouseTracking">
@@ -229,7 +227,6 @@
        <property name="font">
         <font>
          <family>Constantia</family>
-         <pointsize>8</pointsize>
         </font>
        </property>
        <property name="mouseTracking">
@@ -269,7 +266,6 @@
        <property name="font">
         <font>
          <family>Constantia</family>
-         <pointsize>8</pointsize>
         </font>
        </property>
        <property name="mouseTracking">

+ 0 - 42
src/Legacy/widgets/rusificationtreeitem.cpp

@@ -1,42 +0,0 @@
-#include "rusificationtreeitem.h"
-#include <QSettings>
-#include <QDebug>
-
-RusificationTreeItem::RusificationTreeItem(QString name): QTreeWidgetItem(1000), name(name)
-{
-}
-
-void RusificationTreeItem::parseSettingsItem(QSettings &patches_list)
-{
-    patches_list.beginGroup(name);
-    title = patches_list.value("title").toString();
-    description = patches_list.value("descr").toString();
-    patchname = patches_list.value("patchname").toString();
-    parent_name = patches_list.value("parent", "rusification").toString();
-
-    setText(0, title);
-
-    if (name.contains("patch")) {
-        QStringList categories_list = patches_list.value("id").toString().split('|');
-        for (QString category : categories_list)
-            categories.push_back(category.toInt());
-        setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
-    }
-
-    if (name.contains("group")) {
-        setFlags(Qt::ItemIsAutoTristate | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
-        if (parent_name == "rusification") {
-            QFont font;
-            font.setFamily(QStringLiteral("Trajan Pro 3"));
-            font.setPixelSize(16);
-            font.setBold(false);
-            font.setUnderline(false);
-
-            setFont(0, font);
-            setTextColor(0, QColor(207, 166, 68));
-        }
-    }
-
-    qDebug() << title << description << parent_name;
-    patches_list.endGroup();
-}

+ 0 - 24
src/Legacy/widgets/rusificationtreeitem.h

@@ -1,24 +0,0 @@
-#ifndef INCLUDEUSIFICATIONTREEITEM_H
-#define INCLUDEUSIFICATIONTREEITEM_H
-
-#include <QTreeWidgetItem>
-#include <QSettings>
-
-struct RusificationTreeItem : public QTreeWidgetItem
-{
-
-public:
-    explicit RusificationTreeItem(QString name);
-    void parseSettingsItem(QSettings& patches_list);
-
-public:
-    QString name;
-    QString title;
-    QString description;
-    QString patchname;
-
-    QString parent_name;
-    std::vector<int> categories;
-};
-
-#endif // INCLUDEUSIFICATIONTREEITEM_H

+ 1 - 2
src/Legacy/widgets/rusificationwidget.cpp

@@ -1,9 +1,8 @@
 #include "widgets/rusificationwidget.h"
 #include "ui_rusificationwidget.h"
-#include "widgets/rusificationtreeitem.h"
 #include <QDebug>
 
-RusificationWidget::RusificationWidget(QWidget *parent) :
+RusificationWidget::RusificationWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) :
     QWidget(parent),
     ui(new Ui::RusificationWidget)
 {

+ 9 - 2
src/Legacy/widgets/rusificationwidget.h

@@ -3,23 +3,30 @@
 
 #include <QWidget>
 #include <QTimer>
-#include <QTreeWidgetItem>
+#include <QSettings>
 
 namespace Ui {
 class RusificationWidget;
 }
 
+class PatchDownloader;
+class LotroDatManager;
+
 class RusificationWidget : public QWidget
 {
     Q_OBJECT
 
 public:
-    explicit RusificationWidget(QWidget *parent = 0);
+    explicit RusificationWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent = 0);
 
     ~RusificationWidget();
 
 
 private:
+    QSettings* app_settings;
+    PatchDownloader* patch_updater;
+    LotroDatManager* lotro_manager;
+
     Ui::RusificationWidget *ui;
 };
 

+ 64 - 53
src/Legacy/widgets/rusificationwidget.ui

@@ -28,7 +28,7 @@
    <item row="0" column="1" colspan="2">
     <widget class="QWidget" name="widget_15" native="true">
      <property name="sizePolicy">
-      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+      <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
@@ -41,19 +41,19 @@
        <number>30</number>
       </property>
       <item>
-       <widget class="QWidget" name="widget" native="true">
+       <widget class="QWidget" name="widget_7" native="true">
         <property name="styleSheet">
-         <string notr="true">QWidget#widget{
+         <string notr="true">QWidget#widget_7{
 	border-radius: 20px;
 	background-color: rgba(30, 0, 0, 100);
 }</string>
         </property>
-        <layout class="QGridLayout" name="gridLayout">
+        <layout class="QGridLayout" name="gridLayout_6" rowstretch="0,0,0,0,0,0,0,0">
          <property name="leftMargin">
           <number>20</number>
          </property>
          <property name="topMargin">
-          <number>10</number>
+          <number>11</number>
          </property>
          <property name="rightMargin">
           <number>20</number>
@@ -62,7 +62,7 @@
           <number>11</number>
          </property>
          <item row="2" column="0" colspan="4">
-          <widget class="QCheckBox" name="checkBox">
+          <widget class="QCheckBox" name="checkBox_4">
            <property name="font">
             <font>
              <family>Trajan Pro 3</family>
@@ -74,7 +74,7 @@
           </widget>
          </item>
          <item row="0" column="0" colspan="4">
-          <widget class="QLabel" name="label_common">
+          <widget class="QLabel" name="label_8_common_2">
            <property name="sizePolicy">
             <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
              <horstretch>0</horstretch>
@@ -97,7 +97,7 @@
           </widget>
          </item>
          <item row="1" column="3">
-          <spacer name="horizontalSpacer_2">
+          <spacer name="horizontalSpacer_11">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
@@ -110,7 +110,7 @@
           </spacer>
          </item>
          <item row="1" column="0">
-          <spacer name="horizontalSpacer">
+          <spacer name="horizontalSpacer_12">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
@@ -123,7 +123,7 @@
           </spacer>
          </item>
          <item row="1" column="1" colspan="2">
-          <widget class="QLabel" name="label_2">
+          <widget class="QLabel" name="label_14">
            <property name="minimumSize">
             <size>
              <width>70</width>
@@ -144,15 +144,28 @@
            </property>
           </widget>
          </item>
+         <item row="7" column="0" colspan="4">
+          <spacer name="verticalSpacer_4">
+           <property name="orientation">
+            <enum>Qt::Vertical</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>20</width>
+             <height>40</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
          <item row="3" column="0" colspan="4">
-          <widget class="QWidget" name="widget_2" native="true">
+          <widget class="QWidget" name="widget_11" native="true">
            <property name="sizePolicy">
             <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
-           <layout class="QHBoxLayout" name="horizontalLayout">
+           <layout class="QHBoxLayout" name="horizontalLayout_4">
             <property name="spacing">
              <number>7</number>
             </property>
@@ -169,14 +182,14 @@
              <number>0</number>
             </property>
             <item>
-             <widget class="QLabel" name="label_3_common">
+             <widget class="QLabel" name="label_9_common_2">
               <property name="text">
                <string>Статус:</string>
               </property>
              </widget>
             </item>
             <item>
-             <widget class="QLabel" name="label_4_common">
+             <widget class="QLabel" name="label_10_common_2">
               <property name="font">
                <font>
                 <family>a_AlgeriusNr</family>
@@ -190,15 +203,39 @@
            </layout>
           </widget>
          </item>
-         <item row="4" column="0" colspan="4">
-          <widget class="QWidget" name="widget_4" native="true">
+         <item row="5" column="0" colspan="4">
+          <widget class="QWidget" name="widget_16" native="true">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+             <horstretch>0</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
+           <layout class="QVBoxLayout" name="verticalLayout_6">
+            <property name="leftMargin">
+             <number>0</number>
+            </property>
+            <property name="topMargin">
+             <number>0</number>
+            </property>
+            <property name="rightMargin">
+             <number>0</number>
+            </property>
+            <property name="bottomMargin">
+             <number>0</number>
+            </property>
+           </layout>
+          </widget>
+         </item>
+         <item row="6" column="0" colspan="4">
+          <widget class="QWidget" name="widget_17" native="true">
            <property name="sizePolicy">
             <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
-           <layout class="QVBoxLayout" name="verticalLayout">
+           <layout class="QVBoxLayout" name="verticalLayout_7">
             <property name="leftMargin">
              <number>0</number>
             </property>
@@ -212,7 +249,7 @@
              <number>0</number>
             </property>
             <item>
-             <widget class="QLabel" name="label_7_common">
+             <widget class="QLabel" name="label_20_common_2">
               <property name="sizePolicy">
                <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                 <horstretch>0</horstretch>
@@ -233,41 +270,27 @@
              </widget>
             </item>
             <item>
-             <widget class="Line" name="line">
+             <widget class="Line" name="line_4">
               <property name="orientation">
                <enum>Qt::Horizontal</enum>
               </property>
              </widget>
             </item>
             <item>
-             <widget class="QRadioButton" name="radioButton_common">
+             <widget class="QCheckBox" name="checkBox_4_common_2">
               <property name="text">
-               <string>Шрифты (версия 1)</string>
+               <string>Перевод предметов</string>
               </property>
-              <property name="checked">
+              <property name="checkable">
                <bool>true</bool>
               </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QRadioButton" name="radioButton_2_common">
-              <property name="text">
-               <string>Шрифты (версия 2)</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QCheckBox" name="checkBox_common">
-              <property name="text">
-               <string>Перевод предметов</string>
-              </property>
               <property name="checked">
                <bool>true</bool>
               </property>
              </widget>
             </item>
             <item>
-             <widget class="QCheckBox" name="checkBox_2_common">
+             <widget class="QCheckBox" name="checkBox_5_common_2">
               <property name="text">
                <string>Перевод эмоций</string>
               </property>
@@ -607,12 +630,6 @@
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
-           <property name="sizeHint" stdset="0">
-            <size>
-             <width>40</width>
-             <height>20</height>
-            </size>
-           </property>
           </spacer>
          </item>
          <item row="1" column="3">
@@ -620,12 +637,6 @@
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
-           <property name="sizeHint" stdset="0">
-            <size>
-             <width>40</width>
-             <height>20</height>
-            </size>
-           </property>
           </spacer>
          </item>
          <item row="6" column="0" colspan="4">
@@ -942,8 +953,8 @@ QPushButton#cancelButton:hover {
      </property>
      <property name="sizeHint" stdset="0">
       <size>
-       <width>40</width>
-       <height>20</height>
+       <width>0</width>
+       <height>0</height>
       </size>
      </property>
     </spacer>
@@ -955,8 +966,8 @@ QPushButton#cancelButton:hover {
      </property>
      <property name="sizeHint" stdset="0">
       <size>
-       <width>40</width>
-       <height>20</height>
+       <width>0</width>
+       <height>0</height>
       </size>
      </property>
     </spacer>

+ 1 - 1
src/Legacy/widgets/settingswidget.cpp

@@ -7,7 +7,7 @@
 #include <QFileDialog>
 #include <QMessageBox>
 
-SettingsWidget::SettingsWidget(QSettings *settings, QWidget *parent) :
+SettingsWidget::SettingsWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) :
     QWidget(parent), app_settings(settings),
     ui(new Ui::SettingsWidget)
 {

+ 7 - 1
src/Legacy/widgets/settingswidget.h

@@ -9,12 +9,15 @@ namespace Ui {
 class SettingsWidget;
 }
 
+class PatchDownloader;
+class LotroDatManager;
+
 class SettingsWidget : public QWidget
 {
     Q_OBJECT
 
 public:
-    explicit SettingsWidget(QSettings *settings, QWidget *parent = 0);
+    explicit SettingsWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent = 0);
     ~SettingsWidget();
 
 private slots:
@@ -40,6 +43,9 @@ private slots:
 
 private:
     QSettings* app_settings;
+    PatchDownloader* patch_updater;
+    LotroDatManager* lotro_manager;
+
     Ui::SettingsWidget *ui;
     QTimer ui_update_timer;
 };

+ 1 - 1
src/Legacy/widgets/statuswidget.cpp

@@ -8,7 +8,7 @@
 #include <QDebug>
 #include <QMessageBox>
 
-StatusWidget::StatusWidget(PatchDownloader* patch_downloader, QWidget *parent) :
+StatusWidget::StatusWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) :
     QWidget(parent),
     ui(new Ui::StatusWidget)
 {

+ 5 - 1
src/Legacy/widgets/statuswidget.h

@@ -2,19 +2,21 @@
 #define STATUSWIDGET_H
 
 #include <QWidget>
+#include <QSettings>
 
 namespace Ui {
 class StatusWidget;
 }
 
 class PatchDownloader;
+class LotroDatManager;
 
 class StatusWidget : public QWidget
 {
     Q_OBJECT
 
 public:
-    explicit StatusWidget(PatchDownloader* patch_downloader, QWidget *parent = 0);
+    explicit StatusWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent = 0);
     ~StatusWidget();
 
 private slots:
@@ -43,7 +45,9 @@ private slots:
 private:
     Ui::StatusWidget *ui;
 
+    QSettings* app_settings;
     PatchDownloader* patch_updater;
+    LotroDatManager* lotro_manager;
 
     const QColor inWorkColor = QColor(85, 170, 255);
     const QColor readyColor = QColor(0, 170, 0);