Selaa lähdekoodia

Style improvements & implemented check if game updated & fixed lotro exe find

Ivan Arkhipov 3 vuotta sitten
vanhempi
commit
7af9c64665

+ 3 - 1
import/LotroDat/DatFile.h

@@ -31,9 +31,11 @@ class DatFile {
   	void Deinit();
 	
 	static bool checkIfPatchedByLegacyV1(const std::string& filename);
-
+	
 	bool Initialized() const;
 	const std::string& GetFilename() const;
+	
+	int GetDatFileMaxIteration() const;
 	SubfileInfo getSubfileInfo(int file_id) const;
 
 	size_t GetFilesNumInDatFile();

+ 22 - 10
src/Legacy/models/filesystem.cpp

@@ -54,7 +54,7 @@ namespace FileSystem {
 
     QStringList recognizeRegistryLotroPath() {
         QStringList paths;
-
+        qDebug() << "Trying to recognize registry lotro paths!";
         #ifdef _WIN32
             // Windows 8, 10
             QSettings n("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\12bbe590-c890-11d9-9669-0800200c9a66_is1", QSettings::NativeFormat);
@@ -67,8 +67,9 @@ namespace FileSystem {
                             .replace("/LotroLauncher.exe", "")
                             .replace("\"", "");
 
-                    if(fileExists(folder + "/LotroLauncher.exe"))
+                    if (fileExists(folder + "/LotroLauncher.exe")) {
                         paths.append(folder);
+                    }
                 }
             }
 
@@ -76,15 +77,26 @@ namespace FileSystem {
             // Windows 7
             QSettings m("HKEY_CLASSES_ROOT\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache", QSettings::NativeFormat);
             foreach (QString key, m.allKeys()) {
-              if((key.contains("TurbineLauncher.exe") || key.contains("LotroLauncher.exe")) && fileExists(key)){
-                  QString folder = n.value(key).toString()
-                          .replace("\\", "/")
-                          .replace("/TurbineLauncher.exe", "")
-                          .replace("/LotroLauncher.exe", "")
-                          .replace("\"", "");
-
-                  if(fileExists(folder + "/LotroLauncher.exe"))
+                qDebug() << key;
+
+                if ((key.contains("TurbineLauncher.exe") || key.contains("LotroLauncher.exe"))) {
+                    QString folder = n.value(key).toString()
+                                                 .replace("\\", "/")
+                                                 .replace("/TurbineLauncher.exe", "")
+                                                 .replace("/LotroLauncher.exe", "")
+                                                 .replace("\"", "");
+                  if (fileExists(folder + "/LotroLauncher.exe")) {
                       paths.append(folder);
+                  }
+
+                  const QString folder_alternate = QString(key).replace(".ApplicationCompany", "")
+                                                               .replace(".FriendlyAppName", "").replace("\\", "/")
+                                                               .replace("/TurbineLauncher.exe", "")
+                                                               .replace("/LotroLauncher.exe", "")
+                                                               .replace("\"", "");
+                  if (fileExists(folder_alternate + "/LotroLauncher.exe")) {
+                      paths.append(folder_alternate);
+                  }
               }
             }
         #else

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

@@ -28,13 +28,27 @@ QString getComponentNameFromId(int id) {
 PatchInstaller::PatchInstaller(QObject *parent) : QObject(parent) {
         client_local_file_ = new LOTRO_DAT::DatFile(100);
         client_general_file_ = new LOTRO_DAT::DatFile(101);
-        connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, &PatchInstaller::startPatchInstallationChain);
+        connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, [this](){startPatchInstallationChain();});
 }
 
 bool PatchInstaller::initialised() {
     return client_general_file_->Initialized() && client_local_file_->Initialized();
 }
 
+void PatchInstaller::checkIfUpdatedByGame()
+{
+    const int client_local_maxiter = client_local_file_->GetDatFileMaxIteration();
+    const int client_general_maxiter = client_general_file_->GetDatFileMaxIteration();
+
+    const int client_local_saved_maxiter = _current_applied_patches_info.client_local_header_maxiter;
+    const int client_general_saved_maxiter = _current_applied_patches_info.client_general_header_maxiter;
+
+    emit updatedByGameStatusChanged(
+        (client_local_saved_maxiter != -1 && client_local_maxiter != client_local_saved_maxiter) ||
+        (client_general_saved_maxiter != -1 && client_general_maxiter != client_general_saved_maxiter)
+    );
+}
+
 PatchInstaller::~PatchInstaller() {
     deinit();
     delete client_local_file_;
@@ -317,6 +331,10 @@ PatchInstaller::AppliedPatchesInfo PatchInstaller::getAppliedPatchesInfoFromDatF
                 result.fonts_patch_hashsum = QString(str).remove(0, 6);
             } else if (str.startsWith("VIDEOS:")) {
                 result.videos_patch_hashsum = QString(str).remove(0, 7);
+            } else if (str.startsWith("CLIENT_LOCAL_HEADER_MAXITER:")) {
+                result.client_local_header_maxiter = QString(str).remove(0, 28).toInt();
+            } else if (str.startsWith("CLIENT_GENERAL_HEADER_MAXITER:")) {
+                result.client_general_header_maxiter = QString(str).remove(0, 30).toInt();
             }
         }
         if (result.texts_patch_hashsum != "" || result.images_patch_hashsum != "" || result.textures_patch_hashsum != "" ||
@@ -343,6 +361,12 @@ void PatchInstaller::insertPatchesInfoInDatFile(const PatchInstaller::AppliedPat
     patches_info_data += "FONTS:" + info.fonts_patch_hashsum + "\n";
     patches_info_data += "VIDEOS:" + info.videos_patch_hashsum + "\n";
 
+    const int client_local_maxiter = client_local_file_->GetDatFileMaxIteration();
+    const int client_general_maxiter = client_general_file_->GetDatFileMaxIteration();
+
+    patches_info_data += "CLIENT_LOCAL_HEADER_MAXITER:" + QString::number(client_local_maxiter) + "\n";
+    patches_info_data += "CLIENT_GENERAL_HEADER_MAXITER:" + QString::number(client_general_maxiter) + "\n";
+
     QByteArray data = QByteArray((char*)&_applied_patches_file_id, 4) + patches_info_data.toUtf8();
     file_data.binary_data = LOTRO_DAT::BinaryData(data.data(), data.size());
     client_local_file_->PatchFile(file_data, _patch_files_versions, 1, true);
@@ -390,6 +414,8 @@ void PatchInstaller::init()
              << QString::fromStdString(client_local_file_->GetFilename());
 
     _current_applied_patches_info = getAppliedPatchesInfoFromDatFile();
+    checkIfUpdatedByGame();
+
     emit successfullyInitialized();
 }
 
@@ -442,7 +468,7 @@ void PatchInstaller::startGame(bool remove_dat_files) {
     }
 }
 
-void PatchInstaller::startPatchInstallationChain() {
+void PatchInstaller::startPatchInstallationChain(bool force_reinstall_patches) {
     emit started();
     qInfo() << "PatchInstaller: Starting installation chain...";
     const QVector<QString> patches = {"text", "font", "image", "loadscreen", "texture", "sound", "video", "micro"};
@@ -476,10 +502,13 @@ void PatchInstaller::startPatchInstallationChain() {
             hashsum_in_dat_file = _current_applied_patches_info.loadscreens_patch_hashsum;
         }
 
-        if (patch_hashsum == hashsum_in_dat_file) {
+        if (!force_reinstall_patches && patch_hashsum == hashsum_in_dat_file) {
             qDebug() << "Skipping patch " << patch << " because its hashsum (" << patch_hashsum << ") is equal to hashsum in dat file (" << hashsum_in_dat_file << ")";
             continue;
         }
+        if (force_reinstall_patches) {
+            qDebug() << "Forcelly installing patch " << patch << ". Its hashsum (" << patch_hashsum << "). Hashsum in dat file (" << hashsum_in_dat_file << ")";
+        }
 
         const QString real_file_hashsum = FileSystem::fileHash(patch_filename);
         if (!FileSystem::fileExists(patch_filename) || real_file_hashsum != patch_hashsum) {
@@ -530,7 +559,7 @@ void PatchInstaller::startPatchInstallationChain() {
     }
 
     emit progressChanged(current_status);
-    for (const QString patch_name: patch_databases.keys()) {
+    for (const QString& patch_name: patch_databases.keys()) {
         qInfo() << "PatchInstaller: Installing patch " << patch_name;
         installPatch(patch_name, patch_databases[patch_name]);
         patch_databases[patch_name]->CloseDatabase();
@@ -543,6 +572,9 @@ void PatchInstaller::startPatchInstallationChain() {
 
     insertPatchesInfoInDatFile(_current_applied_patches_info);
     qInfo() << "PatchInstaller: Finished installation chain...";
+    if (force_reinstall_patches) {
+        emit updatedByGameStatusChanged(false);
+    }
     emit finished();
 }
 

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

@@ -27,6 +27,8 @@ public:
         QString textures_patch_hashsum = "";
         QString fonts_patch_hashsum = "";
         QString videos_patch_hashsum = "";
+        int client_local_header_maxiter = -1;
+        int client_general_header_maxiter = -1;
     };
 
 public:
@@ -35,9 +37,10 @@ public:
         return instance_;
     }
     bool initialised();
+
     ~PatchInstaller();
 
-    AppliedPatchesInfo getPatchesInfo(); // TODO: Implement
+    AppliedPatchesInfo getPatchesInfo();
 
 private:
     Q_DISABLE_COPY(PatchInstaller)
@@ -49,6 +52,8 @@ private:
 
     explicit PatchInstaller(QObject *parent = nullptr);
 
+    void checkIfUpdatedByGame();
+
     bool datPathIsRelevant();
 
     void installPatch(QString patch_name, LOTRO_DAT::Database* database);
@@ -67,7 +72,7 @@ public slots:
     void deinit();
     void init();
     void startGame(bool remove_dat_files);
-    void startPatchInstallationChain();
+    void startPatchInstallationChain(bool force_reinstall_patches = false);
 
 private slots:
     void onDownloaderProgressChanged(Downloader* context, Downloader::Status progress);
@@ -79,6 +84,7 @@ signals:
     void finished();
     void successfullyInitialized();
     void deinitialized();
+    void updatedByGameStatusChanged(bool updated_by_game);
 
 private:
     LOTRO_DAT::DatFile* client_local_file_;

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

@@ -67,7 +67,7 @@
 background-color: none;</string>
         </property>
         <property name="text">
-         <string>Папка с игрой:</string>
+         <string>Путь к игре:</string>
         </property>
        </widget>
       </item>

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

@@ -17,7 +17,7 @@
    </sizepolicy>
   </property>
   <property name="windowTitle">
-   <string>ВКО: Наследие</string>
+   <string>ВКО: Наследие v2</string>
   </property>
   <property name="autoFillBackground">
    <bool>false</bool>

+ 0 - 3
src/Legacy/widgets/serverstatuswidget.ui

@@ -19,9 +19,6 @@
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <property name="autoFillBackground">
-   <bool>false</bool>
-  </property>
   <layout class="QGridLayout" name="gridLayout">
    <property name="leftMargin">
     <number>0</number>

+ 13 - 6
src/Legacy/widgets/statuswidget.cpp

@@ -49,6 +49,7 @@ StatusWidget::StatusWidget(QWidget *parent)
 
     connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, &StatusWidget::showComponentsStatus);
     connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, [this](){updateButtonStatus();});
+    connect(&PatchInstaller::instance(), &PatchInstaller::updatedByGameStatusChanged, this, [this](bool updated){_need_to_forcely_patch = updated; updateButtonStatus();});
     connect(&PatchInstaller::instance(), &PatchInstaller::deinitialized, this, &StatusWidget::hideComponentsStatus);
 
     connect(&LegacyApplication::instance(), &LegacyApplication::ErrorStatusChanged, this, &StatusWidget::onErrorStatusChanged);
@@ -161,9 +162,9 @@ void StatusWidget::onErrorStatusChanged(AppErrorStatus status)
         updateButtonStatus();
         const QString game_path = Settings::getValue("Lotro/game_path").toString();
         if (game_path == "none") {
-            init_error_type_message = "Добро пожаловать в Наследие!\nПожалуйста, выберите папку с игрой.";
+            init_error_type_message = "Добро пожаловать в Наследие!\nПожалуйста, укажите путь к файлам игры.";
         } else {
-            init_error_type_message = "Добро пожаловать в Наследие!\nНе найдены файлы игры, пожалуйста, выберите корректную папку с игрой!";
+            init_error_type_message = "Добро пожаловать в Наследие!\nНе найдены файлы игры, пожалуйста, укажите корректный путь к файлам игры!";
         }
     } else if (status == E_DAT_FILES_MISSING) {
         _need_to_repair_game_files = true;
@@ -293,7 +294,7 @@ void StatusWidget::onPatchDownloaderProgressChanged(Downloader::Status status) {
 void StatusWidget::onPatchInstallerStarted() {
     all_patch_operations_finished_ = false;
     ui->game_button->setEnabled(false);
-    setToolTipMessage("Начинаем установку компонент русификации...", E_PROCESS);
+    setToolTipMessage("Начинаем установку компонентов русификации...", E_PROCESS);
 }
 
 void StatusWidget::onPatchInstallerFinished() {
@@ -334,6 +335,8 @@ void StatusWidget::on_game_button_clicked()
 {
     if (_need_to_update || _need_to_install_patches) {
         QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::startPatchDownloaderChain, Qt::QueuedConnection);
+    } else if (_need_to_forcely_patch) {
+        QMetaObject::invokeMethod(&PatchInstaller::instance(), "startPatchInstallationChain", Qt::QueuedConnection, Q_ARG(bool, _need_to_forcely_patch));
     } else {
         QMetaObject::invokeMethod(&PatchInstaller::instance(), "startGame", Qt::QueuedConnection, Q_ARG(bool, _need_to_repair_game_files));
     }
@@ -406,12 +409,16 @@ void StatusWidget::onTranslationComponentsNoNeedToPatch() {
 }
 
 void StatusWidget::updateButtonStatus() {
-    if (_need_to_repair_game_files) {
+    if (_need_to_forcely_patch) {
+        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");
+        setToolTipMessage("Произошло обновление игры.\nЧасть данных перезаписана и нуждается в обновлении.", ToolTipState::E_INFO);
+    } else 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("установить");
+        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);

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

@@ -103,6 +103,7 @@ private:
     bool _need_to_install_patches = false;
     bool _need_to_update = false;
     bool _need_to_repair_game_files = false;
+    bool _need_to_forcely_patch = false;
 };
 
 #endif // STATUSWIDGET_H

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

@@ -39,12 +39,12 @@ void WeeklyCodeWidget::updateFontsSizes()
     ui->code->setFont(trajan_10pt);
 }
 
-void WeeklyCodeWidget::resizeEvent(QResizeEvent *event)
+void WeeklyCodeWidget::resizeEvent(QResizeEvent *)
 {
     updateFontsSizes();
 }
 
-void WeeklyCodeWidget::enterEvent(QEvent * event)
+void WeeklyCodeWidget::enterEvent(QEvent *event)
 {
     QWidget::enterEvent(event);
     event->ignore();
@@ -86,7 +86,7 @@ void WeeklyCodeWidget::updateCode()
     code_data = "";
 }
 
-void WeeklyCodeWidget::leaveEvent(QEvent * event)
+void WeeklyCodeWidget::leaveEvent(QEvent *)
 {
 //    qDebug() << Q_FUNC_INFO << this->objectName();
     emit showNoTooltip();