Browse Source

Added sqlite support for Legacy v2 & some minor ui improvements

Ivan Arkhipov 3 years ago
parent
commit
666585154b

+ 1 - 1
src/Legacy/Legacy.pro

@@ -1,7 +1,7 @@
 include( ../../common.pri )
 include( ../../app.pri )
 
-QT       += core gui network
+QT       += core gui network sql
 
 QMAKE_LFLAGS_RELEASE += -static -static-libgcc -static-libstdc++
 

+ 16 - 14
src/Legacy/legacy_plugin_import.cpp

@@ -1,14 +1,16 @@
-// This file is autogenerated by qmake. It imports static plugin classes for
-// static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS.<plugin> variables.
-#include <QtPlugin>
-Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin)
-Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
-Q_IMPORT_PLUGIN(QGifPlugin)
-Q_IMPORT_PLUGIN(QICNSPlugin)
-Q_IMPORT_PLUGIN(QICOPlugin)
-Q_IMPORT_PLUGIN(QJpegPlugin)
-Q_IMPORT_PLUGIN(QTgaPlugin)
-Q_IMPORT_PLUGIN(QTiffPlugin)
-Q_IMPORT_PLUGIN(QWbmpPlugin)
-Q_IMPORT_PLUGIN(QWebpPlugin)
-Q_IMPORT_PLUGIN(QGenericEnginePlugin)
+// This file is autogenerated by qmake. It imports static plugin classes for
+// static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS.<plugin> variables.
+#include <QtPlugin>
+Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin)
+Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
+Q_IMPORT_PLUGIN(QGifPlugin)
+Q_IMPORT_PLUGIN(QICNSPlugin)
+Q_IMPORT_PLUGIN(QICOPlugin)
+Q_IMPORT_PLUGIN(QJpegPlugin)
+Q_IMPORT_PLUGIN(QTgaPlugin)
+Q_IMPORT_PLUGIN(QTiffPlugin)
+Q_IMPORT_PLUGIN(QWbmpPlugin)
+Q_IMPORT_PLUGIN(QWebpPlugin)
+Q_IMPORT_PLUGIN(QGenericEnginePlugin)
+Q_IMPORT_PLUGIN(QSQLiteDriverPlugin)
+Q_IMPORT_PLUGIN(QODBCDriverPlugin)

+ 1 - 0
src/Legacy/legacyapplication.cpp

@@ -6,6 +6,7 @@
 #include <QResource>
 #include <QFontDatabase>
 #include <QMessageLogContext>
+#include <QApplication>
 
 #include "utils.h"
 #include "widgets/mainwindow.h"

+ 35 - 2
src/Legacy/models/patchinstaller.cpp

@@ -4,6 +4,9 @@
 
 #include <QDebug>
 #include <QProcess>
