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
return levelsetup_dir;
}
-static char *getUserGraphicsDir(char *graphics_subdir)
+static char *getCurrentLevelDir()
{
- 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 (level_dir)
+ free(level_dir);
- if (graphics_subdir != NULL)
- usergraphics_dir = getPath3(data_dir, usergraphics_subdir,graphics_subdir);
- else
- usergraphics_dir = getPath2(data_dir, usergraphics_subdir);
+ if (leveldir_current == NULL)
+ return options.level_directory;
+
+ level_dir = getPath2((leveldir_current->user_defined ?
+ getUserLevelDir(NULL) : options.level_directory),
+ leveldir_current->fullpath);
+
+ return level_dir;
+}
+
+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;
}
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;
}
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;
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;
+ /* 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 private artwork directory */
+ filename = getPath2(getUserGraphicsDir(), basename);
+ if (fileExists(filename))
+ return filename;
+
+ /* 3rd try: look for special artwork in configured artwork directory */
+ filename = getPath2(getSetupArtworkDir(artwork.gfx_current), basename);
+ if (fileExists(filename))
+ return filename;
+
+ /* 4th try: look for default artwork in new default artwork directory */
+ filename = getPath2(getDefaultGraphicsDir(GRAPHICS_SUBDIR), basename);
+ if (fileExists(filename))
+ return filename;
+
+ /* 5th 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 image file */
}
-char *getCustomImageFilename(char *basename)
+char *getCustomSoundFilename(char *basename)
{
-#if 0
- if (strcmp(basename, "RocksFont.pcx") == 0)
- {
- char *dir = options.graphics_directory;
+ static char *filename = NULL;
+
+ if (filename != NULL)
+ free(filename);
- printf("checking directory '%s' ...\n", dir);
+ /* 1st try: look for special artwork in current level series directory */
+ filename = getPath3(getCurrentLevelDir(), SOUNDS_DIRECTORY, basename);
+ if (fileExists(filename))
+ return filename;
- /*
- dir = getPath2(options.graphics_directory);
- */
- }
-#endif
+ /* 2nd try: look for special artwork in private artwork directory */
+ filename = getPath2(getUserSoundsDir(), basename);
+ if (fileExists(filename))
+ return filename;
- return getImageFilename(basename);
+ /* 3rd try: look for special artwork in configured artwork directory */
+ filename = getPath2(getSetupArtworkDir(artwork.snd_current), basename);
+ if (fileExists(filename))
+ return filename;
+
+ /* 4th try: look for default artwork in new default artwork directory */
+ filename = getPath2(getDefaultSoundsDir(SOUNDS_SUBDIR), basename);
+ if (fileExists(filename))
+ return filename;
+
+ /* 5th try: look for default artwork in old default artwork directory */
+ filename = getPath2(options.sounds_directory, basename);
+ if (fileExists(filename))
+ return filename;
+
+ return NULL; /* cannot find image file */
+}
+
+char *getCustomSoundConfigFilename()
+{
+ return getCustomSoundFilename(SOUNDSINFO_FILENAME);
+}
+
+char *getCustomMusicDirectory(void)
+{
+ static char *directory = NULL;
+
+ if (directory != NULL)
+ free(directory);
+
+ /* 1st try: look for special artwork in current level series directory */
+ directory = getPath2(getCurrentLevelDir(), MUSIC_DIRECTORY);
+ if (fileExists(directory))
+ return directory;
+
+ /* 2nd try: look for special artwork in private artwork directory */
+ directory = getStringCopy(getUserMusicDir());
+ if (fileExists(directory))
+ return directory;
+
+ /* 3rd try: look for special artwork in configured artwork directory */
+ directory = getStringCopy(getSetupArtworkDir(artwork.mus_current));
+ if (fileExists(directory))
+ return directory;
+
+ /* 4th try: look for default artwork in new default artwork directory */
+ directory = getStringCopy(getDefaultMusicDir(MUSIC_SUBDIR));
+ if (fileExists(directory))
+ return directory;
+
+ /* 5th try: look for default artwork in old default artwork directory */
+ directory = getStringCopy(options.music_directory);
+ if (fileExists(directory))
+ return directory;
+
+ return NULL; /* cannot find image file */
}
void InitTapeDirectory(char *level_subdir)
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;
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); i<TOKEN_VALUE_POSITION; i++)
- entry[i] = ' ';
- entry[i] = '\0';
+ strcat(entry, " ");
+ /* continue with the token's value */
strcat(entry, value);
return entry;
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");
char *check_dir = NULL;
int i;
- if (access(getUserLevelDir(filename), F_OK) == 0) /* file exists */
+ if (access(filename, F_OK) == 0) /* file exists */
loadSetupFileList(filename);
if (setup_file_list == NULL) /* no config file -- look for artwork files */
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)
{
if (!valid_file_found)
{
- Error(ERR_WARN, "ignoring artwork directory '%s'", base_directory);
+ if (options.debug)
+ Error(ERR_WARN, "ignoring artwork directory '%s'", base_directory);
free(directory_path);
free(filename);
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);
}
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);
/* before sorting, the first entries will be from the user directory */
- artwork.gfx_current = artwork.gfx_first;
- artwork.snd_current = artwork.snd_first;
- artwork.mus_current = artwork.mus_first;
+ 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 = artwork.gfx_current->name;
+ artwork.sounds_set_current = artwork.snd_current->name;
+ artwork.music_set_current = artwork.mus_current->name;
+
+#if 0
+ printf("graphics set == %s\n\n", artwork.graphics_set_current);
+ printf("sounds set == %s\n\n", artwork.sounds_set_current);
+ printf("music set == %s\n\n", artwork.music_set_current);
+#endif
sortTreeInfo(&artwork.gfx_first, compareTreeInfoEntries);
sortTreeInfo(&artwork.snd_first, compareTreeInfoEntries);
sortTreeInfo(&artwork.mus_first, compareTreeInfoEntries);
-#if 1
+#if 0
dumpTreeInfo(artwork.gfx_first, 0);
dumpTreeInfo(artwork.snd_first, 0);
dumpTreeInfo(artwork.mus_first, 0);
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<TOKEN_VALUE_POSITION; i++)
- strcat(entry, " ");
+ /* build complete token string */
+ sprintf(token_string, "%s%s", prefix, token_text);
- /* continue with the token's value (which can have different types) */
- strcat(entry, value_string);
+ /* build setup entry line */
+ line = getFormattedSetupEntry(token_string, value_string);
if (token_type == TYPE_KEY_X11)
{
if (strcmp(keyname, "(undefined)") != 0 &&
strcmp(keyname, "(unknown)") != 0)
{
- for (i=strlen(entry); i<50; i++)
- strcat(entry, " ");
+ /* add at least one whitespace */
+ strcat(line, " ");
+ for (i=strlen(line); i<TOKEN_COMMENT_POSITION; i++)
+ strcat(line, " ");
- strcat(entry, "# ");
- strcat(entry, keyname);
+ strcat(line, "# ");
+ strcat(line, keyname);
}
}
- return entry;
+ return line;
}
void LoadLevelSetup_LastSeries()
struct SetupFileList *level_setup_list = NULL;
/* always start with reliable default values */
- leveldir_current = getFirstValidLevelSeries(leveldir_first);
+ leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
/* ----------------------------------------------------------------------- */
/* ~/.<program>/levelsetup.conf */
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"));