added functions to handle network level directories
authorHolger Schemel <info@artsoft.org>
Wed, 22 Aug 2018 09:23:19 +0000 (11:23 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 22 Aug 2018 09:23:19 +0000 (11:23 +0200)
src/libgame/setup.c
src/libgame/setup.h
src/libgame/system.h

index de23a94035ee2ef5da704d97a06e53ec43f21b8a..802c673a54d232db51dc336d6b0de18e0878eb7c 100644 (file)
@@ -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);
index a9ca6109703a8589eed2d944f186674ea1636c3a..90a53154576f894e73fab3f24ab086d2096a00f9 100644 (file)
@@ -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);
 
index 5e61476f721fa110f262056acdf03977d0eba3a5..7c550499acbaed0cce06236df3066048f1290ab9 100644 (file)
 #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"