X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=7c4fc88085bc28bace615f82fec30a274e7901a5;hb=c93f939100438a9047653b2c2c6b86f034e1bb01;hp=63ac0d59b3d67ede1f1027dfad61931a27142439;hpb=3fb9d9cf97f3d4da6066f3c6b2ce84c81b768982;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 63ac0d59..7c4fc880 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -73,10 +73,14 @@ static char *levelclass_desc[NUM_LEVELCLASS_DESC] = IS_ARTWORKCLASS_PRIVATE(n) ? 3 : \ 9) -#define TOKEN_VALUE_POSITION 40 -#define TOKEN_COMMENT_POSITION 60 +#define TOKEN_VALUE_POSITION_SHORT 32 +#define TOKEN_VALUE_POSITION_DEFAULT 40 +#define TOKEN_COMMENT_POSITION_DEFAULT 60 -#define MAX_COOKIE_LEN 256 +#define MAX_COOKIE_LEN 256 + +static int token_value_position = TOKEN_VALUE_POSITION_DEFAULT; +static int token_comment_position = TOKEN_COMMENT_POSITION_DEFAULT; /* ------------------------------------------------------------------------- */ @@ -298,8 +302,8 @@ char *setLevelArtworkDir(TreeInfo *ti) if (ti == NULL || leveldir_current == NULL) return NULL; - artwork_path_ptr = &(LEVELDIR_ARTWORK_PATH(leveldir_current, ti->type)); - artwork_set_ptr = &(LEVELDIR_ARTWORK_SET( leveldir_current, ti->type)); + artwork_path_ptr = LEVELDIR_ARTWORK_PATH_PTR(leveldir_current, ti->type); + artwork_set_ptr = LEVELDIR_ARTWORK_SET_PTR( leveldir_current, ti->type); checked_free(*artwork_path_ptr); @@ -776,7 +780,7 @@ static void SaveUserLevelInfo(); void InitUserLevelDirectory(char *level_subdir) { - if (access(getUserLevelDir(level_subdir), F_OK) != 0) + if (!fileExists(getUserLevelDir(level_subdir))) { createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE); createDirectory(getUserLevelDir(NULL), "main user level", PERMS_PRIVATE); @@ -1110,7 +1114,7 @@ void createDirectory(char *dir, char *text, int permission_class) mode_t group_umask = ~(dir_mode & S_IRWXG); posix_umask(normal_umask & group_umask); - if (access(dir, F_OK) != 0) + if (!fileExists(dir)) if (posix_mkdir(dir, dir_mode) != 0) Error(ERR_WARN, "cannot create %s directory '%s'", text, dir); @@ -1205,7 +1209,7 @@ char *getFormattedSetupEntry(char *token, char *value) /* start with the token and some spaces to format output line */ sprintf(entry, "%s:", token); - for (i = strlen(entry); i < TOKEN_VALUE_POSITION; i++) + for (i = strlen(entry); i < token_value_position; i++) strcat(entry, " "); /* continue with the token's value */ @@ -1413,17 +1417,18 @@ static void *loadSetupFileData(char *filename, boolean use_hash) boolean read_continued_line = FALSE; FILE *file; - if (use_hash) - setup_file_data = newSetupFileHash(); - else - insert_ptr = setup_file_data = newSetupFileList("", ""); - if (!(file = fopen(filename, MODE_READ))) { Error(ERR_WARN, "cannot open configuration file '%s'", filename); + return NULL; } + if (use_hash) + setup_file_data = newSetupFileHash(); + else + insert_ptr = setup_file_data = newSetupFileList("", ""); + while (!feof(file)) { /* read next line of input file */ @@ -1949,10 +1954,21 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, { char *directory_path = getPath2(level_directory, directory_name); char *filename = getPath2(directory_path, LEVELINFO_FILENAME); - SetupFileHash *setup_file_hash = loadSetupFileHash(filename); + SetupFileHash *setup_file_hash; LevelDirTree *leveldir_new = NULL; int i; + /* unless debugging, silently ignore directories without "levelinfo.conf" */ + if (!options.debug && !fileExists(filename)) + { + free(directory_path); + free(filename); + + return FALSE; + } + + setup_file_hash = loadSetupFileHash(filename); + if (setup_file_hash == NULL) { Error(ERR_WARN, "ignoring level directory '%s'", directory_path); @@ -2025,6 +2041,14 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, (leveldir_new->basepath == options.level_directory ? FALSE : TRUE); #endif +#if 1 + /* adjust sort priority if user's private level directory was detected */ + if (leveldir_new->sort_priority == LEVELCLASS_UNDEFINED && + leveldir_new->in_user_dir && + strcmp(leveldir_new->subdir, getLoginName()) == 0) + leveldir_new->sort_priority = LEVELCLASS_PRIVATE_START; +#endif + leveldir_new->user_defined = (leveldir_new->in_user_dir && IS_LEVELCLASS_PRIVATE(leveldir_new)); @@ -2154,7 +2178,7 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, TreeInfo *artwork_new = NULL; int i; - if (access(filename, F_OK) == 0) /* file exists */ + if (fileExists(filename)) setup_file_hash = loadSetupFileHash(filename); if (setup_file_hash == NULL) /* no config file -- look for artwork files */ @@ -2631,11 +2655,13 @@ static void SaveUserLevelInfo() setString(&level_info->author, getRealName()); level_info->levels = 100; level_info->first_level = 1; +#if 0 level_info->sort_priority = LEVELCLASS_PRIVATE_START; level_info->readonly = FALSE; setString(&level_info->graphics_set, GFX_CLASSIC_SUBDIR); setString(&level_info->sounds_set, SND_CLASSIC_SUBDIR); setString(&level_info->music_set, MUS_CLASSIC_SUBDIR); +#endif #else ldi.name = getStringCopy(getLoginName()); ldi.author = getStringCopy(getRealName()); @@ -2648,11 +2674,25 @@ static void SaveUserLevelInfo() ldi.music_set = getStringCopy(MUS_CLASSIC_SUBDIR); #endif + token_value_position = TOKEN_VALUE_POSITION_SHORT; + fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, getCookie("LEVELINFO"))); ldi = *level_info; for (i = 0; i < NUM_LEVELINFO_TOKENS; i++) + { +#if 1 + if (i == LEVELINFO_TOKEN_NAME || + i == LEVELINFO_TOKEN_AUTHOR || + i == LEVELINFO_TOKEN_LEVELS || + i == LEVELINFO_TOKEN_FIRST_LEVEL) + fprintf(file, "%s\n", getSetupLine(levelinfo_tokens, "", i)); + + /* just to make things nicer :) */ + if (i == LEVELINFO_TOKEN_AUTHOR) + fprintf(file, "\n"); +#else if (i != LEVELINFO_TOKEN_IDENTIFIER && i != LEVELINFO_TOKEN_NAME_SORTING && i != LEVELINFO_TOKEN_IMPORTED_FROM && @@ -2660,6 +2700,10 @@ static void SaveUserLevelInfo() i != LEVELINFO_TOKEN_FILENAME && i != LEVELINFO_TOKEN_FILETYPE) fprintf(file, "%s\n", getSetupLine(levelinfo_tokens, "", i)); +#endif + } + + token_value_position = TOKEN_VALUE_POSITION_DEFAULT; fclose(file); @@ -2741,7 +2785,7 @@ char *getSetupLine(struct TokenInfo *token_info, char *prefix, int token_nr) { /* add at least one whitespace */ strcat(line, " "); - for (i = strlen(line); i < TOKEN_COMMENT_POSITION; i++) + for (i = strlen(line); i < token_comment_position; i++) strcat(line, " "); strcat(line, "# ");