/*
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
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, "");
-#endif
+ strlcpy(fs_basedir, "", sizeof(fs_basedir));
#ifdef MACOSX
// FIXME: is there a better way to find the directory outside the .app?
- if (!fs_basedir[0] && strstr(com_argv[0], ".app/"))
+ if (strstr(com_argv[0], ".app/"))
{
char *split;
strlcpy(fs_basedir, com_argv[0], sizeof(fs_basedir));
fs_basedir[split - com_argv[0]] = 0;
}
+#endif
#endif
PK3_OpenLibrary ();
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);
- }
+ // add the game-specific paths
+ // gamedirname1 (typically id1)
+ FS_AddGameHierarchy (gamedirname1);
- // 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)
+ // 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));
+ }
+
+ // 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");
}
- // If "-condebug" is in the command line, remove the previous log file
- if (COM_CheckParm ("-condebug") != 0)
- unlink (va("%s/qconsole.log", fs_gamedir));
+ // 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)
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);
}
/*
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)
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))
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);