Browse Source

Connected patches update functionality

Ivan Arkhipov 3 years ago
parent
commit
bc05d2c271

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

@@ -37,6 +37,7 @@ void PatchDownloader::startPatchDownloaderChain() {
     started_ = true;
     checkForUpdates();
     downloadDatabases();
+    checkForUpdates(); // Check for updates again to ensure all patches are correct
     started_ = false;
     emit finished();
 }
@@ -89,6 +90,8 @@ void PatchDownloader::checkForUpdates() {
         return;
     }
 
+    bool there_are_available_patch_updates = false;
+
     for (int i = 0; i < patches_.size(); ++i) {
         const QString patch = patches_[i];
         const QStringList patch_data = patch_info[i].split(":::");
@@ -103,7 +106,22 @@ void PatchDownloader::checkForUpdates() {
         Settings::setValue("PatchDatabases/" + patch + "/hashsum", patch_data[1]);
         Settings::setValue("PatchDatabases/" + patch + "/datetime", patch_data[2]);
         Settings::setValue("PatchDatabases/" + patch + "/path", patch_filename);
+
+        // Checking if database is enabled in patch settings && file hashsum does not match actual
+        const bool is_database_enabled_in_patch = Settings::getValue("DatabaseDownload/" + patch).toBool();
+        if (is_database_enabled_in_patch) {
+            const QString patch_hashsum = FileSystem::fileExists(patch_filename) ? FileSystem::fileHash(patch_filename) : "none";
+            if (patch_hashsum != patch_data[1]) {
+                there_are_available_patch_updates = true;
+                qDebug() << "CheckForUpdates: Existing patch " << patch << " checksum (" << patch_hashsum << ") does not match actual (" << patch_data[1] << ")";
+            } else {
+                qDebug() << "CheckForUpdates: Existing patch " << patch << " checksum (" << patch_hashsum << ") matches actual (" << patch_data[1] << ")";
+
+            }
+        }
     }
+
+    emit checkForUpdatesStatusChanged(there_are_available_patch_updates);
 }
 
 void PatchDownloader::downloadDatabases() {

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

@@ -35,6 +35,7 @@ signals:
     void started();
     void progressChanged(Downloader::Status status);
     void finished();
+    void checkForUpdatesStatusChanged(bool needUpdate);
 
 private slots:
     void onDownloaderProgressChanged(Downloader* context, Downloader::Status progress);

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

@@ -22,10 +22,12 @@ public:
         bool patched_by_old_legacy;
         bool has_no_patch_mark;
         unsigned long long texts_version;
-        unsigned long long graphics_version;
-        unsigned long long videos_version;
-        unsigned long long audio_version;
+        unsigned long long images_version;
+        unsigned long long sounds_version;
         unsigned long long loadscreens_version;
+        unsigned long long textures_version;
+        unsigned long long fonts_version;
+        unsigned long long videos_version;
     };
 
 

+ 1 - 13
src/Legacy/models/settings.cpp

@@ -23,7 +23,7 @@ QMap<QString, QVariant> defaults = {
     {"Backup/path", "/backup/"},
     {"Backup/creation_time", "none"},
 
-    // Databases download settings
+    // Databases download settings (true means component is enabled)
 
     {"DatabaseDownload/text", false},          // TextsPatch
     {"DatabaseDownload/font", false},          // TextsPatch
@@ -45,18 +45,6 @@ QMap<QString, QVariant> defaults = {
     {"DatabaseNeedInstall/video", false},          // VideosPatch
     {"DatabaseNeedInstall/micro", false},          // MircoPatch
 
-    // Localisation components, showed and edited by user in GUI
-
-    {"Components/texts_main", false},          // TextsPatch
-    {"Components/texts_items", false},         // TextsPatch
-    {"Components/texts_emotes", false},        // TextsPatch
-    {"Components/maps", false},                // ImagesPatch
-    {"Components/loadscreens", false},         // ImagesPatch
-    {"Components/textures", false},            // ImagesPatch
-    {"Components/sounds", false},              // SoundsPatch
-    {"Components/videos", false},              // VideosPatch
-    {"Components/micropatch", false},          // PatchList
-
     // Network settings
 
     {"Network/site_url", "http://translate.lotros.ru/"},

+ 20 - 22
src/Legacy/widgets/statuswidget.cpp

@@ -22,15 +22,15 @@ StatusWidget::StatusWidget(QWidget *parent)
     ui->galadriel_tooltip_example->hide();
     ui->c_progress_bar->setProgress(100);
 
-    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showCompletedTooltip, this, [this](){setToolTipMessage("Еженедельный код скопирован в буфер обмена.", E_INFO);});
-    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showHelpTooltip, this, [this](){setToolTipMessage("Нажмите по еженедельному коду, чтобы скопировать его.", E_INFO);});
-    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showNoTooltip, this, [this](){unsetToolTipMessage(E_INFO);});
+    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showCompletedTooltip, this, [this](){setToolTipMessage("Еженедельный код скопирован в буфер обмена.", E_HINT);});
+    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showHelpTooltip, this, [this](){setToolTipMessage("Нажмите по еженедельному коду, чтобы скопировать его.", E_HINT);});
+    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showNoTooltip, this, [this](){unsetToolTipMessage(E_HINT);});
 
