#include "hash.h"
-#define USE_FILE_IDENTIFIERS FALSE /* do not use identifiers anymore */
#define ENABLE_UNUSED_CODE FALSE /* for currently unused functions */
#define NUM_LEVELCLASS_DESC 8
{
static char *artwork_dir = NULL;
+ if (ti == NULL)
+ return NULL;
+
checked_free(artwork_dir);
artwork_dir = getPath2(ti->basepath, ti->fullpath);
return LEVELDIR_ARTWORK_PATH(leveldir_current, type);
}
+char *getProgramConfigFilename(char *command_filename_ptr)
+{
+ char *command_filename = getStringCopy(command_filename_ptr);
+
+ // strip trailing executable suffix from command filename
+ if (strSuffix(command_filename, ".exe"))
+ command_filename[strlen(command_filename) - 4] = '\0';
+
+ return getStringCat2(command_filename, ".conf");
+}
+
char *getTapeFilename(int nr)
{
static char *filename = NULL;
return filename;
}
+char *getDefaultSetupFilename()
+{
+ return program.config_filename;
+}
+
char *getEditorSetupFilename()
{
static char *filename = NULL;
if (fileExists(filename))
return filename;
-#if defined(CREATE_SPECIAL_EDITION)
- free(filename);
+ if (!strEqual(GFX_FALLBACK_FILENAME, UNDEFINED_FILENAME))
+ {
+ free(filename);
- if (options.debug)
- Error(ERR_WARN, "cannot find artwork file '%s' (using fallback)", basename);
+ if (options.debug)
+ Error(ERR_WARN, "cannot find artwork file '%s' (using fallback)",
+ basename);
- /* 6th try: look for fallback artwork in old default artwork directory */
- /* (needed to prevent errors when trying to access unused artwork files) */
- filename = getImg2(options.graphics_directory, GFX_FALLBACK_FILENAME);
- if (fileExists(filename))
- return filename;
-#endif
+ /* 6th try: look for fallback artwork in old default artwork directory */
+ /* (needed to prevent errors when trying to access unused artwork files) */
+ filename = getImg2(options.graphics_directory, GFX_FALLBACK_FILENAME);
+ if (fileExists(filename))
+ return filename;
+ }
return NULL; /* cannot find specified artwork file anywhere */
}
if (fileExists(filename))
return filename;
-#if defined(CREATE_SPECIAL_EDITION)
- free(filename);
+ if (!strEqual(SND_FALLBACK_FILENAME, UNDEFINED_FILENAME))
+ {
+ free(filename);
- if (options.debug)
- Error(ERR_WARN, "cannot find artwork file '%s' (using fallback)", basename);
+ if (options.debug)
+ Error(ERR_WARN, "cannot find artwork file '%s' (using fallback)",
+ basename);
- /* 6th try: look for fallback artwork in old default artwork directory */
- /* (needed to prevent errors when trying to access unused artwork files) */
- filename = getPath2(options.sounds_directory, SND_FALLBACK_FILENAME);
- if (fileExists(filename))
- return filename;
-#endif
+ /* 6th try: look for fallback artwork in old default artwork directory */
+ /* (needed to prevent errors when trying to access unused artwork files) */
+ filename = getPath2(options.sounds_directory, SND_FALLBACK_FILENAME);
+ if (fileExists(filename))
+ return filename;
+ }
return NULL; /* cannot find specified artwork file anywhere */
}
if (fileExists(filename))
return filename;
-#if defined(CREATE_SPECIAL_EDITION)
- free(filename);
+ if (!strEqual(MUS_FALLBACK_FILENAME, UNDEFINED_FILENAME))
+ {
+ free(filename);
- if (options.debug)
- Error(ERR_WARN, "cannot find artwork file '%s' (using fallback)", basename);
+ if (options.debug)
+ Error(ERR_WARN, "cannot find artwork file '%s' (using fallback)",
+ basename);
- /* 6th try: look for fallback artwork in old default artwork directory */
- /* (needed to prevent errors when trying to access unused artwork files) */
- filename = getPath2(options.music_directory, MUS_FALLBACK_FILENAME);
- if (fileExists(filename))
- return filename;
-#endif
+ /* 6th try: look for fallback artwork in old default artwork directory */
+ /* (needed to prevent errors when trying to access unused artwork files) */
+ filename = getPath2(options.music_directory, MUS_FALLBACK_FILENAME);
+ if (fileExists(filename))
+ return filename;
+ }
return NULL; /* cannot find specified artwork file anywhere */
}
return cookie;
}
+void fprintFileHeader(FILE *file, char *basename)
+{
+ char *prefix = "# ";
+ char *sep1 = "=";
+
+ fprintf_line_with_prefix(file, prefix, sep1, 77);
+ fprintf(file, "%s%s\n", prefix, basename);
+ fprintf_line_with_prefix(file, prefix, sep1, 77);
+ fprintf(file, "\n");
+}
+
int getFileVersionFromCookieString(const char *cookie)
{
const char *ptr_cookie1, *ptr_cookie2;
return TRUE;
}
+
/* ------------------------------------------------------------------------- */
/* setup file list and hash handling functions */
/* ------------------------------------------------------------------------- */
return setup_file_hash;
}
-void checkSetupFileHashIdentifier(SetupFileHash *setup_file_hash,
- char *filename, char *identifier)
-{
-#if USE_FILE_IDENTIFIERS
- char *value = getHashEntry(setup_file_hash, TOKEN_STR_FILE_IDENTIFIER);
-
- if (value == NULL)
- Error(ERR_WARN, "config file '%s' has no file identifier", filename);
- else if (!checkCookieString(value, identifier))
- Error(ERR_WARN, "config file '%s' has wrong file identifier", filename);
-#endif
-}
-
/* ========================================================================= */
/* setup file stuff */
return compare_result;
}
-static void createParentTreeInfoNode(TreeInfo *node_parent)
+static TreeInfo *createParentTreeInfoNode(TreeInfo *node_parent)
{
TreeInfo *ti_new;
if (node_parent == NULL)
- return;
+ return NULL;
ti_new = newTreeInfo();
setTreeInfoToDefaults(ti_new, node_parent->type);
setString(&ti_new->name, ".. (parent directory)");
setString(&ti_new->name_sorting, ti_new->name);
- setString(&ti_new->subdir, "..");
+ setString(&ti_new->subdir, STRING_PARENT_DIRECTORY);
setString(&ti_new->fullpath, node_parent->fullpath);
ti_new->sort_priority = node_parent->sort_priority;
setString(&ti_new->class_desc, getLevelClassDescription(ti_new));
pushTreeInfo(&node_parent->node_group, ti_new);
+
+ return ti_new;
+}
+
+static TreeInfo *createTopTreeInfoNode(TreeInfo *node_first)
+{
+ TreeInfo *ti_new, *ti_new2;
+
+ if (node_first == NULL)
+ return NULL;
+
+ ti_new = newTreeInfo();
+ setTreeInfoToDefaults(ti_new, TREE_TYPE_LEVEL_DIR);
+
+ ti_new->node_parent = NULL;
+ ti_new->parent_link = FALSE;
+
+ setString(&ti_new->identifier, node_first->identifier);
+ setString(&ti_new->name, "level sets");
+ setString(&ti_new->name_sorting, ti_new->name);
+
+ setString(&ti_new->subdir, STRING_TOP_DIRECTORY);
+ setString(&ti_new->fullpath, node_first->fullpath);
+
+ ti_new->sort_priority = node_first->sort_priority;;
+ ti_new->latest_engine = node_first->latest_engine;
+
+ setString(&ti_new->class_desc, "level sets");
+
+ ti_new->node_group = node_first;
+ ti_new->level_group = TRUE;
+
+ ti_new2 = createParentTreeInfoNode(ti_new);
+
+ setString(&ti_new2->name, ".. (main menu)");
+ setString(&ti_new2->name_sorting, ti_new2->name);
+
+ return ti_new;
}
leveldir_new->subdir = getStringCopy(directory_name);
- checkSetupFileHashIdentifier(setup_file_hash, filename,
- getCookie("LEVELINFO"));
-
/* set all structure fields according to the token/value pairs */
ldi = *leveldir_new;
for (i = 0; i < NUM_LEVELINFO_TOKENS; i++)
LoadLevelInfoFromLevelDir(&leveldir_first, NULL, options.level_directory);
LoadLevelInfoFromLevelDir(&leveldir_first, NULL, getUserLevelDir(NULL));
+ leveldir_first = createTopTreeInfoNode(leveldir_first);
+
/* after loading all level set information, clone the level directory tree
and remove all level sets without levels (these may still contain artwork
to be offered in the setup menu as "custom artwork", and are therefore
token_value_position = TOKEN_VALUE_POSITION_SHORT;
- fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
- getCookie("LEVELINFO")));
+ fprintFileHeader(file, LEVELINFO_FILENAME);
ldi = *level_info;
for (i = 0; i < NUM_LEVELINFO_TOKENS; i++)
/* always start with reliable default values */
leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
-#if defined(CREATE_SPECIAL_EDITION_RND_JUE)
- leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
- "jue_start");
- if (leveldir_current == NULL)
- leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
-#endif
+ if (!strEqual(DEFAULT_LEVELSET, UNDEFINED_LEVELSET))
+ {
+ leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
+ DEFAULT_LEVELSET);
+ if (leveldir_current == NULL)
+ leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
+ }
if ((level_setup_hash = loadSetupFileHash(filename)))
{
if (leveldir_current == NULL)
leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
- checkSetupFileHashIdentifier(level_setup_hash, filename,
- getCookie("LEVELSETUP"));
-
freeSetupFileHash(level_setup_hash);
}
else
return;
}
- fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
- getCookie("LEVELSETUP")));
+ fprintFileHeader(file, LEVELSETUP_FILENAME);
if (deactivate_last_level_series)
fprintf(file, "# %s\n# ", "the following level set may have caused a problem and was deactivated");
LevelStats_setSolved(i, 0);
}
- checkSeriesInfo(leveldir_current);
+ checkSeriesInfo();
/* ----------------------------------------------------------------------- */
/* ~/.<program>/levelsetup/<level series>/levelsetup.conf */
}
END_HASH_ITERATION(hash, itr)
- checkSetupFileHashIdentifier(level_setup_hash, filename,
- getCookie("LEVELSETUP"));
-
freeSetupFileHash(level_setup_hash);
}
else
return;
}
- fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
- getCookie("LEVELSETUP")));
+ fprintFileHeader(file, LEVELSETUP_FILENAME);
+
fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_LAST_PLAYED_LEVEL,
level_nr_str));
fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_HANDICAP_LEVEL,