diff --git a/src/ImageCache.cpp b/src/ImageCache.cpp index a11c17e3d7..e7e7a7555b 100644 --- a/src/ImageCache.cpp +++ b/src/ImageCache.cpp @@ -1,8 +1,9 @@ -#include "global.h" +#include "global.h" #include "ImageCache.h" #include "Foreach.h" #include "PrefsManager.h" +#include "RageFileManager.h" #include "RageDisplay.h" #include "RageLog.h" #include "RageSurface.h" @@ -14,6 +15,7 @@ #include "RageTexture.h" #include "RageTextureManager.h" #include "RageUtil.h" +#include "CommonMetrics.h" #include "SongCacheIndex.h" #include "SpecialFiles.h" #include "Sprite.h" @@ -27,6 +29,8 @@ static Preference g_bPalettedImageCache( "PalettedImageCache", false ); //const std::string IMAGE_CACHE_INDEX = SpecialFiles::CACHE_DIR + "images.cache"; #define IMAGE_CACHE_INDEX (SpecialFiles::CACHE_DIR + "images.cache") +#define IMAGE_CACHE_VERSION 1 + /* Call CacheImage to cache a image by path. If the image is already * cached, it'll be recreated. This is efficient if the image hasn't changed, * but we still only do this in TidyUpData for songs. @@ -174,9 +178,36 @@ ImageCache::~ImageCache() UnloadAllImages(); } +static void EmptyDir(RString dir) +{ + ASSERT(dir[dir.size() - 1] == '/'); + + vector asCacheFileNames; + GetDirListing(dir, asCacheFileNames); + for (unsigned i = 0; iRemove(dir + asCacheFileNames[i]); + } +} + void ImageCache::ReadFromDisk() { ImageData.ReadFile( IMAGE_CACHE_INDEX ); // don't care if this fails + + int iCacheVersion = -1; + ImageData.GetValue("Cache", "CacheVersion", iCacheVersion); + if (iCacheVersion == IMAGE_CACHE_VERSION) + return; + + LOG->Trace( "Cache format is out of date. Deleting all cache files." ); + vector ImageDir; + split( CommonMetrics::IMAGES_TO_CACHE, ",", ImageDir ); + for( std::string Image : ImageDir ) + EmptyDir( SpecialFiles::CACHE_DIR+Image+"/" ); + + ImageData.SetValue( "Cache", "CacheVersion", IMAGE_CACHE_VERSION); + ImageData.WriteFile( IMAGE_CACHE_INDEX ); } struct ImageTexture: public RageTexture diff --git a/src/SongCacheIndex.cpp b/src/SongCacheIndex.cpp index 38491007b7..b6220d5c80 100644 --- a/src/SongCacheIndex.cpp +++ b/src/SongCacheIndex.cpp @@ -36,7 +36,7 @@ * path; we don't have to actually look in the directory (to find out the directory hash) * in order to find the cache file. */ -const string CACHE_INDEX = SpecialFiles::CACHE_DIR + "index.cache"; +const string CACHE_INDEX = SpecialFiles::CACHE_DIR + "images.cache"; const string CACHE_DB = SpecialFiles::CACHE_DIR + "cache.db"; const unsigned int CACHE_DB_VERSION = 236; @@ -714,7 +714,8 @@ static void EmptyDir(RString dir) void SongCacheIndex::ReadCacheIndex() { - CacheIndex.ReadFile(CACHE_INDEX); // don't care if this fails + return; + /*CacheIndex.ReadFile(CACHE_INDEX); // don't care if this fails int iCacheVersion = -1; CacheIndex.GetValue("Cache", "CacheVersion", iCacheVersion); @@ -722,25 +723,22 @@ void SongCacheIndex::ReadCacheIndex() return; // OK LOG->Trace( "Cache format is out of date. Deleting all cache files." ); + EmptyDir(SpecialFiles::CACHE_DIR + "Banners/"); EmptyDir( SpecialFiles::CACHE_DIR+"Songs/" ); EmptyDir( SpecialFiles::CACHE_DIR+"Courses/" ); - - // comment out until we stop being really bad at dealing with cache versions (revisit asap) - mina - /* vector ImageDir; split( CommonMetrics::IMAGES_TO_CACHE, ",", ImageDir ); for( std::string Image : ImageDir ) - EmptyDir( SpecialFiles::CACHE_DIR+Image+"/" ); - */ + EmptyDir( SpecialFiles::CACHE_DIR+Image+"/" );*/ - CacheIndex.Clear(); + //CacheIndex.Clear(); /* This is right now in place because our song file paths are apparently being * cached in two distinct areas, and songs were loading from paths in FILEMAN. * This is admittedly a hack for now, but this does bring up a good question on * whether we really need a dedicated cache for future versions of StepMania. */ - FILEMAN->FlushDirCache(); + //FILEMAN->FlushDirCache(); } void SongCacheIndex::SaveCacheIndex()