X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=50060391060a25c04d79acd2b1e55695fe4984e3;hb=30eb586d06bc4d1ee7388dced1c20e530292aa93;hp=f2f5984f702ce2947bfa4c77bc4a4b1ff9086f8b;hpb=79425634db3735af2b7f6cfc1528c6cf7e99b559;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index f2f5984f..50060391 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -31,6 +31,7 @@ #define ENABLE_UNUSED_CODE FALSE /* for currently unused functions */ +#define DEBUG_NO_CONFIG_FILE FALSE /* for extra-verbose debug output */ #define NUM_LEVELCLASS_DESC 8 @@ -156,7 +157,7 @@ static char *getLevelSetupDir(char *level_subdir) return levelsetup_dir; } -static char *getCacheDir() +static char *getCacheDir(void) { static char *cache_dir = NULL; @@ -166,6 +167,16 @@ static char *getCacheDir() return cache_dir; } +static char *getNetworkDir(void) +{ + static char *network_dir = NULL; + + if (network_dir == NULL) + network_dir = getPath2(getUserGameDataDir(), NETWORK_DIRECTORY); + + return network_dir; +} + static char *getLevelDirFromTreeInfo(TreeInfo *node) { static char *level_dir = NULL; @@ -197,12 +208,28 @@ char *getUserLevelDir(char *level_subdir) return userlevel_dir; } -char *getCurrentLevelDir() +char *getNetworkLevelDir(char *level_subdir) +{ + static char *network_level_dir = NULL; + char *data_dir = getNetworkDir(); + char *networklevel_subdir = LEVELS_DIRECTORY; + + checked_free(network_level_dir); + + if (level_subdir != NULL) + network_level_dir = getPath3(data_dir, networklevel_subdir, level_subdir); + else + network_level_dir = getPath2(data_dir, networklevel_subdir); + + return network_level_dir; +} + +char *getCurrentLevelDir(void) { return getLevelDirFromTreeInfo(leveldir_current); } -char *getNewUserLevelSubdir() +char *getNewUserLevelSubdir(void) { static char *new_level_subdir = NULL; char *subdir_prefix = getLoginName(); @@ -240,7 +267,7 @@ static char *getTapeDir(char *level_subdir) return tape_dir; } -static char *getSolutionTapeDir() +static char *getSolutionTapeDir(void) { static char *tape_dir = NULL; char *data_dir = getCurrentLevelDir(); @@ -312,7 +339,7 @@ static char *getClassicArtworkDir(int type) getDefaultMusicDir(MUS_CLASSIC_SUBDIR) : ""); } -static char *getUserGraphicsDir() +static char *getUserGraphicsDir(void) { static char *usergraphics_dir = NULL; @@ -322,7 +349,7 @@ static char *getUserGraphicsDir() return usergraphics_dir; } -static char *getUserSoundsDir() +static char *getUserSoundsDir(void) { static char *usersounds_dir = NULL; @@ -332,7 +359,7 @@ static char *getUserSoundsDir() return usersounds_dir; } -static char *getUserMusicDir() +static char *getUserMusicDir(void) { static char *usermusic_dir = NULL; @@ -542,12 +569,14 @@ char *getScoreFilename(int nr) checked_free(filename); sprintf(basename, "%03d.%s", nr, SCOREFILE_EXTENSION); - filename = getPath2(getScoreDir(leveldir_current->subdir), basename); + + /* used instead of "leveldir_current->subdir" (for network games) */ + filename = getPath2(getScoreDir(levelset.identifier), basename); return filename; } -char *getSetupFilename() +char *getSetupFilename(void) { static char *filename = NULL; @@ -558,12 +587,12 @@ char *getSetupFilename() return filename; } -char *getDefaultSetupFilename() +char *getDefaultSetupFilename(void) { return program.config_filename; } -char *getEditorSetupFilename() +char *getEditorSetupFilename(void) { static char *filename = NULL; @@ -579,7 +608,7 @@ char *getEditorSetupFilename() return filename; } -char *getHelpAnimFilename() +char *getHelpAnimFilename(void) { static char *filename = NULL; @@ -590,7 +619,7 @@ char *getHelpAnimFilename() return filename; } -char *getHelpTextFilename() +char *getHelpTextFilename(void) { static char *filename = NULL; @@ -601,7 +630,7 @@ char *getHelpTextFilename() return filename; } -char *getLevelSetInfoFilename() +char *getLevelSetInfoFilename(void) { static char *filename = NULL; char *basenames[] = @@ -630,7 +659,7 @@ char *getLevelSetInfoFilename() return NULL; } -char *getLevelSetTitleMessageBasename(int nr, boolean initial) +static char *getLevelSetTitleMessageBasename(int nr, boolean initial) { static char basename[32]; @@ -1034,7 +1063,7 @@ void InitScoreDirectory(char *level_subdir) createDirectory(getScoreDir(level_subdir), "level score", permissions); } -static void SaveUserLevelInfo(); +static void SaveUserLevelInfo(void); void InitUserLevelDirectory(char *level_subdir) { @@ -1048,6 +1077,17 @@ void InitUserLevelDirectory(char *level_subdir) } } +void InitNetworkLevelDirectory(char *level_subdir) +{ + if (!directoryExists(getNetworkLevelDir(level_subdir))) + { + createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE); + createDirectory(getNetworkDir(), "network data", PERMS_PRIVATE); + createDirectory(getNetworkLevelDir(NULL), "main network level", PERMS_PRIVATE); + createDirectory(getNetworkLevelDir(level_subdir), "network level", PERMS_PRIVATE); + } +} + void InitLevelSetupDirectory(char *level_subdir) { createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE); @@ -1055,7 +1095,7 @@ void InitLevelSetupDirectory(char *level_subdir) createDirectory(getLevelSetupDir(level_subdir), "level setup", PERMS_PRIVATE); } -void InitCacheDirectory() +static void InitCacheDirectory(void) { createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE); createDirectory(getCacheDir(), "cache data", PERMS_PRIVATE); @@ -1066,7 +1106,7 @@ void InitCacheDirectory() /* some functions to handle lists of level and artwork directories */ /* ------------------------------------------------------------------------- */ -TreeInfo *newTreeInfo() +TreeInfo *newTreeInfo(void) { return checked_calloc(sizeof(TreeInfo)); } @@ -1200,8 +1240,8 @@ TreeInfo *getTreeInfoFromIdentifier(TreeInfo *node, char *identifier) return NULL; } -TreeInfo *cloneTreeNode(TreeInfo **node_top, TreeInfo *node_parent, - TreeInfo *node, boolean skip_sets_without_levels) +static TreeInfo *cloneTreeNode(TreeInfo **node_top, TreeInfo *node_parent, + TreeInfo *node, boolean skip_sets_without_levels) { TreeInfo *node_new; @@ -1228,7 +1268,7 @@ TreeInfo *cloneTreeNode(TreeInfo **node_top, TreeInfo *node_parent, return node_new; } -void cloneTree(TreeInfo **ti_new, TreeInfo *ti, boolean skip_empty_sets) +static void cloneTree(TreeInfo **ti_new, TreeInfo *ti, boolean skip_empty_sets) { TreeInfo *ti_cloned = cloneTreeNode(ti_new, NULL, ti, skip_empty_sets); @@ -1393,7 +1433,7 @@ void sortTreeInfo(TreeInfo **node_first) #define FILE_PERMS_PUBLIC_ALL (MODE_R_ALL | MODE_W_ALL) -char *getHomeDir() +char *getHomeDir(void) { static char *dir = NULL; @@ -1482,7 +1522,7 @@ char *getUserGameDataDir(void) return user_game_data_dir; } -char *getSetupDir() +char *getSetupDir(void) { return getUserGameDataDir(); } @@ -1505,7 +1545,7 @@ static int posix_mkdir(const char *pathname, mode_t mode) #endif } -static boolean posix_process_running_setgid() +static boolean posix_process_running_setgid(void) { #if defined(PLATFORM_UNIX) return (getgid() != getegid()); @@ -1548,7 +1588,7 @@ void createDirectory(char *dir, char *text, int permission_class) posix_umask(last_umask); /* restore previous umask */ } -void InitUserDataDirectory() +void InitUserDataDirectory(void) { createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE); } @@ -1575,7 +1615,7 @@ char *getCookie(char *file_type) sprintf(cookie, "%s_%s_FILE_VERSION_%d.%d", program.cookie_prefix, file_type, - program.version_major, program.version_minor); + program.version_super, program.version_major); return cookie; } @@ -1600,7 +1640,7 @@ int getFileVersionFromCookieString(const char *cookie) const int len_pattern1 = strlen(pattern1); const int len_pattern2 = strlen(pattern2); const int len_pattern = len_pattern1 + len_pattern2; - int version_major, version_minor; + int version_super, version_major; if (len_cookie <= len_pattern) return -1; @@ -1616,10 +1656,10 @@ int getFileVersionFromCookieString(const char *cookie) ptr_cookie2[2] < '0' || ptr_cookie2[2] > '9') return -1; - version_major = ptr_cookie2[0] - '0'; - version_minor = ptr_cookie2[2] - '0'; + version_super = ptr_cookie2[0] - '0'; + version_major = ptr_cookie2[2] - '0'; - return VERSION_IDENT(version_major, version_minor, 0, 0); + return VERSION_IDENT(version_super, version_major, 0, 0); } boolean checkCookieString(const char *cookie, const char *template) @@ -1792,7 +1832,7 @@ static int keys_are_equal(void *key1, void *key2) return (strEqual((char *)key1, (char *)key2)); } -SetupFileHash *newSetupFileHash() +SetupFileHash *newSetupFileHash(void) { SetupFileHash *new_hash = create_hashtable(16, 0.75, get_hash_from_key, keys_are_equal); @@ -2024,7 +2064,9 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, if (!(file = openFile(filename, MODE_READ))) { +#if DEBUG_NO_CONFIG_FILE Error(ERR_DEBUG, "cannot open configuration file '%s'", filename); +#endif return FALSE; } @@ -2165,7 +2207,7 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, return TRUE; } -void saveSetupFileHash(SetupFileHash *hash, char *filename) +static void saveSetupFileHash(SetupFileHash *hash, char *filename) { FILE *file; @@ -2236,27 +2278,30 @@ SetupFileHash *loadSetupFileHash(char *filename) #define LEVELINFO_TOKEN_NAME_SORTING 2 #define LEVELINFO_TOKEN_AUTHOR 3 #define LEVELINFO_TOKEN_YEAR 4 -#define LEVELINFO_TOKEN_IMPORTED_FROM 5 -#define LEVELINFO_TOKEN_IMPORTED_BY 6 -#define LEVELINFO_TOKEN_TESTED_BY 7 -#define LEVELINFO_TOKEN_LEVELS 8 -#define LEVELINFO_TOKEN_FIRST_LEVEL 9 -#define LEVELINFO_TOKEN_SORT_PRIORITY 10 -#define LEVELINFO_TOKEN_LATEST_ENGINE 11 -#define LEVELINFO_TOKEN_LEVEL_GROUP 12 -#define LEVELINFO_TOKEN_READONLY 13 -#define LEVELINFO_TOKEN_GRAPHICS_SET_ECS 14 -#define LEVELINFO_TOKEN_GRAPHICS_SET_AGA 15 -#define LEVELINFO_TOKEN_GRAPHICS_SET 16 -#define LEVELINFO_TOKEN_SOUNDS_SET 17 -#define LEVELINFO_TOKEN_MUSIC_SET 18 -#define LEVELINFO_TOKEN_FILENAME 19 -#define LEVELINFO_TOKEN_FILETYPE 20 -#define LEVELINFO_TOKEN_SPECIAL_FLAGS 21 -#define LEVELINFO_TOKEN_HANDICAP 22 -#define LEVELINFO_TOKEN_SKIP_LEVELS 23 - -#define NUM_LEVELINFO_TOKENS 24 +#define LEVELINFO_TOKEN_PROGRAM_TITLE 5 +#define LEVELINFO_TOKEN_PROGRAM_COPYRIGHT 6 +#define LEVELINFO_TOKEN_PROGRAM_COMPANY 7 +#define LEVELINFO_TOKEN_IMPORTED_FROM 8 +#define LEVELINFO_TOKEN_IMPORTED_BY 9 +#define LEVELINFO_TOKEN_TESTED_BY 10 +#define LEVELINFO_TOKEN_LEVELS 11 +#define LEVELINFO_TOKEN_FIRST_LEVEL 12 +#define LEVELINFO_TOKEN_SORT_PRIORITY 13 +#define LEVELINFO_TOKEN_LATEST_ENGINE 14 +#define LEVELINFO_TOKEN_LEVEL_GROUP 15 +#define LEVELINFO_TOKEN_READONLY 16 +#define LEVELINFO_TOKEN_GRAPHICS_SET_ECS 17 +#define LEVELINFO_TOKEN_GRAPHICS_SET_AGA 18 +#define LEVELINFO_TOKEN_GRAPHICS_SET 19 +#define LEVELINFO_TOKEN_SOUNDS_SET 20 +#define LEVELINFO_TOKEN_MUSIC_SET 21 +#define LEVELINFO_TOKEN_FILENAME 22 +#define LEVELINFO_TOKEN_FILETYPE 23 +#define LEVELINFO_TOKEN_SPECIAL_FLAGS 24 +#define LEVELINFO_TOKEN_HANDICAP 25 +#define LEVELINFO_TOKEN_SKIP_LEVELS 26 + +#define NUM_LEVELINFO_TOKENS 27 static LevelDirTree ldi; @@ -2268,6 +2313,9 @@ static struct TokenInfo levelinfo_tokens[] = { TYPE_STRING, &ldi.name_sorting, "name_sorting" }, { TYPE_STRING, &ldi.author, "author" }, { TYPE_STRING, &ldi.year, "year" }, + { TYPE_STRING, &ldi.program_title, "program_title" }, + { TYPE_STRING, &ldi.program_copyright, "program_copyright" }, + { TYPE_STRING, &ldi.program_company, "program_company" }, { TYPE_STRING, &ldi.imported_from, "imported_from" }, { TYPE_STRING, &ldi.imported_by, "imported_by" }, { TYPE_STRING, &ldi.tested_by, "tested_by" }, @@ -2297,6 +2345,9 @@ static struct TokenInfo artworkinfo_tokens[] = { TYPE_STRING, &ldi.name, "name" }, { TYPE_STRING, &ldi.name_sorting, "name_sorting" }, { TYPE_STRING, &ldi.author, "author" }, + { TYPE_STRING, &ldi.program_title, "program_title" }, + { TYPE_STRING, &ldi.program_copyright, "program_copyright" }, + { TYPE_STRING, &ldi.program_company, "program_company" }, { TYPE_INTEGER, &ldi.sort_priority, "sort_priority" }, { TYPE_STRING, &ldi.basepath, "basepath" }, { TYPE_STRING, &ldi.fullpath, "fullpath" }, @@ -2333,6 +2384,10 @@ static void setTreeInfoToDefaults(TreeInfo *ti, int type) ti->author = getStringCopy(ANONYMOUS_NAME); ti->year = NULL; + ti->program_title = NULL; + ti->program_copyright = NULL; + ti->program_company = NULL; + ti->sort_priority = LEVELCLASS_UNDEFINED; /* default: least priority */ ti->latest_engine = FALSE; /* default: get from level */ ti->parent_link = FALSE; @@ -2406,6 +2461,10 @@ static void setTreeInfoToDefaultsFromParent(TreeInfo *ti, TreeInfo *parent) ti->author = getStringCopy(parent->author); ti->year = getStringCopy(parent->year); + ti->program_title = getStringCopy(parent->program_title); + ti->program_copyright = getStringCopy(parent->program_copyright); + ti->program_company = getStringCopy(parent->program_company); + ti->sort_priority = parent->sort_priority; ti->latest_engine = parent->latest_engine; ti->parent_link = FALSE; @@ -2471,6 +2530,11 @@ static TreeInfo *getTreeInfoCopy(TreeInfo *ti) ti_copy->name_sorting = getStringCopy(ti->name_sorting); ti_copy->author = getStringCopy(ti->author); ti_copy->year = getStringCopy(ti->year); + + ti_copy->program_title = getStringCopy(ti->program_title); + ti_copy->program_copyright = getStringCopy(ti->program_copyright); + ti_copy->program_company = getStringCopy(ti->program_company); + ti_copy->imported_from = getStringCopy(ti->imported_from); ti_copy->imported_by = getStringCopy(ti->imported_by); ti_copy->tested_by = getStringCopy(ti->tested_by); @@ -2528,6 +2592,10 @@ void freeTreeInfo(TreeInfo *ti) checked_free(ti->author); checked_free(ti->year); + checked_free(ti->program_title); + checked_free(ti->program_copyright); + checked_free(ti->program_company); + checked_free(ti->class_desc); checked_free(ti->infotext); @@ -2603,6 +2671,10 @@ void setSetupInfo(struct TokenInfo *token_info, *(char **)setup_value = getStringCopy(token_value); break; + case TYPE_PLAYER: + *(int *)setup_value = get_player_nr_from_string(token_value); + break; + default: break; } @@ -2719,7 +2791,7 @@ static TreeInfo *createTopTreeInfoNode(TreeInfo *node_first) /* functions for handling level and custom artwork info cache */ /* -------------------------------------------------------------------------- */ -static void LoadArtworkInfoCache() +static void LoadArtworkInfoCache(void) { InitCacheDirectory(); @@ -2741,7 +2813,7 @@ static void LoadArtworkInfoCache() artworkinfo_cache_new = newSetupFileHash(); } -static void SaveArtworkInfoCache() +static void SaveArtworkInfoCache(void) { char *filename = getPath2(getCacheDir(), ARTWORKINFO_CACHE_FILE); @@ -2936,7 +3008,9 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, if (setup_file_hash == NULL) { +#if DEBUG_NO_CONFIG_FILE Error(ERR_WARN, "ignoring level directory '%s'", directory_path); +#endif free(directory_path); free(filename); @@ -3094,7 +3168,7 @@ static void LoadLevelInfoFromLevelDir(TreeInfo **node_first, level_directory); } -boolean AdjustGraphicsForEMC() +boolean AdjustGraphicsForEMC(void) { boolean settings_changed = FALSE; @@ -3104,7 +3178,7 @@ boolean AdjustGraphicsForEMC() return settings_changed; } -void LoadLevelInfo() +void LoadLevelInfo(void) { InitUserLevelDirectory(getLoginName()); @@ -3174,8 +3248,10 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, if (!valid_file_found) { +#if DEBUG_NO_CONFIG_FILE if (!strEqual(directory_name, ".")) Error(ERR_WARN, "ignoring artwork directory '%s'", directory_path); +#endif free(directory_path); free(filename); @@ -3347,7 +3423,7 @@ static TreeInfo *getDummyArtworkInfo(int type) return artwork_new; } -void LoadArtworkInfo() +void LoadArtworkInfo(void) { LoadArtworkInfoCache(); @@ -3427,8 +3503,8 @@ void LoadArtworkInfo() #endif } -void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node, - LevelDirTree *level_node) +static void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node, + LevelDirTree *level_node) { int type = (*artwork_node)->type; @@ -3483,7 +3559,7 @@ void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node, } } -void LoadLevelArtworkInfo() +void LoadLevelArtworkInfo(void) { print_timestamp_init("LoadLevelArtworkInfo"); @@ -3620,7 +3696,15 @@ char *getArtworkIdentifierForUserLevelSet(int type) classic_artwork_set); } -boolean checkIfCustomArtworkExistsForCurrentLevelSet() +TreeInfo *getArtworkTreeInfoForUserLevelSet(int type) +{ + char *artwork_set = getArtworkIdentifierForUserLevelSet(type); + TreeInfo *artwork_first_node = ARTWORK_FIRST_NODE(artwork, type); + + return getTreeInfoFromIdentifier(artwork_first_node, artwork_set); +} + +boolean checkIfCustomArtworkExistsForCurrentLevelSet(void) { char *graphics_set = getArtworkIdentifierForUserLevelSet(ARTWORK_TYPE_GRAPHICS); @@ -3779,7 +3863,7 @@ boolean CreateUserLevelSet(char *level_subdir, char *level_name, return TRUE; } -static void SaveUserLevelInfo() +static void SaveUserLevelInfo(void) { CreateUserLevelSet(getLoginName(), getLoginName(), getRealName(), 100, FALSE); } @@ -3838,6 +3922,10 @@ char *getSetupValue(int type, void *value) strcpy(value_string, *(char **)value); break; + case TYPE_PLAYER: + sprintf(value_string, "player_%d", *(int *)value + 1); + break; + default: value_string[0] = '\0'; break; @@ -3887,7 +3975,7 @@ char *getSetupLine(struct TokenInfo *token_info, char *prefix, int token_nr) return line; } -void LoadLevelSetup_LastSeries() +void LoadLevelSetup_LastSeries(void) { /* ----------------------------------------------------------------------- */ /* ~/./levelsetup.conf */ @@ -3967,17 +4055,17 @@ static void SaveLevelSetup_LastSeries_Ext(boolean deactivate_last_level_series) free(filename); } -void SaveLevelSetup_LastSeries() +void SaveLevelSetup_LastSeries(void) { SaveLevelSetup_LastSeries_Ext(FALSE); } -void SaveLevelSetup_LastSeries_Deactivate() +void SaveLevelSetup_LastSeries_Deactivate(void) { SaveLevelSetup_LastSeries_Ext(TRUE); } -static void checkSeriesInfo() +static void checkSeriesInfo(void) { static char *level_directory = NULL; Directory *dir; @@ -3999,7 +4087,7 @@ static void checkSeriesInfo() closeDirectory(dir); } -void LoadLevelSetup_SeriesInfo() +void LoadLevelSetup_SeriesInfo(void) { char *filename; SetupFileHash *level_setup_hash = NULL; @@ -4097,7 +4185,7 @@ void LoadLevelSetup_SeriesInfo() free(filename); } -void SaveLevelSetup_SeriesInfo() +void SaveLevelSetup_SeriesInfo(void) { char *filename; char *level_subdir = leveldir_current->subdir;