Files
itgmania212121/stepmania/src/SongCacheIndex.cpp
T

83 lines
1.7 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"
2003-12-10 09:02:55 +00:00
#define CACHE_DIR "Cache/"
SongCacheIndex *SONGINDEX;
SongCacheIndex::SongCacheIndex()
{
2003-07-22 07:47:27 +00:00
CacheIndex.SetPath( CACHE_DIR "index.cache" );
ReadCacheIndex();
}
SongCacheIndex::~SongCacheIndex()
{
}
static void EmptyDir( CString dir )
{
2003-11-13 00:39:36 +00:00
#ifdef _XBOX
ASSERT(dir[dir.size()-1] == '\\');
#else
ASSERT(dir[dir.size()-1] == '/');
2003-11-13 00:39:36 +00:00
#endif
2003-12-07 04:16:10 +00:00
/* XXX RageFile */
CStringArray asCacheFileNames;
GetDirListing( dir, asCacheFileNames );
for( unsigned i=0; i<asCacheFileNames.size(); i++ )
{
if( !IsADirectory(dir + asCacheFileNames[i]) )
remove( dir + asCacheFileNames[i] );
}
}
void SongCacheIndex::ReadCacheIndex()
{
CacheIndex.ReadFile(); // don't care if this fails
int iCacheVersion;
2003-10-02 02:03:29 +00:00
CacheIndex.GetValue( "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)
{
2003-10-02 02:11:47 +00:00
CacheIndex.SetValue( "Cache", "CacheVersion", FILE_CACHE_VERSION );
CacheIndex.SetValue( "Cache", MangleName(path), hash );
CacheIndex.WriteFile();
}
unsigned SongCacheIndex::GetCacheHash( const CString &path ) const
{
unsigned iDirHash;
2003-10-02 02:03:29 +00:00
CacheIndex.GetValue( "Cache", MangleName(path), iDirHash );
return iDirHash;
}
CString SongCacheIndex::MangleName( const CString &Name )
{
/* We store paths in an INI. We can't store '='. */
CString ret = Name;
ret.Replace( "=", "");
return ret;
}