From 3213b4b32cd6620f88c6db442ebc38753b368441 Mon Sep 17 00:00:00 2001 From: Arno Date: Thu, 4 Jan 2018 05:52:44 +0100 Subject: Improve lookup of cache dir Implement looking up the cache dir as Helper::function. Create it if it doesn't exist. --- filewidget.cpp | 5 ++--- helper.cpp | 14 ++++++++++++++ helper.h | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/filewidget.cpp b/filewidget.cpp index 4872135..397ea63 100644 --- a/filewidget.cpp +++ b/filewidget.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include "filewidget.h" #include "filesorter.h" @@ -48,7 +47,7 @@ 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); + QString cacheDir = Helper::appDataDir(); if(!cacheDir.isEmpty()){ QString cacheFile = QString("%1/%2").arg(cacheDir).arg("cfd.dat"); QFile f(cacheFile); @@ -73,7 +72,7 @@ FileWidget::FileWidget(QWidget *parent) : QWidget(parent), mCopyToMenu(0) { FileWidget::~FileWidget(){ writeHeaderData(); writeSettings(); - QString cacheDir = QStandardPaths::locate(QStandardPaths::HomeLocation, ".shemovcleaner", QStandardPaths::LocateDirectory); + QString cacheDir = Helper::appDataDir(); if(!cacheDir.isEmpty()){ QString cacheFile = QString("%1/%2").arg(cacheDir).arg("cfd.dat"); QFile f(cacheFile); diff --git a/helper.cpp b/helper.cpp index a895ec4..502bfac 100644 --- a/helper.cpp +++ b/helper.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "helper.h" @@ -122,6 +124,18 @@ namespace Helper { return retval; } + const QString appDataDir(){ + QString retval = QStandardPaths::locate(QStandardPaths::HomeLocation, ".shemovcleaner", QStandardPaths::LocateDirectory); + if(retval.isEmpty()){ + QString homeDir = QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory); + QDir d(homeDir); + if(d.mkdir(".shemovcleaner")){ + retval = QString("%1/%2").arg(homeDir).arg(".shemovcleaner"); + } + } + return retval; + } + Duration::Duration() : mHours(0), mMinutes(0), mSeconds(0) {} Duration::Duration(qint64 seconds){ diff --git a/helper.h b/helper.h index 3587183..7c4eece 100644 --- a/helper.h +++ b/helper.h @@ -10,6 +10,7 @@ namespace Helper { const QJsonDocument ffpmegData(const QString &path); const QPixmap preview(const QString &file); const QImage snapshot(const QString &file, int offset); + const QString appDataDir(); class Duration { public: Duration(); -- cgit v1.2.3-70-g09d2