From 026903bbd1fbb268cfe2da074f74f6e4868b5210 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 14 Jun 2003 23:30:21 +0000 Subject: [PATCH] add UncacheSongBanner --- stepmania/src/BannerCache.cpp | 33 ++++++++++++++++++++++++++++++++- stepmania/src/BannerCache.h | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/stepmania/src/BannerCache.cpp b/stepmania/src/BannerCache.cpp index e651ee3295..98eb449dc7 100644 --- a/stepmania/src/BannerCache.cpp +++ b/stepmania/src/BannerCache.cpp @@ -24,7 +24,17 @@ * TEXTUREMAN->IsTextureRegistered() on the ID; it might not be if the banner cache * is missing or disabled. */ - + +/* TODO: A way to purge banners. Right now, if you move songs around, their + * banners will be re-cached with their new hash, but the old cache will never + * be removed and will still be loaded. I don't want loading to be dependent on + * songs, since I want to be able to put banners into an archive easily later. + * Instead, purge banners later, after we load songs. We can do this fast, since + * the banner hash is based only on the banner filename. + * + * We don't need to embed the banner modification time into the hash: it's already + * in the main song cache, so if it changes, the whole song will be re-cached. */ + BannerCache *BANNERCACHE; @@ -244,6 +254,27 @@ static inline int closest( int num, int n1, int n2 ) return n1; } +/* Erase the cache for a path. UNTESTED */ +void BannerCache::UncacheSongBanner( CString BannerPath ) +{ + const CString CachePath = GetBannerCachePath( BannerPath ); + + /* If the image is loaded, free it. */ + if( m_BannerPathToImage.find(BannerPath) != m_BannerPathToImage.end() ) + { + SDL_Surface *img = m_BannerPathToImage[BannerPath]; + SDL_FreeSurface( img ); + m_BannerPathToImage.erase(BannerPath); + } + + /* Remove the image from the INI. */ + BannerData.DeleteKey( BannerPath ); + BannerData.WriteFile(); + + /* Erase the cache file. */ + remove( CachePath.c_str() ); +} + /* We write the cache even if we won't use it, so we don't have to recache everything * if the memory or settings change. */ void BannerCache::CacheSongBanner( CString BannerPath ) diff --git a/stepmania/src/BannerCache.h b/stepmania/src/BannerCache.h index 389efc3739..9cb2330f14 100644 --- a/stepmania/src/BannerCache.h +++ b/stepmania/src/BannerCache.h @@ -21,6 +21,7 @@ public: RageTextureID LoadCachedSongBanner( CString BannerPath ); void CacheSongBanner( CString BannerPath ); + void UncacheSongBanner( CString BannerPath ); }; extern BannerCache *BANNERCACHE; // global and accessable from anywhere in our program