-    connect(ui->news_list, &NewsListWidget::showHelpToolTip, this, [this](){setToolTipMessage("Нажмите на заголовок новости, чтобы открыть её в браузере.", E_INFO);});
-    connect(ui->news_list, &NewsListWidget::showNoToolTip, this, [this](){unsetToolTipMessage(E_INFO);});
+    connect(ui->news_list, &NewsListWidget::showHelpToolTip, this, [this](){setToolTipMessage("Нажмите на заголовок новости, чтобы открыть её в браузере.", E_HINT);});
+    connect(ui->news_list, &NewsListWidget::showNoToolTip, this, [this](){unsetToolTipMessage(E_HINT);});
 
-    connect(ui->server_status_widget, &ServerStatusWidget::showServersTooltip, this, [this](QString message){setToolTipMessage(message, E_INFO);});
-    connect(ui->server_status_widget, &ServerStatusWidget::showNoTooltip, this, [this](){unsetToolTipMessage(E_INFO);});
+    connect(ui->server_status_widget, &ServerStatusWidget::showServersTooltip, this, [this](QString message){setToolTipMessage(message, E_HINT);});
+    connect(ui->server_status_widget, &ServerStatusWidget::showNoTooltip, this, [this](){unsetToolTipMessage(E_HINT);});
 
     connect(&PatchDownloader::instance(), &PatchDownloader::started, this, &StatusWidget::onPatchDownloaderStarted);
     connect(&PatchDownloader::instance(), &PatchDownloader::progressChanged, this, &StatusWidget::onPatchDownloaderProgressChanged);
@@ -49,7 +49,7 @@ StatusWidget::StatusWidget(QWidget *parent)
 
     connect(ui->b_components_status, &TranslationComponents::needToPatch, this, &StatusWidget::onTranslationComponentsNeedToPatch);
     connect(ui->b_components_status, &TranslationComponents::noNeedToPatch, this, &StatusWidget::onTranslationComponentsNoNeedToPatch);
-
+    connect(&PatchDownloader::instance(), &PatchDownloader::checkForUpdatesStatusChanged, this, [this](bool need_update){_need_to_update = need_update; updateButtonStatus();});
     ui->b_components_status->hide();
 
     _components_status_opacity_effect = new QGraphicsOpacityEffect();
@@ -103,10 +103,10 @@ void StatusWidget::unsetToolTipMessage(StatusWidget::ToolTipState state)
 
     if (tooltip_state_ & E_INFO) {
         showing_state = E_INFO;
-    } else if (tooltip_state_ & E_ERROR) {
-        showing_state = E_ERROR;
     } else if (tooltip_state_ & E_PROCESS) {
         showing_state = E_PROCESS;
+    } else if (tooltip_state_ & E_HINT) {
+        showing_state = E_HINT;
     }
 
     QString message_id = tooltip_messages_[showing_state];
@@ -126,7 +126,7 @@ void StatusWidget::onErrorStatusChanged(AppErrorStatus status)
     QString init_error_type_message;
 
     if (status == E_NO_ERRORS) {
-        setToolTipMessage("Инициализация Наследия прошла успешно!", E_ERROR);
+        setToolTipMessage("Инициализация Наследия прошла успешно!", E_INFO);
         ui->news_list->updateNewsWidget();
         ui->server_status_widget->updateServerStatus();
         ui->weekly_code_widget->updateWeeklyCodeWidget();
@@ -147,7 +147,7 @@ void StatusWidget::onErrorStatusChanged(AppErrorStatus status)
     } else if (status == E_NO_SERVER_CONNECTION) {
         init_error_type_message = "Нет связи с серверами Наследия.\nПожалуйста, проверьте соединение с Интернетом.";
     }
