Browse Source

Implemented correct legacy initialization behaviour

Ivan Arkhipov 3 years ago
parent
commit
f9cfa63ff3

+ 1 - 6
src/Legacy/legacyapplication.cpp

@@ -51,10 +51,6 @@ bool LegacyApplication::init() {
 
     qDebug() << "Initialising fonts and resources";
     QDir::setCurrent(QApplication::applicationDirPath());
-    if (!FileSystem::folderExists("backup")) {
-        QDir dir;
-        dir.mkdir("backup");
-    }
 
     QResource::registerResource(QApplication::applicationDirPath() + "/data01.gtr");
     QResource::registerResource(QApplication::applicationDirPath() + "/data02.gtr");
@@ -73,10 +69,8 @@ bool LegacyApplication::init() {
 
     qDebug() << "Starting GUI initialisation...";
     gui = new MainWindow();
-//    connect(this, &LegacyApplication::ErrorStatusChanged, gui, &MainWindow::onErrorStatusChanged);
 
     qDebug() << "Starting functional modules initialisation...";
-
     InitModules();
 
     qDebug() << "Successfully finished the initialization!!!";
@@ -88,6 +82,7 @@ void LegacyApplication::InitModules() {
     modules_init_timer_.stop();
     AppErrorStatus status = CheckAppPrerequesities();
     emit ErrorStatusChanged(status);
+    qDebug() << "NEW ERROR STATUS: " << status;
 
     if (status == E_NO_ERRORS) {
         QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::init, Qt::BlockingQueuedConnection);

+ 1 - 1
src/Legacy/legacyapplication.h

@@ -29,7 +29,7 @@ public:
 signals:
     void ErrorStatusChanged(AppErrorStatus status);
 
-private slots:
+public slots:
     void InitModules();
 
 private:

+ 4 - 0
src/Legacy/models/patchdownloader.cpp

@@ -6,6 +6,10 @@
 
 void PatchDownloader::init() {
     for (const QString& patch: patches_) {
+        if (patch_downloaders_.count(patch) > 0) {
+            // Skipping initialization for already initialized patch downloaders;
+            continue;
+        }
         Downloader* patch_downloader = new Downloader(this);
         patch_downloaders_[patch] = patch_downloader;
         patch_downloaders_status_[patch_downloader] = Downloader::Status();

+ 4 - 0
src/Legacy/models/patchinstaller.cpp

@@ -236,6 +236,10 @@ void PatchInstaller::installVideos(LOTRO_DAT::Database* database) {
 
 void PatchInstaller::init()
 {
+    if (client_local_file_->Initialized() || client_general_file_->Initialized()) {
+        // Firstly - deinitializing existing client_local files.
+        deinit();
+    }
     qDebug() << __FUNCTION__ << "Starting initialisation of LotroDatManager";
     qRegisterMetaType<PatchInstaller::Status>();
 

+ 8 - 10
src/Legacy/utils.cpp

@@ -152,21 +152,19 @@ AppErrorStatus CheckAppPrerequesities() {
 
 QDebug operator<<(QDebug dbg, const AppErrorStatus &status)
 {
-    bool wrong_game_folder = (status & E_WRONG_GAME_FOLDER);
-    bool dat_files_missing = (status & E_DAT_FILES_MISSING);
-    bool wrong_file_permissions = (status & E_WRONG_FILE_PERMISSIONS);
-    bool cannot_access_dat_files = (status & E_CANNOT_ACCESS_DAT_FILES);
-    bool dat_file_incorrect = (status & E_DAT_FILE_INCORRECT);
-    bool no_server_connection = (status & E_NO_SERVER_CONNECTION);
-
-    dbg.nospace() << "ErrorStatus ( "
+    bool wrong_game_folder = (status == E_WRONG_GAME_FOLDER);
+    bool dat_files_missing = (status == E_DAT_FILES_MISSING);
+    bool wrong_file_permissions = (status == E_WRONG_FILE_PERMISSIONS);
+    bool dat_file_incorrect = (status == E_DAT_FILE_INCORRECT);
+    bool no_server_connection = (status == E_NO_SERVER_CONNECTION);
+
+    dbg.nospace() << "ErrorStatus: "
         << (wrong_game_folder ? "Wrong game folder! " : "")
         << (dat_files_missing ? "Dat files missing! " : "")
         << (wrong_file_permissions ? "Wrong file permissions! " : "")
-        << (cannot_access_dat_files ? "Cannot access dat files! " : "")
         << (dat_file_incorrect ? "Incorrect dat file! " : "")
         << (no_server_connection ? "No server connection! " : "")
-        << ")";
+        << ";";
 
     return dbg;
 }

+ 3 - 4
src/Legacy/utils.h

@@ -16,10 +16,9 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const
 bool checkSingleAppInstance();
 
 enum AppErrorStatus : int {
-    E_WRONG_GAME_FOLDER = 32,
-    E_DAT_FILES_MISSING = 16,
-    E_WRONG_FILE_PERMISSIONS = 8,
-    E_CANNOT_ACCESS_DAT_FILES = 4,
+    E_WRONG_GAME_FOLDER = 16,
+    E_DAT_FILES_MISSING = 8,
+    E_WRONG_FILE_PERMISSIONS = 4,
     E_DAT_FILE_INCORRECT = 2,
     E_NO_SERVER_CONNECTION = 1,
     E_NO_ERRORS = 0

+ 3 - 3
src/Legacy/widgets/gamesettings.cpp

@@ -5,6 +5,7 @@
 #include "models/filesystem.h"
 #include "models/patchinstaller.h"
 #include "models/patchdownloader.h"
+#include "legacyapplication.h"
 
 #include <QFileDialog>
 
@@ -31,7 +32,7 @@ void GameSettings::setActualParametersValues()
 {
     QString game_path = Settings::getValue("Lotro/game_path").toString();
     if (game_path == "none") {
-        game_path = "Путь к файлам игры не выбран";
+        game_path = "(не выбрана)";
     }
     ui->game_folder_path->setText(game_path);
 
@@ -61,9 +62,8 @@ void GameSettings::on_change_folder_button_clicked()
     ui->game_folder_path->setText(game_folder);
 
     Settings::setValue("Lotro/game_path", game_folder);
-
     QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::deinit, Qt::QueuedConnection);
-    QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::init, Qt::QueuedConnection);
+    QMetaObject::invokeMethod(&LegacyApplication::instance(), &LegacyApplication::InitModules, Qt::DirectConnection);
 }
 
 void GameSettings::on_lotro_base_language_combobox_currentIndexChanged(int index)

+ 0 - 6
src/Legacy/widgets/mainwindow.cpp

@@ -88,12 +88,6 @@ MainWindow::~MainWindow()
     delete ui;
 }
 
-void MainWindow::onErrorStatusChanged(AppErrorStatus status)
-{
-    // TODO: Settings widget
-//    status_widget_->onErrorStatusChanged(status);
-}
-
 void MainWindow::updateFontSizes()
 {
     ui->menuentry_1->setFont(trajan_9pt);

+ 0 - 1
src/Legacy/widgets/mainwindow.h

@@ -34,7 +34,6 @@ public:
     ~MainWindow();
 
 public slots:
-    void onErrorStatusChanged(AppErrorStatus status);
     void updateFontSizes();
 
 signals:

+ 39 - 65
src/Legacy/widgets/statuswidget.cpp

@@ -2,8 +2,8 @@
 #include "statuswidget.h"
 
 #include "models/patchdownloader.h"
-
-#include "widgets/mainwindow.h"
+#include "models/settings.h"
+#include "legacyapplication.h"
 
 #include "constants.h"
 
@@ -45,6 +45,8 @@ StatusWidget::StatusWidget(QWidget *parent)
     connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, &StatusWidget::showComponentsStatus);
     connect(&PatchInstaller::instance(), &PatchInstaller::deinitialized, this, &StatusWidget::hideComponentsStatus);
 
+    connect(&LegacyApplication::instance(), &LegacyApplication::ErrorStatusChanged, this, &StatusWidget::onErrorStatusChanged);
+
     connect(ui->b_components_status, &TranslationComponents::needToPatch, this, &StatusWidget::onTranslationComponentsNeedToPatch);
     connect(ui->b_components_status, &TranslationComponents::noNeedToPatch, this, &StatusWidget::onTranslationComponentsNoNeedToPatch);
 
@@ -76,12 +78,6 @@ void StatusWidget::updateFontsSizes()
 
 void StatusWidget::setToolTipMessage(QString message, StatusWidget::ToolTipState state)
 {
-    if (state == E_RANDOM) {
-        random_tooltip_generator_timer_.start();
-    } else {
-        random_tooltip_generator_timer_.stop();
-    }
-
     tooltip_messages_[state] = message;
     tooltip_state_ = ToolTipState(int(tooltip_state_) | int(state));
 
@@ -118,12 +114,6 @@ void StatusWidget::unsetToolTipMessage(StatusWidget::ToolTipState state)
         message_id = "E_PROCESS";
     }
 
-    if (showing_state == E_RANDOM) {
-        random_tooltip_generator_timer_.start();
-    } else {
-        random_tooltip_generator_timer_.stop();
-    }
-
     if (!tooltip_widgets_.contains(message_id)) {
         createTooltipMessageWidget(message_id);
     }
@@ -133,59 +123,31 @@ void StatusWidget::unsetToolTipMessage(StatusWidget::ToolTipState state)
 
 void StatusWidget::onErrorStatusChanged(AppErrorStatus status)
 {
+    QString init_error_type_message;
+
     if (status == E_NO_ERRORS) {
-        init_error_type_message_ = "";
-        unsetToolTipMessage(E_ERROR);
+        setToolTipMessage("Запуск прошёл успешно!", E_ERROR);
         ui->news_list->updateNewsWidget();
         ui->server_status_widget->updateServerStatus();
         ui->weekly_code_widget->updateWeeklyCodeWidget();
         return;
+    } else if (status == E_WRONG_GAME_FOLDER) {
+        const QString game_path = Settings::getValue("Lotro/game_path").toString();
+        if (game_path == "none") {
+            init_error_type_message = "Добро пожаловать в Наследие!\nПожалуйста, выберите папку с игрой.";
+        } else {
+            init_error_type_message = "Добро пожаловать в Наследие!\nНе найдены файлы игры, пожалуйста, выберите корректную папку с игрой!";
+        }
+    } else if (status == E_DAT_FILES_MISSING) {
+        init_error_type_message = "Некоторые файлы данных игры не найдены.\nНажмите на кнопку \"Исправить\", чтобы запустить лаунчер игры, который автоматически перекачает нужные файлы.";
+    } else if (status == E_WRONG_FILE_PERMISSIONS) {
+        init_error_type_message = "Недостаточно прав для изменения файлов игры.\nПопробуйте запустить Наследие от имени администратора.";
+    } else if (status == E_DAT_FILE_INCORRECT) {
+        init_error_type_message = "Некоторые файлы игры несовместимы с этой версией Наследия.\nНажмите на кнопку \"Исправить\", чтобы запустить лаунчер игры, который автоматически скачает нужные файлы.";
+    } else if (status == E_NO_SERVER_CONNECTION) {
+        init_error_type_message = "Нет связи с серверами Наследия.\nПожалуйста, проверьте соединение с Интернетом.";
     }
-
-    error_timeout_message_ = "Повторная попытка инициализации через 10 секунд";
-    if (status & E_WRONG_GAME_FOLDER) {
-        init_error_type_message_ = "Ошибка инициализации: некорректная папка с игрой!\n";
-        setToolTipMessage(init_error_type_message_ + error_timeout_message_, E_ERROR);
-        return;
-    }
-
-    if (status & E_DAT_FILES_MISSING) {
-        init_error_type_message_ = "Ошибка инициализации: отсутствуют файлы данных игры!\n";
-        setToolTipMessage(init_error_type_message_ + error_timeout_message_, E_ERROR);
-        return;
-    }
-
-    if (status & E_WRONG_FILE_PERMISSIONS) {
-        init_error_type_message_ = "Ошибка инициализации: недостаточно прав для изменения файлов данных!\n";
-        setToolTipMessage(init_error_type_message_ + error_timeout_message_, E_ERROR);
-        return;
-    }
-
-    if (status & E_CANNOT_ACCESS_DAT_FILES) {
-        init_error_type_message_ = "Ошибка инициализации: нет доступа к файлам данных!\n";
-        setToolTipMessage(init_error_type_message_ + error_timeout_message_, E_ERROR);
-        return;
-    }
-
-    if (status & E_DAT_FILE_INCORRECT) {
-        init_error_type_message_ = "Ошибка инициализации: формат файла данных устарел или некорректен!\n";
-        setToolTipMessage(init_error_type_message_ + error_timeout_message_, E_ERROR);
-        return;
-    }
-
-    if (status & E_NO_SERVER_CONNECTION) {
-        init_error_type_message_ = "Ошибка инициализации: нет связи с сервером Наследия!\n";
-        setToolTipMessage(init_error_type_message_ + error_timeout_message_, E_ERROR);
-        return;
-    }
-}
-
-void StatusWidget::onSecondsToNextTryToInitChanged(size_t seconds_elapsed)
-{
-    if (!init_error_type_message_.isEmpty()) {
-        error_timeout_message_ = "Повторная попытка инициализации через " + QString::number(seconds_elapsed) + " секунд";
-        setToolTipMessage(init_error_type_message_ + error_timeout_message_, E_ERROR);
-    }
+    setToolTipMessage(init_error_type_message, E_ERROR);
 }
 
 void StatusWidget::resizeEvent(QResizeEvent *)
@@ -371,17 +333,29 @@ void StatusWidget::on_check_for_updates_button_clicked()
 
 void StatusWidget::showComponentsStatus() {
     _components_status_opacity_animation->disconnect();
+    if (_components_status_opacity_animation->state() == QAbstractAnimation::Running) {
+        _components_status_opacity_animation->pause();
+    }
     ui->b_components_status->show();
-    _components_status_opacity_animation->stop();
     _components_status_opacity_animation->setEndValue(1);
-    _components_status_opacity_animation->start();
+    if (_components_status_opacity_animation->state() == QAbstractAnimation::Stopped) {
+        _components_status_opacity_animation->start();
+    } else {
+        _components_status_opacity_animation->resume();
+    }
 }
 
 void StatusWidget::hideComponentsStatus() {
     if (this->isVisible()) {
-        _components_status_opacity_animation->stop();
+        if (_components_status_opacity_animation->state() == QAbstractAnimation::Running) {
+            _components_status_opacity_animation->pause();
+        }
         _components_status_opacity_animation->setEndValue(0);
-        _components_status_opacity_animation->start();
+        if (_components_status_opacity_animation->state() == QAbstractAnimation::Stopped) {
+            _components_status_opacity_animation->start();
+        } else {
+            _components_status_opacity_animation->resume();
+        }
         connect(_components_status_opacity_animation, &QPropertyAnimation::finished, ui->b_components_status, &QWidget::hide);
     }
 }

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

@@ -41,15 +41,12 @@ public slots:
 
     void unsetToolTipMessage(ToolTipState state);
 
-    // for LegacyApplication signals
-    void onErrorStatusChanged(AppErrorStatus status);
-
-    void onSecondsToNextTryToInitChanged(size_t seconds_elapsed);
-
 protected:
     void resizeEvent(QResizeEvent *event) override;
 
 private slots:
+    void onErrorStatusChanged(AppErrorStatus status);
+
     void generateRandomTooltipMessage();
 
     void fadeBetweenToolTips(QString tooltip_id);
@@ -102,9 +99,6 @@ private:
     QTimer random_tooltip_generator_timer_;
     QTimer process_completed_tooltip_hide_timer_;
 
-    QString init_error_type_message_ = "";
-    QString error_timeout_message_ = "";
-
     QGraphicsOpacityEffect* _components_status_opacity_effect;
     QPropertyAnimation* _components_status_opacity_animation;
     bool _need_to_install_patches = false;

+ 3 - 3
src/Legacy/widgets/statuswidget.ui

@@ -226,9 +226,9 @@ QPushButton#game_button:disabled {
    <property name="geometry">
     <rect>
      <x>290</x>
-     <y>390</y>
+     <y>370</y>
      <width>521</width>
-     <height>91</height>
+     <height>111</height>
     </rect>
    </property>
    <property name="font">
@@ -289,7 +289,7 @@ QPushButton#game_button:disabled {
      <x>310</x>
      <y>150</y>
      <width>471</width>
-     <height>221</height>
+     <height>201</height>
     </rect>
    </property>
    <property name="styleSheet">