Files
itgmania212121/stepmania/src/SongCacheIndex.cpp
T

68 lines
1.5 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-08-23 00:57:48 +00:00
2003-02-14 06:59:56 +00:00
#include <sys/stat.h>
#include <sys/types.h>
#include "SongCacheIndex.h"
#include "RageLog.h"
#include "RageUtil.h"
2003-02-16 04:28:17 +00:00
#include "song.h"
2003-07-22 07:47:27 +00:00
#include "arch/arch.h"
#define CACHE_DIR BASE_PATH "Cache" SLASH
SongCacheIndex *SONGINDEX;
SongCacheIndex::SongCacheIndex()
{
2003-07-22 07:47:27 +00:00
CreateDirectories( CACHE_DIR "Songs" );
CacheIndex.SetPath( CACHE_DIR "index.cache" );
ReadCacheIndex();
}
SongCacheIndex::~SongCacheIndex()
{
}
static void EmptyDir( CString dir )
{
ASSERT(dir[dir.size()-1] == '/');
CStringArray asCacheFileNames;
GetDirListing( dir, asCacheFileNames );
for( unsigned i=0; i<asCacheFileNames.size(); i++ )
remove( dir + asCacheFileNames[i] );
}
void SongCacheIndex::ReadCacheIndex()
{
CacheIndex.ReadFile(); // don't care if this fails
int iCacheVersion;
CacheIndex.GetValueI( "Cache", "CacheVersion", iCacheVersion );
if( iCacheVersion == FILE_CACHE_VERSION )
return; /* OK */
LOG->Trace( "Cache format is out of date. Deleting all cache files." );
2003-07-22 07:47:27 +00:00
EmptyDir( CACHE_DIR );
EmptyDir( CACHE_DIR "Banners" SLASH );
EmptyDir( CACHE_DIR "Songs" SLASH );
CacheIndex.Reset();
}
void SongCacheIndex::AddCacheIndex(const CString &path, unsigned hash)
{
CacheIndex.SetValueI( "Cache", "CacheVersion", FILE_CACHE_VERSION );
CacheIndex.SetValueU( "Cache", path, hash );
CacheIndex.WriteFile();
}
unsigned SongCacheIndex::GetCacheHash( const CString &path ) const
{
unsigned iDirHash;
CacheIndex.GetValueU( "Cache", path, iDirHash );
return iDirHash;
}