provide a list of all gamedirs with modinfo.txt in fs_all_gamedirs for later use...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 6 Aug 2009 19:06:22 +0000 (19:06 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 6 Aug 2009 19:06:22 +0000 (19:06 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9099 d7cf8633-e32d-0410-b094-e92efae38249

fs.c
fs.h

diff --git a/fs.c b/fs.c
index d4b1517..18c98c6 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -317,6 +317,10 @@ char fs_basedir[MAX_OSPATH];
 int fs_numgamedirs = 0;
 char fs_gamedirs[MAX_GAMEDIRS][MAX_QPATH];
 
+// list of all gamedirs with modinfo.txt
+gamedir_t *fs_all_gamedirs = NULL;
+int fs_all_gamedirs_count = 0;
+
 cvar_t scr_screenshot_name = {0, "scr_screenshot_name","dp", "prefix name for saved screenshots (changes based on -game commandline, as well as which game mode is running; the date is encoded using strftime escapes)"};
 cvar_t fs_empty_files_in_pack_mark_deletions = {0, "fs_empty_files_in_pack_mark_deletions", "0", "if enabled, empty files in a pak/pk3 count as not existing but cancel the search in further packs, effectively allowing patch pak/pk3 files to 'delete' files"};
 
@@ -1422,7 +1426,17 @@ const char *FS_CheckGameDir(const char *gamedir)
 
        ret = FS_SysCheckGameDir(va("%s%s/", fs_userdir, gamedir));
        if(ret)
+       {
+               if(!*ret)
+               {
+                       // get description from basedir
+                       ret = FS_SysCheckGameDir(va("%s%s/", fs_basedir, gamedir));
+                       if(ret)
+                               return ret;
+                       return "";
+               }
                return ret;
+       }
 
        ret = FS_SysCheckGameDir(va("%s%s/", fs_basedir, gamedir));
        if(ret)
@@ -1431,6 +1445,54 @@ const char *FS_CheckGameDir(const char *gamedir)
        return fs_checkgamedir_missing;
 }
 
+static void FS_ListGameDirs()
+{
+       stringlist_t list, list2;
+       int i, j;
+       const char *info;
+
+       fs_all_gamedirs_count = 0;
+       if(fs_all_gamedirs)
+               Mem_Free(fs_all_gamedirs);
+
+       stringlistinit(&list);
+       listdirectory(&list, va("%s/", fs_basedir), "");
+       listdirectory(&list, va("%s/", fs_userdir), "");
+       stringlistsort(&list);
+
+       stringlistinit(&list2);
+       for(i = 0; i < list.numstrings; ++i)
+       {
+               if(i)
+                       if(!strcmp(list.strings[i-1], list.strings[i]))
+                               continue;
+               info = FS_CheckGameDir(list.strings[i]);
+               if(!info)
+                       continue;
+               if(info == fs_checkgamedir_missing)
+                       continue;
+               if(!*info)
+                       continue;
+               stringlistappend(&list2, list.strings[i]); 
+       }
+       stringlistfreecontents(&list);
+
+       fs_all_gamedirs = Mem_Alloc(fs_mempool, list2.numstrings * sizeof(*fs_all_gamedirs));
+       for(i = 0; i < list2.numstrings; ++i)
+       {
+               info = FS_CheckGameDir(list2.strings[i]);
+               // all this cannot happen any more, but better be safe than sorry
+               if(!info)
+                       continue;
+               if(info == fs_checkgamedir_missing)
+                       continue;
+               if(!*info)
+                       continue;
+               strlcpy(fs_all_gamedirs[fs_all_gamedirs_count].name, list2.strings[i], sizeof(fs_all_gamedirs[j].name));
+               strlcpy(fs_all_gamedirs[fs_all_gamedirs_count].description, info, sizeof(fs_all_gamedirs[j].description));
+               ++fs_all_gamedirs_count;
+       }
+}
 
 /*
 ================
@@ -1567,6 +1629,8 @@ void FS_Init (void)
        if (fs_basedir[0] && fs_basedir[strlen(fs_basedir) - 1] != '/' && fs_basedir[strlen(fs_basedir) - 1] != '\\')
                strlcat(fs_basedir, "/", sizeof(fs_basedir));
 
+       FS_ListGameDirs();
+
        p = FS_CheckGameDir(gamedirname1);
        if(!p || p == fs_checkgamedir_missing)
                Con_Printf("WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname1);
diff --git a/fs.h b/fs.h
index d98216d..78909aa 100644 (file)
--- a/fs.h
+++ b/fs.h
@@ -79,6 +79,15 @@ int FS_CheckNastyPath (const char *path, qboolean isgamedir);
 extern const char *const fs_checkgamedir_missing; // "(missing)"
 const char *FS_CheckGameDir(const char *gamedir); // returns NULL if nasty, fs_checkgamedir_missing (exact pointer) if missing
 
+typedef struct
+{
+       char name[MAX_OSPATH];
+       char description[8192];
+}
+gamedir_t;
+extern gamedir_t *fs_all_gamedirs; // terminated by entry with empty name
+extern int fs_all_gamedirs_count;
+
 qboolean FS_ChangeGameDirs(int numgamedirs, char gamedirs[][MAX_QPATH], qboolean complain, qboolean failmissing);
 qboolean FS_IsRegisteredQuakePack(const char *name);
 int FS_CRCFile(const char *filename, size_t *filesizepointer);