Skip to content

Commit f3b6bdc

Browse files
JouswayMinaciousGrace
authored andcommitted
Fixing imagecache (etternagame#194)
1 parent 657d713 commit f3b6bdc

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/ImageCache.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#include "global.h"
1+
#include "global.h"
22

33
#include "ImageCache.h"
44
#include "Foreach.h"
55
#include "PrefsManager.h"
6+
#include "RageFileManager.h"
67
#include "RageDisplay.h"
78
#include "RageLog.h"
89
#include "RageSurface.h"
@@ -14,6 +15,7 @@
1415
#include "RageTexture.h"
1516
#include "RageTextureManager.h"
1617
#include "RageUtil.h"
18+
#include "CommonMetrics.h"
1719
#include "SongCacheIndex.h"
1820
#include "SpecialFiles.h"
1921
#include "Sprite.h"
@@ -27,6 +29,8 @@ static Preference<bool> g_bPalettedImageCache( "PalettedImageCache", false );
2729
//const std::string IMAGE_CACHE_INDEX = SpecialFiles::CACHE_DIR + "images.cache";
2830
#define IMAGE_CACHE_INDEX (SpecialFiles::CACHE_DIR + "images.cache")
2931

32+
#define IMAGE_CACHE_VERSION 1
33+
3034
/* Call CacheImage to cache a image by path. If the image is already
3135
* cached, it'll be recreated. This is efficient if the image hasn't changed,
3236
* but we still only do this in TidyUpData for songs.
@@ -174,9 +178,36 @@ ImageCache::~ImageCache()
174178
UnloadAllImages();
175179
}
176180

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+
177194
void ImageCache::ReadFromDisk()
178195
{
179196
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 );
180211
}
181212

182213
struct ImageTexture: public RageTexture

src/SongCacheIndex.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* path; we don't have to actually look in the directory (to find out the directory hash)
3737
* in order to find the cache file.
3838
*/
39-
const string CACHE_INDEX = SpecialFiles::CACHE_DIR + "index.cache";
39+
const string CACHE_INDEX = SpecialFiles::CACHE_DIR + "images.cache";
4040
const string CACHE_DB = SpecialFiles::CACHE_DIR + "cache.db";
4141
const unsigned int CACHE_DB_VERSION = 236;
4242

@@ -714,33 +714,31 @@ static void EmptyDir(RString dir)
714714

715715
void SongCacheIndex::ReadCacheIndex()
716716
{
717-
CacheIndex.ReadFile(CACHE_INDEX); // don't care if this fails
717+
return;
718+
/*CacheIndex.ReadFile(CACHE_INDEX); // don't care if this fails
718719
719720
int iCacheVersion = -1;
720721
CacheIndex.GetValue("Cache", "CacheVersion", iCacheVersion);
721722
if (iCacheVersion == FILE_CACHE_VERSION)
722723
return; // OK
723724
724725
LOG->Trace( "Cache format is out of date. Deleting all cache files." );
726+
EmptyDir(SpecialFiles::CACHE_DIR + "Banners/");
725727
EmptyDir( SpecialFiles::CACHE_DIR+"Songs/" );
726728
EmptyDir( SpecialFiles::CACHE_DIR+"Courses/" );
727729
728-
729-
// comment out until we stop being really bad at dealing with cache versions (revisit asap) - mina
730-
/*
731730
vector<RString> ImageDir;
732731
split( CommonMetrics::IMAGES_TO_CACHE, ",", ImageDir );
733732
for( std::string Image : ImageDir )
734-
EmptyDir( SpecialFiles::CACHE_DIR+Image+"/" );
735-
*/
733+
EmptyDir( SpecialFiles::CACHE_DIR+Image+"/" );*/
736734

737-
CacheIndex.Clear();
735+
//CacheIndex.Clear();
738736
/* This is right now in place because our song file paths are apparently being
739737
* cached in two distinct areas, and songs were loading from paths in FILEMAN.
740738
* This is admittedly a hack for now, but this does bring up a good question on
741739
* whether we really need a dedicated cache for future versions of StepMania.
742740
*/
743-
FILEMAN->FlushDirCache();
741+
//FILEMAN->FlushDirCache();
744742
}
745743

746744
void SongCacheIndex::SaveCacheIndex()

0 commit comments

Comments
 (0)