+
+/* -------------------------------------------------------------------------- */
+/* functions for handling custom artwork info cache */
+/* -------------------------------------------------------------------------- */
+
+#define ARTWORKINFO_CACHE_FILENAME "cache.conf"
+
+static void LoadArtworkInfoCache()
+{
+ if (artworkinfo_hash == NULL)
+ {
+ char *filename = getPath2(getSetupDir(), ARTWORKINFO_CACHE_FILENAME);
+
+ /* try to load artwork info hash from already existing cache file */
+ artworkinfo_hash = loadSetupFileHash(filename);
+
+ /* if no artwork info cache file was found, start with empty hash */
+ if (artworkinfo_hash == NULL)
+ artworkinfo_hash = newSetupFileHash();
+
+ free(filename);
+ }
+}
+
+static void SaveArtworkInfoCache()
+{
+ char *filename = getPath2(getSetupDir(), ARTWORKINFO_CACHE_FILENAME);
+
+ saveSetupFileHash(artworkinfo_hash, filename);
+
+ free(filename);
+}
+
+static TreeInfo *getArtworkInfoFromCache(char *identifier, int type)
+{
+ char *type_string = ARTWORK_DIRECTORY(type);
+ char *token_prefix = getStringCat2WithSeparator(type_string, identifier, ".");
+ char *cache_entry = getHashEntry(artworkinfo_hash, token_prefix);
+ boolean cached = (cache_entry != NULL && strEqual(cache_entry, "true"));
+ TreeInfo *artwork_new = NULL;
+
+ if (cached)
+ {
+ int i;
+
+ printf("::: LOADING existing hash entry for '%s' ...\n", identifier);
+
+ artwork_new = newTreeInfo();
+ setTreeInfoToDefaults(artwork_new, type);
+
+ /* set all structure fields according to the token/value pairs */
+ ldi = *artwork_new;
+ for (i = 0; artworkinfo_tokens[i].type != -1; i++)
+ {
+ char *token = getStringCat2WithSeparator(token_prefix,
+ artworkinfo_tokens[i].text, ".");
+ char *value = getHashEntry(artworkinfo_hash, token);
+
+ printf("::: - setting '%s' => '%s'\n", token, value);
+
+ setSetupInfo(artworkinfo_tokens, i, value);
+
+ /* check if cache entry for this item is invalid or incomplete */
+ if (value == NULL)
+ {
+ printf("::: - WARNING: cache entry '%s' invalid\n", token);
+
+ cached = FALSE;
+ }
+
+ checked_free(token);
+ }
+ *artwork_new = ldi;
+
+ if (!cached)
+ freeTreeInfo(artwork_new);
+ }
+
+ free(token_prefix);
+
+ return artwork_new;
+}
+
+
+/* -------------------------------------------------------------------------- */
+/* functions for loading level info and custom artwork info */
+/* -------------------------------------------------------------------------- */
+