]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Append path in listdirectory automatically.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 14 Feb 2008 20:12:35 +0000 (20:12 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 14 Feb 2008 20:12:35 +0000 (20:12 +0000)
Remove .. and . from directory listings in the Win32 code, too.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8092 d7cf8633-e32d-0410-b094-e92efae38249

common.h
filematch.c
fs.c
menu.c

index d464958371021229494a5ba7e6d27ee069841df8..1a9659a9c5ea83f9802eeea212b5fcea640f1bca 100644 (file)
--- a/common.h
+++ b/common.h
@@ -316,7 +316,7 @@ typedef struct stringlist_s
 int matchpattern(const char *in, const char *pattern, int caseinsensitive);
 void stringlistinit(stringlist_t *list);
 void stringlistfreecontents(stringlist_t *list);
-void stringlistappend(stringlist_t *list, char *text);
+void stringlistappend(stringlist_t *list, const char *text);
 void stringlistsort(stringlist_t *list);
 void listdirectory(stringlist_t *list, const char *path);
 
index eeae427d4a595a909889728bf3cdba150dfd23b2..bb5a942d982312a1525d337b8e41aacd1b144cfd 100644 (file)
@@ -78,7 +78,7 @@ void stringlistfreecontents(stringlist_t *list)
                Z_Free(list->strings);
 }
 
-void stringlistappend(stringlist_t *list, char *text)
+void stringlistappend(stringlist_t *list, const char *text)
 {
        size_t textlen;
        char **oldstrings;
@@ -119,6 +119,15 @@ void stringlistsort(stringlist_t *list)
 }
 
 // operating system specific code
+static void adddirentry( stringlist_t *list, const char *path, const char *name )
+{
+       if (strcmp(name, ".") && strcmp(name, ".."))
+       {
+               char fullpath[MAX_OSPATH];
+               dpsnprintf (fullpath, sizeof (fullpath), "%s%s", path, name);
+               stringlistappend(list, fullpath);
+       }
+}
 #ifdef WIN32
 #include <io.h>
 void listdirectory(stringlist_t *list, const char *path)
@@ -127,17 +136,15 @@ void listdirectory(stringlist_t *list, const char *path)
        char pattern[4096], *c;
        struct _finddata_t n_file;
        long hFile;
-       strlcpy (pattern, path, sizeof (pattern));
+       strlcpy (pattern, *path ? path : "./", sizeof (pattern));
        strlcat (pattern, "*", sizeof (pattern));
        // ask for the directory listing handle
        hFile = _findfirst(pattern, &n_file);
        if(hFile == -1)
                return;
-       // start a new chain with the the first name
-       stringlistappend(list, n_file.name);
-       // iterate through the directory
-       while (_findnext(hFile, &n_file) == 0)
-               stringlistappend(list, n_file.name);
+       do {
+               adddirentry(list, path, n_file.name );
+       } while (_findnext(hFile, &n_file) == 0);
        _findclose(hFile);
 
        // convert names to lowercase because windows does not care, but pattern matching code often does
@@ -152,12 +159,11 @@ void listdirectory(stringlist_t *list, const char *path)
 {
        DIR *dir;
        struct dirent *ent;
-       dir = opendir(path);
+       dir = opendir( *path ? path : "./" );
        if (!dir)
                return;
        while ((ent = readdir(dir)))
-               if (strcmp(ent->d_name, ".") && strcmp(ent->d_name, ".."))
-                       stringlistappend(list, ent->d_name);
+               adddirentry(list, path, ent->d_name);
        closedir(dir);
 }
 #endif
diff --git a/fs.c b/fs.c
index eee8a47d0c5e7afbb0346197574410d4914eb625..ad6e55b50e774a05f7e9eef5bcf87f9c8672996a 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -960,7 +960,6 @@ void FS_AddGameDirectory (const char *dir)
        int i;
        stringlist_t list;
        searchpath_t *search;
-       char pakfile[MAX_OSPATH];
 
        strlcpy (fs_gamedir, dir, sizeof (fs_gamedir));
 
@@ -973,8 +972,7 @@ void FS_AddGameDirectory (const char *dir)
        {
                if (!strcasecmp(FS_FileExtension(list.strings[i]), "pak"))
                {
-                       dpsnprintf (pakfile, sizeof (pakfile), "%s%s", dir, list.strings[i]);
-                       FS_AddPack_Fullpath(pakfile, NULL, false);
+                       FS_AddPack_Fullpath(list.strings[i], NULL, false);
                }
        }
 
@@ -983,8 +981,7 @@ void FS_AddGameDirectory (const char *dir)
        {
                if (!strcasecmp(FS_FileExtension(list.strings[i]), "pk3"))
                {
-                       dpsnprintf (pakfile, sizeof (pakfile), "%s%s", dir, list.strings[i]);
-                       FS_AddPack_Fullpath(pakfile, NULL, false);
+                       FS_AddPack_Fullpath(list.strings[i], NULL, false);
                }
        }
 
@@ -2605,17 +2602,17 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
                        listdirectory(&dirlist, netpath);
                        for (dirlistindex = 0;dirlistindex < dirlist.numstrings;dirlistindex++)
                        {
-                               dpsnprintf(temp, sizeof(temp), "%s%s", basepath, dirlist.strings[dirlistindex]);
-                               if (matchpattern(temp, (char *)pattern, true))
+                               const char *direntry = dirlist.strings[dirlistindex];
+                               if (matchpattern(direntry, (char *)pattern, true))
                                {
                                        for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
-                                               if (!strcmp(resultlist.strings[resultlistindex], temp))
+                                               if (!strcmp(resultlist.strings[resultlistindex], direntry))
                                                        break;
                                        if (resultlistindex == resultlist.numstrings)
                                        {
-                                               stringlistappend(&resultlist, temp);
+                                               stringlistappend(&resultlist, direntry);
                                                if (!quiet && developer_loading.integer)
-                                                       Con_Printf("SearchDirFile: %s\n", temp);
+                                                       Con_Printf("SearchDirFile: %s\n", direntry);
                                        }
                                }
                        }
diff --git a/menu.c b/menu.c
index afae9ad2296602c7b8f8ee8dadd70678538fae12..5ba0fe60fe70c50de504e6afa2a0951dc5619193 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -4466,12 +4466,19 @@ void ModList_RebuildList(void)
 {
        int i,j;
        stringlist_t list;
+       int basedirlength; 
 
        stringlistinit(&list);
        if (fs_basedir[0])
+       {
                listdirectory(&list, fs_basedir);
+               basedirlength = strlen( fs_basedir );
+       }
        else
+       {
                listdirectory(&list, "./");
+               basedirlength = 2;
+       }
        stringlistsort(&list);
        modlist_count = 0;
        modlist_numenabled = fs_numgamedirs;
@@ -4486,7 +4493,7 @@ void ModList_RebuildList(void)
                if (FS_CheckNastyPath (list.strings[i], true)) continue;
                if (!FS_CheckGameDir(list.strings[i])) continue;
 
-               strlcpy (modlist[modlist_count].dir, list.strings[i], sizeof(modlist[modlist_count].dir));
+               strlcpy (modlist[modlist_count].dir, list.strings[i] + basedirlength, sizeof(modlist[modlist_count].dir));
                //check currently loaded mods
                modlist[modlist_count].loaded = false;
                if (fs_numgamedirs)