diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 50b744ca9a..d577e0a4d2 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -20,6 +20,7 @@ #include "MsdFile.h" #include "RageSoundStream.h" #include "RageException.h" +#include "SongCacheIndex.h" const int FILE_CACHE_VERSION = 61; // increment this when Song or Notes changes to invalidate cache @@ -292,25 +293,7 @@ bool Song::LoadFromSongDir( CString sDir ) // // First look in the cache for this song (without loading NoteData) // - IniFile ini; - ini.SetPath( "Cache\\index.cache" ); - if( !ini.ReadFile() ) - goto load_without_cache; - - int iCacheVersion; - ini.GetValueI( "Cache", "CacheVersion", iCacheVersion ); - if( iCacheVersion != FILE_CACHE_VERSION ) - { - LOG->Trace( "Cache format is out of date. Deleting all cache files." ); - CStringArray asCacheFileNames; - GetDirListing( "Cache\\*.*", asCacheFileNames ); - for( int i=0; iGetCacheHash(m_sSongDir); if( GetHashForDirectory(m_sSongDir) == iDirHash ) // this cache is up to date { if( !DoesFileExist(GetCacheFilePath()) ) @@ -1237,16 +1220,7 @@ void Song::SaveToCacheFile() { LOG->Trace( "Song::SaveToCacheFile()" ); - // - // First look in the cache for this song (without loading NoteData) - // - IniFile ini; - ini.SetPath( "Cache\\index.cache" ); - ini.ReadFile(); // don't care if this fails - - ini.SetValueI( "Cache", "CacheVersion", FILE_CACHE_VERSION ); - ini.SetValueI( "Cache", m_sSongDir, GetHashForDirectory(m_sSongDir) ); - ini.WriteFile(); + SONGINDEX->AddCacheIndex(m_sSongDir, GetHashForDirectory(m_sSongDir)); SaveToSMFile( GetCacheFilePath() ); } diff --git a/stepmania/src/SongCacheIndex.cpp b/stepmania/src/SongCacheIndex.cpp new file mode 100644 index 0000000000..ce31771dc3 --- /dev/null +++ b/stepmania/src/SongCacheIndex.cpp @@ -0,0 +1,48 @@ +#include "SongCacheIndex.h" +#include "RageLog.h" +#include "RageUtil.h" +#include "Song.h" + +SongCacheIndex *SONGINDEX; + +SongCacheIndex::SongCacheIndex() +{ + CacheIndex.SetPath( "Cache\\index.cache" ); + ReadCacheIndex(); +} + +SongCacheIndex::~SongCacheIndex() +{ + +} + +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." ); + CStringArray asCacheFileNames; + GetDirListing( "Cache/*.*", asCacheFileNames ); + for( int i=0; i