Pārlūkot izejas kodu

Added old legacy patches check and small ui fixes & improvements

Ivan Arkhipov 4 gadi atpakaļ
vecāks
revīzija
0eeddbd95f

+ 2 - 0
import/LotroDat/DatFile.h

@@ -29,6 +29,8 @@ class DatFile {
   	bool Init(const std::string& filename);
 	void LoadAllFilesInfo();
   	void Deinit();
+	
+	static bool checkIfPatchedByLegacyV1(const std::string& filename);
 
 	bool Initialized() const;
 	const std::string& GetFilename() const;

+ 17 - 3
src/Legacy/models/patchinstaller.cpp

@@ -299,7 +299,6 @@ PatchInstaller::AppliedPatchesInfo PatchInstaller::getAppliedPatchesInfoFromDatF
         if (text_data_splitted.length() < 0 || text_data_splitted[0] != _patch_mark_header) {
             return result;
         }
-        result.has_no_patch_mark = false;
         for (const QString& str: text_data_splitted) {
             if (str.startsWith("TEXTS:")) {
                 result.texts_patch_hashsum = QString(str).remove(0, 6);
@@ -317,8 +316,13 @@ PatchInstaller::AppliedPatchesInfo PatchInstaller::getAppliedPatchesInfoFromDatF
                 result.videos_patch_hashsum = QString(str).remove(0, 7);
             }
         }
+        if (result.texts_patch_hashsum != "" || result.images_patch_hashsum != "" || result.textures_patch_hashsum != "" ||
+            result.sounds_patch_hashsum != "" || result.videos_patch_hashsum != "" || result.fonts_patch_hashsum != "" ||
+            result.loadscreens_patch_hashsum != "")
+        {
+            result.has_no_patch_mark = false;
+        }
     }
-    // TODO: PATCHED BY OLD LEGACY CHECK
     return result;
 }
 
@@ -386,7 +390,7 @@ void PatchInstaller::init()
     emit successfullyInitialized();
 }
 
