diff ui/mainwindow.cpp @ 857:9bab4fc3a1fe

Delete old lists and rename the currently installed list to list-installed.txt
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 04 Aug 2014 15:06:16 +0200
parents d33834129d2a
children 4efd6378c001
line wrap: on
line diff
--- a/ui/mainwindow.cpp	Thu Jul 31 12:56:26 2014 +0200
+++ b/ui/mainwindow.cpp	Mon Aug 04 15:06:16 2014 +0200
@@ -29,6 +29,7 @@
 #include <QCheckBox>
 #include <QButtonGroup>
 #include <QToolButton>
+#include <QStandardPaths>
 
 #include "certificatelist.h"
 #include "downloader.h"
@@ -1068,11 +1069,44 @@
             qWarning() << "Error accessing settings";
             return; /* Try again with next check */
         }
+        /* Rename the installed list to list-installed.txt so that external
+         * programs (like the uninstaller can easily recognize it). */
+        QString dataLoc =
+            QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+        QDir dataDir(dataLoc);
+        if (!dataDir.exists()) {
+            /* Should not happen */
+            qWarning() << "Data dir removed.";
+            return;
+        }
 
-        mSettings.setValue("List/installed", listFileName);
+        QFileInfo oldList (dataDir.absoluteFilePath("list-installed.txt"));
+        if (oldList.exists()) {
+            qDebug() << "Removing old list: " << oldList.filePath();
+            if (!QFile::remove(oldList.filePath())) {
+                qWarning() << "Removal of old list failed.";
+                return;
+            }
+        }
+        QFile newList(listFileName);
+        if (!newList.rename(oldList.filePath())) {
+            qWarning() << "Failed to rename new list.";
+            return;
+        }
+
+        mSettings.setValue("List/installed", oldList.filePath());
         mSettings.setValue("List/installedDate", listFileDate);
-        mInstalledList = mListToInstall;
+        mInstalledList = CertificateList(oldList.filePath().toUtf8().constData());
+        if (!mInstalledList.isValid()) {
+            /* Something went wrong. Go back to square one. */
+            qWarning () << "List corrupted after installation";
+            mInstalledList = CertificateList();
+            QFile::remove(oldList.filePath());
+            mSettings.remove("List/installed");
+            mSettings.remove("List/installedDate");
+        }
         mListToInstall = CertificateList();
+
     }
     mUpdatesManual->clear();
     loadCertificateList();

http://wald.intevation.org/projects/trustbridge/