From 274484ecdaf6a699b9b2862ba3bb35ef0c1b1408 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 23 Feb 2011 10:49:42 +0100 Subject: [PATCH] FS improvements from NetRadiant: "forbidden" directories, and pk3dirs --- tools/quake3/common/cmdlib.c | 8 +++----- tools/quake3/common/cmdlib.h | 4 ++++ tools/quake3/common/vfs.c | 34 +++++++++++++++++++++++++++++++--- tools/quake3/common/vfs.h | 5 ++++- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index 6e4a0520..85068de3 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -250,9 +250,7 @@ char *ExpandArg (const char *path) char *ExpandPath (const char *path) { static char full[1024]; - if (!qdir) - Error ("ExpandPath called without qdir set"); - if (path[0] == '/' || path[0] == '\\' || path[1] == ':') { + if (!*qdir || path[0] == '/' || path[0] == '\\' || path[1] == ':') { strcpy( full, path ); return full; } @@ -263,8 +261,8 @@ char *ExpandPath (const char *path) char *ExpandGamePath (const char *path) { static char full[1024]; - if (!qdir) - Error ("ExpandGamePath called without qdir set"); + if (!*gamedir) + Error ("ExpandGamePath called without gamedir set"); if (path[0] == '/' || path[0] == '\\' || path[1] == ':') { strcpy( full, path ); return full; diff --git a/tools/quake3/common/cmdlib.h b/tools/quake3/common/cmdlib.h index afb62d92..f85be38f 100644 --- a/tools/quake3/common/cmdlib.h +++ b/tools/quake3/common/cmdlib.h @@ -53,7 +53,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #endif +#ifdef PATH_MAX +#define MAX_OS_PATH PATH_MAX +#else #define MAX_OS_PATH 1024 +#endif #define MEM_BLOCKSIZE 4096 // the dec offsetof macro doesnt work very well... diff --git a/tools/quake3/common/vfs.c b/tools/quake3/common/vfs.c index 4ca24572..f8cda41c 100644 --- a/tools/quake3/common/vfs.c +++ b/tools/quake3/common/vfs.c @@ -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; } diff --git a/tools/quake3/common/vfs.h b/tools/quake3/common/vfs.h index 44b3ffad..dec1170d 100644 --- a/tools/quake3/common/vfs.h +++ b/tools/quake3/common/vfs.h @@ -31,11 +31,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef _VFS_H_ #define _VFS_H_ -#define VFS_MAXDIRS 8 +#define VFS_MAXDIRS 64 void vfsInitDirectory (const char *path); 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_ -- 2.39.2