Prechádzať zdrojové kódy

Implemented backup operations progress show in Settings widget

Ivan Arkhipov 5 rokov pred
rodič
commit
da2dc6d67b

+ 19 - 16
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,32 +328,39 @@ 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)

+ 19 - 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;

+ 2 - 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();
@@ -52,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;

+ 41 - 1
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,44 @@ 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/path");
+
+    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;

+ 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();