-/* -------------------------------------------------------------------------
- Zip cache support
- ------------------------------------------------------------------------- */
-
-/* Use the zip cache */
-// No, don't
-//#define ZIP_CACHE
-
-#ifdef ZIP_CACHE
-
-/* ZIP cache entries */
-#define ZIP_CACHE_MAX 5
-
-/* ZIP cache buffer LRU ( Last Recently Used )
- zip_cache_map[0] is the newer
- zip_cache_map[ZIP_CACHE_MAX-1] is the older
-*/
-static ZIP* zip_cache_map[ZIP_CACHE_MAX];
-
-static ZIP* cache_openzip(int pathtype, int pathindex, const char* zipfile) {
- ZIP* zip;
- unsigned i;
-
- /* search in the cache buffer */
- for(i=0;i<ZIP_CACHE_MAX;++i) {
- if (zip_cache_map[i] && zip_cache_map[i]->pathtype == pathtype && zip_cache_map[i]->pathindex == pathindex && strcmp(zip_cache_map[i]->zip,zipfile)==0) {
- /* found */
- unsigned j;
-
-/*
- WriteLog("Zip cache HIT for %s\n", zipfile);
-*/
-
- /* reset the zip directory */
- rewindzip( zip_cache_map[i] );
-
- /* store */
- zip = zip_cache_map[i];
-
- /* shift */
- for(j=i;j>0;--j)
- zip_cache_map[j] = zip_cache_map[j-1];
-
- /* set the first entry */
- zip_cache_map[0] = zip;
-
- return zip_cache_map[0];
- }
- }
- /* not found */
-
-/*
- WriteLog("Zip cache FAIL for %s\n", zipfile);
-*/
-
- /* open the zip */
- zip = openzip( pathtype, pathindex, zipfile );
- if (!zip)
- return 0;
-
- /* close the oldest entry */
- if (zip_cache_map[ZIP_CACHE_MAX-1]) {
- /* close last zip */
- closezip(zip_cache_map[ZIP_CACHE_MAX-1]);
- /* reset the entry */
- zip_cache_map[ZIP_CACHE_MAX-1] = 0;
- }
-
- /* shift */
- for(i=ZIP_CACHE_MAX-1;i>0;--i)
- zip_cache_map[i] = zip_cache_map[i-1];
-
- /* set the first entry */
- zip_cache_map[0] = zip;
-
- return zip_cache_map[0];
-}
-
-static void cache_closezip(ZIP* zip) {
- unsigned i;
-
- /* search in the cache buffer */
- for(i=0;i<ZIP_CACHE_MAX;++i) {
- if (zip_cache_map[i]==zip) {
- /* close zip */
- closezip(zip);
-
- /* reset cache entry */
- zip_cache_map[i] = 0;
- return;
-
- }
- }
- /* not found */
-
- /* close zip */
- closezip(zip);
-}
-
-/* CK980415 added to allow osd code to clear zip cache for auditing--each time
- the user opens up an audit for a game we should reread the zip */
-void unzip_cache_clear()
-{
- unsigned i;
-
- /* search in the cache buffer for any zip info and clear it */
- for(i=0;i<ZIP_CACHE_MAX;++i) {
- if (zip_cache_map[i] != NULL) {
- /* close zip */
- closezip(zip_cache_map[i]);
-
- /* reset cache entry */
- zip_cache_map[i] = 0;
-/* return; */
-
- }
- }
-}
-
-#define cache_suspendzip(a) suspendzip(a)
-
-#else
-
-#define cache_openzip(a,b,c) openzip(a,b,c)
-#define cache_closezip(a) closezip(a)
-#define cache_suspendzip(a) closezip(a)
-
-#define unzip_cache_clear()
-
-#endif
-