1
- #include " global.h"
1
+ #include " global.h"
2
2
3
3
#include " ImageCache.h"
4
4
#include " Foreach.h"
5
5
#include " PrefsManager.h"
6
+ #include " RageFileManager.h"
6
7
#include " RageDisplay.h"
7
8
#include " RageLog.h"
8
9
#include " RageSurface.h"
14
15
#include " RageTexture.h"
15
16
#include " RageTextureManager.h"
16
17
#include " RageUtil.h"
18
+ #include " CommonMetrics.h"
17
19
#include " SongCacheIndex.h"
18
20
#include " SpecialFiles.h"
19
21
#include " Sprite.h"
@@ -27,6 +29,8 @@ static Preference<bool> g_bPalettedImageCache( "PalettedImageCache", false );
27
29
// const std::string IMAGE_CACHE_INDEX = SpecialFiles::CACHE_DIR + "images.cache";
28
30
#define IMAGE_CACHE_INDEX (SpecialFiles::CACHE_DIR + " images.cache" )
29
31
32
+ #define IMAGE_CACHE_VERSION 1
33
+
30
34
/* Call CacheImage to cache a image by path. If the image is already
31
35
* cached, it'll be recreated. This is efficient if the image hasn't changed,
32
36
* but we still only do this in TidyUpData for songs.
@@ -174,9 +178,36 @@ ImageCache::~ImageCache()
174
178
UnloadAllImages ();
175
179
}
176
180
181
+ static void EmptyDir (RString dir)
182
+ {
183
+ ASSERT (dir[dir.size () - 1 ] == ' /' );
184
+
185
+ vector<RString> asCacheFileNames;
186
+ GetDirListing (dir, asCacheFileNames);
187
+ for (unsigned i = 0 ; i<asCacheFileNames.size (); i++)
188
+ {
189
+ if (!IsADirectory (dir + asCacheFileNames[i]))
190
+ FILEMAN->Remove (dir + asCacheFileNames[i]);
191
+ }
192
+ }
193
+
177
194
void ImageCache::ReadFromDisk ()
178
195
{
179
196
ImageData.ReadFile ( IMAGE_CACHE_INDEX ); // don't care if this fails
197
+
198
+ int iCacheVersion = -1 ;
199
+ ImageData.GetValue (" Cache" , " CacheVersion" , iCacheVersion);
200
+ if (iCacheVersion == IMAGE_CACHE_VERSION)
201
+ return ;
202
+
203
+ LOG->Trace ( " Cache format is out of date. Deleting all cache files." );
204
+ vector<RString> ImageDir;
205
+ split ( CommonMetrics::IMAGES_TO_CACHE, " ," , ImageDir );
206
+ for ( std::string Image : ImageDir )
207
+ EmptyDir ( SpecialFiles::CACHE_DIR+Image+" /" );
208
+
209
+ ImageData.SetValue ( " Cache" , " CacheVersion" , IMAGE_CACHE_VERSION);
210
+ ImageData.WriteFile ( IMAGE_CACHE_INDEX );
180
211
}
181
212
182
213
struct ImageTexture : public RageTexture
0 commit comments