X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=4cd8921ee06d11326f84eca64bae5db3304c3e61;hb=c781e660ed2fe6ad36c9eee0a77d64ee07163030;hp=20160fc7baed3682ea55cb71b019886cce0ec534;hpb=bc8503fee1600305a9e915da07d5f2c29d9890b6;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 20160fc7..4cd8921e 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -270,19 +270,19 @@ static char *getDefaultMusicDir(char *music_subdir) static char *getDefaultArtworkSet(int type) { - return (type == TREE_TYPE_GRAPHICS_DIR ? GRAPHICS_SUBDIR : - type == TREE_TYPE_SOUNDS_DIR ? SOUNDS_SUBDIR : - type == TREE_TYPE_MUSIC_DIR ? MUSIC_SUBDIR : ""); + return (type == TREE_TYPE_GRAPHICS_DIR ? GFX_CLASSIC_SUBDIR : + type == TREE_TYPE_SOUNDS_DIR ? SND_CLASSIC_SUBDIR : + type == TREE_TYPE_MUSIC_DIR ? MUS_CLASSIC_SUBDIR : ""); } static char *getDefaultArtworkDir(int type) { return (type == TREE_TYPE_GRAPHICS_DIR ? - getDefaultGraphicsDir(GRAPHICS_SUBDIR) : + getDefaultGraphicsDir(GFX_CLASSIC_SUBDIR) : type == TREE_TYPE_SOUNDS_DIR ? - getDefaultSoundsDir(SOUNDS_SUBDIR) : + getDefaultSoundsDir(SND_CLASSIC_SUBDIR) : type == TREE_TYPE_MUSIC_DIR ? - getDefaultMusicDir(MUSIC_SUBDIR) : ""); + getDefaultMusicDir(MUS_CLASSIC_SUBDIR) : ""); } static char *getUserGraphicsDir() @@ -327,44 +327,22 @@ static char *getSetupArtworkDir(TreeInfo *ti) return artwork_dir; } -void setLevelArtworkDir(TreeInfo *ti) +char *setLevelArtworkDir(TreeInfo *ti) { char **artwork_path_ptr, **artwork_set_ptr; TreeInfo *level_artwork; - TreeInfo *tst1 = getTreeInfoFromIdentifier(leveldir_first, "jue1"); - printf("::: XXX 0.1 '%s'\n", tst1->graphics_path); - if (ti == NULL || leveldir_current == NULL) - return; + return NULL; artwork_path_ptr = &(LEVELDIR_ARTWORK_PATH(leveldir_current, ti->type)); artwork_set_ptr = &(LEVELDIR_ARTWORK_SET( leveldir_current, ti->type)); - printf("::: ['%s', '%s']\n", tst1->identifier, leveldir_current->identifier); - - printf("::: XXX 0.2 '%s' [%x]\n", tst1->graphics_path, tst1->graphics_path); - -#if 1 if (*artwork_path_ptr != NULL) - { - if (ti->type == 0) - printf("::: free'ing '%s' [%x] [%x] [type %d] ...\n", - *artwork_path_ptr, *artwork_path_ptr, - leveldir_current->graphics_path, ti->type); - free(*artwork_path_ptr); - } -#endif - - printf("::: XXX 0.3 '%s' [%x]\n", tst1->graphics_path, tst1->graphics_path); if ((level_artwork = getTreeInfoFromIdentifier(ti, *artwork_set_ptr))) - { *artwork_path_ptr = getStringCopy(getSetupArtworkDir(level_artwork)); - - printf(":1: setting to '%s' [type %d] ...\n", *artwork_path_ptr, ti->type); - } else { /* No (or non-existing) artwork configured in "levelinfo.conf". This would @@ -383,23 +361,17 @@ void setLevelArtworkDir(TreeInfo *ti) { *artwork_path_ptr = getStringCopy(getDefaultArtworkDir(ti->type)); *artwork_set_ptr = getStringCopy(getDefaultArtworkSet(ti->type)); - - if (ti->type == 0) - printf(":2: setting to '%s' [type %d] ...\n", - *artwork_path_ptr, ti->type); } else { *artwork_path_ptr = getStringCopy(UNDEFINED_FILENAME); *artwork_set_ptr = NULL; - - if (ti->type == 0) - printf(":3: setting to '%s' [type %d] ...\n", - *artwork_path_ptr, ti->type); } free(dir); } + + return *artwork_set_ptr; } inline static char *getLevelArtworkSet(int type) @@ -476,7 +448,7 @@ char *getSetupFilename() return filename; } -static char *getCorrectedImageBasename(char *basename) +static char *getCorrectedArtworkBasename(char *basename) { char *basename_corrected = basename; @@ -491,7 +463,7 @@ static char *getCorrectedImageBasename(char *basename) /* if corrected filename is still longer than standard MS-DOS filename size (8 characters + 1 dot + 3 characters file extension), shorten filename by writing file extension after 8th basename character */ - if (strlen(basename_corrected) > 8+1+3) + if (strlen(basename_corrected) > 8 + 1 + 3) { static char *msdos_filename = NULL; @@ -499,7 +471,9 @@ static char *getCorrectedImageBasename(char *basename) free(msdos_filename); msdos_filename = getStringCopy(basename_corrected); - strncpy(&msdos_filename[8], &basename[strlen(basename) - 1+3], 1+3 + 1); + strncpy(&msdos_filename[8], &basename[strlen(basename) - (1+3)], 1+3 +1); + + basename_corrected = msdos_filename; } } #endif @@ -515,7 +489,7 @@ char *getCustomImageFilename(char *basename) if (filename != NULL) free(filename); - basename = getCorrectedImageBasename(basename); + basename = getCorrectedArtworkBasename(basename); if (!setup.override_level_graphics) { @@ -552,7 +526,7 @@ char *getCustomImageFilename(char *basename) } /* 4th try: look for default artwork in new default artwork directory */ - filename = getPath2(getDefaultGraphicsDir(GRAPHICS_SUBDIR), basename); + filename = getPath2(getDefaultGraphicsDir(GFX_CLASSIC_SUBDIR), basename); if (fileExists(filename)) return filename; @@ -574,6 +548,8 @@ char *getCustomSoundFilename(char *basename) if (filename != NULL) free(filename); + basename = getCorrectedArtworkBasename(basename); + if (!setup.override_level_sounds) { /* 1st try: look for special artwork in current level series directory */ @@ -609,7 +585,7 @@ char *getCustomSoundFilename(char *basename) } /* 4th try: look for default artwork in new default artwork directory */ - filename = getPath2(getDefaultSoundsDir(SOUNDS_SUBDIR), basename); + filename = getPath2(getDefaultSoundsDir(SND_CLASSIC_SUBDIR), basename); if (fileExists(filename)) return filename; @@ -693,7 +669,7 @@ char *getCustomMusicDirectory(void) } /* 4th try: look for default artwork in new default artwork directory */ - directory = getStringCopy(getDefaultMusicDir(MUSIC_SUBDIR)); + directory = getStringCopy(getDefaultMusicDir(MUS_CLASSIC_SUBDIR)); if (fileExists(directory)) return directory; @@ -1922,13 +1898,6 @@ void LoadLevelInfo() LoadLevelInfoFromLevelDir(&leveldir_first, NULL, options.level_directory); LoadLevelInfoFromLevelDir(&leveldir_first, NULL, getUserLevelDir(NULL)); - { - TreeInfo *tst1 = getTreeInfoFromIdentifier(leveldir_first, "jue1"); - TreeInfo *tst2 = getTreeInfoFromIdentifier(leveldir_first, "demojue"); - printf("::: ??? 1 '%s' [%x, %x]\n", tst1->graphics_path, - tst1->graphics_path, tst2->graphics_path); - } - /* before sorting, the first entries will be from the user directory */ leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); @@ -2204,7 +2173,7 @@ void LoadArtworkInfo() getTreeInfoFromIdentifier(artwork.gfx_first, setup.graphics_set); if (artwork.gfx_current == NULL) artwork.gfx_current = - getTreeInfoFromIdentifier(artwork.gfx_first, GRAPHICS_SUBDIR); + getTreeInfoFromIdentifier(artwork.gfx_first, GFX_CLASSIC_SUBDIR); if (artwork.gfx_current == NULL) artwork.gfx_current = getFirstValidTreeInfoEntry(artwork.gfx_first); @@ -2212,7 +2181,7 @@ void LoadArtworkInfo() getTreeInfoFromIdentifier(artwork.snd_first, setup.sounds_set); if (artwork.snd_current == NULL) artwork.snd_current = - getTreeInfoFromIdentifier(artwork.snd_first, SOUNDS_SUBDIR); + getTreeInfoFromIdentifier(artwork.snd_first, SND_CLASSIC_SUBDIR); if (artwork.snd_current == NULL) artwork.snd_current = getFirstValidTreeInfoEntry(artwork.snd_first); @@ -2220,7 +2189,7 @@ void LoadArtworkInfo() getTreeInfoFromIdentifier(artwork.mus_first, setup.music_set); if (artwork.mus_current == NULL) artwork.mus_current = - getTreeInfoFromIdentifier(artwork.mus_first, MUSIC_SUBDIR); + getTreeInfoFromIdentifier(artwork.mus_first, MUS_CLASSIC_SUBDIR); if (artwork.mus_current == NULL) artwork.mus_current = getFirstValidTreeInfoEntry(artwork.mus_first); @@ -2307,7 +2276,7 @@ void LoadLevelArtworkInfo() getTreeInfoFromIdentifier(artwork.gfx_first, setup.graphics_set); if (artwork.gfx_current == NULL) artwork.gfx_current = - getTreeInfoFromIdentifier(artwork.gfx_first, GRAPHICS_SUBDIR); + getTreeInfoFromIdentifier(artwork.gfx_first, GFX_CLASSIC_SUBDIR); if (artwork.gfx_current == NULL) artwork.gfx_current = getFirstValidTreeInfoEntry(artwork.gfx_first); } @@ -2318,7 +2287,7 @@ void LoadLevelArtworkInfo() getTreeInfoFromIdentifier(artwork.snd_first, setup.sounds_set); if (artwork.snd_current == NULL) artwork.snd_current = - getTreeInfoFromIdentifier(artwork.snd_first, SOUNDS_SUBDIR); + getTreeInfoFromIdentifier(artwork.snd_first, SND_CLASSIC_SUBDIR); if (artwork.snd_current == NULL) artwork.snd_current = getFirstValidTreeInfoEntry(artwork.snd_first); } @@ -2329,7 +2298,7 @@ void LoadLevelArtworkInfo() getTreeInfoFromIdentifier(artwork.mus_first, setup.music_set); if (artwork.mus_current == NULL) artwork.mus_current = - getTreeInfoFromIdentifier(artwork.mus_first, MUSIC_SUBDIR); + getTreeInfoFromIdentifier(artwork.mus_first, MUS_CLASSIC_SUBDIR); if (artwork.mus_current == NULL) artwork.mus_current = getFirstValidTreeInfoEntry(artwork.mus_first); } @@ -2371,9 +2340,9 @@ static void SaveUserLevelInfo() ldi.first_level = 1; ldi.sort_priority = LEVELCLASS_USER_START; ldi.readonly = FALSE; - setString(&ldi.graphics_set, GRAPHICS_SUBDIR); - setString(&ldi.sounds_set, SOUNDS_SUBDIR); - setString(&ldi.music_set, MUSIC_SUBDIR); + setString(&ldi.graphics_set, GFX_CLASSIC_SUBDIR); + setString(&ldi.sounds_set, SND_CLASSIC_SUBDIR); + setString(&ldi.music_set, MUS_CLASSIC_SUBDIR); #else ldi.name = getStringCopy(getLoginName()); ldi.author = getStringCopy(getRealName()); @@ -2381,9 +2350,9 @@ static void SaveUserLevelInfo() ldi.first_level = 1; ldi.sort_priority = LEVELCLASS_USER_START; ldi.readonly = FALSE; - ldi.graphics_set = getStringCopy(GRAPHICS_SUBDIR); - ldi.sounds_set = getStringCopy(SOUNDS_SUBDIR); - ldi.music_set = getStringCopy(MUSIC_SUBDIR); + ldi.graphics_set = getStringCopy(GFX_CLASSIC_SUBDIR); + ldi.sounds_set = getStringCopy(SND_CLASSIC_SUBDIR); + ldi.music_set = getStringCopy(MUS_CLASSIC_SUBDIR); #endif fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, @@ -2396,9 +2365,10 @@ static void SaveUserLevelInfo() fprintf(file, "%s\n", getSetupLine(levelinfo_tokens, "", i)); fclose(file); - free(filename); SetFilePermissions(filename, PERMS_PRIVATE); + + free(filename); } char *getSetupValue(int type, void *value) @@ -2545,9 +2515,10 @@ void SaveLevelSetup_LastSeries() level_subdir)); fclose(file); - free(filename); SetFilePermissions(filename, PERMS_PRIVATE); + + free(filename); } static void checkSeriesInfo() @@ -2694,7 +2665,8 @@ void SaveLevelSetup_SeriesInfo() handicap_level_str)); fclose(file); - free(filename); SetFilePermissions(filename, PERMS_PRIVATE); + + free(filename); }