]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/common/vfs.c
FS improvements from NetRadiant: "forbidden" directories, and pk3dirs
[xonotic/netradiant.git] / tools / quake3 / common / vfs.c
index 4ca2457225bb54b9c75f300b43ce8719cf0b6428..f8cda41cf9d13337a403f62f3fe69f892261fd1a 100644 (file)
@@ -78,8 +78,10 @@ typedef struct
 
 static GSList*  g_unzFiles;
 static GSList*  g_pakFiles;
-static char     g_strDirs[VFS_MAXDIRS][PATH_MAX];
+static char     g_strDirs[VFS_MAXDIRS][PATH_MAX+1];
 static int      g_numDirs;
+char     g_strForbiddenDirs[VFS_MAXDIRS][PATH_MAX+1];
+int      g_numForbiddenDirs = 0;
 static gboolean g_bUsePak = TRUE;
 
 // =============================================================================
@@ -168,13 +170,24 @@ void vfsInitDirectory (const char *path)
   char filename[PATH_MAX];
   char *dirlist;
   GDir *dir;
+  int j;
   
-  if (g_numDirs == (VFS_MAXDIRS-1))
+  for(j = 0; j < g_numForbiddenDirs; ++j)
+  {
+    if(!Q_stricmp(path, g_strForbiddenDirs[j])
+    || (strlen(path) > strlen(g_strForbiddenDirs[j]) && path[strlen(path) - strlen(g_strForbiddenDirs[j]) - 1] == '/' && !Q_stricmp(path + strlen(path) - strlen(g_strForbiddenDirs[j]), g_strForbiddenDirs[j])))
+      break;
+  }
+  if(j < g_numForbiddenDirs)
+    return;
+  
+  if (g_numDirs == VFS_MAXDIRS)
     return;
   
   Sys_Printf ("VFS Init: %s\n", path);
   
-  strcpy (g_strDirs[g_numDirs], path);
+  strncpy (g_strDirs[g_numDirs], path, PATH_MAX);
+  g_strDirs[g_numDirs][PATH_MAX] = 0;
   vfsFixDOSName (g_strDirs[g_numDirs]);
   vfsAddSlash (g_strDirs[g_numDirs]);
   g_numDirs++;
@@ -191,10 +204,25 @@ void vfsInitDirectory (const char *path)
         if(name == NULL)
           break;
 
+        for(j = 0; j < g_numForbiddenDirs; ++j)
+          if(!Q_stricmp(name, g_strForbiddenDirs[j]))
+            break;
+        if(j < g_numForbiddenDirs)
+          continue;
         dirlist = g_strdup(name);
 
         {
           char *ext = strrchr (dirlist, '.');
+         if(ext && !Q_stricmp(ext, ".pk3dir"))
+         {
+           if (g_numDirs == VFS_MAXDIRS)
+             continue;
+           snprintf(g_strDirs[g_numDirs], PATH_MAX, "%s/%s", path, name);
+           g_strDirs[g_numDirs][PATH_MAX] = '\0';
+           vfsFixDOSName (g_strDirs[g_numDirs]);
+           vfsAddSlash (g_strDirs[g_numDirs]);
+           ++g_numDirs;
+         }
           if ((ext == NULL) || (Q_stricmp (ext, ".pk3") != 0))
             continue;
         }