+ artwork.gfx_current =
+ getTreeInfoFromIdentifier(artwork.gfx_first, setup.graphics_set);
+ if (artwork.gfx_current == NULL)
+ artwork.gfx_current =
+ getTreeInfoFromIdentifier(artwork.gfx_first, GFX_CLASSIC_SUBDIR);
+ if (artwork.gfx_current == NULL)
+ artwork.gfx_current = getFirstValidTreeInfoEntry(artwork.gfx_first);
+
+ artwork.snd_current =
+ getTreeInfoFromIdentifier(artwork.snd_first, setup.sounds_set);
+ if (artwork.snd_current == NULL)
+ artwork.snd_current =
+ getTreeInfoFromIdentifier(artwork.snd_first, SND_CLASSIC_SUBDIR);
+ if (artwork.snd_current == NULL)
+ artwork.snd_current = getFirstValidTreeInfoEntry(artwork.snd_first);
+
+ artwork.mus_current =
+ getTreeInfoFromIdentifier(artwork.mus_first, setup.music_set);
+ if (artwork.mus_current == NULL)
+ artwork.mus_current =
+ getTreeInfoFromIdentifier(artwork.mus_first, MUS_CLASSIC_SUBDIR);
+ if (artwork.mus_current == NULL)
+ artwork.mus_current = getFirstValidTreeInfoEntry(artwork.mus_first);
+
+ artwork.gfx_current_identifier = artwork.gfx_current->identifier;
+ artwork.snd_current_identifier = artwork.snd_current->identifier;
+ artwork.mus_current_identifier = artwork.mus_current->identifier;
+
+#if 0
+ printf("graphics set == %s\n\n", artwork.gfx_current_identifier);
+ printf("sounds set == %s\n\n", artwork.snd_current_identifier);
+ printf("music set == %s\n\n", artwork.mus_current_identifier);
+#endif
+
+ sortTreeInfo(&artwork.gfx_first);
+ sortTreeInfo(&artwork.snd_first);
+ sortTreeInfo(&artwork.mus_first);
+
+#if 0
+ dumpTreeInfo(artwork.gfx_first, 0);
+ dumpTreeInfo(artwork.snd_first, 0);
+ dumpTreeInfo(artwork.mus_first, 0);
+#endif
+}
+
+void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
+ LevelDirTree *level_node)
+{
+ /* recursively check all level directories for artwork sub-directories */
+
+ while (level_node)
+ {
+ /* check all tree entries for artwork, but skip parent link entries */
+ if (!level_node->parent_link)
+ {
+ TreeInfo *topnode_last = *artwork_node;
+ char *path = getPath2(getLevelDirFromTreeInfo(level_node),
+ ARTWORK_DIRECTORY((*artwork_node)->type));
+
+#if 0
+ printf("::: looking in directory '%s' for '%s' ...\n",
+ path, ARTWORK_DIRECTORY((*artwork_node)->type));
+#endif
+
+#if 1
+ char *type_string = ARTWORK_DIRECTORY((*artwork_node)->type);
+ char *identifier = level_node->subdir;
+ char *type_identifier = getStringCat2WithSeparator(type_string,
+ identifier, ".");
+ char *cache_entry = getHashEntry(level_artwork_info_hash,
+ type_identifier);
+ boolean cached = (cache_entry != NULL && strEqual(cache_entry, "true"));
+
+ if (cached)
+ {
+ int i;
+
+ printf("::: LOADING existing hash entry for '%s' ...\n",
+ identifier);
+
+ char *type_dir = ARTWORK_DIRECTORY((*artwork_node)->type);
+ TreeInfo *artwork_new = newTreeInfo();
+
+ setTreeInfoToDefaults(artwork_new, (*artwork_node)->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 = getStringCat3WithSeparator(type_dir, identifier,
+ artworkinfo_tokens[i].text,
+ ".");
+ char *value = getHashEntry(level_artwork_info_hash, token);
+
+ printf("::: - '%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 0
+ if (artwork_new->name_sorting == NULL)
+ {
+ printf("::: BOOOM!\n");
+ exit(10);
+ }
+#endif
+
+ if (cached)
+ pushTreeInfo(artwork_node, artwork_new);
+ else
+ freeTreeInfo(artwork_new);
+ }
+
+ if (!cached)
+ LoadArtworkInfoFromArtworkDir(artwork_node, NULL, path,
+ (*artwork_node)->type);
+#else
+ LoadArtworkInfoFromArtworkDir(artwork_node, NULL, path,
+ (*artwork_node)->type);
+#endif
+
+#if 1
+ if (!cached && topnode_last != *artwork_node)
+#else
+ if (topnode_last != *artwork_node)
+#endif
+ {
+ free((*artwork_node)->identifier);
+ free((*artwork_node)->name);
+ free((*artwork_node)->name_sorting);
+
+ (*artwork_node)->identifier = getStringCopy(level_node->subdir);
+ (*artwork_node)->name = getStringCopy(level_node->name);
+ (*artwork_node)->name_sorting = getStringCopy(level_node->name);
+
+ (*artwork_node)->sort_priority = level_node->sort_priority;
+ (*artwork_node)->color = LEVELCOLOR((*artwork_node));
+
+#if 1
+ {
+ int i;
+
+ printf("::: adding hash entry for set '%s' ...\n", type_identifier);
+
+ setHashEntry(level_artwork_info_hash, type_identifier, "true");
+
+ ldi = **artwork_node;
+ for (i = 0; artworkinfo_tokens[i].type != -1; i++)
+ {
+ char *token = getStringCat2WithSeparator(type_identifier,
+ artworkinfo_tokens[i].text,
+ ".");
+ char *value = getSetupValue(artworkinfo_tokens[i].type,
+ artworkinfo_tokens[i].value);
+ if (value != NULL)
+ {
+ setHashEntry(level_artwork_info_hash, token, value);
+
+ printf("::: - setting '%s' => '%s'\n\n",
+ token, value);
+ }
+
+ if (strEqual(artworkinfo_tokens[i].text, "name_sorting"))
+ printf("::: - '%s' => '%s' => '%s'\n",
+ identifier, token,
+ (*artwork_node)->name_sorting);
+
+ checked_free(token);
+ }
+ }
+#endif
+ }
+
+ free(path);
+ free(type_identifier);
+ }
+
+ if (level_node->node_group != NULL)
+ LoadArtworkInfoFromLevelInfo(artwork_node, level_node->node_group);
+
+ level_node = level_node->next;
+ }
+}
+
+void LoadLevelArtworkInfo()
+{
+ DrawInitText("Looking for custom level artwork:", 120, FC_GREEN);