#include "global.h" #include #include #include "SongCacheIndex.h" #include "RageLog.h" #include "RageUtil.h" #include "song.h" #include "arch/arch.h" #define CACHE_DIR BASE_PATH "Cache" SLASH SongCacheIndex *SONGINDEX; SongCacheIndex::SongCacheIndex() { CreateDirectories( CACHE_DIR "Songs" ); CacheIndex.SetPath( CACHE_DIR "index.cache" ); ReadCacheIndex(); } SongCacheIndex::~SongCacheIndex() { } static void EmptyDir( CString dir ) { #ifdef _XBOX ASSERT(dir[dir.size()-1] == '\\'); #else ASSERT(dir[dir.size()-1] == '/'); #endif CStringArray asCacheFileNames; GetDirListing( dir, asCacheFileNames ); for( unsigned i=0; iTrace( "Cache format is out of date. Deleting all cache files." ); EmptyDir( CACHE_DIR ); EmptyDir( CACHE_DIR "Banners" SLASH ); EmptyDir( CACHE_DIR "Songs" SLASH ); CacheIndex.Reset(); } void SongCacheIndex::AddCacheIndex(const CString &path, unsigned hash) { CacheIndex.SetValue( "Cache", "CacheVersion", FILE_CACHE_VERSION ); CacheIndex.SetValue( "Cache", MangleName(path), hash ); CacheIndex.WriteFile(); } unsigned SongCacheIndex::GetCacheHash( const CString &path ) const { unsigned iDirHash; 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; }