+#include <QApplication>
+#include <QSqlQuery>
+
 
 QString getComponentNameFromId(int id) {
     switch (id) {
@@ -19,7 +22,9 @@ QString getComponentNameFromId(int id) {
     return "none";
 }
 
-PatchInstaller::PatchInstaller(QObject *parent) :  QObject(parent) {
+PatchInstaller::PatchInstaller(QObject *parent)
+    : QObject(parent)
+    , orig_files_db(QSqlDatabase::addDatabase("QSQLITE")) {
 }
 
 bool PatchInstaller::initialised() {
@@ -48,6 +53,7 @@ bool PatchInstaller::datPathIsRelevant() {
 }
 
 void PatchInstaller::deinit() {
+    orig_files_db.close();
     if (client_local_file_)
         client_local_file_->Deinit();
     if (client_general_file_)
@@ -96,14 +102,25 @@ void PatchInstaller::installPatch(QString patch_name, LOTRO_DAT::Database* datab
             continue;
         }
         const int dat_id = file.options["did"] ? file.options["did"].as<int>() : 0;
-
+        const int file_id = file.options["fid"].as<int>();
+        int file_version = -1;
         if (dat_id == E_CLIENT_LOCAL) {
             client_local_file_->PatchFile(file);
+            file_version = client_local_file_->GetFileVersion(file_id);
         } else if (dat_id == E_CLIENT_GENERAL) {
             client_general_file_->PatchFile(file);
+            file_version = client_local_file_->GetFileVersion(file_id);
         } else {
             qWarning() << "Unknown dat id parameter for file " << file.options["fid"].as<long long>() << " (dat id value = " << dat_id << "), SKIPPING!";
         }
+
+        if (file_version != 721359) {
+            const QString query = "INSERT INTO `patch_data` (`file_id`, `options`) VALUES ('"
+                    + QString::number(file_id) + "', '" + QString::number(file_version)
+                    + "') ON CONFLICT(`file_id`) DO UPDATE SET `options`='" + QString::number(file_version) + "';";
+            qDebug() << "EXECUTING: " << query;
+            orig_files_db.exec(query);
+        }
     }
     Settings::setValue("DatabaseNeedInstall/" + patch_name, false);
     return;
@@ -253,6 +270,22 @@ void PatchInstaller::init()
         return;
     }
 
+    // Initializing db for original files backup
+    QString database_path = game_folder + "/LotroLegacy/orig_files.db";
+    if (!FileSystem::fileExists(database_path)) {
+        FileSystem::createFilePath(database_path);
+    }
+    orig_files_db.setDatabaseName(database_path);
+    if (!orig_files_db.open()) {
+        qCritical() << "Initializing PatchInstaller - Cannot open backup database!!!!!!! " << database_path;
+    }
+    orig_files_db.exec(create_table_query);
+    orig_files_db.exec("PRAGMA synchronous = OFF");
+    orig_files_db.exec("PRAGMA count_changes = OFF");
+    orig_files_db.exec("PRAGMA journal_mode = MEMORY");
+    orig_files_db.exec("PRAGMA temp_store = MEMORY");
+    orig_files_db.exec("PRAGMA encoding = \"UTF-8\";");
+
     qDebug() << "LotroDatManager initialisation successfull! Dat files: "
              << QString::fromStdString(client_general_file_->GetFilename())
              << QString::fromStdString(client_local_file_->GetFilename());

+ 9 - 4
src/Legacy/models/patchinstaller.h

@@ -2,10 +2,7 @@
 #define LEGACYAPP_H
 
 #include <QObject>
-#include <QSettings>
-#include <QApplication>
-#include <QVector>
-#include <QVariant>
+#include <QSqlDatabase>
 
 #include "models/downloader.h"
 #include <LotroDat/datfile.h>
@@ -71,6 +68,14 @@ private:
     LOTRO_DAT::DatFile* client_local_file_;
     LOTRO_DAT::DatFile* client_general_file_;
 
+    QSqlDatabase orig_files_db;
+    const QString create_table_query = "CREATE TABLE IF NOT EXISTS `patch_data` "
+                                       "(`file_id` INTEGER PRIMARY KEY,"
+                                       "`binary_data` BLOB, "
+                                       "`text_data` TEXT, "
+                                       "`options` TEXT NOT NULL)";
+
+//    const QString upset_table_value_query = "INSERT INTO `patch_data` (`file_id`, ``) VALUES (?);";
     Status current_status;
     int download_video_finished_videos = 0;
     int download_video_total_videos = 0;

+ 2 - 2
src/Legacy/widgets/mainwindow.cpp

@@ -285,8 +285,8 @@ void MainWindow::onPatchOperationsFinished()
 
 void MainWindow::makeConnections()
 {
-//    connect(legacy_patches_, &PatchList::patchOperationsStarted, this, &MainWindow::onPatchOperationsStarted);
-//    connect(legacy_patches_, &PatchList::patchOperationsFinished, this, &MainWindow::onPatchOperationsFinished);
+    connect(&PatchInstaller::instance(), &PatchInstaller::started, this, &MainWindow::onPatchOperationsStarted);
+    connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, &MainWindow::onPatchOperationsFinished);
 }
 
 void MainWindow::setupMenuHoverWidget()

+ 51 - 44
src/Legacy/widgets/settingswidget.cpp

@@ -38,9 +38,12 @@ SettingsWidget::SettingsWidget(QWidget *parent)
 //    ui->content_scroll_area->verticalScrollBar()->installEventFilter(scroller);
 
     ui->patch_installing_label->hide();
-//    connect(legacy_patches, &PatchList::patchOperationsStarted, this, &SettingsWidget::onPatchTotalOperationsStarted);
-//    connect(legacy_patches, &PatchList::patchOperationsFinished, this, &SettingsWidget::onPatchTotalOperationsFinished);
-//    connect(legacy_patches, &PatchList::backupSettingsInfoChanged, this, &SettingsWidget::onBackupSettingsInfoChanged);
+    connect(&PatchInstaller::instance(), &PatchInstaller::started, this, &SettingsWidget::onPatchTotalOperationsStarted);
+    connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, &SettingsWidget::onPatchTotalOperationsFinished);
+    connect(&PatchDownloader::instance(), &PatchDownloader::started, this, &SettingsWidget::onPatchTotalOperationsStarted);
+    connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, &SettingsWidget::onPatchTotalOperationsFinished);
+
+    //    connect(legacy_patches, &PatchList::backupSettingsInfoChanged, this, &SettingsWidget::onBackupSettingsInfoChanged);
 //    connect(legacy_patches->getManager(), &LotroDatManager::statusChanged, this, &SettingsWidget::onLotroManagerProcessChanged);
 
     ui->apply_changes_button->hide();
