diskmanager: save configured disk cache location
This commit is contained in:
@@ -39,16 +39,18 @@ DiskManager* DiskManager::instance_ = nullptr;
|
|||||||
DiskManager::DiskManager()
|
DiskManager::DiskManager()
|
||||||
{
|
{
|
||||||
// Add default cache location
|
// Add default cache location
|
||||||
QFile default_disk_cache_file(QDir(FileFunctions::GetConfigurationLocation()).filePath(QStringLiteral("defaultdiskcache")));
|
QFile default_disk_cache_file(GetDefaultDiskCacheConfigFile());
|
||||||
if (default_disk_cache_file.open(QFile::ReadOnly)) {
|
if (default_disk_cache_file.open(QFile::ReadOnly)) {
|
||||||
QString default_dir = default_disk_cache_file.readAll();
|
QString default_dir = default_disk_cache_file.readAll();
|
||||||
|
|
||||||
if (FileFunctions::DirectoryIsValid(default_dir, true)) {
|
if (!default_dir.isEmpty()) {
|
||||||
GetOpenFolder(default_dir);
|
if (FileFunctions::DirectoryIsValid(default_dir, true)) {
|
||||||
} else {
|
GetOpenFolder(default_dir);
|
||||||
QMessageBox::warning(nullptr,
|
} else {
|
||||||
tr("Disk Cache Error"),
|
QMessageBox::warning(nullptr,
|
||||||
tr("Unable to set custom application disk cache. Using default instead."));
|
tr("Disk Cache Error"),
|
||||||
|
tr("Unable to set custom application disk cache. Using default instead."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default_disk_cache_file.close();
|
default_disk_cache_file.close();
|
||||||
@@ -56,7 +58,7 @@ DiskManager::DiskManager()
|
|||||||
|
|
||||||
// If no custom default was loaded, load default
|
// If no custom default was loaded, load default
|
||||||
if (open_folders_.isEmpty()) {
|
if (open_folders_.isEmpty()) {
|
||||||
GetOpenFolder(QDir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("mediacache"));
|
GetOpenFolder(GetDefaultDiskCachePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile disk_cache_index(QDir(FileFunctions::GetConfigurationLocation()).filePath(QStringLiteral("diskcache")));
|
QFile disk_cache_index(QDir(FileFunctions::GetConfigurationLocation()).filePath(QStringLiteral("diskcache")));
|
||||||
@@ -75,6 +77,14 @@ DiskManager::DiskManager()
|
|||||||
|
|
||||||
DiskManager::~DiskManager()
|
DiskManager::~DiskManager()
|
||||||
{
|
{
|
||||||
|
QFile default_disk_cache_file(GetDefaultDiskCacheConfigFile());
|
||||||
|
if (default_disk_cache_file.open(QFile::WriteOnly)) {
|
||||||
|
if (GetDefaultDiskCachePath() != GetDefaultCachePath()) {
|
||||||
|
default_disk_cache_file.write(GetDefaultCachePath().toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
default_disk_cache_file.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiskManager::CreateInstance()
|
void DiskManager::CreateInstance()
|
||||||
@@ -145,6 +155,16 @@ bool DiskManager::ShowDiskCacheChangeConfirmationDialog(QWidget *parent)
|
|||||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok);
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString DiskManager::GetDefaultDiskCacheConfigFile()
|
||||||
|
{
|
||||||
|
return QDir(FileFunctions::GetConfigurationLocation()).filePath(QStringLiteral("defaultdiskcache"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DiskManager::GetDefaultDiskCachePath()
|
||||||
|
{
|
||||||
|
return QDir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("mediacache");
|
||||||
|
}
|
||||||
|
|
||||||
DiskCacheFolder::DiskCacheFolder(const QString &path, QObject *parent) :
|
DiskCacheFolder::DiskCacheFolder(const QString &path, QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -131,6 +131,10 @@ public:
|
|||||||
|
|
||||||
static bool ShowDiskCacheChangeConfirmationDialog(QWidget* parent);
|
static bool ShowDiskCacheChangeConfirmationDialog(QWidget* parent);
|
||||||
|
|
||||||
|
static QString GetDefaultDiskCacheConfigFile();
|
||||||
|
|
||||||
|
static QString GetDefaultDiskCachePath();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void Accessed(const QString& cache_folder, const QByteArray& hash);
|
void Accessed(const QString& cache_folder, const QByteArray& hash);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user