-void PatchInstaller::startGame() {
+void PatchInstaller::startGame(bool remove_dat_files) {
     QString game_folder = Settings::getValue("Lotro/game_path").toString();
 
     if (game_folder == "none") {
@@ -408,6 +412,16 @@ void PatchInstaller::startGame() {
     client_general_file_->Deinit();
     client_local_file_->Deinit();
 
+    if (remove_dat_files) {
+        QString game_folder = Settings::getValue("Lotro/game_path").toString();
+        QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
+
+        QString client_local_filepath = game_folder + "/client_local_" + locale_prefix + ".dat";
+        QString client_general_filepath = game_folder + "/client_general.dat";
+        QFile::remove(client_local_filepath);
+        QFile::remove(client_general_filepath);
+    }
+
     QString username = Settings::getValue("Account/username").toString();
     QString password = Settings::getValue("Account/password").toString();
     if (!username.isEmpty() && !password.isEmpty()) {

+ 2 - 3
src/Legacy/models/patchinstaller.h

@@ -19,8 +19,7 @@ public:
     };
 
     struct AppliedPatchesInfo {
-        bool patched_by_old_legacy = false;
-        bool has_no_patch_mark = false;
+        bool has_no_patch_mark = true;
         QString texts_patch_hashsum = "";
         QString images_patch_hashsum = "";
         QString sounds_patch_hashsum = "";
@@ -67,7 +66,7 @@ private:
 public slots:
     void deinit();
     void init();
-    void startGame();
+    void startGame(bool remove_dat_files);
     void startPatchInstallationChain();
 
 private slots:

+ 9 - 0
src/Legacy/utils.cpp

@@ -130,6 +130,13 @@ AppErrorStatus CheckAppPrerequesities() {
             return E_WRONG_FILE_PERMISSIONS;
         }
 
+        if (LOTRO_DAT::DatFile::checkIfPatchedByLegacyV1(client_local_file.absoluteFilePath().toStdString())) {
+            return E_PATCHED_BY_OLD_LEGACY;
+        }
+        if (LOTRO_DAT::DatFile::checkIfPatchedByLegacyV1(client_general_file.absoluteFilePath().toStdString())) {
+            return E_PATCHED_BY_OLD_LEGACY;
+        }
+
         LOTRO_DAT::DatFile file(0);
         if (!file.Init(client_local_file.absoluteFilePath().toStdString())) {
             return E_DAT_FILE_INCORRECT;
@@ -152,6 +159,7 @@ AppErrorStatus CheckAppPrerequesities() {
 
 QDebug operator<<(QDebug dbg, const AppErrorStatus &status)
 {
+    bool patched_by_old_legacy = (status == E_PATCHED_BY_OLD_LEGACY);
     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);
@@ -164,6 +172,7 @@ QDebug operator<<(QDebug dbg, const AppErrorStatus &status)
         << (wrong_file_permissions ? "Wrong file permissions! " : "")
         << (dat_file_incorrect ? "Incorrect dat file! " : "")
         << (no_server_connection ? "No server connection! " : "")
+        << (patched_by_old_legacy ? "Patched by legacy v1! ": "")
         << ";";
 
     return dbg;

+ 1 - 0
src/Legacy/utils.h

@@ -16,6 +16,7 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const
 bool checkSingleAppInstance();
 
 enum AppErrorStatus : int {
+    E_PATCHED_BY_OLD_LEGACY = 32,
     E_WRONG_GAME_FOLDER = 16,
     E_DAT_FILES_MISSING = 8,
     E_WRONG_FILE_PERMISSIONS = 4,

+ 36 - 10
src/Legacy/widgets/statuswidget.cpp

@@ -43,6 +43,7 @@ StatusWidget::StatusWidget(QWidget *parent)
     connect(&PatchInstaller::instance(), &PatchInstaller::videosDownloadProgressChanged, this, &StatusWidget::onPatchInstallerVideoProgressChanged);
 
     connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, &StatusWidget::showComponentsStatus);
+    connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, [this](){updateButtonStatus();});
     connect(&PatchInstaller::instance(), &PatchInstaller::deinitialized, this, &StatusWidget::hideComponentsStatus);
 
     connect(&LegacyApplication::instance(), &LegacyApplication::ErrorStatusChanged, this, &StatusWidget::onErrorStatusChanged);
@@ -100,10 +101,10 @@ void StatusWidget::unsetToolTipMessage(StatusWidget::ToolTipState state)
 
     ToolTipState showing_state = E_RANDOM;
 
-    if (tooltip_state_ & E_INFO) {
-        showing_state = E_INFO;
-    } else if (tooltip_state_ & E_PROCESS) {
+    if (tooltip_state_ & E_PROCESS) {
         showing_state = E_PROCESS;
+    } else if (tooltip_state_ & E_INFO) {
+        showing_state = E_INFO;
     } else if (tooltip_state_ & E_HINT) {
         showing_state = E_HINT;
     }
@@ -129,8 +130,16 @@ void StatusWidget::onErrorStatusChanged(AppErrorStatus status)
         ui->news_list->updateNewsWidget();
         ui->server_status_widget->updateServerStatus();
         ui->weekly_code_widget->updateWeeklyCodeWidget();
+        _need_to_repair_game_files = false;
+        updateButtonStatus();
         return;
+    } else if (status == E_PATCHED_BY_OLD_LEGACY) {
+        _need_to_repair_game_files = true;
+        updateButtonStatus();
+        init_error_type_message = "Некоторые файлы игры несовместимы с этой версией Наследия.\nНажмите на кнопку \"Исправить\", чтобы запустить лаунчер игры, который автоматически скачает нужные файлы.";
     } else if (status == E_WRONG_GAME_FOLDER) {
+        _need_to_repair_game_files = false;
+        updateButtonStatus();
         const QString game_path = Settings::getValue("Lotro/game_path").toString();
         if (game_path == "none") {
             init_error_type_message = "Добро пожаловать в Наследие!\nПожалуйста, выберите папку с игрой.";
@@ -138,12 +147,20 @@ void StatusWidget::onErrorStatusChanged(AppErrorStatus status)
             init_error_type_message = "Добро пожаловать в Наследие!\nНе найдены файлы игры, пожалуйста, выберите корректную папку с игрой!";
         }
     } else if (status == E_DAT_FILES_MISSING) {
+        _need_to_repair_game_files = true;
+        updateButtonStatus();
         init_error_type_message = "Некоторые файлы данных игры не найдены.\nНажмите на кнопку \"Исправить\", чтобы запустить лаунчер игры, который автоматически перекачает нужные файлы.";
     } else if (status == E_WRONG_FILE_PERMISSIONS) {
+        _need_to_repair_game_files = false;
+        updateButtonStatus();
         init_error_type_message = "Недостаточно прав для изменения файлов игры.\nПопробуйте запустить Наследие от имени администратора.";
     } else if (status == E_DAT_FILE_INCORRECT) {
+        _need_to_repair_game_files = true;
+        updateButtonStatus();
         init_error_type_message = "Некоторые файлы игры несовместимы с этой версией Наследия.\nНажмите на кнопку \"Исправить\", чтобы запустить лаунчер игры, который автоматически скачает нужные файлы.";
     } else if (status == E_NO_SERVER_CONNECTION) {
+        _need_to_repair_game_files = false;
+        updateButtonStatus();
         init_error_type_message = "Нет связи с серверами Наследия.\nПожалуйста, проверьте соединение с Интернетом.";
     }
     setToolTipMessage(init_error_type_message, E_INFO);
@@ -264,6 +281,7 @@ void StatusWidget::onPatchInstallerFinished() {
     all_patch_operations_finished_ = true;
     ui->game_button->setEnabled(true);
     unsetToolTipMessage(E_PROCESS);
+    updateButtonStatus();
 }
 
 void StatusWidget::onPatchInstallerProgressChanged(PatchInstaller::Status status) {
@@ -297,10 +315,11 @@ void StatusWidget::on_game_button_clicked()
 {
     if (_need_to_update || _need_to_install_patches) {
         QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::startPatchDownloaderChain, Qt::QueuedConnection);
-        return;
+    } else {
+        QMetaObject::invokeMethod(&PatchInstaller::instance(), "startGame", Qt::QueuedConnection, Q_ARG(bool, _need_to_repair_game_files));
     }
-
-    QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::startGame, Qt::QueuedConnection);
+    ui->game_button->setDisabled(true);
+    setToolTipMessage("Готовимся к запуску...", E_PROCESS);
 }
 
 void StatusWidget::createTooltipMessageWidget(QString tooltip_id)
@@ -373,16 +392,23 @@ void StatusWidget::onTranslationComponentsNoNeedToPatch() {
 }
 
 void StatusWidget::updateButtonStatus() {
-    if (_need_to_update) {
-        setToolTipMessage("Доступны обновления русификации.\nНажмите \"Обновить\", чтобы начать загрузку.", ToolTipState::E_INFO);
-        ui->game_button->setText("ОБНОВИТЬ");
+    if (_need_to_repair_game_files) {
+        ui->game_button->setText("исправить");
         ui->game_button->setStyleSheet("QPushButton#game_button { \n	color: white;\n	border-image: url(:/buttons/button_big_yellow.png);\n}\n\nQPushButton#game_button:hover {\n	color: white;\n	border-image: url(:/buttons/button_big_yellow_over.png);\n}\n\nQPushButton#game_button:pressed {\n	color: white;\n	border-image: url(:/buttons/button_big_yellow_pressed.png);\n}\n\nQPushButton#game_button:disabled {\n	color: white;\n	border-image: url(:/buttons/button_big_disabled.png);\n}\n");
     } else if (_need_to_install_patches) {
         setToolTipMessage("Выбранные компоненты требуют установки.\nНажмите \"Установить\", чтобы начать их установку.", ToolTipState::E_INFO);
         ui->game_button->setText("установить");
         ui->game_button->setStyleSheet("QPushButton#game_button { \n	color: white;\n	border-image: url(:/buttons/button_big_yellow.png);\n}\n\nQPushButton#game_button:hover {\n	color: white;\n	border-image: url(:/buttons/button_big_yellow_over.png);\n}\n\nQPushButton#game_button:pressed {\n	color: white;\n	border-image: url(:/buttons/button_big_yellow_pressed.png);\n}\n\nQPushButton#game_button:disabled {\n	color: white;\n	border-image: url(:/buttons/button_big_disabled.png);\n}\n");
+    } else if (_need_to_update) {
+        setToolTipMessage("Доступны обновления русификации.\nНажмите \"Обновить\", чтобы начать загрузку.", ToolTipState::E_INFO);
+        ui->game_button->setText("ОБНОВИТЬ");
+        ui->game_button->setStyleSheet("QPushButton#game_button { \n	color: white;\n	border-image: url(:/buttons/button_big_yellow.png);\n}\n\nQPushButton#game_button:hover {\n	color: white;\n	border-image: url(:/buttons/button_big_yellow_over.png);\n}\n\nQPushButton#game_button:pressed {\n	color: white;\n	border-image: url(:/buttons/button_big_yellow_pressed.png);\n}\n\nQPushButton#game_button:disabled {\n	color: white;\n	border-image: url(:/buttons/button_big_disabled.png);\n}\n");
     } else {
-        setToolTipMessage("Установлена последняя версия русификации.\nНажмите \"Играть\", чтобы запустить игру.", ToolTipState::E_INFO);
+        if (!PatchInstaller::instance().getPatchesInfo().has_no_patch_mark) {
+            setToolTipMessage("Установлена последняя версия русификации.\nНажмите \"Играть\", чтобы запустить игру.", ToolTipState::E_INFO);
+        } else {
+            setToolTipMessage("Добро пожаловать в Наследие!\nВыберите компоненты русификации для установки.", ToolTipState::E_INFO);
+        }
         ui->game_button->setText("ИГРАТЬ");
         ui->game_button->setStyleSheet("QPushButton#game_button { \n	color: white;\n	border-image: url(:/buttons/button_big_normal.png);\n}\n\nQPushButton#game_button:hover {\n	color: white;\n	border-image: url(:/buttons/button_big_over.png);\n}\n\nQPushButton#game_button:pressed {\n	color: white;\n	border-image: url(:/buttons/button_big_pressed.png);\n}\n\nQPushButton#game_button:disabled {\n	color: white;\n	border-image: url(:/buttons/button_big_disabled.png);\n}\n");
     }

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

@@ -100,6 +100,7 @@ private:
     QPropertyAnimation* _components_status_opacity_animation;
     bool _need_to_install_patches = false;
     bool _need_to_update = false;
+    bool _need_to_repair_game_files = false;
 };
 
 #endif // STATUSWIDGET_H