@@ -521,51 +524,55 @@ void SettingsWidget::on_interface_scale_combobox_currentIndexChanged(const QStri
 
 void SettingsWidget::onPatchTotalOperationsStarted()
 {
-    patch_operations_running_ = true;
-    ui->patch_installing_label->show();
-
-    ui->change_folder_button->setEnabled(false);
-    ui->lotro_base_language_combobox->setEnabled(false);
-
-    ui->backup_create_button->setEnabled(false);
-    ui->backup_restore_button->setEnabled(false);
-    ui->backup_remove_button->setEnabled(false);
-
-    ui->patch_texts_checkbox->setEnabled(false);
-    ui->patch_items_checkbox->setEnabled(false);
-    ui->patch_emotes_checkbox->setEnabled(false);
-    ui->patch_maps_checkbox->setEnabled(false);
-    ui->patch_textures_checkbox->setEnabled(false);
-    ui->patch_loadscreens_checkbox->setEnabled(false);
-    ui->patch_sounds_checkbox->setEnabled(false);
-    ui->patch_video_checkbox->setEnabled(false);
-    ui->patch_force_apply_button->setEnabled(false);
-    ui->micropatch_checkbox->setEnabled(false);
+    patch_operations_running_++;
+    if (patch_operations_running_ == 1) {
+        ui->patch_installing_label->show();
+
+        ui->change_folder_button->setEnabled(false);
+        ui->lotro_base_language_combobox->setEnabled(false);
+
+        ui->backup_create_button->setEnabled(false);
+        ui->backup_restore_button->setEnabled(false);
+        ui->backup_remove_button->setEnabled(false);
+
+        ui->patch_texts_checkbox->setEnabled(false);
+        ui->patch_items_checkbox->setEnabled(false);
+        ui->patch_emotes_checkbox->setEnabled(false);
+        ui->patch_maps_checkbox->setEnabled(false);
+        ui->patch_textures_checkbox->setEnabled(false);
+        ui->patch_loadscreens_checkbox->setEnabled(false);
+        ui->patch_sounds_checkbox->setEnabled(false);
+        ui->patch_video_checkbox->setEnabled(false);
+        ui->patch_force_apply_button->setEnabled(false);
+        ui->micropatch_checkbox->setEnabled(false);
+    }
 }
 
 void SettingsWidget::onPatchTotalOperationsFinished()
 {
-    patch_operations_running_ = false;
-    ui->patch_installing_label->hide();
-    settings_backup_ = Settings::createSettingsBackup();
-
-    ui->change_folder_button->setEnabled(true);
-    ui->lotro_base_language_combobox->setEnabled(true);
-
-    ui->backup_create_button->setEnabled(true);
-    ui->backup_restore_button->setEnabled(true);
-    ui->backup_remove_button->setEnabled(true);
-
-    ui->patch_texts_checkbox->setEnabled(true);
-    ui->patch_items_checkbox->setEnabled(true);
-    ui->patch_emotes_checkbox->setEnabled(true);
-    ui->patch_maps_checkbox->setEnabled(true);
-    ui->patch_textures_checkbox->setEnabled(true);
-    ui->patch_loadscreens_checkbox->setEnabled(true);
-    ui->patch_sounds_checkbox->setEnabled(true);
-    ui->patch_video_checkbox->setEnabled(true);
-    ui->patch_force_apply_button->setEnabled(true);
-    ui->micropatch_checkbox->setEnabled(true);
+    patch_operations_running_--;
+    if (patch_operations_running_ == 0) {
+        ui->patch_installing_label->hide();
+        settings_backup_ = Settings::createSettingsBackup();
+
+        ui->change_folder_button->setEnabled(true);
+        ui->lotro_base_language_combobox->setEnabled(true);
+
+        ui->backup_create_button->setEnabled(true);
+        ui->backup_restore_button->setEnabled(true);
+        ui->backup_remove_button->setEnabled(true);
+
+        ui->patch_texts_checkbox->setEnabled(true);
+        ui->patch_items_checkbox->setEnabled(true);
+        ui->patch_emotes_checkbox->setEnabled(true);
+        ui->patch_maps_checkbox->setEnabled(true);
+        ui->patch_textures_checkbox->setEnabled(true);
+        ui->patch_loadscreens_checkbox->setEnabled(true);
+        ui->patch_sounds_checkbox->setEnabled(true);
+        ui->patch_video_checkbox->setEnabled(true);
+        ui->patch_force_apply_button->setEnabled(true);
+        ui->micropatch_checkbox->setEnabled(true);
+    }
 }
 
 void SettingsWidget::on_apply_changes_button_clicked()

+ 1 - 1
src/Legacy/widgets/settingswidget.h

@@ -174,7 +174,7 @@ private slots:
 
 
 private:
-    bool patch_operations_running_ = false;
+    int patch_operations_running_ = 0;
 
     Ui::SettingsWidget *ui = nullptr;
 

+ 25 - 8
src/Legacy/widgets/statuswidget.cpp

@@ -45,7 +45,7 @@ StatusWidget::StatusWidget(QWidget *parent)
     connect(&random_tooltip_generator_timer_, &QTimer::timeout, this, &StatusWidget::generateRandomTooltipMessage);
     random_tooltip_generator_timer_.start();
 
-    process_completed_tooltip_hide_timer_.setInterval(10 * 1000); // 10 seconds message "Installation completed" will be shown
+    process_completed_tooltip_hide_timer_.setInterval(4 * 1000); // 4 seconds message "Installation completed" will be shown
     process_completed_tooltip_hide_timer_.stop();
     connect(&process_completed_tooltip_hide_timer_, &QTimer::timeout, this, [this](){unsetToolTipMessage(E_PROCESS); process_completed_tooltip_hide_timer_.stop();});
 }
