Explorar o código

Continued adding functionality of LotroDatManager to GUI

Ivan Arkhipov %!s(int64=5) %!d(string=hai) anos
pai
achega
ac36eb181b

+ 54 - 19
src/Legacy/models/lotrodatmanager.cpp

@@ -12,14 +12,12 @@
 #include <iostream>
 #include <fstream>
 
-Q_DECLARE_METATYPE(LOTRO_DAT::FILE_TYPE)
-Q_DECLARE_METATYPE(LOTRO_DAT::SubfileData)
+Q_DECLARE_METATYPE(LOTRO_DAT::DatLocaleManager::LOCALE)
 
 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>();
+    qRegisterMetaType<LOTRO_DAT::DatLocaleManager::LOCALE>();
 }
 
 bool LotroDatManager::Initialised()
@@ -34,12 +32,15 @@ bool LotroDatManager::NotPatched()
 
 void LotroDatManager::InitialiseManager()
 {
+    qDebug() << "Initialising .dat manager";
     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")) {
 
+        qDebug() << "Finished initialisation .dat manager - error: required files not found!";
+
         emit caughtError(QString("InitialiseManager"), {"FileNotFound"});
         emit processFinished();
         return;
@@ -53,6 +54,8 @@ void LotroDatManager::InitialiseManager()
         client_local_file.Deinitialize();
         client_general_file.Deinitialize();
 
+        qDebug() << "Finished initialisation .dat manager - error: DatFile initialisation error!";
+
         emit caughtError(QString("InitialiseManager"), {"InitialisationError"});
         emit processFinished();
         return;
@@ -64,38 +67,65 @@ void LotroDatManager::InitialiseManager()
 void LotroDatManager::DeinitialiseManager()
 {
     emit processStarted();
+    qDebug() << "Started DEinitialisation .dat manager.";
     client_local_file.Deinitialize();
     client_general_file.Deinitialize();
+    qDebug() << "Finished DEinitialisation .dat manager.";
     emit processFinished();
 }
 
 void LotroDatManager::StartGame(LOTRO_DAT::DatLocaleManager::LOCALE locale)
 {
     emit processStarted();
+    qDebug() << "Starting game!";
 
     client_general_file.GetLocaleManager().SetLocale(locale);
     client_local_file.GetLocaleManager().SetLocale(locale);
 
     QString game_folder = app_settings->value("General/game_folder_path", QString()).toString();
 
-    if (!FileSystem::fileExists(QApplication::applicationDirPath() + "/GameLauncher.exe")) {
+    if (!FileSystem::fileExists(QApplication::applicationDirPath() + "/Launcher.exe")) {
         emit caughtError("StartGame", {"NoGameLauncherInLegacyDir"});
+        qDebug() << "Starting game FAILED - no game launcher in legacy directory found!";
         emit processFinished();
         return;
     }
 
-    if (!QFile::remove(game_folder + "/LotroLauncher.exe")) {
-        emit caughtError("StartGame", {"NoAccessToLotroLauncher"});
-        emit processFinished();
-        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();
+            return;
+        }
 
-    if (!QFile::copy(QApplication::applicationDirPath() + "/GameLauncher.exe", game_folder + "/LotroLauncher.exe")) {
-        emit caughtError("StartGame", {"NoAccessToGameLauncher"});
-        emit processFinished();
-        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();
+            return;
+        }
+
+        QFile file(game_folder + "/legacy_path.txt");
+        file.open(QIODevice::WriteOnly);
+        QTextStream out(&file);
+        out << QApplication::applicationDirPath() + "/LegacyLauncher.exe";
+        file.close();
+    } 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();
+            return;
+        }
     }
 
+    qDebug() << "Starting game finished!!";
     startLotroLauncherWithParameters(locale);
     emit processFinished();
 }
