]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
vfspk3 in q3map2: also support -fs_forbiddenpath
authorRudolf Polzer <divverent@alientrap.org>
Sat, 7 Aug 2010 15:32:57 +0000 (17:32 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Sat, 7 Aug 2010 15:32:57 +0000 (17:32 +0200)
plugins/vfspk3/vfs.cpp
tools/quake3/common/vfs.c
tools/quake3/common/vfs.h
tools/quake3/q3map2/path_init.c

index ca5d3853540a5aca1d279c69de3e0b60b8932f27..e10c1ce636c1a5f9417883267833dee3dd7e684c 100644 (file)
@@ -315,12 +315,17 @@ void InitDirectory(const char* directory, ArchiveModules& archiveModules)
 
   for(j = 0; j < g_numForbiddenDirs; ++j)
   {
+    printf("match against %s?\n", g_strForbiddenDirs[j]);
     if(!string_compare_nocase_upper(directory, g_strForbiddenDirs[j])
     || (string_length(directory) > string_length(g_strForbiddenDirs[j]) && directory[string_length(directory) - string_length(g_strForbiddenDirs[j]) - 1] == '/' && !string_compare_nocase_upper(directory + string_length(directory) - string_length(g_strForbiddenDirs[j]), g_strForbiddenDirs[j])))
       break;
+    printf("not matched\n");
   }
   if(j < g_numForbiddenDirs)
+  {
+    printf("Directory %s matched by forbidden dirs, removed\n", directory);
     return;
+  }
 
   if (g_numDirs == VFS_MAXDIRS)
     return;
index f4dbb54349d3daa83913d436503f976b29e4467a..547ee70a960ab3f2b272b5b10f2a896d60252869 100644 (file)
@@ -41,19 +41,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // Leonardo Zide (leo@lokigames.com)
 //
 
-#include <stdio.h>
-
-#if defined (__linux__) || defined (__APPLE__)
-#include <dirent.h>
-#include <unistd.h>
-#else
-#include <wtypes.h>
-#include <io.h>
-#define R_OK 04
-#define S_ISDIR(mode) (mode & _S_IFDIR)
-#define PATH_MAX 260
-#endif
-
 #include <string.h>
 #include <stdlib.h>
 #include <sys/stat.h>
@@ -78,8 +65,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 +157,24 @@ void vfsInitDirectory (const char *path)
   char filename[PATH_MAX];
   char *dirlist;
   GDir *dir;
+  int j;
+
+  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,6 +191,12 @@ 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);
 
         {
index d2e4d6fd402b115030e14655f415be4b1429e63b..de1992d20f03aa8fde7de4a46a8052d4372527f6 100644 (file)
@@ -31,6 +31,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #ifndef _VFS_H_
 #define _VFS_H_
 
+// to get PATH_MAX
+#include <stdio.h>
+#if defined (__linux__) || defined (__APPLE__)
+#include <dirent.h>
+#include <unistd.h>
+#else
+#include <wtypes.h>
+#include <io.h>
+#define R_OK 04
+#define S_ISDIR(mode) (mode & _S_IFDIR)
+#define PATH_MAX 260
+#endif
+
 #define VFS_MAXDIRS 64
 
 void vfsInitDirectory (const char *path);
@@ -38,4 +51,7 @@ void vfsShutdown ();
 int vfsGetFileCount (const char *filename);
 int vfsLoadFile (const char *filename, void **buffer, int index);
 
+extern char     g_strForbiddenDirs[VFS_MAXDIRS][PATH_MAX+1];
+extern int      g_numForbiddenDirs;
+
 #endif // _VFS_H_
index cce52117b67fedc10efc04c6850a4f2f2e13671a..8674d87f9185d8b72ab22d6f1e50709844dd30a5 100644 (file)
@@ -359,6 +359,21 @@ void InitPaths( int *argc, char **argv )
                        argv[ i ] = NULL;
                }
 
+               /* -fs_forbiddenpath */
+               else if( strcmp( argv[ i ], "-fs_forbiddenpath" ) == 0 )
+               {
+                       if( ++i >= *argc )
+                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
+                       argv[ i - 1 ] = NULL;
+                       if(g_numForbiddenDirs < VFS_MAXDIRS)
+                       {
+                               strncpy(g_strForbiddenDirs[g_numForbiddenDirs], argv[i], PATH_MAX);
+                               g_strForbiddenDirs[g_numForbiddenDirs][PATH_MAX] = 0;
+                               ++g_numForbiddenDirs;
+                       }
+                       argv[ i ] = NULL;
+               }
+
                /* -fs_basepath */
                else if( strcmp( argv[ i ], "-fs_basepath" ) == 0 )
                {