diff options
author | Arno <arno@disconnect.de> | 2018-01-02 23:10:08 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-01-02 23:10:08 +0100 |
commit | aab351093e3ba713f1179a797d0f5929bdb4c92c (patch) | |
tree | 512b6858491e209f4d7be1f9fe46a0921c8523df /filewidget.cpp | |
parent | b5dc8c10367537aec8ce7c061f608ca896ec9f36 (diff) | |
download | ShemovCleaner-aab351093e3ba713f1179a797d0f5929bdb4c92c.tar.gz ShemovCleaner-aab351093e3ba713f1179a797d0f5929bdb4c92c.tar.bz2 ShemovCleaner-aab351093e3ba713f1179a797d0f5929bdb4c92c.zip |
Save CachedFileData to disk
Since we already have the data, save it to speed up the start.
Surprisingly, the hardest part was to figure out how to use
QStandardPaths to find a location where to save the file. I went with
the semi-hardcoded path HomeLocation/.shemovcleaner, even though we're
on windows.
Diffstat (limited to 'filewidget.cpp')
-rw-r--r-- | filewidget.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/filewidget.cpp b/filewidget.cpp index e2be4e1..458dd45 100644 --- a/filewidget.cpp +++ b/filewidget.cpp @@ -31,6 +31,7 @@ #include <QApplication> #include <QContextMenuEvent> #include <QDirIterator> +#include <QStandardPaths> #include "filewidget.h" #include "filesorter.h" @@ -47,6 +48,19 @@ FileWidget::FileWidget(QWidget *parent) : QWidget(parent), mCopyToMenu(0) { mFileCopier = new FileCopier(this); mCopyProgress = new ProgressDialog; mFileCache.setMaxCost(500); + QString cacheDir = QStandardPaths::locate(QStandardPaths::HomeLocation, ".shemovcleaner", QStandardPaths::LocateDirectory); + if(!cacheDir.isEmpty()){ + QString cacheFile = QString("%1/%2").arg(cacheDir).arg("cfd.dat"); + QFile f(cacheFile); + if(f.open(QIODevice::ReadOnly)){ + QDataStream in(&f); + while(!in.atEnd()){ + CachedFileData *fd = new CachedFileData; + in >> *fd; + mFileCache.insert(fd->fullPath, fd); + } + } + } connect(mFileCopier, SIGNAL(newFile(QString,QString,qint64)), this, SLOT(setupProgress(QString,QString,qint64))); connect(mFileCopier, SIGNAL(bytesRead(qint64)), this, SLOT(setCopyProgress(qint64))); connect(mFileCopier, SIGNAL(bytesReadIntval(qint64,qint64)), this, SLOT(setCopySummary(qint64,qint64))); @@ -59,6 +73,19 @@ FileWidget::FileWidget(QWidget *parent) : QWidget(parent), mCopyToMenu(0) { FileWidget::~FileWidget(){ writeHeaderData(); writeSettings(); + QString cacheDir = QStandardPaths::locate(QStandardPaths::HomeLocation, ".shemovcleaner", QStandardPaths::LocateDirectory); + if(!cacheDir.isEmpty()){ + QString cacheFile = QString("%1/%2").arg(cacheDir).arg("cfd.dat"); + QFile f(cacheFile); + if(f.open(QIODevice::WriteOnly)){ + QDataStream out(&f); + QList<QString> entries = mFileCache.keys(); + for(const QString &e : entries){ + CachedFileData *entry = mFileCache[e]; + out << *entry; + } + } + } } void FileWidget::setupGui(){ |