Add ability to customize cache folder

Add an advanced settings page, currently only housing the "Cache" category

Fix #541
This commit is contained in:
Rasmus Karlsson
2018-08-19 16:20:14 +02:00
parent 3fc91bded5
commit a07255be2d
9 changed files with 133 additions and 14 deletions
+24 -1
View File
@@ -1,5 +1,7 @@
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDir>
@@ -33,6 +35,27 @@ bool Paths::isPortable()
return this->portable_.get();
}
QString Paths::cacheDirectory()
{
static QStringSetting cachePathSetting = [] {
QStringSetting cachePathSetting("/cache/path");
cachePathSetting.connect([](const auto &newPath, auto) {
QDir().mkpath(newPath); //
});
return cachePathSetting;
}();
auto path = cachePathSetting.getValue();
if (path == "") {
return this->cacheDirectory_;
}
return path;
}
void Paths::initAppFilePathHash()
{
this->applicationFilePathHash =
@@ -104,7 +127,7 @@ void Paths::initSubDirectories()
makePath("");
this->settingsDirectory = makePath("Settings");
this->cacheDirectory = makePath("Cache");
this->cacheDirectory_ = makePath("Cache");
this->messageLogDirectory = makePath("Logs");
this->miscDirectory = makePath("Misc");
}
+5 -3
View File
@@ -19,9 +19,6 @@ public:
// Directory for settings files. Same as <appDataDirectory>/Settings
QString settingsDirectory;
// Directory for cache files. Same as <appDataDirectory>/Misc
QString cacheDirectory;
// Directory for message log files. Same as <appDataDirectory>/Misc
QString messageLogDirectory;
@@ -34,6 +31,8 @@ public:
bool createFolder(const QString &folderPath);
bool isPortable();
QString cacheDirectory();
private:
void initAppFilePathHash();
void initCheckPortable();
@@ -41,6 +40,9 @@ private:
void initSubDirectories();
boost::optional<bool> portable_;
// Directory for cache files. Same as <appDataDirectory>/Misc
QString cacheDirectory_;
};
Paths *getPaths();
+2
View File
@@ -153,6 +153,8 @@ public:
IntSetting startUpNotification = {"/misc/startUpNotification", 0};
QStringSetting currentVersion = {"/misc/currentVersion", ""};
QStringSetting cachePath = {"/cache/path", ""};
void saveSnapshot();
void restoreSnapshot();