]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - fs.c
cleaned up almost all direct indexing of matrix4x4_t structures to go through proper...
[xonotic/darkplaces.git] / fs.c
diff --git a/fs.c b/fs.c
index f982e226bad6a218ec4d522cf6a752ae3cf3c4f3..b7b74d92f54415775661954c7da8d969ee0123a5 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -1,7 +1,7 @@
 /*
        DarkPlaces file system
 
-       Copyright (C) 2003-2005 Mathieu Olivier
+       Copyright (C) 2003-2006 Mathieu Olivier
 
        This program is free software; you can redistribute it and/or
        modify it under the terms of the GNU General Public License
@@ -1061,14 +1061,13 @@ void FS_Init (void)
 
        fs_mempool = Mem_AllocPool("file management", 0, NULL);
 
-       strcpy(fs_gamedir, "");
+       strlcpy(fs_gamedir, "", sizeof(fs_gamedir));
 
 // If the base directory is explicitly defined by the compilation process
 #ifdef DP_FS_BASEDIR
-       strcpy(fs_basedir, DP_FS_BASEDIR);
-
+       strlcpy(fs_basedir, DP_FS_BASEDIR, sizeof(fs_basedir));
 #else
-       strcpy(fs_basedir, "");
+       strlcpy(fs_basedir, "", sizeof(fs_basedir));
 
 #ifdef MACOSX
        // FIXME: is there a better way to find the directory outside the .app?
@@ -1123,43 +1122,66 @@ void FS_Init (void)
                                fs_searchpaths = search;
                        }
                }
-               return;
        }
-
-       // add the game-specific paths
-       // gamedirname1 (typically id1)
-       FS_AddGameHierarchy (gamedirname1);
-
-       // add the game-specific path, if any
-       if (gamedirname2)
+       else
        {
-               fs_modified = true;
-               FS_AddGameHierarchy (gamedirname2);
-       }
-
-       // set the com_modname (reported in server info)
-       strlcpy(com_modname, gamedirname1, sizeof(com_modname));
+               // add the game-specific paths
+               // gamedirname1 (typically id1)
+               FS_AddGameHierarchy (gamedirname1);
 
-       // -game <gamedir>
-       // Adds basedir/gamedir as an override game
-       // LordHavoc: now supports multiple -game directories
-       for (i = 1;i < com_argc;i++)
-       {
-               if (!com_argv[i])
-                       continue;
-               if (!strcmp (com_argv[i], "-game") && i < com_argc-1)
+               // add the game-specific path, if any
+               if (gamedirname2)
                {
-                       i++;
                        fs_modified = true;
-                       FS_AddGameHierarchy (com_argv[i]);
-                       // update the com_modname
-                       strlcpy (com_modname, com_argv[i], sizeof (com_modname));
+                       FS_AddGameHierarchy (gamedirname2);
                }
+
+               // set the com_modname (reported in server info)
+               strlcpy(com_modname, gamedirname1, sizeof(com_modname));
+
+               // -game <gamedir>
+               // Adds basedir/gamedir as an override game
+               // LordHavoc: now supports multiple -game directories
+               for (i = 1;i < com_argc;i++)
+               {
+                       if (!com_argv[i])
+                               continue;
+                       if (!strcmp (com_argv[i], "-game") && i < com_argc-1)
+                       {
+                               i++;
+                               fs_modified = true;
+                               FS_AddGameHierarchy (com_argv[i]);
+                               // update the com_modname
+                               strlcpy (com_modname, com_argv[i], sizeof (com_modname));
+                       }
+               }
+
+               // If "-condebug" is in the command line, remove the previous log file
+               if (COM_CheckParm ("-condebug") != 0)
+                       unlink (va("%s/qconsole.log", fs_gamedir));
        }
 
-       // If "-condebug" is in the command line, remove the previous log file
-       if (COM_CheckParm ("-condebug") != 0)
-               unlink (va("%s/qconsole.log", fs_gamedir));
+       // look for the pop.lmp file and set registered to true if it is found
+       if (gamemode == GAME_NORMAL && !FS_FileExists("gfx/pop.lmp"))
+       {
+               if (fs_modified)
+                       Con_Print("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n");
+               else
+                       Con_Print("Playing shareware version.\n");
+       }
+       else
+       {
+               Cvar_Set ("registered", "1");
+               if (gamemode == GAME_NORMAL || gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE)
+                       Con_Print("Playing registered version.\n");
+       }
+
+       // set the default screenshot name to either the mod name or the
+       // gamemode screenshot name
+       if (fs_modified)
+               Cvar_SetQuick (&scr_screenshot_name, com_modname);
+       else
+               Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
 }
 
 void FS_Init_Commands(void)
@@ -1169,13 +1191,6 @@ void FS_Init_Commands(void)
        Cmd_AddCommand ("path", FS_Path_f, "print searchpath (game directories and archives)");
        Cmd_AddCommand ("dir", FS_Dir_f, "list files in searchpath matching an * filename pattern, one per line");
        Cmd_AddCommand ("ls", FS_Ls_f, "list files in searchpath matching an * filename pattern, multiple per line");
-
-       // set the default screenshot name to either the mod name or the
-       // gamemode screenshot name
-       if (fs_modified)
-               Cvar_SetQuick (&scr_screenshot_name, com_modname);
-       else
-               Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
 }
 
 /*
@@ -2074,17 +2089,19 @@ FS_StripExtension
 void FS_StripExtension (const char *in, char *out, size_t size_out)
 {
        char *last = NULL;
+       char currentchar;
 
        if (size_out == 0)
                return;
 
-       while (*in && size_out > 1)
+       while ((currentchar = *in) && size_out > 1)
        {
-               if (*in == '.')
+               if (currentchar == '.')
                        last = out;
-               else if (*in == '/' || *in == '\\' || *in == ':')
+               else if (currentchar == '/' || currentchar == '\\' || currentchar == ':')
                        last = NULL;
-               *out++ = *in++;
+               *out++ = currentchar;
+               in++;
                size_out--;
        }
        if (last)
@@ -2222,7 +2239,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
                        pak = searchpath->pack;
                        for (i = 0;i < pak->numfiles;i++)
                        {
-                               strcpy(temp, pak->files[i].name);
+                               strlcpy(temp, pak->files[i].name, sizeof(temp));
                                while (temp[0])
                                {
                                        if (matchpattern(temp, (char *)pattern, true))
@@ -2302,10 +2319,12 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
                numchars = 0;
                for (listtemp = liststart;listtemp;listtemp = listtemp->next)
                {
+                       size_t textlen;
                        search->filenames[numfiles] = search->filenamesbuffer + numchars;
-                       strcpy(search->filenames[numfiles], listtemp->text);
+                       textlen = strlen(listtemp->text) + 1;
+                       memcpy(search->filenames[numfiles], listtemp->text, textlen);
                        numfiles++;
-                       numchars += (int)strlen(listtemp->text) + 1;
+                       numchars += (int)textlen;
                }
                if (liststart)
                        stringlistfree(liststart);