Ver código fonte

Merge branch 'f/LEGACY-11-Settings-widgets-buttons-and-logic' of LotRO_Legacy/Legacy_v2 into dev

Ivan Arkhipov 4 anos atrás
pai
commit
ecdb54fb0a

+ 21 - 18
src/Legacy/models/lotrodatmanager.cpp

@@ -297,16 +297,12 @@ void LotroDatManager::enableCategory(QString patch_name, LotroDatManager::Catego
         emit operationFinished("enableCategory", {patch_name, category}, false);
         return;
     }
-    client_local_file_.GetFileSystem().CommitDirectories();
-    client_local_file_.GetLocaleManager().CommitLocales();
 
     if (client_general_file_.GetLocaleManager().EnableCategory(category).result != LOTRO_DAT::SUCCESS) {
         emit errorOccured("enableCategory", {patch_name, category}, "ErrorEnableCategoryClientGeneral");
         emit operationFinished("enableCategory", {patch_name, category}, false);
         return;
     }
-    client_general_file_.GetFileSystem().CommitDirectories();
-    client_general_file_.GetLocaleManager().CommitLocales();
 
     emit operationFinished("enableCategory", {patch_name, category});
 }
@@ -332,42 +328,49 @@ void LotroDatManager::disableCategory(QString patch_name, LotroDatManager::Categ
 
 void LotroDatManager::createBackup()
 {
-    // TODO: Error handling
     emit operationStarted("createBackup");
     QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
-    client_local_file_.GetBackupManager().CreateBackup((QApplication::applicationDirPath() + "/backup/client_local_" + locale_prefix + ".dat").toStdString());
-    client_general_file_.GetBackupManager().CreateBackup((QApplication::applicationDirPath() + "/backup/client_general.dat").toStdString());
-    emit operationFinished("createBackup");
+    QString client_local_backup_path = QApplication::applicationDirPath() + Settings::getValue("Backup/path").toString() + "client_local_" + locale_prefix + ".dat";
+    QString client_general_backup_path = QApplication::applicationDirPath() + Settings::getValue("Backup/path").toString() + "client_general.dat";
+    auto loc_res = client_local_file_.GetBackupManager().CreateBackup(client_local_backup_path.toStdString());
+    auto gen_res = client_general_file_.GetBackupManager().CreateBackup(client_general_backup_path.toStdString());
+    bool operations_result = (loc_res.result == LOTRO_DAT::SUCCESS && gen_res.result == LOTRO_DAT::SUCCESS);
+
+    emit operationFinished("createBackup", {client_local_backup_path, client_general_backup_path}, operations_result);
 }
 
 void LotroDatManager::restoreFromBackup()
 {
-    // TODO: Error handling
     emit operationStarted("restoreFromBackup");
     QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
-    client_local_file_.GetBackupManager().RestoreFromBackup((QApplication::applicationDirPath() + "/backup/client_local_" + locale_prefix + ".dat").toStdString());
-    client_general_file_.GetBackupManager().RestoreFromBackup((QApplication::applicationDirPath() + "/backup/client_general.dat").toStdString());
-    emit operationFinished("restoreFromBackup");
+    QString client_local_backup_path = QApplication::applicationDirPath() + Settings::getValue("Backup/path").toString() + "client_local_" + locale_prefix + ".dat";
+    QString client_general_backup_path = QApplication::applicationDirPath() + Settings::getValue("Backup/path").toString() + "client_general.dat";
+    auto loc_res = client_local_file_.GetBackupManager().RestoreFromBackup(client_local_backup_path.toStdString());
+    auto gen_res = client_general_file_.GetBackupManager().RestoreFromBackup(client_general_backup_path.toStdString());
+    bool operations_result = (loc_res.result == LOTRO_DAT::SUCCESS && gen_res.result == LOTRO_DAT::SUCCESS);
+    emit operationFinished("restoreFromBackup", {}, operations_result);
 }
 
 void LotroDatManager::removeBackup()
 {
-    // TODO: Error handling
     emit operationStarted("removeBackup");
     QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
-    client_local_file_.GetBackupManager().RemoveBackup((QApplication::applicationDirPath() + "/backup/client_local_" + locale_prefix + ".dat").toStdString());
-    client_general_file_.GetBackupManager().RemoveBackup((QApplication::applicationDirPath() + "/backup/client_general.dat").toStdString());
-    emit operationFinished("removeBackup");
+    QString client_local_backup_path = QApplication::applicationDirPath() + Settings::getValue("Backup/path").toString() + "client_local_" + locale_prefix + ".dat";
+    QString client_general_backup_path = QApplication::applicationDirPath() + Settings::getValue("Backup/path").toString() + "client_general.dat";
+    auto loc_res = client_local_file_.GetBackupManager().RemoveBackup(client_local_backup_path.toStdString());
+    auto gen_res = client_general_file_.GetBackupManager().RemoveBackup(client_general_backup_path.toStdString());
+    bool operations_result = (loc_res.result == LOTRO_DAT::SUCCESS && gen_res.result == LOTRO_DAT::SUCCESS);
+    emit operationFinished("removeBackup", {}, operations_result);
 }
 
 bool LotroDatManager::startLotroLauncherWithParameters(LOTRO_DAT::DatLocaleManager::LOCALE locale)
 {
     QStringList args;
-    if (Settings::getValue("Lotro/skip_raw_download").toString() == "True") {
+    if (Settings::getValue("Lotro/skip_raw_download").toBool()) {
         args << "-skiprawdownload";
     }
 
-    if (Settings::getValue("Lotro/no_splash_screen").toString() == "True") {
+    if (Settings::getValue("Lotro/no_splash_screen").toBool()) {
         args << "-nosplashscreen";
     }
 

+ 2 - 0
src/Legacy/models/patch/graphicspatch.cpp

@@ -290,6 +290,8 @@ void GraphicsPatch::installLoadscreens()
         progress.install_finished_parts++;
         emit progressChanged(progress, this);
     }
+
+    Settings::setValue("DatabaseNeedInstall/loadscreen", false);
 }
 
 void GraphicsPatch::enableLoadscreens()

+ 2 - 2
src/Legacy/models/patch/videospatch.cpp

@@ -102,13 +102,13 @@ void VideosPatch::download()
 
 void VideosPatch::install()
 {
-    QThread::sleep(3);
+    QThread::msleep(500);
     emit operationFinished(E_INSTALL, this);
 }
 
 void VideosPatch::activate()
 {
-    QThread::sleep(3);
+    QThread::msleep(500);
     emit operationFinished(E_ACTIVATE, this);
 }
 

+ 37 - 0
src/Legacy/models/patchlist.cpp

@@ -38,6 +38,7 @@ PatchList::PatchList(LotroDatManager *mgr, QObject *parent) : QObject(parent)
     connect(sounds_patch_, &SoundsPatch::progressChanged, this, &PatchList::onPatchOperationProgressChanged, Qt::QueuedConnection);
     connect(videos_patch_, &VideosPatch::progressChanged, this, &PatchList::onPatchOperationProgressChanged, Qt::QueuedConnection);
 
+    connect(lotro_mgr_, &LotroDatManager::operationStarted, this, &PatchList::onLotroManagerOperationStarted, Qt::QueuedConnection);
     connect(lotro_mgr_, &LotroDatManager::operationFinished, this, &PatchList::onLotroManagerOperationFinished, Qt::QueuedConnection);
 
     qInfo() << "PatchList: Patchset threads initialized, starting workers";
@@ -113,6 +114,7 @@ void PatchList::onPatchOperationProgressChanged(Patch::OperationProgress operati
 
 void PatchList::onLotroManagerOperationFinished(QString operation_name, QVector<QVariant>, bool result)
 {
+    qDebug() << "LotroManager: operation finished " << operation_name;
     if (operation_name == "initializeManager") {
         --active_operations_num_;
 
@@ -128,6 +130,18 @@ void PatchList::onLotroManagerOperationFinished(QString operation_name, QVector<
         }
     }
     if (operation_name == "createBackup" || operation_name == "restoreFromBackup" || operation_name == "removeBackup") {
+        if (operation_name == "createBackup" && result) {
+            Settings::setValue("Backup/installed", true);
+            Settings::setValue("Backup/creation_time", QDateTime::currentDateTime().toString("dd-MM-yyyy HH:mm:ss"));
+        }
+
+        if (operation_name == "removeBackup" && result) {
+            Settings::setValue("Backup/installed", false);
+            Settings::setValue("Backup/creation_time", "none");
+        }
+
+        emit backupSettingsInfoChanged();
+
         --active_operations_num_;
         if (active_operations_num_ == 0) {
             emit patchOperationsFinished();
@@ -135,6 +149,11 @@ void PatchList::onLotroManagerOperationFinished(QString operation_name, QVector<
     }
 }
 
+void PatchList::onLotroManagerOperationStarted(QString operation_name, QVector<QVariant>)
+{
+    qDebug() << "LotroManager: operation started " << operation_name;
+}
+
 void PatchList::startAutoUpdate()
 {
     auto_updates_enabled_ = true;
@@ -222,3 +241,21 @@ void PatchList::update()
     }
 }
 
+void PatchList::forceInstallPatches()
+{
+    if (active_operations_num_ > 0) {
+        qWarning() << "Trying to start force patch installation, while there are already some operations running!";
+    	return;
+    }
+
+    auto is_database_enabled = [](QString db_name) -> bool {
+        return Settings::getValue("DatabaseDownload/" + db_name).toBool();
+    };
+
+    for (const QString& db_name : QStringList(
+            {"text", "font", "image", "loadscreen",
+            "texture", "sound", "video", "micro"})) {
+        Settings::setValue("DatabaseNeedInstall/" + db_name, is_database_enabled(db_name));
+    }
+    update();
+}

+ 4 - 0
src/Legacy/models/patchlist.h

@@ -27,6 +27,7 @@ signals:
     void progressChanged(Patch::OperationProgress total_status);
     void patchOperationsStarted();
     void patchOperationsFinished();
+    void backupSettingsInfoChanged();
 
 public slots:
     void startAutoUpdate();
@@ -43,6 +44,8 @@ public slots:
 
     void removeBackup();
 
+    void forceInstallPatches();
+
 private slots:
     void onPatchOperationStarted(Patch::Operation operation, Patch* patch);
     void onPatchOperationFinished(Patch::Operation operation, Patch* patch);
@@ -50,6 +53,7 @@ private slots:
 
 private slots:
     void onLotroManagerOperationFinished(QString operation_name, QVector<QVariant> args, bool result);
+    void onLotroManagerOperationStarted(QString operation_name, QVector<QVariant> args);
 
 private:
     LotroDatManager *lotro_mgr_ = nullptr;

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

@@ -40,6 +40,8 @@ SettingsWidget::SettingsWidget(PatchList *legacy_patches, QWidget *parent)
     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(legacy_patches->getManager(), &LotroDatManager::statusChanged, this, &SettingsWidget::onLotroManagerProcessChanged);
 
     ui->apply_changes_button->hide();
     ui->apply_changes_label->hide();
@@ -78,7 +80,7 @@ void SettingsWidget::setActualParametersValues()
     ui->skiprawdownload_checkbox->setChecked(Settings::getValue("Lotro/skip_raw_download").toBool());
     ui->nosplashscreen_checkbox->setChecked(Settings::getValue("Lotro/no_splash_screen").toBool());
 
-    QString backup_status = Settings::getValue("Backup/installed").toBool() ? "Отсутствует" : "Активна";
+    QString backup_status = Settings::getValue("Backup/installed").toBool() ? "Активна" : "Отсутствует";
     ui->backup_status_value->setText(backup_status);
     ui->backup_path_value->setText(QApplication::applicationDirPath() + Settings::getValue("Backup/path").toString());
     QString backup_creation_time = Settings::getValue("Backup/creation_time").toString();
@@ -195,6 +197,46 @@ void SettingsWidget::resizeEvent(QResizeEvent *)
     ui->apply_changes_button->setMinimumSize(QSize(160, 60) * coefficient);
 }
 
+void SettingsWidget::onLotroManagerProcessChanged(LotroDatManager::Status status)
+{
+    if (status.status != LOTRO_DAT::DatStatus::E_BACKUP_CREATING &&
+            status.status != LOTRO_DAT::DatStatus::E_BACKUP_REMOVING &&
+            status.status != LOTRO_DAT::DatStatus::E_BACKUP_RESTORING) {
+        return;
+    }
+
+    QString operation;
+    if (status.status == LOTRO_DAT::DatStatus::E_BACKUP_CREATING) {
+        operation = "Создание копии";
+    }
+    if (status.status == LOTRO_DAT::DatStatus::E_BACKUP_REMOVING) {
+        operation = "Удаление копии";
+    }
+    if (status.status == LOTRO_DAT::DatStatus::E_BACKUP_RESTORING) {
+        operation = "Восстановление данных";
+    }
+
+    operation = operation + " " + QString::number(status.percentage, 'f', 1) + "%";
+    ui->backup_status_value->setText(operation);
+}
+
+void SettingsWidget::onBackupSettingsInfoChanged()
+{
+    settings_backup_["Backup/installed"] = Settings::getValue("Backup/installed");
+    settings_backup_["Backup/path"] = Settings::getValue("Backup/path");
+    settings_backup_["Backup/creation_time"] = Settings::getValue("Backup/creation_time");
+
+    QString backup_status = Settings::getValue("Backup/installed").toBool() ? "Активна" : "Отсутствует";
+    ui->backup_status_value->setText(backup_status);
+
+    ui->backup_path_value->setText(QApplication::applicationDirPath() + Settings::getValue("Backup/path").toString());
+
+    QString backup_creation_time = Settings::getValue("Backup/creation_time").toString();
+    if (backup_creation_time == "none")
+        backup_creation_time = "-";
+    ui->backup_creation_time_value->setText(backup_creation_time);
+}
+
 void SettingsWidget::processParameterChange() {
     if (!settings_changed_) {
         settings_changed_ = true;
@@ -416,7 +458,7 @@ void SettingsWidget::on_patch_video_checkbox_clicked()
 
 void SettingsWidget::on_patch_force_apply_button_clicked()
 {
- // TODO(endevir): Implement
+    QMetaObject::invokeMethod(legacy_patches_, "forceInstallPatches");
 }
 
 void SettingsWidget::on_micropatch_checkbox_clicked()

+ 5 - 0
src/Legacy/widgets/settingswidget.h

@@ -13,6 +13,7 @@
 #include <QWheelEvent>
 
 #include "models/settings.h"
+#include "models/lotrodatmanager.h"
 
 namespace Ui {
 class SettingsWidget;
@@ -122,6 +123,10 @@ protected:
     void resizeEvent(QResizeEvent *event) override;
 
 private slots:
+    void onLotroManagerProcessChanged(LotroDatManager::Status status);
+
+    void onBackupSettingsInfoChanged();
+
     void processParameterChange();
 
     void checkIfParametersWereReset();

+ 26 - 2
src/Legacy/widgets/settingswidget.ui

@@ -394,7 +394,7 @@ QScrollBar:vertical {
     <property name="geometry">
      <rect>
       <x>0</x>
-      <y>-455</y>
+      <y>-87</y>
       <width>651</width>
       <height>976</height>
      </rect>
@@ -692,6 +692,9 @@ background-color: none;</string>
              <property name="cursor">
               <cursorShape>PointingHandCursor</cursorShape>
              </property>
+             <property name="focusPolicy">
+              <enum>Qt::NoFocus</enum>
+             </property>
              <property name="styleSheet">
               <string notr="true">border-image: url(:/buttons/folder.png);
 background-color: none;</string>
@@ -939,6 +942,9 @@ background-color: none;</string>
                <pointsize>8</pointsize>
               </font>
              </property>
+             <property name="focusPolicy">
+              <enum>Qt::NoFocus</enum>
+             </property>
              <property name="autoFillBackground">
               <bool>false</bool>
              </property>
@@ -968,6 +974,9 @@ QPushButton:default {
              <property name="text">
               <string>Cоздать копию</string>
              </property>
+             <property name="flat">
+              <bool>false</bool>
+             </property>
             </widget>
            </item>
            <item>
@@ -978,6 +987,9 @@ QPushButton:default {
                <pointsize>9</pointsize>
               </font>
              </property>
+             <property name="focusPolicy">
+              <enum>Qt::NoFocus</enum>
+             </property>
              <property name="autoFillBackground">
               <bool>false</bool>
              </property>
@@ -1007,6 +1019,9 @@ QPushButton:default {
              <property name="text">
               <string> Восстановить данные из копии </string>
              </property>
+             <property name="flat">
+              <bool>false</bool>
+             </property>
             </widget>
            </item>
            <item>
@@ -1017,6 +1032,9 @@ QPushButton:default {
                <pointsize>8</pointsize>
               </font>
              </property>
+             <property name="focusPolicy">
+              <enum>Qt::NoFocus</enum>
+             </property>
              <property name="autoFillBackground">
               <bool>false</bool>
              </property>
@@ -1046,6 +1064,9 @@ QPushButton:default {
              <property name="text">
               <string>Удалить копию</string>
              </property>
+             <property name="flat">
+              <bool>false</bool>
+             </property>
             </widget>
            </item>
           </layout>
@@ -1631,6 +1652,9 @@ border-radius: 3px;</string>
             <pointsize>9</pointsize>
            </font>
           </property>
+          <property name="focusPolicy">
+           <enum>Qt::NoFocus</enum>
+          </property>
           <property name="autoFillBackground">
            <bool>false</bool>
           </property>
@@ -1658,7 +1682,7 @@ QPushButton:default {
 }</string>
           </property>
           <property name="text">
-           <string>Повторно применить все патчи Наследия</string>
+           <string>Переустановить все компоненты русификации</string>
           </property>
          </widget>
         </item>