@@ -108,8 +138,8 @@ void LotroDatManager::ChangeTranslationLanguage()
 
 void LotroDatManager::InstallActivePatches()
 {
-    InstallPatches();
-    ApplyTexts();
+    InstallPatches();   // Installing means inserting necessary data
+    ApplyTexts();       // Applying means activating patched data
     ApplyImages();
     ApplySounds();
     InstallLoadscreens();
@@ -230,8 +260,13 @@ void LotroDatManager::InstallVideos()
         if (!QDir(target_folder).exists())
             QDir(target_folder).mkpath(target_folder);
 
-        if (FileSystem::fileExists(target_folder + filename))
-            QFile::remove(target_folder + filename);
+        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);
@@ -341,7 +376,7 @@ bool LotroDatManager::startLotroLauncherWithParameters(LOTRO_DAT::DatLocaleManag
     QStringList args;
     args << "-skiprawdownload";
     if (locale == LOTRO_DAT::DatLocaleManager::PATCHED)
-        args << "-disablePatch";
+        args << "gamelaunch" << "-disablePatch";
 
     client_general_file.Deinitialize();
     client_local_file.Deinitialize();

+ 0 - 1
src/Legacy/models/lotrodatmanager.h

@@ -59,7 +59,6 @@ signals:
     void textStatusChanged();
     void imagesStatusChanged();
     void soundsStatusChanged();
-
     void generalStatusChanged();
 
     // general signals. First argument is process_name, second - processed values

+ 1 - 1
src/Legacy/widgets/mainwindow.ui

@@ -158,7 +158,7 @@
         <string notr="true">color:rgb(255, 255, 255);</string>
        </property>
        <property name="text">
-        <string>ИНФОРМАЦИЯ</string>
+        <string>ГЛАВНАЯ</string>
        </property>
        <property name="scaledContents">
         <bool>true</bool>

+ 36 - 117
src/Legacy/widgets/settingswidget.cpp

@@ -1,6 +1,7 @@
 #include "widgets/settingswidget.h"
 #include "ui_settingswidget.h"
 #include "models/filesystem.h"
+#include "models/lotrodatmanager.h"
 #include "widgets/mainwindow.h"
 
 #include <QDebug>
@@ -8,71 +9,18 @@
 #include <QMessageBox>
 
 SettingsWidget::SettingsWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) :
-    QWidget(parent), app_settings(settings),
+    QWidget(parent), app_settings(settings), lotro_manager(lotro_dat_manager),
     ui(new Ui::SettingsWidget)
 {
     ui->setupUi(this);
-    ui_update_timer.setInterval(500);
-    connect(&ui_update_timer, &QTimer::timeout, this, &SettingsWidget::updateUI);
-    ui_update_timer.start();
+    ui->folder_value_common->setText(app_settings->value("General/game_folder_path", "Не выбрана").toString());
 }
 
 SettingsWidget::~SettingsWidget()
 {
-    ui_update_timer.stop();
     delete ui;
 }
 
