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>
|
|
|
|
|
|
2002-08-21 02:13:08 +00:00
|
|
|
#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/"
|
2002-08-21 02:13:08 +00:00
|
|
|
|
|
|
|
|
SongCacheIndex *SONGINDEX;
|
|
|
|
|
|
|
|
|
|
SongCacheIndex::SongCacheIndex()
|
|
|
|
|
{
|
2003-07-22 07:47:27 +00:00
|
|
|
CacheIndex.SetPath( CACHE_DIR "index.cache" );
|
2002-08-21 02:13:08 +00:00
|
|
|
ReadCacheIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SongCacheIndex::~SongCacheIndex()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-04 20:36:38 +00:00
|
|
|
static void EmptyDir( CString dir )
|
|
|
|
|
{
|
2003-11-13 00:39:36 +00:00
|
|
|
#ifdef _XBOX
|
|
|
|
|
ASSERT(dir[dir.size()-1] == '\\');
|
|
|
|
|
#else
|
2003-06-04 20:36:38 +00:00
|
|
|
ASSERT(dir[dir.size()-1] == '/');
|
2003-11-13 00:39:36 +00:00
|
|
|
#endif
|
2003-06-04 20:36:38 +00:00
|
|
|
|
2003-12-07 04:16:10 +00:00
|
|
|
/* XXX RageFile */
|
2003-06-04 20:36:38 +00:00
|
|
|
CStringArray asCacheFileNames;
|
|
|
|
|
GetDirListing( dir, asCacheFileNames );
|
|
|
|
|
for( unsigned i=0; i<asCacheFileNames.size(); i++ )
|
2003-11-04 06:51:28 +00:00
|
|
|
{
|
|
|
|
|
if( !IsADirectory(dir + asCacheFileNames[i]) )
|
|
|
|
|
remove( dir + asCacheFileNames[i] );
|
|
|
|
|
}
|
2003-06-04 20:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-21 02:13:08 +00:00
|
|
|
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 );
|
2002-08-21 02:13:08 +00:00
|
|
|
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 );
|
2003-05-29 17:21:58 +00:00
|
|
|
|
2002-08-21 02:13:08 +00:00
|
|
|
CacheIndex.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 19:36:54 +00:00
|
|
|
void SongCacheIndex::AddCacheIndex(const CString &path, unsigned hash)
|
2002-08-21 02:13:08 +00:00
|
|
|
{
|
2003-10-02 02:11:47 +00:00
|
|
|
CacheIndex.SetValue( "Cache", "CacheVersion", FILE_CACHE_VERSION );
|
|
|
|
|
CacheIndex.SetValue( "Cache", MangleName(path), hash );
|
2002-08-21 02:13:08 +00:00
|
|
|
CacheIndex.WriteFile();
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 19:36:54 +00:00
|
|
|
unsigned SongCacheIndex::GetCacheHash( const CString &path ) const
|
2002-08-21 02:13:08 +00:00
|
|
|
{
|
2003-05-22 19:36:54 +00:00
|
|
|
unsigned iDirHash;
|
2003-10-02 02:03:29 +00:00
|
|
|
CacheIndex.GetValue( "Cache", MangleName(path), iDirHash );
|
2002-08-21 02:13:08 +00:00
|
|
|
return iDirHash;
|
|
|
|
|
}
|
2003-09-16 05:16:57 +00:00
|
|
|
|
|
|
|
|
CString SongCacheIndex::MangleName( const CString &Name )
|
|
|
|
|
{
|
|
|
|
|
/* We store paths in an INI. We can't store '='. */
|
|
|
|
|
CString ret = Name;
|
|
|
|
|
ret.Replace( "=", "");
|
|
|
|
|
return ret;
|
|
|
|
|
}
|