X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=5ce14db2245335eb9b72044ba3171e7442cf5a66;hb=b81f28710057e7d84528b65b92e9b4d1aaadab6c;hp=edfa4d35502891929c4a6cdbb1d50a515688b0bc;hpb=bcb3453f710b95ec98b188b95574bea9ab336e96;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index edfa4d35..5ce14db2 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -79,10 +79,32 @@ static char *levelclass_desc[NUM_LEVELCLASS_DESC] = IS_LEVELCLASS_USER(n) ? 7 : \ 9) -#define TOKEN_VALUE_POSITION 30 +#define TOKEN_VALUE_POSITION 40 +#define TOKEN_COMMENT_POSITION 60 #define MAX_COOKIE_LEN 256 +#define ARTWORKINFO_FILENAME(type) ((type) == TREE_TYPE_GRAPHICS_DIR ? \ + GRAPHICSINFO_FILENAME : \ + (type) == TREE_TYPE_SOUNDS_DIR ? \ + SOUNDSINFO_FILENAME : \ + (type) == TREE_TYPE_MUSIC_DIR ? \ + MUSICINFO_FILENAME : "") + +#define ARTWORK_DIRECTORY(type) ((type) == TREE_TYPE_GRAPHICS_DIR ? \ + GRAPHICS_DIRECTORY : \ + (type) == TREE_TYPE_SOUNDS_DIR ? \ + SOUNDS_DIRECTORY : \ + (type) == TREE_TYPE_MUSIC_DIR ? \ + MUSIC_DIRECTORY : "") + +#define OPTIONS_ARTWORK_DIRECTORY(type) ((type) == TREE_TYPE_GRAPHICS_DIR ? \ + options.graphics_directory : \ + (type) == TREE_TYPE_SOUNDS_DIR ? \ + options.sounds_directory : \ + (type) == TREE_TYPE_MUSIC_DIR ? \ + options.music_directory : "") + /* ------------------------------------------------------------------------- */ /* file functions */ @@ -166,53 +188,98 @@ static char *getLevelSetupDir(char *level_subdir) return levelsetup_dir; } -static char *getUserGraphicsDir(char *graphics_subdir) +static char *getLevelDirFromTreeInfo(TreeInfo *node) { - static char *usergraphics_dir = NULL; - char *data_dir = getUserDataDir(); - char *usergraphics_subdir = GRAPHICS_DIRECTORY; + static char *level_dir = NULL; - if (usergraphics_dir) - free(usergraphics_dir); + if (node == NULL) + return options.level_directory; - if (graphics_subdir != NULL) - usergraphics_dir = getPath3(data_dir, usergraphics_subdir,graphics_subdir); - else - usergraphics_dir = getPath2(data_dir, usergraphics_subdir); + if (level_dir) + free(level_dir); + + level_dir = getPath2((node->user_defined ? getUserLevelDir(NULL) : + options.level_directory), node->fullpath); + + return level_dir; +} + +static char *getCurrentLevelDir() +{ + return getLevelDirFromTreeInfo(leveldir_current); +} + +static char *getDefaultGraphicsDir(char *graphics_subdir) +{ + static char *graphics_dir = NULL; + + if (graphics_subdir == NULL) + return options.graphics_directory; + + if (graphics_dir) + free(graphics_dir); + + graphics_dir = getPath2(options.graphics_directory, graphics_subdir); + + return graphics_dir; +} + +static char *getDefaultSoundsDir(char *sounds_subdir) +{ + static char *sounds_dir = NULL; + + if (sounds_subdir == NULL) + return options.sounds_directory; + + if (sounds_dir) + free(sounds_dir); + + sounds_dir = getPath2(options.sounds_directory, sounds_subdir); + + return sounds_dir; +} + +static char *getDefaultMusicDir(char *music_subdir) +{ + static char *music_dir = NULL; + + if (music_subdir == NULL) + return options.music_directory; + + if (music_dir) + free(music_dir); + + music_dir = getPath2(options.music_directory, music_subdir); + + return music_dir; +} + +static char *getUserGraphicsDir() +{ + static char *usergraphics_dir = NULL; + + if (usergraphics_dir == NULL) + usergraphics_dir = getPath2(getUserDataDir(), GRAPHICS_DIRECTORY); return usergraphics_dir; } -static char *getUserSoundsDir(char *sounds_subdir) +static char *getUserSoundsDir() { static char *usersounds_dir = NULL; - char *data_dir = getUserDataDir(); - char *usersounds_subdir = SOUNDS_DIRECTORY; - - if (usersounds_dir) - free(usersounds_dir); - if (sounds_subdir != NULL) - usersounds_dir = getPath3(data_dir, usersounds_subdir,sounds_subdir); - else - usersounds_dir = getPath2(data_dir, usersounds_subdir); + if (usersounds_dir == NULL) + usersounds_dir = getPath2(getUserDataDir(), SOUNDS_DIRECTORY); return usersounds_dir; } -static char *getUserMusicDir(char *music_subdir) +static char *getUserMusicDir() { static char *usermusic_dir = NULL; - char *data_dir = getUserDataDir(); - char *usermusic_subdir = MUSIC_DIRECTORY; - - if (usermusic_dir) - free(usermusic_dir); - if (music_subdir != NULL) - usermusic_dir = getPath3(data_dir, usermusic_subdir,music_subdir); - else - usermusic_dir = getPath2(data_dir, usermusic_subdir); + if (usermusic_dir == NULL) + usermusic_dir = getPath2(getUserDataDir(), MUSIC_DIRECTORY); return usermusic_dir; } @@ -226,11 +293,7 @@ char *getLevelFilename(int nr) free(filename); sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION); - filename = getPath3((leveldir_current->user_defined ? - getUserLevelDir(NULL) : - options.level_directory), - leveldir_current->fullpath, - basename); + filename = getPath2(getCurrentLevelDir(), basename); return filename; } @@ -275,7 +338,19 @@ char *getSetupFilename() return filename; } -static char *getImageBasename(char *basename) +static char *getSetupArtworkDir(TreeInfo *ti) +{ + static char *artwork_dir = NULL; + + if (artwork_dir != NULL) + free(artwork_dir); + + artwork_dir = getPath2(ti->basepath, ti->fullpath); + + return artwork_dir; +} + +static char *getCorrectedImageBasename(char *basename) { char *result = basename; @@ -292,34 +367,119 @@ static char *getImageBasename(char *basename) return result; } -char *getImageFilename(char *basename) +static boolean fileExists(char *filename) +{ +#if 0 + printf("checking file '%s'\n", filename); +#endif + + return (access(filename, F_OK) == 0); +} + +char *getCustomImageFilename(char *basename) { static char *filename = NULL; if (filename != NULL) free(filename); - filename = getPath2(options.graphics_directory, getImageBasename(basename)); + basename = getCorrectedImageBasename(basename); - return filename; + if (!setup.override_level_graphics) + { + /* 1st try: look for special artwork in current level series directory */ + filename = getPath3(getCurrentLevelDir(), GRAPHICS_DIRECTORY, basename); + if (fileExists(filename)) + return filename; + } + + /* 2nd try: look for special artwork in configured artwork directory */ + filename = getPath2(getSetupArtworkDir(artwork.gfx_current), basename); + if (fileExists(filename)) + return filename; + + /* 3rd try: look for default artwork in new default artwork directory */ + filename = getPath2(getDefaultGraphicsDir(GRAPHICS_SUBDIR), basename); + if (fileExists(filename)) + return filename; + + /* 4th try: look for default artwork in old default artwork directory */ + filename = getPath2(options.graphics_directory, basename); + if (fileExists(filename)) + return filename; + + return NULL; /* cannot find specified artwork file anywhere */ } -char *getCustomImageFilename(char *basename) +char *getCustomSoundFilename(char *basename) { -#if 0 - if (strcmp(basename, "RocksFont.pcx") == 0) + static char *filename = NULL; + + if (filename != NULL) + free(filename); + + if (!setup.override_level_sounds) { - char *dir = options.graphics_directory; + /* 1st try: look for special artwork in current level series directory */ + filename = getPath3(getCurrentLevelDir(), SOUNDS_DIRECTORY, basename); + if (fileExists(filename)) + return filename; + } + + /* 2nd try: look for special artwork in configured artwork directory */ + filename = getPath2(getSetupArtworkDir(artwork.snd_current), basename); + if (fileExists(filename)) + return filename; + + /* 3rd try: look for default artwork in new default artwork directory */ + filename = getPath2(getDefaultSoundsDir(SOUNDS_SUBDIR), basename); + if (fileExists(filename)) + return filename; + + /* 4th try: look for default artwork in old default artwork directory */ + filename = getPath2(options.sounds_directory, basename); + if (fileExists(filename)) + return filename; - printf("checking directory '%s' ...\n", dir); + return NULL; /* cannot find specified artwork file anywhere */ +} + +char *getCustomSoundConfigFilename() +{ + return getCustomSoundFilename(SOUNDSINFO_FILENAME); +} + +char *getCustomMusicDirectory(void) +{ + static char *directory = NULL; + + if (directory != NULL) + free(directory); - /* - dir = getPath2(options.graphics_directory); - */ + if (!setup.override_level_music) + { + /* 1st try: look for special artwork in current level series directory */ + directory = getPath2(getCurrentLevelDir(), MUSIC_DIRECTORY); + if (fileExists(directory)) + return directory; } -#endif - return getImageFilename(basename); + /* 2nd try: look for special artwork in configured artwork directory */ + directory = getStringCopy(getSetupArtworkDir(artwork.mus_current)); + if (fileExists(directory)) + return directory; + + /* 3rd try: look for default artwork in new default artwork directory */ + directory = getStringCopy(getDefaultMusicDir(MUSIC_SUBDIR)); + if (fileExists(directory)) + return directory; + + /* 4th try: look for default artwork in old default artwork directory */ + directory = getStringCopy(options.music_directory); + if (fileExists(directory)) + return directory; + + return NULL; /* cannot find specified artwork file anywhere */ } void InitTapeDirectory(char *level_subdir) @@ -434,23 +594,23 @@ boolean validLevelSeries(TreeInfo *node) return (node != NULL && !node->node_group && !node->parent_link); } -TreeInfo *getFirstValidLevelSeries(TreeInfo *node) +TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *node) { if (node == NULL) { - if (leveldir_first) /* start with first level directory entry */ - return getFirstValidLevelSeries(leveldir_first); + if (node->node_top) /* start with first tree entry */ + return getFirstValidTreeInfoEntry(*node->node_top); else return NULL; } else if (node->node_group) /* enter level group (step down into tree) */ - return getFirstValidLevelSeries(node->node_group); + return getFirstValidTreeInfoEntry(node->node_group); else if (node->parent_link) /* skip start entry of level group */ { if (node->next) /* get first real level series entry */ - return getFirstValidLevelSeries(node->next); + return getFirstValidTreeInfoEntry(node->next); else /* leave empty level group and go on */ - return getFirstValidLevelSeries(node->node_parent->next); + return getFirstValidTreeInfoEntry(node->node_parent->next); } else /* this seems to be a regular level series */ return node; @@ -462,7 +622,7 @@ TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *node) return NULL; if (node->node_parent == NULL) /* top level group */ - return leveldir_first; + return *node->node_top; else /* sub level group */ return node->node_parent->node_group; } @@ -534,21 +694,24 @@ TreeInfo *getTreeInfoFromFilenameExt(TreeInfo *node, char *filename) return NULL; } -TreeInfo *getTreeInfoFromFilename(char *filename) +TreeInfo *getTreeInfoFromFilename(TreeInfo *ti, char *filename) { - return getTreeInfoFromFilenameExt(leveldir_first, filename); + return getTreeInfoFromFilenameExt(ti, filename); } void dumpTreeInfo(TreeInfo *node, int depth) { int i; + printf("Dumping TreeInfo:\n"); + while (node) { - for (i=0; ifilename, node->name); + printf("filename == '%s' (%s) [%s]\n", + node->filename, node->name, node->name_short); if (node->node_group != NULL) dumpTreeInfo(node->node_group, depth + 1); @@ -841,11 +1004,12 @@ char *getFormattedSetupEntry(char *token, char *value) int i; static char entry[MAX_LINE_LEN]; + /* start with the token and some spaces to format output line */ sprintf(entry, "%s:", token); for (i=strlen(entry); itype = type; + + ldi->node_top = (ldi->type == TREE_TYPE_LEVEL_DIR ? &leveldir_first : + ldi->type == TREE_TYPE_GRAPHICS_DIR ? &artwork.gfx_first : + ldi->type == TREE_TYPE_SOUNDS_DIR ? &artwork.snd_first : + ldi->type == TREE_TYPE_MUSIC_DIR ? &artwork.mus_first : + NULL); + ldi->node_parent = NULL; ldi->node_group = NULL; ldi->next = NULL; @@ -1083,8 +1255,6 @@ static void setTreeInfoToDefaults(TreeInfo *ldi) ldi->cl_first = -1; ldi->cl_cursor = -1; - ldi->type = TREE_TYPE_GENERIC; - ldi->filename = NULL; ldi->fullpath = NULL; ldi->basepath = NULL; @@ -1092,26 +1262,32 @@ static void setTreeInfoToDefaults(TreeInfo *ldi) ldi->name_short = NULL; ldi->name_sorting = NULL; ldi->author = getStringCopy(ANONYMOUS_NAME); - ldi->imported_from = NULL; - ldi->levels = 0; - ldi->first_level = 0; - ldi->last_level = 0; + ldi->sort_priority = LEVELCLASS_UNDEFINED; /* default: least priority */ - ldi->level_group = FALSE; ldi->parent_link = FALSE; ldi->user_defined = FALSE; - ldi->readonly = TRUE; ldi->color = 0; ldi->class_desc = NULL; - ldi->handicap_level = 0; + + if (ldi->type == TREE_TYPE_LEVEL_DIR) + { + ldi->imported_from = NULL; + ldi->levels = 0; + ldi->first_level = 0; + ldi->last_level = 0; + ldi->level_group = FALSE; + ldi->handicap_level = 0; + ldi->readonly = TRUE; + } } -static void setTreeInfoToDefaultsFromParent(TreeInfo *ldi, - TreeInfo *parent) +static void setTreeInfoToDefaultsFromParent(TreeInfo *ldi, TreeInfo *parent) { if (parent == NULL) { - setTreeInfoToDefaults(ldi); + Error(ERR_WARN, "setTreeInfoToDefaultsFromParent(): parent == NULL"); + + setTreeInfoToDefaults(ldi, TREE_TYPE_GENERIC); return; } @@ -1137,6 +1313,7 @@ static void setTreeInfoToDefaultsFromParent(TreeInfo *ldi, ldi->level_group = FALSE; ldi->parent_link = FALSE; + ldi->node_top = parent->node_top; ldi->node_parent = parent; ldi->node_group = NULL; ldi->next = NULL; @@ -1210,24 +1387,28 @@ static int compareTreeInfoEntries(const void *object1, const void *object2) static void createParentTreeInfoNode(TreeInfo *node_parent) { - TreeInfo *leveldir_new = newTreeInfo(); + TreeInfo *ti_new; - setTreeInfoToDefaults(leveldir_new); + if (node_parent == NULL) + return; - leveldir_new->node_parent = node_parent; - leveldir_new->parent_link = TRUE; + ti_new = newTreeInfo(); + setTreeInfoToDefaults(ti_new, node_parent->type); - leveldir_new->name = ".. (parent directory)"; - leveldir_new->name_short = getStringCopy(leveldir_new->name); - leveldir_new->name_sorting = getStringCopy(leveldir_new->name); + ti_new->node_parent = node_parent; + ti_new->parent_link = TRUE; - leveldir_new->filename = ".."; - leveldir_new->fullpath = getStringCopy(node_parent->fullpath); + ti_new->name = ".. (parent directory)"; + ti_new->name_short = getStringCopy(ti_new->name); + ti_new->name_sorting = getStringCopy(ti_new->name); - leveldir_new->sort_priority = node_parent->sort_priority; - leveldir_new->class_desc = getLevelClassDescription(leveldir_new); + ti_new->filename = ".."; + ti_new->fullpath = getStringCopy(node_parent->fullpath); - pushTreeInfo(&node_parent->node_group, leveldir_new); + ti_new->sort_priority = node_parent->sort_priority; + ti_new->class_desc = getLevelClassDescription(ti_new); + + pushTreeInfo(&node_parent->node_group, ti_new); } /* forward declaration for recursive call by "LoadLevelInfoFromLevelDir()" */ @@ -1246,7 +1427,7 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, if (setup_file_list == NULL) { - Error(ERR_WARN, "ignoring level directory '%s'", level_directory); + Error(ERR_WARN, "ignoring level directory '%s'", directory_path); free(directory_path); free(filename); @@ -1256,8 +1437,12 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, leveldir_new = newTreeInfo(); + if (node_parent) + setTreeInfoToDefaultsFromParent(leveldir_new, node_parent); + else + setTreeInfoToDefaults(leveldir_new, TREE_TYPE_LEVEL_DIR); + checkSetupFileListIdentifier(setup_file_list, getCookie("LEVELINFO")); - setTreeInfoToDefaultsFromParent(leveldir_new, node_parent); /* set all structure fields according to the token/value pairs */ ldi = *leveldir_new; @@ -1266,6 +1451,12 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, getTokenValue(setup_file_list, levelinfo_tokens[i].text)); *leveldir_new = ldi; + if (strcmp(leveldir_new->name, ANONYMOUS_NAME) == 0) + { + free(leveldir_new->name); + leveldir_new->name = getStringCopy(leveldir_new->filename); + } + DrawInitText(leveldir_new->name, 150, FC_YELLOW); if (leveldir_new->name_short == NULL) @@ -1362,6 +1553,11 @@ static void LoadLevelInfoFromLevelDir(TreeInfo **node_first, free(directory_path); + if (strcmp(directory_name, GRAPHICS_DIRECTORY) == 0 || + strcmp(directory_name, SOUNDS_DIRECTORY) == 0 || + strcmp(directory_name, MUSIC_DIRECTORY) == 0) + continue; + valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent, level_directory, directory_name); @@ -1390,7 +1586,8 @@ void LoadLevelInfo() LoadLevelInfoFromLevelDir(&leveldir_first, NULL, options.level_directory); LoadLevelInfoFromLevelDir(&leveldir_first, NULL, getUserLevelDir(NULL)); - leveldir_current = getFirstValidLevelSeries(leveldir_first); + /* before sorting, the first entries will be from the user directory */ + leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); if (leveldir_first == NULL) Error(ERR_EXIT, "cannot find any valid level series in any directory"); @@ -1402,27 +1599,19 @@ void LoadLevelInfo() #endif } -/* declaration for recursive call by "LoadArtworkInfoFromArtworkConf()" */ -static void LoadArtworkInfoFromArtworkDir(TreeInfo **, TreeInfo *, char *,int); - static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, TreeInfo *node_parent, char *base_directory, char *directory_name, int type) { char *directory_path = getPath2(base_directory, directory_name); - char *filename = - getPath2(directory_path, - (type == TREE_TYPE_GRAPHICS_DIR ? GRAPHICSINFO_FILENAME : - type == TREE_TYPE_SOUNDS_DIR ? SOUNDSINFO_FILENAME : - type == TREE_TYPE_MUSIC_DIR ? MUSICINFO_FILENAME : "")); + char *filename = getPath2(directory_path, ARTWORKINFO_FILENAME(type)); struct SetupFileList *setup_file_list = NULL; TreeInfo *artwork_new = NULL; - char *check_dir = NULL; int i; - if (access(getUserLevelDir(filename), F_OK) == 0) /* file exists */ - loadSetupFileList(filename); + if (access(filename, F_OK) == 0) /* file exists */ + setup_file_list = loadSetupFileList(filename); if (setup_file_list == NULL) /* no config file -- look for artwork files */ { @@ -1430,15 +1619,13 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, struct dirent *dir_entry; boolean valid_file_found = FALSE; - if ((dir = opendir(base_directory)) != NULL) + if ((dir = opendir(directory_path)) != NULL) { while ((dir_entry = readdir(dir)) != NULL) { char *entry_name = dir_entry->d_name; - if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(entry_name)) || - (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(entry_name)) || - (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(entry_name))) + if (FileIsArtworkType(entry_name, type)) { valid_file_found = TRUE; break; @@ -1450,7 +1637,8 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, if (!valid_file_found) { - Error(ERR_WARN, "ignoring artwork directory '%s'", base_directory); + if (strcmp(directory_name, ".") != 0) + Error(ERR_WARN, "ignoring artwork directory '%s'", directory_path); free(directory_path); free(filename); @@ -1460,11 +1648,15 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, } artwork_new = newTreeInfo(); - setTreeInfoToDefaultsFromParent(artwork_new, node_parent); + + if (node_parent) + setTreeInfoToDefaultsFromParent(artwork_new, node_parent); + else + setTreeInfoToDefaults(artwork_new, type); artwork_new->filename = getStringCopy(directory_name); - if (setup_file_list) + if (setup_file_list) /* (before defining ".color" and ".class_desc") */ { #if 0 checkSetupFileListIdentifier(setup_file_list, getCookie("...")); @@ -1477,6 +1669,12 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, getTokenValue(setup_file_list, levelinfo_tokens[i].text)); *artwork_new = ldi; + if (strcmp(artwork_new->name, ANONYMOUS_NAME) == 0) + { + free(artwork_new->name); + artwork_new->name = getStringCopy(artwork_new->filename); + } + DrawInitText(artwork_new->name, 150, FC_YELLOW); if (artwork_new->name_short == NULL) @@ -1485,41 +1683,52 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, if (artwork_new->name_sorting == NULL) artwork_new->name_sorting = getStringCopy(artwork_new->name); } - else - { - if (artwork_new->name != NULL) - free(artwork_new->name); - - if (strcmp(artwork_new->filename, ".") == 0) - artwork_new->name = getStringCopy("default"); - else - artwork_new->name = getStringCopy(artwork_new->filename); - - artwork_new->name_short = getStringCopy(artwork_new->name); - artwork_new->name_sorting = getStringCopy(artwork_new->name); - } if (node_parent == NULL) /* top level group */ { - artwork_new->basepath = base_directory; - artwork_new->fullpath = artwork_new->filename; + artwork_new->basepath = getStringCopy(base_directory); + artwork_new->fullpath = getStringCopy(artwork_new->filename); } else /* sub level group */ { - artwork_new->basepath = node_parent->basepath; + artwork_new->basepath = getStringCopy(node_parent->basepath); artwork_new->fullpath = getPath2(node_parent->fullpath, directory_name); } - check_dir = (type == TREE_TYPE_GRAPHICS_DIR ? options.graphics_directory : - type == TREE_TYPE_SOUNDS_DIR ? options.sounds_directory : - type == TREE_TYPE_MUSIC_DIR ? options.music_directory : ""); artwork_new->user_defined = - (artwork_new->basepath == check_dir ? FALSE : TRUE); + (artwork_new->basepath == OPTIONS_ARTWORK_DIRECTORY(type) ? FALSE : TRUE); -#if 0 + /* (may use ".sort_priority" from "setup_file_list" above) */ artwork_new->color = LEVELCOLOR(artwork_new); artwork_new->class_desc = getLevelClassDescription(artwork_new); -#endif + + if (setup_file_list == NULL) /* (after determining ".user_defined") */ + { + if (artwork_new->name != NULL) + free(artwork_new->name); + + if (strcmp(artwork_new->filename, ".") == 0) + { + if (artwork_new->user_defined) + { + artwork_new->name = getStringCopy("private"); + artwork_new->sort_priority = LEVELCLASS_USER; + } + else + { + artwork_new->name = getStringCopy("classic"); + artwork_new->sort_priority = LEVELCLASS_CLASSICS; + } + + artwork_new->color = LEVELCOLOR(artwork_new); + artwork_new->class_desc = getLevelClassDescription(artwork_new); + } + else + artwork_new->name = getStringCopy(artwork_new->filename); + + artwork_new->name_short = getStringCopy(artwork_new->name); + artwork_new->name_sorting = getStringCopy(artwork_new->name); + } pushTreeInfo(node_first, artwork_new); @@ -1541,12 +1750,7 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, if ((dir = opendir(base_directory)) == NULL) { - if ((type == TREE_TYPE_GRAPHICS_DIR && - base_directory == options.graphics_directory) || - (type == TREE_TYPE_SOUNDS_DIR && - base_directory == options.sounds_directory) || - (type == TREE_TYPE_MUSIC_DIR && - base_directory == options.music_directory)) + if (base_directory == OPTIONS_ARTWORK_DIRECTORY(type)) Error(ERR_WARN, "cannot read directory '%s'", base_directory); return; } @@ -1575,6 +1779,7 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, free(directory_path); + /* check if this directory contains artwork with or without config file */ valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent, base_directory, directory_name, type); @@ -1582,14 +1787,10 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, closedir(dir); - if (!valid_entry_found) - { - /* check if this directory directly contains an artwork config file */ - valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent, - base_directory, ".", - type); - } - + /* check if this directory directly contains artwork itself */ + valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent, + base_directory, ".", + type); if (!valid_entry_found) Error(ERR_WARN, "cannot find any valid artwork in directory '%s'", base_directory); @@ -1603,26 +1804,48 @@ void LoadArtworkInfo() options.graphics_directory, TREE_TYPE_GRAPHICS_DIR); LoadArtworkInfoFromArtworkDir(&artwork.gfx_first, NULL, - getUserGraphicsDir(NULL), + getUserGraphicsDir(), TREE_TYPE_GRAPHICS_DIR); LoadArtworkInfoFromArtworkDir(&artwork.snd_first, NULL, options.sounds_directory, TREE_TYPE_SOUNDS_DIR); LoadArtworkInfoFromArtworkDir(&artwork.snd_first, NULL, - getUserSoundsDir(NULL), + getUserSoundsDir(), TREE_TYPE_SOUNDS_DIR); LoadArtworkInfoFromArtworkDir(&artwork.mus_first, NULL, options.music_directory, TREE_TYPE_MUSIC_DIR); LoadArtworkInfoFromArtworkDir(&artwork.mus_first, NULL, - getUserMusicDir(NULL), + getUserMusicDir(), TREE_TYPE_MUSIC_DIR); - artwork.gfx_current = artwork.gfx_first; - artwork.snd_current = artwork.snd_first; - artwork.mus_current = artwork.mus_first; + /* before sorting, the first entries will be from the user directory */ + artwork.gfx_current = + getTreeInfoFromFilename(artwork.gfx_first, setup.graphics_set); + if (artwork.gfx_current == NULL) + artwork.gfx_current = getFirstValidTreeInfoEntry(artwork.gfx_first); + + artwork.snd_current = + getTreeInfoFromFilename(artwork.snd_first, setup.sounds_set); + if (artwork.snd_current == NULL) + artwork.snd_current = getFirstValidTreeInfoEntry(artwork.snd_first); + + artwork.mus_current = + getTreeInfoFromFilename(artwork.mus_first, setup.music_set); + if (artwork.mus_current == NULL) + artwork.mus_current = getFirstValidTreeInfoEntry(artwork.mus_first); + + artwork.graphics_set_current_name = artwork.gfx_current->name; + artwork.sounds_set_current_name = artwork.snd_current->name; + artwork.music_set_current_name = artwork.mus_current->name; + +#if 0 + printf("graphics set == %s\n\n", artwork.graphics_set_current_name); + printf("sounds set == %s\n\n", artwork.sounds_set_current_name); + printf("music set == %s\n\n", artwork.music_set_current_name); +#endif sortTreeInfo(&artwork.gfx_first, compareTreeInfoEntries); sortTreeInfo(&artwork.snd_first, compareTreeInfoEntries); @@ -1635,6 +1858,72 @@ void LoadArtworkInfo() #endif } +void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node, + LevelDirTree *level_node) +{ + /* recursively check all level directories for artwork sub-directories */ + + while (level_node) + { + char *path = getPath2(getLevelDirFromTreeInfo(level_node), + ARTWORK_DIRECTORY((*artwork_node)->type)); + +#if 0 + if (!level_node->parent_link) + printf("CHECKING '%s' ['%s', '%s'] ...\n", path, + level_node->filename, level_node->name); +#endif + + if (!level_node->parent_link) + { + TreeInfo *topnode_last = *artwork_node; + + LoadArtworkInfoFromArtworkDir(artwork_node, NULL, path, + (*artwork_node)->type); + + if (topnode_last != *artwork_node) + { + free((*artwork_node)->name); + free((*artwork_node)->name_sorting); + free((*artwork_node)->name_short); + + (*artwork_node)->name = getStringCopy(level_node->name); + (*artwork_node)->name_sorting = getStringCopy(level_node->name); + (*artwork_node)->name_short = getStringCopy(level_node->filename); + + (*artwork_node)->sort_priority = level_node->sort_priority; + (*artwork_node)->color = LEVELCOLOR((*artwork_node)); + } + } + + free(path); + + 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); + LoadArtworkInfoFromLevelInfo(&artwork.snd_first, leveldir_first); + LoadArtworkInfoFromLevelInfo(&artwork.mus_first, leveldir_first); + + sortTreeInfo(&artwork.gfx_first, compareTreeInfoEntries); + sortTreeInfo(&artwork.snd_first, compareTreeInfoEntries); + sortTreeInfo(&artwork.mus_first, compareTreeInfoEntries); + +#if 1 + dumpTreeInfo(artwork.gfx_first, 0); + dumpTreeInfo(artwork.snd_first, 0); + dumpTreeInfo(artwork.mus_first, 0); +#endif +} + static void SaveUserLevelInfo() { char *filename; @@ -1651,7 +1940,7 @@ static void SaveUserLevelInfo() } /* always start with reliable default values */ - setTreeInfoToDefaults(&ldi); + setTreeInfoToDefaults(&ldi, TREE_TYPE_LEVEL_DIR); ldi.name = getLoginName(); ldi.author = getRealName(); @@ -1679,6 +1968,9 @@ char *getSetupValue(int type, void *value) { static char value_string[MAX_LINE_LEN]; + if (value == NULL) + return NULL; + switch (type) { case TYPE_BOOLEAN: @@ -1720,19 +2012,18 @@ char *getSetupValue(int type, void *value) char *getSetupLine(struct TokenInfo *token_info, char *prefix, int token_nr) { int i; - static char entry[MAX_LINE_LEN]; + char *line; + static char token_string[MAX_LINE_LEN]; int token_type = token_info[token_nr].type; void *setup_value = token_info[token_nr].value; char *token_text = token_info[token_nr].text; char *value_string = getSetupValue(token_type, setup_value); - /* start with the prefix, token and some spaces to format output line */ - sprintf(entry, "%s%s:", prefix, token_text); - for (i=strlen(entry); i/levelsetup.conf */ @@ -1773,9 +2066,10 @@ void LoadLevelSetup_LastSeries() char *last_level_series = getTokenValue(level_setup_list, TOKEN_STR_LAST_LEVEL_SERIES); - leveldir_current = getTreeInfoFromFilename(last_level_series); + leveldir_current = getTreeInfoFromFilename(leveldir_first, + last_level_series); if (leveldir_current == NULL) - leveldir_current = leveldir_first; + leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); checkSetupFileListIdentifier(level_setup_list, getCookie("LEVELSETUP"));