+ if (artwork.gfx_first == NULL)
+ artwork.gfx_first = getDummyArtworkInfo(TREE_TYPE_GRAPHICS_DIR);
+ if (artwork.snd_first == NULL)
+ artwork.snd_first = getDummyArtworkInfo(TREE_TYPE_SOUNDS_DIR);
+ if (artwork.mus_first == NULL)
+ artwork.mus_first = getDummyArtworkInfo(TREE_TYPE_MUSIC_DIR);
+
+ /* before sorting, the first entries will be from the user directory */
+ 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, compareTreeInfoEntries);
+ sortTreeInfo(&artwork.snd_first, compareTreeInfoEntries);
+ sortTreeInfo(&artwork.mus_first, compareTreeInfoEntries);
+
+#if 0
+ dumpTreeInfo(artwork.gfx_first, 0);
+ dumpTreeInfo(artwork.snd_first, 0);
+ dumpTreeInfo(artwork.mus_first, 0);
+#endif
+}
+
+void LoadArtworkInfoFromLevelNode(ArtworkDirTree **artwork_node,
+ LevelDirTree *level_node,
+ char *artwork_directory)
+{
+ TreeInfo *topnode_last = *artwork_node;
+ char *path = getPath2(getLevelDirFromTreeInfo(level_node), artwork_directory);
+
+#if 1
+ printf("::: CHECKING '%s' ...\n", path);
+#endif
+
+ LoadArtworkInfoFromArtworkDir(artwork_node, NULL, path,(*artwork_node)->type);
+
+ if (topnode_last != *artwork_node)
+ {
+ 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));
+ }
+
+ free(path);
+}
+
+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)
+ {
+#if 1
+ struct
+ {
+ int type;
+ char *dir;
+ }
+ artwork_type_dirs[] =
+ {
+ { ARTWORK_TYPE_GRAPHICS, GRAPHICS_DIRECTORY },
+ { ARTWORK_TYPE_GRAPHICS, GRAPHICS_ECS_DIRECTORY },
+ { ARTWORK_TYPE_GRAPHICS, GRAPHICS_AGA_DIRECTORY },
+ { ARTWORK_TYPE_SOUNDS, SOUNDS_DIRECTORY },
+ { ARTWORK_TYPE_MUSIC, MUSIC_DIRECTORY },
+ { -1, NULL }
+ };
+ int i;
+
+ for (i = 0; artwork_type_dirs[i].type != -1; i++)
+ if ((*artwork_node)->type == artwork_type_dirs[i].type)
+ LoadArtworkInfoFromLevelNode(artwork_node, level_node,
+ artwork_type_dirs[i].dir);
+#else
+ TreeInfo *topnode_last = *artwork_node;
+ char *path = getPath2(getLevelDirFromTreeInfo(level_node),
+ ARTWORK_DIRECTORY((*artwork_node)->type));
+
+ LoadArtworkInfoFromArtworkDir(artwork_node, NULL, path,
+ (*artwork_node)->type);
+
+ if (topnode_last != *artwork_node)
+ {
+ 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));
+ }
+
+ free(path);
+#endif
+ }
+
+ 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);
+
+ LoadArtworkInfoFromLevelInfo(&artwork.gfx_first, leveldir_first_all);
+ LoadArtworkInfoFromLevelInfo(&artwork.snd_first, leveldir_first_all);
+ LoadArtworkInfoFromLevelInfo(&artwork.mus_first, leveldir_first_all);
+
+ /* needed for reloading level artwork not known at ealier stage */
+
+ if (strcmp(artwork.gfx_current_identifier, setup.graphics_set) != 0)
+ {
+ 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);
+ }
+
+ if (strcmp(artwork.snd_current_identifier, setup.sounds_set) != 0)
+ {
+ 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);
+ }
+
+ if (strcmp(artwork.mus_current_identifier, setup.music_set) != 0)
+ {
+ 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);
+ }