@@ -64,18 +64,21 @@ 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));
 
-    qDebug() << "Setting tooltip message " << message << " with state " << int(state) << ", new state = " << tooltip_state_;
     QString message_id = message;
     if (state == E_PROCESS) {
         message_id = "E_PROCESS";
     }
 
     if (tooltip_state_ < state * 2) {
-        qDebug() << "FADING TOOLTIP to " << message_id;
-
         if (!tooltip_widgets_.contains(message_id)) {
             createTooltipMessageWidget(message_id);
         }
@@ -103,11 +106,16 @@ 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);
     }
     tooltip_widgets_[message_id]->setText(tooltip_messages_[showing_state]);
-    qDebug() << "UNSETTING TOOLTIP to " << message_id << ", deleting state " << state << ", showing state " << showing_state;
     fadeBetweenToolTips(message_id);
 }
 
@@ -206,7 +214,14 @@ void StatusWidget::resizeEvent(QResizeEvent *)
 void StatusWidget::generateRandomTooltipMessage()
 {
     quint32 number = QRandomGenerator::system()->generate();
-    setToolTipMessage("СЛУЧАЙНОЕ СООБЩЕНИЕ №" + QString::number(number), E_RANDOM);
+
+    QVector<QString> messages = {
+        "<p style=\"font-size: 22px; \">Atra du evarínya ono varda! Я видела тебя в своём зеркале...</p>",
+        "<p style=\"font-size: 22px; \">Опасно ходить в рейды в одиночку! Зачищать инсты лучше в хорошей компании :)</p>",
+        "<p style=\"font-size: 22px; \">Какое-то ещё мудрое высказывание в стиле эльфов...</p>",
+        "<p style=\"font-size: 22px; \">Мудрые сидят в дискорде Наследия, <a href=\"https://discord.gg/j25MdKR\" style=\"color: yellow\">присоединяйся</a>!</p>",
+    };
+    setToolTipMessage(messages[number % messages.size()], E_RANDOM);
 }
 
 void StatusWidget::fadeBetweenToolTips(QString tooltip_id)
