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 de23a94..802c673 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 a9ca610..90a5315 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 5e61476..7c55049 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"