From: Holger Schemel Date: Wed, 22 Aug 2018 09:23:19 +0000 (+0200) Subject: added functions to handle network level directories X-Git-Tag: 4.1.1.0~63 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=c3e9cc5a7524e88ca789982a803b805272448c0b;p=rocksndiamonds.git added functions to handle network level directories --- diff --git a/src/libgame/setup.c b/src/libgame/setup.c index de23a940..802c673a 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -167,6 +167,16 @@ static char *getCacheDir() return cache_dir; } +static char *getNetworkDir() +{ + 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; @@ -198,6 +208,22 @@ char *getUserLevelDir(char *level_subdir) return userlevel_dir; } +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() { return getLevelDirFromTreeInfo(leveldir_current); @@ -1049,6 +1075,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); diff --git a/src/libgame/setup.h b/src/libgame/setup.h index a9ca6109..90a53154 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -250,6 +250,7 @@ char *getCustomMusicDirectory(void); void InitTapeDirectory(char *); void InitScoreDirectory(char *); void InitUserLevelDirectory(char *); +void InitNetworkLevelDirectory(char *); void InitLevelSetupDirectory(char *); TreeInfo *newTreeInfo(); @@ -276,6 +277,7 @@ char *getPersonalDataDir(void); char *getUserGameDataDir(void); char *getSetupDir(void); char *getUserLevelDir(char *); +char *getNetworkLevelDir(char *); char *getCurrentLevelDir(void); char *getNewUserLevelSubdir(void); diff --git a/src/libgame/system.h b/src/libgame/system.h index 5e61476f..7c550499 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -567,6 +567,7 @@ #define DOCS_DIRECTORY "docs" #define CACHE_DIRECTORY "cache" #define CONF_DIRECTORY "conf" +#define NETWORK_DIRECTORY "network" #define GFX_CLASSIC_SUBDIR "gfx_classic" #define SND_CLASSIC_SUBDIR "snd_classic"