mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 09:04:33 +02:00
add genericcache version setting to TomahawkSettings, check for the cache versions in TomahawkCache/InfossystemCache and delete cache if it is old
This commit is contained in:
@@ -701,9 +701,20 @@ TomahawkSettings::setInfoSystemCacheVersion( uint version )
|
||||
uint
|
||||
TomahawkSettings::infoSystemCacheVersion() const
|
||||
{
|
||||
return value( "infosystemcacheversion", 3 ).toUInt();
|
||||
return value( "infosystemcacheversion", 0 ).toUInt();
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkSettings::setGenericCacheVersion( uint version )
|
||||
{
|
||||
setValue( "genericcacheversion", version );
|
||||
}
|
||||
|
||||
uint
|
||||
TomahawkSettings::genericCacheVersion() const
|
||||
{
|
||||
return value( "genericcacheversion", 0 ).toUInt();
|
||||
}
|
||||
|
||||
QString
|
||||
TomahawkSettings::storageCacheLocation() const
|
||||
|
@@ -60,6 +60,9 @@ public:
|
||||
uint infoSystemCacheVersion() const;
|
||||
void setInfoSystemCacheVersion( uint version );
|
||||
|
||||
uint genericCacheVersion() const;
|
||||
void setGenericCacheVersion( uint version );
|
||||
|
||||
bool watchForChanges() const;
|
||||
void setWatchForChanges( bool watch );
|
||||
|
||||
|
@@ -25,6 +25,10 @@
|
||||
#include "utils/Logger.h"
|
||||
#include "Source.h"
|
||||
|
||||
#if QT_VERSION <= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
#include "utils/TomahawkCache.h"
|
||||
#endif
|
||||
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QCryptographicHash>
|
||||
@@ -42,6 +46,16 @@ InfoSystemCache::InfoSystemCache( QObject* parent )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
|
||||
if ( TomahawkSettings::instance()->infoSystemCacheVersion() < INFOSYSTEM_CACHE_VERSION )
|
||||
{
|
||||
#if QT_VERSION <= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
TomahawkUtils::Cache::instance()->removeDirectoryRecursively( m_cacheBaseDir );
|
||||
#else
|
||||
QDir(m_cacheBaseDir)::removeRecursively();
|
||||
#endif
|
||||
TomahawkSettings::instance()->setInfoSystemCacheVersion( INFOSYSTEM_CACHE_VERSION );
|
||||
}
|
||||
|
||||
m_pruneTimer.setInterval( 300000 );
|
||||
m_pruneTimer.setSingleShot( false );
|
||||
connect( &m_pruneTimer, SIGNAL( timeout() ), SLOT( pruneTimerFired() ) );
|
||||
|
@@ -34,6 +34,8 @@ namespace Tomahawk
|
||||
namespace InfoSystem
|
||||
{
|
||||
|
||||
#define INFOSYSTEM_CACHE_VERSION 4
|
||||
|
||||
class DLLEXPORT InfoSystemCache : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@@ -45,6 +45,16 @@ Cache::Cache()
|
||||
, m_cacheBaseDir( TomahawkSettings::instance()->storageCacheLocation() + "/GenericCache/" )
|
||||
, m_cacheManifest( m_cacheBaseDir + "cachemanifest.ini", QSettings::IniFormat )
|
||||
{
|
||||
if ( TomahawkSettings::instance()->genericCacheVersion() < CACHE_VERSION )
|
||||
{
|
||||
#if QT_VERSION <= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
removeDirectoryRecursively( m_cacheBaseDir );
|
||||
#else
|
||||
QDir( m_cacheBaseDir )::removeRecursively();
|
||||
#endif
|
||||
TomahawkSettings::instance()->setGenericCacheVersion( CACHE_VERSION );
|
||||
}
|
||||
|
||||
m_pruneTimer.setInterval( 300000 );
|
||||
m_pruneTimer.setSingleShot( false );
|
||||
connect( &m_pruneTimer, SIGNAL( timeout() ), SLOT( pruneTimerFired() ) );
|
||||
@@ -116,6 +126,33 @@ Cache::getData( const QString& identifier, const QString& key )
|
||||
}
|
||||
|
||||
|
||||
#if QT_VERSION <= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
bool
|
||||
Cache::removeDirectoryRecursively(const QString& dirName)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
QDir dir(dirName);
|
||||
if (dir.exists(dirName)) {
|
||||
foreach( QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst) ) {
|
||||
if (info.isDir()) {
|
||||
result = removeDirectoryRecursively(info.absoluteFilePath());
|
||||
}
|
||||
else {
|
||||
result = QFile::remove(info.absoluteFilePath());
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
result = dir.rmdir(dirName);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
Cache::putData( const QString& identifier, qint64 maxAge, const QString& key, const QVariant& value )
|
||||
{
|
||||
|
@@ -26,10 +26,13 @@
|
||||
#include <QSettings>
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include <QDir>
|
||||
|
||||
namespace TomahawkUtils
|
||||
{
|
||||
|
||||
#define CACHE_VERSION 1
|
||||
|
||||
/**
|
||||
* Internal data structure. Don't use.
|
||||
*/
|
||||
@@ -78,6 +81,15 @@ public:
|
||||
* @return the data, if found, if not found an invalid QVariant is returned.
|
||||
*/
|
||||
QVariant getData( const QString& identifier, const QString& key );
|
||||
#if QT_VERSION <= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
/**
|
||||
* Recursively deletes all files & directories in a folder
|
||||
* Only needed in Qt4
|
||||
* @param dirName the directory which should be deleted
|
||||
* @return if the removal was successfull or not
|
||||
*/
|
||||
bool removeDirectoryRecursively( const QString& dirName );
|
||||
#endif
|
||||
|
||||
private slots:
|
||||
void pruneTimerFired();
|
||||
|
Reference in New Issue
Block a user