Browse Source

Merge branch 'f/LEGACY-10-Old-patches-cleanup' of LotRO_Legacy/Legacy_v2 into dev

Ivan Arkhipov 4 years ago
parent
commit
8992d7b64d
3 changed files with 50 additions and 3 deletions
  1. 47 2
      src/Legacy/models/patchlist.cpp
  2. 2 0
      src/Legacy/models/patchlist.h
  3. 1 1
      src/Legacy/models/settings.cpp

+ 47 - 2
src/Legacy/models/patchlist.cpp

@@ -1,6 +1,7 @@
 #include "patchlist.h"
 
 #include <QDebug>
+#include <QDirIterator>
 
 PatchList::PatchList(LotroDatManager *mgr, QObject *parent) : QObject(parent)
 {
@@ -220,6 +221,7 @@ void PatchList::onPatchOperationFinished(Patch::Operation, Patch*)
 {
     --active_operations_num_;
     if (active_operations_num_ == 0) {
+        cleanUpPatchDirectory();
         emit patchOperationsFinished();
     }
 }
@@ -253,9 +255,52 @@ void PatchList::forceInstallPatches()
     };
 
     for (const QString& db_name : QStringList(
-            {"text", "font", "image", "loadscreen",
-            "texture", "sound", "video", "micro"})) {
+            {"text", "font", "image", "loadscreen", "texture", "sound", "video", "micro"})) {
         Settings::setValue("DatabaseNeedInstall/" + db_name, is_database_enabled(db_name));
     }
+
     update();
 }
+
+void PatchList::cleanUpPatchDirectory()
+{
+    QStringList databases_filenames;
+
+    QSettings settings;
+    settings.beginGroup("PatchDatabases/");
+    qDebug() << "cleanUpPatchDirectory: Iterating through groups: " << settings.childGroups();
+
+    for (const QString& key : settings.childGroups()) {
+        settings.beginGroup(key);
+        QString filename = settings.value("path").toString();
+        if (!filename.isEmpty()) {
+            databases_filenames << filename;
+        }
+        settings.endGroup();
+    }
+    settings.endGroup();
+
+    QDirIterator patch_dir_iterator(
+                    Settings::getValue("General/PatchDownloadDir").toString(),
+                    QDir::NoDotAndDotDot | QDir::Files,
+                    QDirIterator::Subdirectories
+                );
+
+    while (patch_dir_iterator.hasNext()) {
+        qDebug() << "cleanUpPatchDirectory: found " << patch_dir_iterator.next();
+        bool is_file_actual = false;
+        for (const QString& file_path : databases_filenames) {
+            if (QFileInfo(file_path) == patch_dir_iterator.fileInfo()) {
+                is_file_actual = true;
+                break;
+            }
+        }
+
+        if (!is_file_actual) {
+            qDebug() << "cleanUpPatchDirectory: file" << patch_dir_iterator.filePath()
+                     << "is not in patch list. Removing";
+
+            QFile::remove(patch_dir_iterator.filePath());
+        }
+    }
+}

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

@@ -46,6 +46,8 @@ public slots:
 
     void forceInstallPatches();
 
+    void cleanUpPatchDirectory();
+
 private slots:
     void onPatchOperationStarted(Patch::Operation operation, Patch* patch);
     void onPatchOperationFinished(Patch::Operation operation, Patch* patch);

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

@@ -89,7 +89,7 @@ void setDefaultSettings()
 
 QVariant getValue(QString key) {
     QSettings settings;
-    return settings.value(key, defaults[key]);
+    return settings.value(key, defaults.value(key, QVariant()));
 }
 
 void setValue(QString key, QVariant value) {