-void SettingsWidget::updateUI()
-{
-    if (!qApp)
-        return;
-
-//    QString path = app->properties.value("settings/lotro_folder", "(не выбрана)").toString();
-//    ui->folder_value_common->setText(path);
-
-//    ui->data_protection_checkbox_common->setChecked(app->properties.value("settings/data_protection", 1).toBool());
-//    ui->restore_checkbox_common->setChecked(app->properties.value("settings/auto_restore", 1).toBool());
-//    ui->download_updates_checkbox_common->setChecked(app->properties.value("settings/download_updates", 1).toBool());
-//    ui->expert_tabs_checkbox_common->setChecked(app->properties.value("settings/expert_mode", 0).toBool());
-//    ui->restrict_download_speed_checkbox_common->setChecked(app->properties.value("settings/limit_download_speed", 0).toBool());
-//    ui->download_restrict_slider->setValue(app->properties.value("settings/download_speed", 64).toInt());
-
-//    if (app->properties.value("settings/expert_mode", 0).toBool()) {
-//        ui->management_widget->show();
-//        ui->data_protection_checkbox_common->show();
-//        ui->restore_checkbox_common->show();
-//    } else {
-//        ui->management_widget->hide();
-//        ui->data_protection_checkbox_common->hide();
-//        ui->restore_checkbox_common->hide();
-//    }
-
-//    int locale_index = 0;
-//    QString value = app->properties.value("settings/locale", "English").toString();
-
-//    if (value == "English")
-//        locale_index = 0;
-//    if (value == "DE")
-//        locale_index = 1;
-//    if (value == "FR")
-//        locale_index = 2;
-
-//    ui->lotro_patch_language_combobox_common->setCurrentIndex(locale_index);
-}
-
-void SettingsWidget::on_download_restrict_slider_valueChanged(int value)
-{
-//    if (value >= 1024) {
-//        double new_value = double(value) / 1024;
-//        ui->download_speed_label_common->setText(QString::number(new_value, 'g', 2) + " Мб/с");
-//    } else {
-//        ui->download_speed_label_common->setText(QString::number(value) + " Кб/с");
-//    }
-//    app->properties.setValue("settings/download_speed", value);
-//    app->properties.sync();
-}
-
 void SettingsWidget::on_interface_scale_combobox_common_currentIndexChanged(const QString &arg1)
 {
     MainWindow* window = qobject_cast<MainWindow*>(qApp->activeWindow());
@@ -89,82 +37,53 @@ void SettingsWidget::on_interface_scale_combobox_common_currentIndexChanged(cons
     app_settings->setValue("general/ui_scale", value);
 }
 
-void SettingsWidget::on_change_folder_button_clicked()
-{
-//    QStringList known_paths = FileSystem::recognizeRegistryLotroPath();
-//    QString template_path = known_paths.size() > 0 ? known_paths[0] : "";
-//    QString str = QFileDialog::getOpenFileName(0, "Расположение игры", template_path, "LotroLauncher.exe");
-//    QString path = str.replace("/LotroLauncher.exe", "").replace("\\", "/").replace("//", "/");
-
-//    if (!FileSystem::fileExists(path + "/LotroLauncher.exe")) {
-//        QMessageBox error_box("Ошибка!", "Похоже, указана неверная папка с игрой. Не могу найти файл LotroLauncher.exe",
-//                              QMessageBox::Critical, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
-
-//        return;
-//    }
-
-//    if (!FileSystem::fileExists(path + "/client_local_English.dat")) {
-//        QMessageBox pmbx("Файл данных не найден",
-//                         "Файл данных client_local_English.dat не обнаружен в папке с игрой. Запустить лаунчер игры с целью скачать недостающие данные?",
-//                         QMessageBox::Warning,
-//                         QMessageBox::Yes,
-//                         QMessageBox::No,
-//                         QMessageBox::NoButton);
-
-//        if (pmbx.exec() == QMessageBox::Yes) {
-//            // Start LotRO;
-//            return;
-//        } else {
-//            // Set status Файл данных не найден
-//        }
-//    }
-
-//    app->properties.setValue("settings/lotro_folder", path);
-//    app->properties.sync();
-//    ui->folder_value_common->setText(path);
-}
+void SettingsWidget::on_change_folder_button_clicked() {
+    QStringList known_paths = FileSystem::recognizeRegistryLotroPath();
+    QString template_path = known_paths.empty() ? "" : known_paths[0];
+    QString str = QFileDialog::getOpenFileName(0, "Расположение игры", template_path, "LotroLauncher.exe");
+    QString game_folder= str.replace("/LotroLauncher.exe", "").replace("\\", "/").replace("//", "/");
 
-void SettingsWidget::on_data_protection_checkbox_common_stateChanged(int arg1)
-{
-//    app->properties.setValue("settings/data_protection", arg1);
-//    app->properties.sync();
+    if (app_settings->value("General/game_folder_path", "").toString() == game_folder)
+        return;
+
+    app_settings->setValue("General/game_folder_path", game_folder);
+    ui->folder_value_common->setText(game_folder);
+    QMetaObject::invokeMethod(lotro_manager, "InitialiseManager", Qt::QueuedConnection);
 }
 
-void SettingsWidget::on_restore_checkbox_common_stateChanged(int arg1)
+void SettingsWidget::on_lotro_patch_language_combobox_common_activated(int index)
 {
-//    app->properties.setValue("settings/auto_restore", arg1);
-//    app->properties.sync();
+    QString value = "";
+    if (index == 0)
+        value = "English";
+    if (index == 1)
+        value = "DE";
+    if (index == 2)
+        value = "FR";
+
+    if (app_settings->value("General/original_locale", "").toString() == value)
+        return;
+
+    app_settings->setValue("General/original_locale", value);
+    QMetaObject::invokeMethod(lotro_manager, "InitialiseManager", Qt::QueuedConnection);
 }
 
-void SettingsWidget::on_download_updates_checkbox_common_stateChanged(int arg1)
+void SettingsWidget::on_patch_all_button_common_clicked()
 {
-//    app->properties.setValue("settings/download_updates", arg1);
-//    app->properties.sync();
+    QMetaObject::invokeMethod(lotro_manager, "InstallActivePatches", Qt::QueuedConnection);
 }
 
-void SettingsWidget::on_expert_tabs_checkbox_common_stateChanged(int arg1)
+void SettingsWidget::on_remove_backup_common_clicked()
 {
-//    app->properties.setValue("settings/expert_mode", arg1);
-//    app->properties.sync();
+    QMetaObject::invokeMethod(lotro_manager, "RemoveBackup", Qt::QueuedConnection);
 }
 
-void SettingsWidget::on_restrict_download_speed_checkbox_common_stateChanged(int arg1)
+void SettingsWidget::on_create_backup_common_clicked()
 {
-//    app->properties.setValue("settings/limit_download_speed", arg1);
-//    app->properties.sync();
+    QMetaObject::invokeMethod(lotro_manager, "CreateBackup", Qt::QueuedConnection);
 }
 
-
-void SettingsWidget::on_lotro_patch_language_combobox_common_activated(int index)
+void SettingsWidget::on_restore_backup_common_clicked()
 {
-//    QString value = "";
-//    if (index == 0)
-//        value = "English";
-//    if (index == 1)
-//        value = "DE";
-//    if (index == 2)
-//        value = "FR";
-//
-//    app->properties.setValue("settings/locale", value);
-//    app->properties.sync();
+    QMetaObject::invokeMethod(lotro_manager, "RestoreBackup", Qt::QueuedConnection);
 }

+ 8 - 14
src/Legacy/widgets/settingswidget.h

@@ -21,33 +21,27 @@ public:
     ~SettingsWidget();
 
 private slots:
-    void updateUI();
-
-    void on_download_restrict_slider_valueChanged(int value);
 
     void on_interface_scale_combobox_common_currentIndexChanged(const QString &arg1);
 
     void on_change_folder_button_clicked();
 
-    void on_data_protection_checkbox_common_stateChanged(int arg1);
-
-    void on_restore_checkbox_common_stateChanged(int arg1);
-
-    void on_download_updates_checkbox_common_stateChanged(int arg1);
-
-    void on_expert_tabs_checkbox_common_stateChanged(int arg1);
-
-    void on_restrict_download_speed_checkbox_common_stateChanged(int arg1);
-
     void on_lotro_patch_language_combobox_common_activated(int index);
 
+    void on_patch_all_button_common_clicked();
+    
+    void on_remove_backup_common_clicked();
+    
+    void on_create_backup_common_clicked();
+    
+    void on_restore_backup_common_clicked();
+    
 private:
     QSettings* app_settings;
     PatchDownloader* patch_updater;
     LotroDatManager* lotro_manager;
 
     Ui::SettingsWidget *ui;
-    QTimer ui_update_timer;
 };
 
 #endif // SETTINGSWIDGET_H

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

@@ -2,6 +2,7 @@
 #include "ui_statuswidget.h"
 #include "widgets/mainwindow.h"
 #include "models/patchdownloader.h"
+#include "models/lotrodatmanager.h"
 
 #include <QDesktopServices>
 #include <QUrl>
@@ -9,7 +10,7 @@
 #include <QMessageBox>
 
 StatusWidget::StatusWidget(QSettings* settings, PatchDownloader* patch_downloader, LotroDatManager* lotro_dat_manager, QWidget *parent) :
-    QWidget(parent),
+    QWidget(parent), lotro_manager(lotro_dat_manager),
     ui(new Ui::StatusWidget)
 {
 
@@ -102,3 +103,8 @@ void StatusWidget::on_donate_link_button_clicked()
 {
     QDesktopServices::openUrl(QUrl("http://translate.lotros.ru/donate"));
 }
+
+void StatusWidget::on_game_button_clicked()
+{
+    QMetaObject::invokeMethod(lotro_manager, "StartGame", Qt::QueuedConnection, Q_ARG(LOTRO_DAT::DatLocaleManager::LOCALE, LOTRO_DAT::DatLocaleManager::PATCHED));
+}

+ 2 - 0
src/Legacy/widgets/statuswidget.h

@@ -42,6 +42,8 @@ private slots:
 
     void on_donate_link_button_clicked();
 
+    void on_game_button_clicked();
+
 private:
     Ui::StatusWidget *ui;