فهرست منبع

Simplified LotroDatManager class

Patch management role will be moved to Patch class and its derivatives
Ivan Arkhipov 5 سال پیش
والد
کامیت
7190c23904
2فایلهای تغییر یافته به همراه137 افزوده شده و 398 حذف شده
  1. 114 363
      src/Legacy/models/lotrodatmanager.cpp
  2. 23 35
      src/Legacy/models/lotrodatmanager.h

+ 114 - 363
src/Legacy/models/lotrodatmanager.cpp

@@ -1,31 +1,23 @@
 #include "lotrodatmanager.h"
-#include "filesystem.h"
-#include "LotroDat/Subfiles/TextSubFile.h"
-#include "models/patchdownloader.h"
+#include "models/filesystem.h"
 #include "models/settings.h"
 
-#include <QtConcurrent/QtConcurrent>
-#include <QFontDatabase>
-#include <QMessageBox>
 #include <QDebug>
-
-#include <string>
-#include <iostream>
-#include <fstream>
+#include <QProcess>
 
 Q_DECLARE_METATYPE(LOTRO_DAT::DatLocaleManager::LOCALE)
-Q_DECLARE_METATYPE(QVector<QVariant>)
+Q_DECLARE_METATYPE(LotroDatManager::Category)
+
 
 LotroDatManager::LotroDatManager(QObject *parent) :
     QObject(parent) {
 
-    qRegisterMetaType<QVector<QVariant>>();
     qRegisterMetaType<LOTRO_DAT::DatLocaleManager::LOCALE>();
 }
 
 bool LotroDatManager::Initialised()
 {
-    return client_local_file.Initialized() && client_general_file.Initialized();
+    return client_general_file.Initialized() && client_local_file.Initialized();
 }
 
 bool LotroDatManager::NotPatched()
@@ -38,72 +30,72 @@ unsigned LotroDatManager::getPercent()
     return client_local_file.GetStatusModule().GetPercentage();
 }
 
-QString LotroDatManager::getCurrentInstallingPatchName()
+void LotroDatManager::initializeManager()
 {
-    return current_installing_patch_name;
-}
+    emit operationStarted("initializeManager");
+    qDebug() << __FUNCTION__ << "Starting initialisation of LotroDatManager";
 