@@ -275,14 +290,14 @@ void StatusWidget::onPatchInstallerStarted() {
     all_patch_operations_finished_ = false;
     ui->game_button->setEnabled(false);
     ui->check_for_updates_button->setEnabled(false);
-    setToolTipMessage("Подготовка русификатора...", E_PROCESS);
+    setToolTipMessage("<p style=\"font-size: 22px; \">Подготовка русификатора...</p>", E_PROCESS);
 }
 
 void StatusWidget::onPatchInstallerFinished() {
     all_patch_operations_finished_ = true;
     ui->game_button->setEnabled(true);
     ui->check_for_updates_button->setEnabled(true);
-    setToolTipMessage("Все операции выполнены!", E_PROCESS);
+    setToolTipMessage("<p style=\"font-size: 22px; \">Все операции выполнены!</p>", E_PROCESS);
     process_completed_tooltip_hide_timer_.start();
 }
 
@@ -324,6 +339,8 @@ void StatusWidget::createTooltipMessageWidget(QString tooltip_id)
     tooltip_widgets_[tooltip_id]->setStyleSheet(ui->galadriel_tooltip_example->styleSheet());
     tooltip_widgets_[tooltip_id]->setFont(ui->galadriel_tooltip_example->font());
     tooltip_widgets_[tooltip_id]->setWordWrap(true);
+    tooltip_widgets_[tooltip_id]->setOpenExternalLinks(true);
+
     tooltip_widgets_[tooltip_id]->setAlignment(Qt::AlignCenter);
 
     tooltip_effects_[tooltip_id] = new QGraphicsOpacityEffect(tooltip_widgets_[tooltip_id]);

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

@@ -4,6 +4,7 @@
 #include <QWidget>
 #include <QSettings>
 #include <QTime>
+#include <QElapsedTimer>
 #include <QMap>
 #include <QPropertyAnimation>
 #include <QGraphicsOpacityEffect>
@@ -84,9 +85,7 @@ private:
     QMap<QString, QPropertyAnimation*> tooltip_animations_;
     QString current_tooltip_message_;
 
-//    QMap<Patch*, Patch::Operation> patch_operations;
-
-    QTime last_statusbar_update_time_;
+    QElapsedTimer last_statusbar_update_time_;
 
     ToolTipState tooltip_state_ = E_RANDOM;
     QMap<ToolTipState, QString> tooltip_messages_;