=============================================================================
*/
-void FS_Dir_f(void);
-void FS_Ls_f(void);
-void FS_Which_f(void);
+void FS_Dir_f(cmd_state_t *cmd);
+void FS_Ls_f(cmd_state_t *cmd);
+void FS_Which_f(cmd_state_t *cmd);
static searchpath_t *FS_FindFile (const char *name, int* index, qboolean quiet);
static packfile_t* FS_AddFileToPack (const char* name, pack_t* pack,
gamedir_t *fs_all_gamedirs = NULL;
int fs_all_gamedirs_count = 0;
-cvar_t scr_screenshot_name = {CVAR_NORESETTODEFAULTS, "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"};
-cvar_t cvar_fs_gamedir = {CVAR_READONLY | CVAR_NORESETTODEFAULTS, "fs_gamedir", "", "the list of currently selected gamedirs (use the 'gamedir' command to change this)"};
+cvar_t scr_screenshot_name = {CVAR_CLIENT | CVAR_NORESETTODEFAULTS, "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 = {CVAR_CLIENT | CVAR_SERVER, "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"};
+cvar_t cvar_fs_gamedir = {CVAR_CLIENT | CVAR_SERVER | CVAR_READONLY | CVAR_NORESETTODEFAULTS, "fs_gamedir", "", "the list of currently selected gamedirs (use the 'gamedir' command to change this)"};
/*
// 1st uint8 : general purpose bit flag
// Check bits 0 (encryption), 3 (data descriptor after the file), and 5 (compressed patched data (?))
//
- // LordHavoc: bit 3 would be a problem if we were scanning the archive
+ // LadyHavoc: bit 3 would be a problem if we were scanning the archive
// but is not a problem in the central directory where the values are
// always real.
//
============
*/
-static void FS_Path_f (void)
+static void FS_Path_f(cmd_state_t *cmd)
{
searchpath_t *s;
}
else
{
- Con_Printf("unable to load pak \"%s\"\n", pakfile);
+ Con_Errorf("unable to load pak \"%s\"\n", pakfile);
return false;
}
}
// -game <gamedir>
// Adds basedir/gamedir as an override game
- // LordHavoc: now supports multiple -game directories
+ // LadyHavoc: now supports multiple -game directories
// set the com_modname (reported in server info)
*gamedirbuf = 0;
for (i = 0;i < fs_numgamedirs;i++)
else
Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
- if((i = COM_CheckParm("-modname")) && i < com_argc - 1)
- strlcpy(com_modname, com_argv[i+1], sizeof(com_modname));
+ if((i = COM_CheckParm("-modname")) && i < sys.argc - 1)
+ strlcpy(com_modname, sys.argv[i+1], sizeof(com_modname));
// If "-condebug" is in the command line, remove the previous log file
if (COM_CheckParm ("-condebug") != 0)
// look for the pop.lmp file and set registered to true if it is found
if (FS_FileExists("gfx/pop.lmp"))
- Cvar_Set ("registered", "1");
+ Cvar_SetValueQuick(®istered, 1);
switch(gamemode)
{
case GAME_NORMAL:
W_UnloadAll();
}
-static void FS_Rescan_f(void)
+static void FS_Rescan_f(cmd_state_t *cmd)
{
FS_Rescan();
}
if (cls.demoplayback)
{
- CL_Disconnect_f();
+ CL_Disconnect_f(&cmd_client);
cls.demonum = 0;
}
// unload all sounds so they will be reloaded from the new files as needed
- S_UnloadAllSounds_f();
-
- // close down the video subsystem, it will start up again when the config finishes...
- VID_Stop();
- vid_opened = false;
+ S_UnloadAllSounds_f(&cmd_client);
// restart the video subsystem after the config is executed
- Cbuf_InsertText("\nloadconfig\nvid_restart\n\n");
+ Cbuf_InsertText(&cmd_client, "\nloadconfig\nvid_restart\n\n");
return true;
}
FS_GameDir_f
================
*/
-static void FS_GameDir_f (void)
+static void FS_GameDir_f(cmd_state_t *cmd)
{
int i;
int numgamedirs;
char gamedirs[MAX_GAMEDIRS][MAX_QPATH];
- if (Cmd_Argc() < 2)
+ if (Cmd_Argc(cmd) < 2)
{
Con_Printf("gamedirs active:");
for (i = 0;i < fs_numgamedirs;i++)
return;
}
- numgamedirs = Cmd_Argc() - 1;
+ numgamedirs = Cmd_Argc(cmd) - 1;
if (numgamedirs > MAX_GAMEDIRS)
{
Con_Printf("Too many gamedirs (%i > %i)\n", numgamedirs, MAX_GAMEDIRS);
}
for (i = 0;i < numgamedirs;i++)
- strlcpy(gamedirs[i], Cmd_Argv(i+1), sizeof(gamedirs[i]));
+ strlcpy(gamedirs[i], Cmd_Argv(cmd, i+1), sizeof(gamedirs[i]));
if ((cls.state == ca_connected && !cls.demoplayback) || sv.active)
{
const char **new_argv;
int i = 0;
int args_left = 256;
- new_argv = (const char **)Mem_Alloc(fs_mempool, sizeof(*com_argv) * (com_argc + args_left + 2));
- if(com_argc == 0)
+ new_argv = (const char **)Mem_Alloc(fs_mempool, sizeof(*sys.argv) * (sys.argc + args_left + 2));
+ if(sys.argc == 0)
new_argv[0] = "dummy"; // Can't really happen.
else
- new_argv[0] = com_argv[0];
+ new_argv[0] = sys.argv[0];
++i;
p = buf;
while(COM_ParseToken_Console(&p))
++i;
}
// Now: i <= args_left + 1.
- if (com_argc >= 1)
+ if (sys.argc >= 1)
{
- memcpy((char *)(&new_argv[i]), &com_argv[1], sizeof(*com_argv) * (com_argc - 1));
- i += com_argc - 1;
+ memcpy((char *)(&new_argv[i]), &sys.argv[1], sizeof(*sys.argv) * (sys.argc - 1));
+ i += sys.argc - 1;
}
- // Now: i <= args_left + (com_argc || 1).
+ // Now: i <= args_left + (sys.argc || 1).
new_argv[i] = NULL;
- com_argv = new_argv;
- com_argc = i;
-}
-
-/*
-================
-FS_Init_SelfPack
-================
-*/
-void FS_Init_SelfPack (void)
-{
- PK3_OpenLibrary ();
- fs_mempool = Mem_AllocPool("file management", 0, NULL);
-
- // Load darkplaces.opt from the FS.
- if (!COM_CheckParm("-noopt"))
- {
- char *buf = (char *) FS_SysLoadFile("darkplaces.opt", tempmempool, true, NULL);
- if(buf)
- COM_InsertFlags(buf);
- Mem_Free(buf);
- }
-
-#ifndef USE_RWOPS
- // Provide the SelfPack.
- if (!COM_CheckParm("-noselfpack"))
- {
- if (com_selffd >= 0)
- {
- fs_selfpack = FS_LoadPackPK3FromFD(com_argv[0], com_selffd, true);
- if(fs_selfpack)
- {
- FS_AddSelfPack();
- if (!COM_CheckParm("-noopt"))
- {
- char *buf = (char *) FS_LoadFile("darkplaces.opt", tempmempool, true, NULL);
- if(buf)
- COM_InsertFlags(buf);
- Mem_Free(buf);
- }
- }
- }
- }
-#endif
+ sys.argv = new_argv;
+ sys.argc = i;
}
static int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t userdirsize)
#endif
}
-/*
-================
-FS_Init
-================
-*/
-void FS_Init (void)
+void FS_Init_Commands(void)
+{
+ Cvar_RegisterVariable (&scr_screenshot_name);
+ Cvar_RegisterVariable (&fs_empty_files_in_pack_mark_deletions);
+ Cvar_RegisterVariable (&cvar_fs_gamedir);
+
+ Cmd_AddCommand(CMD_SHARED, "gamedir", FS_GameDir_f, "changes active gamedir list (can take multiple arguments), not including base directory (example usage: gamedir ctf)");
+ Cmd_AddCommand(CMD_SHARED, "fs_rescan", FS_Rescan_f, "rescans filesystem for new pack archives and any other changes");
+ Cmd_AddCommand(CMD_SHARED, "path", FS_Path_f, "print searchpath (game directories and archives)");
+ Cmd_AddCommand(CMD_SHARED, "dir", FS_Dir_f, "list files in searchpath matching an * filename pattern, one per line");
+ Cmd_AddCommand(CMD_SHARED, "ls", FS_Ls_f, "list files in searchpath matching an * filename pattern, multiple per line");
+ Cmd_AddCommand(CMD_SHARED, "which", FS_Which_f, "accepts a file name as argument and reports where the file is taken from");
+}
+
+static void FS_Init_Dir (void)
{
const char *p;
int i;
// Overrides the system supplied base directory (under GAMENAME)
// COMMANDLINEOPTION: Filesystem: -basedir <path> chooses what base directory the game data is in, inside this there should be a data directory for the game (for example id1)
i = COM_CheckParm ("-basedir");
- if (i && i < com_argc-1)
+ if (i && i < sys.argc-1)
{
- strlcpy (fs_basedir, com_argv[i+1], sizeof (fs_basedir));
+ strlcpy (fs_basedir, sys.argv[i+1], sizeof (fs_basedir));
i = (int)strlen (fs_basedir);
if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
fs_basedir[i-1] = 0;
dpsnprintf(fs_basedir, sizeof(fs_basedir), "/sdcard/%s/", gameuserdirname);
#elif defined(MACOSX)
// FIXME: is there a better way to find the directory outside the .app, without using Objective-C?
- if (strstr(com_argv[0], ".app/"))
+ if (strstr(sys.argv[0], ".app/"))
{
char *split;
- strlcpy(fs_basedir, com_argv[0], sizeof(fs_basedir));
+ strlcpy(fs_basedir, sys.argv[0], sizeof(fs_basedir));
split = strstr(fs_basedir, ".app/");
if (split)
{
strlcat(fs_basedir, "/", sizeof(fs_basedir));
// Add the personal game directory
- if((i = COM_CheckParm("-userdir")) && i < com_argc - 1)
- dpsnprintf(fs_userdir, sizeof(fs_userdir), "%s/", com_argv[i+1]);
+ if((i = COM_CheckParm("-userdir")) && i < sys.argc - 1)
+ dpsnprintf(fs_userdir, sizeof(fs_userdir), "%s/", sys.argv[i+1]);
else if (COM_CheckParm("-nohome"))
*fs_userdir = 0; // user wants roaming installation, no userdir
else
p = FS_CheckGameDir(gamedirname1);
if(!p || p == fs_checkgamedir_missing)
- Con_Printf("WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname1);
+ Con_Warnf("WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname1);
if(gamedirname2)
{
p = FS_CheckGameDir(gamedirname2);
if(!p || p == fs_checkgamedir_missing)
- Con_Printf("WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname2);
+ Con_Warnf("WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname2);
}
// -game <gamedir>
// Adds basedir/gamedir as an override game
- // LordHavoc: now supports multiple -game directories
- for (i = 1;i < com_argc && fs_numgamedirs < MAX_GAMEDIRS;i++)
+ // LadyHavoc: now supports multiple -game directories
+ for (i = 1;i < sys.argc && fs_numgamedirs < MAX_GAMEDIRS;i++)
{
- if (!com_argv[i])
+ if (!sys.argv[i])
continue;
- if (!strcmp (com_argv[i], "-game") && i < com_argc-1)
+ if (!strcmp (sys.argv[i], "-game") && i < sys.argc-1)
{
i++;
- p = FS_CheckGameDir(com_argv[i]);
+ p = FS_CheckGameDir(sys.argv[i]);
if(!p)
- Sys_Error("Nasty -game name rejected: %s", com_argv[i]);
+ Sys_Error("Nasty -game name rejected: %s", sys.argv[i]);
if(p == fs_checkgamedir_missing)
- Con_Printf("WARNING: -game %s%s/ not found!\n", fs_basedir, com_argv[i]);
+ Con_Warnf("WARNING: -game %s%s/ not found!\n", fs_basedir, sys.argv[i]);
// add the gamedir to the list of active gamedirs
- strlcpy (fs_gamedirs[fs_numgamedirs], com_argv[i], sizeof(fs_gamedirs[fs_numgamedirs]));
+ strlcpy (fs_gamedirs[fs_numgamedirs], sys.argv[i], sizeof(fs_gamedirs[fs_numgamedirs]));
fs_numgamedirs++;
}
}
fs_mutex = Thread_CreateMutex();
}
-void FS_Init_Commands(void)
+/*
+================
+FS_Init_SelfPack
+================
+*/
+void FS_Init_SelfPack (void)
{
- Cvar_RegisterVariable (&scr_screenshot_name);
- Cvar_RegisterVariable (&fs_empty_files_in_pack_mark_deletions);
- Cvar_RegisterVariable (&cvar_fs_gamedir);
+ char *buf;
+
+ // Load darkplaces.opt from the FS.
+ if (!COM_CheckParm("-noopt"))
+ {
+ buf = (char *) FS_SysLoadFile("darkplaces.opt", tempmempool, true, NULL);
+ if(buf)
+ {
+ COM_InsertFlags(buf);
+ Mem_Free(buf);
+ }
+ }
+
+#ifndef USE_RWOPS
+ // Provide the SelfPack.
+ if (!COM_CheckParm("-noselfpack") && sys.selffd >= 0)
+ {
+ fs_selfpack = FS_LoadPackPK3FromFD(sys.argv[0], sys.selffd, true);
+ if(fs_selfpack)
+ {
+ FS_AddSelfPack();
+ if (!COM_CheckParm("-noopt"))
+ {
+ buf = (char *) FS_LoadFile("darkplaces.opt", tempmempool, true, NULL);
+ if(buf)
+ {
+ COM_InsertFlags(buf);
+ Mem_Free(buf);
+ }
+ }
+ }
+ }
+#endif
+}
+
+/*
+================
+FS_Init
+================
+*/
+
+void FS_Init(void)
+{
+ fs_mempool = Mem_AllocPool("file management", 0, NULL);
+
+ FS_Init_Commands();
+
+ PK3_OpenLibrary ();
+
+ // initialize the self-pack (must be before COM_InitGameType as it may add command line options)
+ FS_Init_SelfPack();
+
+ // detect gamemode from commandline options or executable name
+ COM_InitGameType();
- Cmd_AddCommand ("gamedir", FS_GameDir_f, "changes active gamedir list (can take multiple arguments), not including base directory (example usage: gamedir ctf)");
- Cmd_AddCommand ("fs_rescan", FS_Rescan_f, "rescans filesystem for new pack archives and any other changes");
- 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");
- Cmd_AddCommand ("which", FS_Which_f, "accepts a file name as argument and reports where the file is taken from");
+ FS_Init_Dir();
}
/*
opt = O_CREAT | O_APPEND;
break;
default:
- Con_Printf ("FS_SysOpen(%s, %s): invalid mode\n", filepath, mode);
+ Con_Errorf ("FS_SysOpen(%s, %s): invalid mode\n", filepath, mode);
return FILEDESC_INVALID;
}
for (ind = 1; mode[ind] != '\0'; ind++)
dolock = true;
break;
default:
- Con_Printf ("FS_SysOpen(%s, %s): unknown character in mode (%c)\n",
+ Con_Errorf ("FS_SysOpen(%s, %s): unknown character in mode (%c)\n",
filepath, mode, mode[ind]);
}
}
// No Zlib DLL = no compressed files
if (!zlib_dll && (pfile->flags & PACKFILE_FLAG_DEFLATED))
{
- Con_Printf("WARNING: can't open the compressed file %s\n"
+ Con_Warnf("WARNING: can't open the compressed file %s\n"
"You need the Zlib DLL to use compressed files\n",
pfile->name);
return NULL;
}
#endif
- // LordHavoc: FILEDESC_SEEK affects all duplicates of a handle so we do it before
+ // LadyHavoc: FILEDESC_SEEK affects all duplicates of a handle so we do it before
// the dup() call to avoid having to close the dup_handle on error here
if (FILEDESC_SEEK (pack->handle, pfile->offset, SEEK_SET) == -1)
{
{
if (FILEDESC_SEEK (file->handle, file->buff_ind - file->buff_len, SEEK_CUR) == -1)
{
- Con_Printf("WARNING: could not seek in %s.\n", file->filename);
+ Con_Warnf("WARNING: could not seek in %s.\n", file->filename);
}
}
FS_Purge (file);
// Write the buffer and update the position
- // LordHavoc: to hush a warning about passing size_t to an unsigned int parameter on Win64 we do this as multiple writes if the size would be too big for an integer (we never write that big in one go, but it's a theory)
+ // LadyHavoc: to hush a warning about passing size_t to an unsigned int parameter on Win64 we do this as multiple writes if the size would be too big for an integer (we never write that big in one go, but it's a theory)
while (written < (fs_offset_t)datasize)
{
// figure out how much to write in one chunk
buffer = (unsigned char *)Mem_Alloc (tempmempool, buffersize);
// Skip all data until we reach the requested offset
- while (offset > file->position)
+ while (offset > (file->position - file->buff_len + file->buff_ind))
{
- fs_offset_t diff = offset - file->position;
+ fs_offset_t diff = offset - (file->position - file->buff_len + file->buff_ind);
fs_offset_t count, len;
count = (diff > buffersize) ? buffersize : diff;
return (int)numfiles;
}
-static void FS_ListDirectoryCmd (const char* cmdname, int oneperline)
+static void FS_ListDirectoryCmd (cmd_state_t *cmd, const char* cmdname, int oneperline)
{
const char *pattern;
- if (Cmd_Argc() >= 3)
+ if (Cmd_Argc(cmd) >= 3)
{
Con_Printf("usage:\n%s [path/pattern]\n", cmdname);
return;
}
- if (Cmd_Argc() == 2)
- pattern = Cmd_Argv(1);
+ if (Cmd_Argc(cmd) == 2)
+ pattern = Cmd_Argv(cmd, 1);
else
pattern = "*";
if (!FS_ListDirectory(pattern, oneperline))
Con_Print("No files found.\n");
}
-void FS_Dir_f(void)
+void FS_Dir_f(cmd_state_t *cmd)
{
- FS_ListDirectoryCmd("dir", true);
+ FS_ListDirectoryCmd(cmd, "dir", true);
}
-void FS_Ls_f(void)
+void FS_Ls_f(cmd_state_t *cmd)
{
- FS_ListDirectoryCmd("ls", false);
+ FS_ListDirectoryCmd(cmd, "ls", false);
}
-void FS_Which_f(void)
+void FS_Which_f(cmd_state_t *cmd)
{
const char *filename;
int index;
searchpath_t *sp;
- if (Cmd_Argc() != 2)
+ if (Cmd_Argc(cmd) != 2)
{
- Con_Printf("usage:\n%s <file>\n", Cmd_Argv(0));
+ Con_Printf("usage:\n%s <file>\n", Cmd_Argv(cmd, 0));
return;
}
- filename = Cmd_Argv(1);
+ filename = Cmd_Argv(cmd, 1);
sp = FS_FindFile(filename, &index, true);
if (!sp) {
Con_Printf("%s isn't anywhere\n", filename);