-void LotroDatManager::InitialiseManager()
-{
-    qDebug() << "Initialising .dat manager";
-    emit processStarted("InitialiseManager");
     QString game_folder = Settings::getValue("Lotro/game_path").toString();
     QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
 
-    if (game_folder == "none" || !FileSystem::fileExists(game_folder + "client_local_" + locale_prefix + ".dat")
-            || !FileSystem::fileExists(game_folder + "client_general.dat")) {
+    QString client_local_filepath = game_folder + "/client_local_" + locale_prefix + ".dat";
+    QString client_general_filepath = game_folder + "/client_general.dat";
 
-        qDebug() << "Finished initialisation .dat manager - error: required files not found!";
+    if (game_folder == "none") {
+        qDebug() << __FUNCTION__ << "Finished initialisation LotroDatManager - error: .dat files not found!";
+        emit errorOccured("initializeManager", {}, "FolderNotDefined");
+        emit operationFinished("initializeManager", {}, false);
+        return;
+    }
 
-        emit caughtError(QString("InitialiseManager"), {"FileNotFound"});
-        emit processFinished("InitialiseManager");
+    if (!FileSystem::fileExists(client_local_filepath) || !FileSystem::fileExists(client_general_filepath)) {
+        emit errorOccured("initializeManager", {}, "DatFilesNotFound");
+        emit operationFinished("initializeManager", {}, false);
         return;
     }
 
     // Updating file permissions to be sure, that they're not in read-only mode
 
-    if (!QFile::setPermissions((game_folder + "/client_local_" + locale_prefix + ".dat"), QFileDevice::Permission(0x6666))) {
-        qDebug() << "Unable to update permissions on client_local_* file!";
+    if (!QFile::setPermissions(client_local_filepath, QFileDevice::Permission(0x6666))) {
+        qDebug() << __FUNCTION__ << "Unable to update permissions on client_local_* file!";
     }
 
-    if (!QFile::setPermissions((game_folder + "/client_general.dat"), QFileDevice::Permission(0x6666))) {
-        qDebug() << "Unable to update permissions on client_general* file!";
+    if (!QFile::setPermissions(client_general_filepath, QFileDevice::Permission(0x6666))) {
+        qDebug() << __FUNCTION__ << "Unable to update permissions on client_general* file!";
     }
 
     // Initialising client_local_*.dat file and client_general.dat
 
-    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 client_local_init_res = client_local_file.Initialise(client_local_filepath.toStdString(), 0);
+    auto client_general_init_res = client_general_file.Initialise(client_general_filepath.toStdString(), 1);
 
     if (client_local_init_res.result != LOTRO_DAT::SUCCESS
-            || client_general_init_res.result != LOTRO_DAT::SUCCESS) {
+        || client_general_init_res.result != LOTRO_DAT::SUCCESS)
+    {
         client_local_file.Deinitialize();
         client_general_file.Deinitialize();
 
-        qDebug() << "Finished initialisation .dat manager - error: DatFile initialisation error!";
+        qDebug() << __FUNCTION__ << "Finished LotroDatManager initialisation - error: DatFile initialisation error!";
 
-        emit caughtError(QString("InitialiseManager"), {"InitialisationError"});
-        emit processFinished("InitialiseManager");
+        emit errorOccured("initializeManager", {}, "DatInitError");
+        emit operationFinished("initializeManager", {}, false);
         return;
     }
 
-    emit processFinished("InitialiseManager");
+    emit operationFinished("initializeManager", {}, true);
 }
 
-void LotroDatManager::DeinitialiseManager()
+void LotroDatManager::deinitializeManager()
 {
-    emit processStarted("DeinitialiseManager");
-    qDebug() << "Started DEinitialisation .dat manager.";
+    emit operationStarted("deinitializeManager");
     client_local_file.Deinitialize();
     client_general_file.Deinitialize();
-    qDebug() << "Finished DEinitialisation .dat manager.";
-    emit processFinished("DeinitialiseManager");
+    emit operationFinished("deinitializeManager");
 }
 
-void LotroDatManager::StartGame(LOTRO_DAT::DatLocaleManager::LOCALE locale)
+void LotroDatManager::startGame(LOTRO_DAT::DatLocaleManager::LOCALE locale)
 {
-    emit processStarted("StartGame");
-    qDebug() << "Starting game!";
+    emit operationStarted("startGame", {locale});
 
     client_general_file.GetLocaleManager().SetLocale(locale);
     client_local_file.GetLocaleManager().SetLocale(locale);
@@ -111,33 +103,33 @@ void LotroDatManager::StartGame(LOTRO_DAT::DatLocaleManager::LOCALE locale)
     QString game_folder = Settings::getValue("Lotro/game_path").toString();
 
     if (game_folder == "none") {
-        emit caughtError("StartGame", {"GameFolderNotSet"});
-        qDebug() << "Starting game FAILED - game folder wasnt set!";
-        emit processFinished("StartGame");
+        qDebug() << __FUNCTION__ << "Starting game FAILED - game folder wasnt set!";
+        emit errorOccured("startGame", {locale}, "GameFolderNotSet");
+        emit operationFinished("startGame", {locale}, false);
         return;
     }
 
     if (!FileSystem::fileExists(QApplication::applicationDirPath() + "/Launcher.exe")) {
-        emit caughtError("StartGame", {"NoGameLauncherInLegacyDir"});
-        qDebug() << "Starting game FAILED - no game launcher in legacy directory found!";
-        emit processFinished("StartGame");
+        qDebug() << __FUNCTION__ << "Starting game FAILED - no game launcher in legacy directory found!";
+        emit errorOccured("startGame", {locale}, "NoGameLauncherInLegacyDir");
+        emit operationFinished("startGame", {locale}, false);
         return;
     }
 
     if (locale == LOTRO_DAT::DatLocaleManager::PATCHED) {
         QFile::remove(game_folder + "/lotro_ru.exe");
         if (!QFile::copy(QApplication::applicationDirPath() + "/LotroLauncher.exe", game_folder + "/lotro_ru.exe")) {
-            emit caughtError("StartGame", {"NoAccessToGameLauncher"});
-            qDebug() << "Starting game FAILED - cannot copy LotroLauncher to LotroLauncher_fwd!!";
-            emit processFinished("StartGame");
+            qDebug() << __FUNCTION__ << "Starting game FAILED - cannot copy LotroLauncher to lotro_ru.exe!!";
+            emit errorOccured("startGame", {locale}, "LauncherCopyFailed");
+            emit operationFinished("startGame", {locale}, false);
             return;
         }
 
         QFile::remove(game_folder + "/LotroLauncher.exe");
         if (!QFile::copy(QApplication::applicationDirPath() + "/Launcher.exe", game_folder + "/LotroLauncher.exe")) {
-            emit caughtError("StartGame", {"NoAccessToGameLauncher"});
-            qDebug() << "Starting game FAILED - cannot copy GameLauncher to LotroLauncher!!";
-            emit processFinished("StartGame");
+            qDebug() << __FUNCTION__ << "Starting game FAILED - cannot copy GameLauncher to LotroLauncher!!";
+            emit errorOccured("startGame", {locale}, "NoAccessToGameLauncher");
+            emit operationFinished("startGame", {locale}, false);
             return;
         }
 
@@ -149,358 +141,117 @@ void LotroDatManager::StartGame(LOTRO_DAT::DatLocaleManager::LOCALE locale)
     } else {
         QFile::remove(game_folder + "/LotroLauncher.exe");
         if (!QFile::copy(QApplication::applicationDirPath() + "/LotroLauncher.exe", game_folder + "/LotroLauncher.exe")) {
-            qDebug() << QApplication::applicationDirPath() + "/LotroLauncher.exe";
-            qDebug() << game_folder + "/LotroLauncher.exe";
-            emit caughtError("StartGame", {"NoAccessToGameLauncher"});
-            qDebug() << "Starting game FAILED - cannot copy LotroLauncher from working dir to LotroLauncher in lotro dir!!";
-            emit processFinished("StartGame");
+            qDebug() << __FUNCTION__ << "Starting game FAILED - cannot copy LotroLauncher from working dir to LotroLauncher in lotro dir!!";
+            emit errorOccured("startGame", {locale}, "NoAccessToGameLauncher");
+            emit operationFinished("startGame", {locale}, false);
             return;
         }
     }
 
-    qDebug() << "Starting game finished!!";
-    startLotroLauncherWithParameters(locale);
-    emit processFinished("StartGame");
-}
-
-void LotroDatManager::ChangeTranslationLanguage()
-{
-    DeinitialiseManager();
-    InitialiseManager();
-}
-
-void LotroDatManager::InstallActivePatches()
-{
-    SetupAllPatches();   // Setup means inserting necessary data
-    ApplyTexts();       // Applying means activating patched data
-    ApplyImages();
-    ApplySounds();
-}
-
-void LotroDatManager::SetupAllPatches()
-{
-    foreach (QString patch_name, all_patch_names) {
-        if (Settings::getValue("DatabaseDownload/" + patch_name).toString() == "Disabled") {
-            continue;
-        }
-
-        emit processStarted("SetupPatch", {patch_name});
-        current_installing_patch_name = patch_name;
-
-        if (patch_name == "video") {
-            InstallVideos();
-            Settings::setValue("DatabaseApplied/" + patch_name, "True");
-            current_installing_patch_name = "none";
-            emit processFinished("SetupPatch", {patch_name});
-            return;
-        }
-
-        if (patch_name == "loadscreen") {
-            InstallLoadscreens();
-            Settings::setValue("DatabaseApplied/" + patch_name, "True");
-            current_installing_patch_name = "none";
-            emit processFinished("SetupPatch", {patch_name});
-            return;
-        }
-
-        QString database_path = Settings::getValue("DatabasePath/" + patch_name).toString(); //patch_downloader->getDatabasePathByPatchName(patch_name);
-        if (database_path == "none") {
-            qDebug() << __FUNCTION__ << "Database for " << patch_name << " has no database path! Skipping!";
-            continue;
-        }
-
-        LOTRO_DAT::Database db;
-        if (!db.InitDatabase(database_path.toStdString())) {
-            emit caughtError("InstallPatches", {"ErrorInitDatabase"});
-            continue;
-        }
-
-        if (client_local_file.GetPatcher().PatchAllDatabase(&db).result != LOTRO_DAT::SUCCESS)
-            emit caughtError("InstallPatches", {"ErrorCannotPatch", "client_local"});
-
-        if (client_general_file.GetPatcher().PatchAllDatabase(&db).result != LOTRO_DAT::SUCCESS)
-            emit caughtError("InstallPatches", {"ErrorCannotPatch", "client_general"});
-
-        db.CloseDatabase();
-
-        Settings::setValue("DatabaseApplied/" + patch_name, "True");
-        current_installing_patch_name = "none";
-        emit processFinished("SetupPatch", {patch_name});
-    }
-}
-
-void LotroDatManager::InstallLoadscreens()
-{
-    emit processStarted("InstallLoadscreens");
-
-    if (Settings::getValue("DatabaseDownload/loadscreen").toString() == "Disabled") {
-        emit processFinished("InstallLoadscreens", {"Success"});
+    if (!startLotroLauncherWithParameters(locale)) {
+        emit errorOccured("startGame", {locale}, "StartLotroLauncherWithParametersFailed");
+        emit operationFinished("startGame", {locale}, false);
         return;
     }
 
-    QString game_folder = Settings::getValue("Lotro/game_path").toString();
-    QString locale_prefix = Settings::getValue("Lotro/original_locale").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";
+    emit operationFinished("startGame", {locale}, true);
+}
 
-    QString folder = game_folder + "/raw/" + raw_folder + "/logo/";
+void LotroDatManager::installPatch(QString patch_name, QString database_path)
+{
+    emit operationStarted("installPatch", {patch_name, database_path});
+    LOTRO_DAT::Database db;
 
-    if (!FileSystem::folderExists(folder)) {
-        emit processFinished("InstallLoadscreens", {"Error", "Incorrect folder"});
+    if (!db.InitDatabase(database_path.toStdString())) {
+        emit errorOccured("installPatch", {patch_name, database_path}, "ErrorInitDatabase");
+        emit operationFinished("installPatch", {patch_name, database_path}, false);
         return;
     }
 
-    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 = Settings::getValue("DatabasePath/loadscreen").toString();
-    if (database_path == "none") {
-        qDebug() << __FUNCTION__ << "No path to loadscreens patch found!";
+    if (client_local_file.GetPatcher().PatchAllDatabase(&db).result != LOTRO_DAT::SUCCESS) {
+        db.CloseDatabase();
+        emit errorOccured("installPatch", {patch_name, database_path}, "ErrorPatchClientLocal");
+        emit operationFinished("installPatch", {patch_name, database_path}, false);
         return;
     }
 
-    LOTRO_DAT::Database db;
-    if (!db.InitDatabase(database_path.toStdString())) {
-        emit caughtError("InstallLoadscreens", {"ErrorInitDatabase"});
-        emit processFinished("InstallLoadscreens");
+    if (client_general_file.GetPatcher().PatchAllDatabase(&db).result != LOTRO_DAT::SUCCESS) {
+        db.CloseDatabase();
+        emit errorOccured("installPatch", {patch_name, database_path});
+        emit operationFinished("installPatch", {patch_name, database_path}, false);
         return;
     }
 
-    for (size_t i = 0; i < qMin(db.CountRows(), size_t(filenames.size())); i++) {
-        LOTRO_DAT::SubfileData subfile = db.GetNextFile();
-
-        if (subfile.binary_data.Empty())
-            continue;
-
-        QFile::remove(folder + filenames[i]);
-        subfile.binary_data.WriteToFile((folder + filenames[i]).toStdString());
-    }
     db.CloseDatabase();
-    emit processFinished("InstallLoadscreens");
+    emit operationFinished("installPatch", {patch_name, database_path}, true);
 }
 
-void LotroDatManager::InstallVideos()
+void LotroDatManager::enableCategory(QString patch_name, LotroDatManager::Category category)
 {
-    if (Settings::getValue("DatabaseDownload/video").toString() == "Disabled")
-        return;
-
-    emit processStarted("InstallVideos");
-
-    QString game_folder = Settings::getValue("Lotro/game_path").toString();
-
-    if (game_folder == "none") {
-        qDebug() << __FUNCTION__ << "No path to game folder found!";
-        emit caughtError("InstallVideos", {"ErrorGameFolderNotFound"});
-        emit processFinished("InstallVideos");
-        return;
-    }
+    emit operationStarted("enableCategory", {patch_name, category});
 
-    QString database_path = Settings::getValue("DatabasePath/video").toString();
-
-    if (database_path == "none") {
-        qDebug() << __FUNCTION__ << "No path to videos patch found!";
-        emit caughtError("InstallVideos", {"ErrorFindDatabase"});
-        emit processFinished("InstallVideos");
+    if (client_local_file.GetLocaleManager().EnableCategory(category).result != LOTRO_DAT::SUCCESS) {
+        emit errorOccured("enableCategory", {patch_name, category}, "ErrorEnableCategoryClientLocal");
+        emit operationFinished("enableCategory", {patch_name, category}, false);
         return;
     }
 
-    LOTRO_DAT::Database db;
-    if (!db.InitDatabase(database_path.toStdString())) {
-        emit caughtError("InstallVideos", {"ErrorInitDatabase"});
-        emit processFinished("InstallVideos");
+    if (client_general_file.GetLocaleManager().EnableCategory(category).result != LOTRO_DAT::SUCCESS) {
+        emit errorOccured("enableCategory", {patch_name, category}, "ErrorEnableCategoryClientGeneral");
+        emit operationFinished("enableCategory", {patch_name, category}, false);
         return;
     }
 
-    for(size_t i = 0; i < db.CountRows(); i++) {
-        LOTRO_DAT::SubfileData subfile = db.GetNextFile();
-
-        if (subfile.Empty())
-            continue;
-
-        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>()) + "/";
-
-        if (!QDir(target_folder).exists())
-            QDir(target_folder).mkpath(target_folder);
-
-        if (FileSystem::fileExists(target_folder + filename)) {
-            if (FileSystem::fileHash(target_folder + filename) == hash) {
-                continue;
-            } else {
-                QFile::remove(target_folder + filename);
-            }
-        }
-
-        Downloader video_downloader;
-        video_downloader.setUrl(url);
-        video_downloader.targetFile = new QFile(target_folder + filename);
-        video_downloader.targetFile->open(QIODevice::ReadWrite);
-        video_downloader.start();
-// TODO: Progress notification on video download!
-//        connect(&video_downloader, &Downloader::progressChanged, this, &LotroDatManager::VideoDownloadProgressChanged);
-        video_downloader.waitForDownloaded();
-        video_downloader.targetFile->close();
-        video_downloader.targetFile->deleteLater();
-
-        if (FileSystem::fileHash(target_folder + filename) != hash) {
-            emit caughtError("InstallVideos", {"IncorrectHash", hash, FileSystem::fileHash(target_folder + filename), target_folder, filename, url});
-        }
-    }
-    db.CloseDatabase();
-
-    emit processFinished("InstallVideos");
+    emit operationFinished("enableCategory", {patch_name, category});
 }
 
-void LotroDatManager::InstallUpdates()
+void LotroDatManager::disableCategory(QString patch_name, LotroDatManager::Category category)
 {
-    emit processStarted("InstallUpdates");
-    foreach (QString patch_name, all_patch_names) {
-        if (Settings::getValue("DatabaseDownload/" + patch_name).toString() == "Disabled" ||
-            Settings::getValue("DatabaseApplied/" + patch_name).toString() == "True")
-        {
-            continue;
-        }
-
-        emit processStarted("SetupPatch", {patch_name});
-        current_installing_patch_name = patch_name;
-
-        if (patch_name == "video") {
-            InstallVideos();
-            Settings::setValue("DatabaseApplied/" + patch_name, "True");
-            current_installing_patch_name = "none";
-        }
-
-        if (patch_name == "loadscreen") {
-            InstallLoadscreens();
-            Settings::setValue("DatabaseApplied/" + patch_name, "True");
-            current_installing_patch_name = "none";
-        }
-
-        QString database_path = Settings::getValue("PatchPath/" + patch_name).toString();
-        if (database_path == "none") {
-            qDebug() << __FUNCTION__ << "Database for " << patch_name << " has no database path! Skipping!";
-            continue;
-        }
-
-        LOTRO_DAT::Database db;
-        if (!db.InitDatabase(database_path.toStdString())) {
-            emit caughtError("InstallPatches", {"ErrorInitDatabase"});
-            continue;
-        }
-
-        if (client_local_file.GetPatcher().PatchAllDatabase(&db).result != LOTRO_DAT::SUCCESS)
-            emit caughtError("InstallPatches", {"ErrorCannotPatch", "client_local"});
+    emit operationStarted("disableCategory", {patch_name, category});
 
-        if (client_general_file.GetPatcher().PatchAllDatabase(&db).result != LOTRO_DAT::SUCCESS)
-            emit caughtError("InstallPatches", {"ErrorCannotPatch", "client_general"});
-
-        db.CloseDatabase();
+    if (client_local_file.GetLocaleManager().DisableCategory(category).result != LOTRO_DAT::SUCCESS) {
+        emit errorOccured("disableCategory", {patch_name, category}, "ErrorDisableCategoryClientLocal");
+        emit operationFinished("disableCategory", {patch_name, category}, false);
+        return;
+    }
 
-        Settings::setValue("DatabaseApplied/" + patch_name, "True");
-        current_installing_patch_name = "none";
-        emit processFinished("SetupPatch", {patch_name});
+    if (client_general_file.GetLocaleManager().DisableCategory(category).result != LOTRO_DAT::SUCCESS) {
+        emit errorOccured("disableCategory", {patch_name, category}, "ErrorDisableCategoryClientGeneral");
+        emit operationFinished("disableCategory", {patch_name, category}, false);
+        return;
     }
-}
 
-void LotroDatManager::InstallMicroPatch()
-{
-    // TODO
+    emit operationFinished("disableCategory", {patch_name, category}, true);
 }
 
-void LotroDatManager::CreateBackup()
+void LotroDatManager::createBackup()
 {
-    emit processStarted("CreateBackup");
+    // TODO: Error handling
+    emit operationStarted("createBackup");
     QString locale_prefix = Settings::getValue("Lotro/original_locale").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("CreateBackup");
+    emit operationFinished("createBackup");
 }
 
-void LotroDatManager::RestoreFromBackup()
+void LotroDatManager::restoreFromBackup()
 {
-    emit processStarted("CreateBackup");
+    // TODO: Error handling
+    emit operationStarted("restoreFromBackup");
     QString locale_prefix = Settings::getValue("Lotro/original_locale").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("CreateBackup");
+    emit operationFinished("restoreFromBackup");
 }
 
-void LotroDatManager::RemoveBackup()
+void LotroDatManager::removeBackup()
 {
-    emit processStarted("CreateBackup");
+    // TODO: Error handling
+    emit operationStarted("removeBackup");
     QString locale_prefix = Settings::getValue("Lotro/original_locale").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("CreateBackup");
-}
-
-void LotroDatManager::ApplyTexts()
-{
-    if (Settings::getValue("Components/texts_main").toString() == "Enabled") {
-        client_local_file.GetLocaleManager().EnableCategory(100);
-    } else {
-        client_local_file.GetLocaleManager().DisableCategory(100);
-    }
-
-    if (Settings::getValue("Components/texts_emotes").toString() == "Enabled") {
-        client_local_file.GetLocaleManager().EnableCategory(101);
-    } else {
-        client_local_file.GetLocaleManager().DisableCategory(101);
-    }
-
-    if (Settings::getValue("Components/texts_items").toString() == "Enabled") {
-        client_local_file.GetLocaleManager().EnableCategory(102);
-    } else {
-        client_local_file.GetLocaleManager().DisableCategory(102);
-    }
-}
-
-void LotroDatManager::ApplyImages() {
-    if (Settings::getValue("Components/maps").toString() == "Enabled") {
-        client_local_file.GetLocaleManager().EnableCategory(200);
-    } else {
-        client_local_file.GetLocaleManager().DisableCategory(200);
-    }
-}
-
-void LotroDatManager::ApplySounds() {
-    emit processStarted("ApplySounds");
-    if (Settings::getValue("Components/sounds").toString() == "Enabled") {
-        client_local_file.GetLocaleManager().EnableCategory(300);
-    } else {
-        client_local_file.GetLocaleManager().DisableCategory(300);
-    }
-
-    if (Settings::getValue("Components/videos").toString() == "Enabled") {
-        client_local_file.GetLocaleManager().EnableCategory(103);
-    } else {
-        client_local_file.GetLocaleManager().DisableCategory(103);
-    }
-    emit processFinished("ApplySounds");
+    emit operationFinished("removeBackup");
 }
 
 bool LotroDatManager::startLotroLauncherWithParameters(LOTRO_DAT::DatLocaleManager::LOCALE locale)
@@ -521,28 +272,28 @@ bool LotroDatManager::startLotroLauncherWithParameters(LOTRO_DAT::DatLocaleManag
     client_general_file.Deinitialize();
     client_local_file.Deinitialize();
 
-    if(FileSystem::fileExists(QApplication::applicationDirPath() + "/user.ini")){
-        QSettings login(QApplication::applicationDirPath() + "/user.ini", QSettings::IniFormat);
-        login.beginGroup("Account");
-        QString username = login.value("username", "").toString();
-        QString password = login.value("password", "").toString();
-        login.endGroup();
+    QString username = Settings::getValue("Account/username").toString();
+    QString password = Settings::getValue("Account/password").toString();
+    if (!username.isEmpty() && !password.isEmpty()) {
         args << "-username" << username << "-password" << password;
     }
 
-    qDebug() << "Запускаем игру со следующими аргументами: " << args;
+    qDebug() << __FUNCTION__ << "Starting game with arguments: " << args;
 
     QFile f(Settings::getValue("Lotro/game_path").toString() + "/LotroLauncher.exe");
     QProcess process;
 
     if (FileSystem::fileExists(f.fileName())) {
-        if(f.fileName().contains(" ")) f.setFileName("\"" + f.fileName() + "\"");
+        if (f.fileName().contains(" ")) {
+            f.setFileName("\"" + f.fileName() + "\"");
+        }
+
         process.startDetached(f.fileName(), args);
         process.waitForFinished(-1);
         QApplication::quit();
         return true;
     } else {
-        emit caughtError("startLotroLauncherWithParameters", {"LotroLauncherNotFound"});
         return false;
     }
 }
+

+ 23 - 35
src/Legacy/models/lotrodatmanager.h

@@ -9,12 +9,21 @@
 
 #include <LotroDat/LotroDat.h>
 
-class PatchDownloader;
-
 class LotroDatManager : public QObject
 {
     Q_OBJECT
 
+public:
+    enum Category : int {
+        E_TEXTS_COMMON = 100,
+        E_TEXTS_ITEMS = 101,
+        E_TEXTS_EMOTES = 102,
+        E_TEXTS_VIDEOS = 103,
+        E_MAPS_COMMON = 200,
+        E_TEXTURES_COMMON = 201,
+        E_AUDIOS_COMMON = 300
+    };
+
 public:
     explicit LotroDatManager(QObject *parent = nullptr);
 
@@ -22,57 +31,36 @@ public:
 
     bool NotPatched();
 
-// TODO:
-//    bool IsRusificationActive();
-
     unsigned getPercent();
 
-    QString getCurrentInstallingPatchName();
-
 public slots:
-    void InitialiseManager();
+    void initializeManager();
 
-    void DeinitialiseManager();
+    void deinitializeManager();
 
-    void StartGame(LOTRO_DAT::DatLocaleManager::LOCALE locale);
+    void startGame(LOTRO_DAT::DatLocaleManager::LOCALE locale);
 
-    void ChangeTranslationLanguage();
+    void installPatch(QString patch_name, QString database_path);
 
-    void InstallActivePatches();
+    void enableCategory(QString patch_name, Category category);
 
-    void SetupAllPatches();
+    void disableCategory(QString patch_name, Category category);
 
-    void InstallUpdates();
+    void createBackup();
 
-    void InstallMicroPatch();
+    void restoreFromBackup();
 
-    void CreateBackup();
-
-    void RestoreFromBackup();
-
-    void RemoveBackup();
+    void removeBackup();
 
 private:
     bool startLotroLauncherWithParameters(LOTRO_DAT::DatLocaleManager::LOCALE locale);
-    void ApplyTexts();
-    void ApplyImages();
-    void ApplySounds();
-    void InstallLoadscreens();
-    void InstallVideos();
 
 signals:
-    // general signals. First argument is process_name, second - processed values
-    void processStarted(QString, QVector<QVariant> parameters = QVector<QVariant>());
-    void processFinished(QString, QVector<QVariant> parameters = QVector<QVariant>());
-    void caughtError(QString, QVector<QVariant>);
+    void operationStarted(QString operation_name, QVector<QVariant> args = {});
+    void errorOccured(QString operation_name, QVector<QVariant> args = {}, QString message = "No error message provided");
+    void operationFinished(QString operation_name, QVector<QVariant> args = {}, bool successful = true);
 
 private:
-    const QStringList all_patch_names = {"sound", "text", "image", "loadscreen", "texture", "font", "video"};
-
-    QString current_installing_patch_name;
-    int video_percent;
-    int loadscreens_percent;
-
     LOTRO_DAT::DatFile client_local_file;
     LOTRO_DAT::DatFile client_general_file;
 };