-    setToolTipMessage(init_error_type_message, E_ERROR);
+    setToolTipMessage(init_error_type_message, E_INFO);
 }
 
 void StatusWidget::resizeEvent(QResizeEvent *)
@@ -300,6 +300,10 @@ void StatusWidget::onPatchInstallerVideoProgressChanged(int finished_videos, int
 
 void StatusWidget::on_game_button_clicked()
 {
+    if (_need_to_update || _need_to_install_patches) {
+        QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::startPatchDownloaderChain, Qt::QueuedConnection);
+        return;
+    }
 }
 
 void StatusWidget::createTooltipMessageWidget(QString tooltip_id)
@@ -373,21 +377,15 @@ void StatusWidget::onTranslationComponentsNoNeedToPatch() {
 
 void StatusWidget::updateButtonStatus() {
     if (_need_to_update) {
-        setToolTipMessage("Доступна новая версия русификации. Нажмите \"Обновить\", чтобы начать загрузку.", ToolTipState::E_INFO);
+        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 {
-        unsetToolTipMessage(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");
-    }
-
-    if (_need_to_install_patches) {
-        setToolTipMessage("Нажмите \"Установить\", чтобы начать процесс русификации.", ToolTipState::E_INFO);
+    } 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 {
-        unsetToolTipMessage(ToolTipState::E_INFO);
+        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");
     }

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

@@ -25,9 +25,9 @@ class StatusWidget : public QWidget
 public:
     // States. Higher state value means higher priority on visualisation
     enum ToolTipState : int {
-        E_INFO =    0b1000,
-        E_ERROR =   0b0100,
-        E_PROCESS = 0b0010,
+        E_HINT =    0b1000,
+        E_PROCESS = 0b0100,
+        E_INFO =    0b0010,
         E_RANDOM =  0b0001
     };
 

+ 35 - 35
src/Legacy/widgets/translationcomponents.cpp

@@ -53,20 +53,18 @@ TranslationComponents::~TranslationComponents()
 void TranslationComponents::resetSwitchesToDefault() {
     PatchInstaller::AppliedPatchesInfo info = PatchInstaller::instance().getPatchesInfo();
 
-    Settings::setValue("Components/texts_main", info.texts_version != 0);
-    Settings::setValue("Components/texts_emotes", info.texts_version != 0);
-    Settings::setValue("Components/texts_items", info.texts_version != 0);
-    Settings::setValue("Components/texts_videos", info.videos_version != 0);
-    Settings::setValue("Components/maps", info.graphics_version != 0);
-    Settings::setValue("Components/textures", info.graphics_version != 0);
-    Settings::setValue("Components/sounds", info.audio_version != 0);
-    Settings::setValue("Components/videos", info.videos_version != 0);
-    Settings::setValue("Components/loadscreens", info.loadscreens_version != 0);
-
-    ui->texts_block_switch->setValue(info.texts_version != 0);
-    ui->graphics_block_switch->setValue(info.graphics_version != 0);
+    Settings::setValue("DatabaseDownload/text", info.texts_version != 0);
+    Settings::setValue("DatabaseDownload/font", info.texts_version != 0);
+    Settings::setValue("DatabaseDownload/image", info.images_version != 0);
+    Settings::setValue("DatabaseDownload/loadscreen", info.loadscreens_version != 0);
+    Settings::setValue("DatabaseDownload/texture", info.texts_version != 0);
+    Settings::setValue("DatabaseDownload/sound", info.sounds_version != 0);
+    Settings::setValue("DatabaseDownload/video", info.texts_version != 0);
+
+    ui->texts_block_switch->setValue(info.texts_version != 0 && info.fonts_version != 0);
+    ui->graphics_block_switch->setValue(info.images_version != 0 && info.textures_version != 0);
     ui->video_block_switch->setValue(info.videos_version != 0);
-    ui->audio_block_switch->setValue(info.audio_version != 0);
+    ui->audio_block_switch->setValue(info.sounds_version != 0);
     ui->loadscreens_block_switch->setValue(info.loadscreens_version != 0);
 }
 
@@ -87,52 +85,54 @@ void TranslationComponents::enableControls() {
 }
 
 void TranslationComponents::onTextsChange(bool new_value) {
-    Settings::setValue("Components/texts_main", new_value);
-    Settings::setValue("Components/texts_emotes", new_value);
-    Settings::setValue("Components/texts_items", new_value);
+    Settings::setValue("DatabaseDownload/text", new_value);
+    Settings::setValue("DatabaseDownload/font", new_value);
     checkIfSettingsDoNotMatchCurrentDatState();
+    QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
 }
 
 void TranslationComponents::onImagesChange(bool new_value) {
-    Settings::setValue("Components/maps", new_value);
-    Settings::setValue("Components/textures", new_value);
+    Settings::setValue("DatabaseDownload/image", new_value);
+    Settings::setValue("DatabaseDownload/texture", new_value);
     checkIfSettingsDoNotMatchCurrentDatState();
+    QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
 }
 
 void TranslationComponents::onVideosChange(bool new_value) {
-    Settings::setValue("Components/videos", new_value);
-    Settings::setValue("Components/texts_videos", new_value);
+    Settings::setValue("DatabaseDownload/video", new_value);
     checkIfSettingsDoNotMatchCurrentDatState();
+    QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
 }
 
 void TranslationComponents::onSoundsChange(bool new_value) {
-    Settings::setValue("Components/sounds", new_value);
+    Settings::setValue("DatabaseDownload/sound", new_value);
     checkIfSettingsDoNotMatchCurrentDatState();
+    QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
 }
 
 void TranslationComponents::onLoadscreensChange(bool new_value) {
-    Settings::setValue("Components/loadscreens", new_value);
+    Settings::setValue("DatabaseDownload/loadscreen", new_value);
     checkIfSettingsDoNotMatchCurrentDatState();
+    QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
 }
 
 void TranslationComponents::checkIfSettingsDoNotMatchCurrentDatState() {
     PatchInstaller::AppliedPatchesInfo info = PatchInstaller::instance().getPatchesInfo();
     bool texts_enabled = info.texts_version != 0;
-    bool images_enabled = info.graphics_version != 0;
-    bool videos_enabled = info.videos_version != 0;
-    bool sounds_enabled = info.audio_version != 0;
+    bool images_enabled = info.images_version != 0;
+    bool sounds_enabled = info.sounds_version != 0;
     bool loadscreens_enabled = info.loadscreens_version != 0;
+    bool textures_enabled = info.textures_version != 0;
+    bool fonts_enabled = info.fonts_version != 0;
+    bool videos_enabled = info.videos_version != 0;
 
-    bool match = Settings::getValue("Components/texts_main").toBool() == texts_enabled &&
-                 Settings::getValue("Components/texts_emotes").toBool() == texts_enabled &&
-                 Settings::getValue("Components/texts_items").toBool() == texts_enabled &&
-                 Settings::getValue("Components/maps").toBool() == images_enabled &&
-                 Settings::getValue("Components/textures").toBool() == images_enabled &&
-                 Settings::getValue("Components/videos").toBool() == videos_enabled &&
-                 Settings::getValue("Components/texts_videos").toBool() == videos_enabled &&
-                 Settings::getValue("Components/sounds").toBool() == sounds_enabled &&
-                 Settings::getValue("Components/loadscreens").toBool() == loadscreens_enabled;
-
+    bool match = Settings::getValue("DatabaseDownload/text").toBool() == texts_enabled &&
+                 Settings::getValue("DatabaseDownload/font").toBool() == fonts_enabled &&
+                 Settings::getValue("DatabaseDownload/image").toBool() == images_enabled &&
+                 Settings::getValue("DatabaseDownload/loadscreen").toBool() == loadscreens_enabled &&
+                 Settings::getValue("DatabaseDownload/texture").toBool() == textures_enabled &&
+                 Settings::getValue("DatabaseDownload/sound").toBool() == sounds_enabled &&
+                 Settings::getValue("DatabaseDownload/video").toBool() == videos_enabled;
     if (!match) {
         emit needToPatch();
     } else {