nuke Qexpand_squiggle. instead, expand ~ to $HOME on qfs initialization and

cache the value.

don't call Qopen directly in the engine. instead call QFS_Open (generic) or
QFS_WOpen (write only, zip flag).

rework QFS_NextFilename to use a dstring (avoiding a potential buffer
overflow), support 10000 files and work from the top-level fs_userpath
directory. adjust QFS_WriteFile and QFS_WriteBuffers etc to suit.

make sw32 screenshots actually get written.

hopefully everything gets written to the right places :)
This commit is contained in:
Bill Currie 2003-05-23 17:17:01 +00:00
parent c5be2fb501
commit c2c3a62956
28 changed files with 254 additions and 630 deletions

View file

@ -61,37 +61,46 @@ typedef struct gamedir_s {
extern searchpath_t *qfs_searchpaths; extern searchpath_t *qfs_searchpaths;
extern gamedir_t *qfs_gamedir; extern gamedir_t *qfs_gamedir;
extern struct cvar_s *fs_userpath;
extern struct cvar_s *fs_sharepath; extern struct cvar_s *fs_sharepath;
extern struct cvar_s *fs_userpath;
extern const char *qfs_userpath;
extern int file_from_pak; extern int file_from_pak;
extern int qfs_filesize; extern int qfs_filesize;
struct cache_user_s; struct cache_user_s;
struct dstring_s;
char *QFS_CompressPath (const char *pth); void QFS_Init (const char *game);
void QFS_Gamedir (const char *dir);
QFile *QFS_Open (const char *path, const char *mode);
QFile *QFS_WOpen (const char *path, int zip);
void QFS_WriteFile (const char *filename, void *data, int len); void QFS_WriteFile (const char *filename, void *data, int len);
void QFS_WriteBuffers (const char *filename, int count, ...); void QFS_WriteBuffers (const char *filename, int count, ...);
struct dstring_s;
int _QFS_FOpenFile (const char *filename, QFile **gzfile, struct dstring_s *foundname, int zip); int _QFS_FOpenFile (const char *filename, QFile **gzfile,
struct dstring_s *foundname, int zip);
int QFS_FOpenFile (const char *filename, QFile **gzfile); int QFS_FOpenFile (const char *filename, QFile **gzfile);
void QFS_FileBase (const char *in, char *out);
void QFS_DefaultExtension (char *path, const char *extension);
const char *QFS_SkipPath (const char *pathname);
void QFS_StripExtension (const char *in, char *out);
int QFS_NextFilename (char *filename, const char *prefix, const char *ext);
const char *QFS_FileExtension (const char *in);
QFile *QFS_WOpen (const char *path, int zip);
int QFS_Rename (const char *old, const char *new);
byte *QFS_LoadFile (const char *path, int usehunk); byte *QFS_LoadFile (const char *path, int usehunk);
byte *QFS_LoadStackFile (const char *path, void *buffer, int bufsize); byte *QFS_LoadStackFile (const char *path, void *buffer, int bufsize);
byte *QFS_LoadTempFile (const char *path); byte *QFS_LoadTempFile (const char *path);
byte *QFS_LoadHunkFile (const char *path); byte *QFS_LoadHunkFile (const char *path);
void QFS_LoadCacheFile (const char *path, struct cache_user_s *cu); void QFS_LoadCacheFile (const char *path, struct cache_user_s *cu);
void QFS_CreatePath (const char *path); void QFS_CreatePath (const char *path);
void QFS_Gamedir (const char *dir); int QFS_Rename (const char *old, const char *new);
void QFS_Init (const char *game); int QFS_Remove (const char *path);
int QFS_NextFilename (struct dstring_s *filename, const char *prefix,
const char *ext);
void QFS_FileBase (const char *in, char *out);
void QFS_DefaultExtension (char *path, const char *extension);
void QFS_StripExtension (const char *in, char *out);
char *QFS_CompressPath (const char *pth);
const char *QFS_SkipPath (const char *pathname);
const char *QFS_FileExtension (const char *in);
#endif // __quakefs_h #endif // __quakefs_h

View file

@ -32,7 +32,6 @@
typedef struct QFile_s QFile; typedef struct QFile_s QFile;
void Qexpand_squiggle(const char *path, char *dest);
int Qrename(const char *old, const char *new); int Qrename(const char *old, const char *new);
int Qremove(const char *path); int Qremove(const char *path);
int Qfilesize (QFile *file); int Qfilesize (QFile *file);

View file

@ -391,7 +391,7 @@ C_Print (const char *fmt, va_list args)
// log all messages to file // log all messages to file
if (con_debuglog) if (con_debuglog)
Sys_DebugLog (va ("%s/%s/qconsole.log", fs_userpath->string, Sys_DebugLog (va ("%s/%s/qconsole.log", qfs_userpath,
qfs_gamedir->dir.def), "%s", buffer->str); qfs_gamedir->dir.def), "%s", buffer->str);
if (!con_initialized) if (!con_initialized)

View file

@ -244,7 +244,7 @@ sv_logfile_f (cvar_t *var)
} else { } else {
flags = nva ("a"); flags = nva ("a");
} }
log_file = Qopen (va ("%s/%s", fs_userpath->string, fname), flags); log_file = QFS_Open (fname, flags);
free (flags); free (flags);
free (fname); free (fname);
} }

View file

@ -162,8 +162,7 @@ bi_File_Open (progs_t *pr)
if (do_write && !file_writeable (path)) if (do_write && !file_writeable (path))
goto error; goto error;
*file = Qopen (va ("%s/%s/%s", fs_userpath->string, *file = QFS_Open (va ("%s/%s", qfs_gamedir->dir.def, path), mode);
qfs_gamedir->dir.def, path), mode);
if (!*file) if (!*file)
goto error; goto error;
R_INT (pr) = (file - res->handles) + 1; R_INT (pr) = (file - res->handles) + 1;

View file

@ -127,7 +127,7 @@ bi_QFS_WriteFile (progs_t *pr)
int count = P_INT (pr, 2); int count = P_INT (pr, 2);
check_buffer (pr, buf, count, "QFS_WriteFile"); check_buffer (pr, buf, count, "QFS_WriteFile");
QFS_WriteFile (filename, buf, count); QFS_WriteFile (va ("%s/%s", qfs_gamedir->dir.def, filename), buf, count);
} }
void void

View file

@ -756,7 +756,7 @@ GIB_File_Transform_Path_Null (dstring_t * path)
static int static int
GIB_File_Transform_Path_Secure (dstring_t * path) GIB_File_Transform_Path_Secure (dstring_t * path)
{ {
char *s, e_dir[MAX_OSPATH]; char *s;
for (s = strchr (path->str, '\\'); s; s = strchr (s, '\\')) for (s = strchr (path->str, '\\'); s; s = strchr (s, '\\'))
*s = '/'; *s = '/';
@ -766,8 +766,7 @@ GIB_File_Transform_Path_Secure (dstring_t * path)
dstring_insertstr (path, 0, "/"); dstring_insertstr (path, 0, "/");
dstring_insertstr (path, 0, qfs_gamedir->dir.def); dstring_insertstr (path, 0, qfs_gamedir->dir.def);
dstring_insertstr (path, 0, "/"); dstring_insertstr (path, 0, "/");
Qexpand_squiggle (fs_userpath->string, e_dir); dstring_insertstr (path, 0, qfs_userpath);
dstring_insertstr (path, 0, e_dir);
return 0; return 0;
} }
@ -822,7 +821,8 @@ GIB_File_Write_f (void)
} }
path = GIB_Argv (1); path = GIB_Argv (1);
QFS_WriteFile (path, GIB_Argv(2), GIB_Argd(2)->size-1); QFS_WriteFile (va ("%s/%s", qfs_gamedir->dir.def, path),
GIB_Argv(2), GIB_Argd(2)->size-1);
} }
static void static void

View file

@ -40,6 +40,11 @@ static __attribute__ ((unused)) const char rcsid[] =
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
#ifdef HAVE_IO_H
# include <io.h>
#else
# include <pwd.h>
#endif
#include <ctype.h> #include <ctype.h>
#include <dirent.h> #include <dirent.h>
@ -118,6 +123,8 @@ cvar_t *fs_userpath;
cvar_t *fs_sharepath; cvar_t *fs_sharepath;
cvar_t *fs_dirconf; cvar_t *fs_dirconf;
const char *qfs_userpath;
int qfs_filesize; int qfs_filesize;
searchpath_t *qfs_searchpaths; searchpath_t *qfs_searchpaths;
@ -571,9 +578,7 @@ QFS_WriteFile (const char *filename, void *data, int len)
char name[MAX_OSPATH]; char name[MAX_OSPATH];
QFile *f; QFile *f;
snprintf (name, sizeof (name), "%s/%s", qfs_gamedir->dir.def, filename); f = QFS_WOpen (filename, 0);
f = QFS_WOpen (name, 0);
if (!f) { if (!f) {
Sys_Error ("Error opening %s", filename); Sys_Error ("Error opening %s", filename);
} }
@ -591,20 +596,17 @@ QFS_WriteFile (const char *filename, void *data, int len)
void void
QFS_WriteBuffers (const char *filename, int count, ...) QFS_WriteBuffers (const char *filename, int count, ...)
{ {
char name[MAX_OSPATH];
va_list args; va_list args;
QFile *f; QFile *f;
va_start (args, count); va_start (args, count);
snprintf (name, sizeof (name), "%s/%s", qfs_gamedir->dir.def, filename); f = QFS_WOpen (filename, 0);
f = QFS_WOpen (name, 0);
if (!f) { if (!f) {
Sys_Error ("Error opening %s", filename); Sys_Error ("Error opening %s", filename);
} }
Sys_Printf ("QFS_WriteBuffers: %s\n", name); Sys_Printf ("QFS_WriteBuffers: %s\n", filename);
while (count--) { while (count--) {
void *data = va_arg (args, void *); void *data = va_arg (args, void *);
int len = va_arg (args, int); int len = va_arg (args, int);
@ -626,8 +628,6 @@ QFS_CreatePath (const char *path)
char *ofs; char *ofs;
char e_path[MAX_OSPATH]; char e_path[MAX_OSPATH];
Qexpand_squiggle (path, e_path);
for (ofs = e_path + 1; *ofs; ofs++) { for (ofs = e_path + 1; *ofs; ofs++) {
if (*ofs == '/') { // create the directory if (*ofs == '/') { // create the directory
*ofs = 0; *ofs = 0;
@ -1086,10 +1086,6 @@ static void
QFS_AddDirectory (const char *dir) QFS_AddDirectory (const char *dir)
{ {
searchpath_t *search; searchpath_t *search;
char e_dir[MAX_OSPATH];
Qexpand_squiggle (dir, e_dir);
dir = e_dir;
// add the directory to the search path // add the directory to the search path
search = calloc (1, sizeof (searchpath_t)); search = calloc (1, sizeof (searchpath_t));
@ -1111,7 +1107,7 @@ QFS_AddGameDirectory (const char *dir)
if (strcmp (fs_sharepath->string, fs_userpath->string) != 0) if (strcmp (fs_sharepath->string, fs_userpath->string) != 0)
QFS_AddDirectory (va ("%s/%s", fs_sharepath->string, dir)); QFS_AddDirectory (va ("%s/%s", fs_sharepath->string, dir));
QFS_AddDirectory (va ("%s/%s", fs_userpath->string, dir)); QFS_AddDirectory (va ("%s/%s", qfs_userpath, dir));
} }
/* /*
@ -1129,6 +1125,38 @@ QFS_Gamedir (const char *dir)
Cache_Flush (); Cache_Flush ();
} }
static char *
expand_squiggle (const char *path)
{
char *home;
#ifndef _WIN32
struct passwd *pwd_ent;
#endif
if (strncmp (path, "~/", 2) != 0) {
return strdup (path);
}
#ifdef _WIN32
// LordHavoc: first check HOME to duplicate previous version behavior
// (also handy if someone wants it elsewhere than their windows directory)
home = getenv ("HOME");
if (!home || !home[0])
home = getenv ("WINDIR");
#else
if ((pwd_ent = getpwuid (getuid ()))) {
home = pwd_ent->pw_dir;
} else
home = getenv ("HOME");
#endif
if (home)
return nva ("%s%s", home, path + 1); // skip leading ~
return strdup (path);
}
void void
QFS_Init (const char *game) QFS_Init (const char *game)
{ {
@ -1144,6 +1172,8 @@ QFS_Init (const char *game)
Cmd_AddCommand ("path", QFS_Path_f, "Show what paths Quake is using"); Cmd_AddCommand ("path", QFS_Path_f, "Show what paths Quake is using");
qfs_userpath = expand_squiggle (fs_userpath->string);
qfs_load_config (); qfs_load_config ();
qfs_game = game; qfs_game = game;
@ -1225,48 +1255,49 @@ QFS_DefaultExtension (char *path, const char *extension)
} }
int int
QFS_NextFilename (char *filename, const char *prefix, const char *ext) QFS_NextFilename (dstring_t *filename, const char *prefix, const char *ext)
{ {
char *digits; char *digits;
char checkname[MAX_OSPATH], exp[MAX_OSPATH];
int i; int i;
strncpy (filename, prefix, MAX_OSPATH - 4); dsprintf (filename, "%s0000%s", prefix, ext);
filename[MAX_OSPATH - 4] = 0; digits = filename->str + strlen (prefix);
digits = filename + strlen (filename);
strcat (filename, "000");
strncat (filename, ext, MAX_OSPATH - strlen (filename));
Qexpand_squiggle (fs_userpath->string, exp);
for (i = 0; i <= 999; i++) { for (i = 0; i <= 9999; i++) {
digits[0] = i / 100 + '0'; digits[0] = i / 1000 + '0';
digits[1] = i / 100 % 10 + '0';
digits[1] = i / 10 % 10 + '0'; digits[1] = i / 10 % 10 + '0';
digits[2] = i % 10 + '0'; digits[2] = i % 10 + '0';
snprintf (checkname, sizeof (checkname), if (Sys_FileTime (va ("%s/%s/%s", qfs_userpath, qfs_gamedir->dir.def,
"%s/%s/%s", exp, qfs_gamedir->dir.def, filename->str)) == -1)
filename);
if (Sys_FileTime (checkname) == -1)
return 1; // file doesn't exist return 1; // file doesn't exist
} }
return 0; return 0;
} }
QFile * QFile *
QFS_WOpen (const char *path, int zip) QFS_Open (const char *path, const char *mode)
{ {
dstring_t *full_path = dstring_new (); dstring_t *full_path = dstring_new ();
QFile *file; QFile *file;
char mode[4] = "wb\000\000";
if (zip) dsprintf (full_path, "%s/%s", qfs_userpath, path);
mode[2] = bound (1, zip, 9) + '0';
dsprintf (full_path, "%s/%s", fs_userpath->string, path);
QFS_CreatePath (full_path->str); QFS_CreatePath (full_path->str);
file = Qopen (full_path->str, mode); file = Qopen (full_path->str, mode);
dstring_delete (full_path); dstring_delete (full_path);
return file; return file;
} }
QFile *
QFS_WOpen (const char *path, int zip)
{
char mode[4] = "wb\000\000";
if (zip)
mode[2] = bound (1, zip, 9) + '0';
return QFS_Open (path, mode);
}
int int
QFS_Rename (const char *old, const char *new) QFS_Rename (const char *old, const char *new)
{ {
@ -1274,11 +1305,23 @@ QFS_Rename (const char *old, const char *new)
dstring_t *full_new = dstring_new (); dstring_t *full_new = dstring_new ();
int ret; int ret;
dsprintf (full_old, "%s/%s", fs_userpath->string, old); dsprintf (full_old, "%s/%s", qfs_userpath, old);
dsprintf (full_new, "%s/%s", fs_userpath->string, new); dsprintf (full_new, "%s/%s", qfs_userpath, new);
QFS_CreatePath (full_new->str); QFS_CreatePath (full_new->str);
ret = Qrename (full_old->str, full_new->str); ret = Qrename (full_old->str, full_new->str);
dstring_delete (full_old); dstring_delete (full_old);
dstring_delete (full_new); dstring_delete (full_new);
return ret; return ret;
} }
int
QFS_Remove (const char *path)
{
dstring_t *full_path = dstring_new ();
int ret;
dsprintf (full_path, "%s/%s", qfs_userpath, path);
ret = Qremove (full_path->str);
dstring_delete (full_path);
return ret;
}

View file

@ -42,11 +42,6 @@ static __attribute__ ((unused)) const char rcsid[] =
#ifdef HAVE_STRINGS_H #ifdef HAVE_STRINGS_H
# include <strings.h> # include <strings.h>
#endif #endif
#ifdef HAVE_IO_H
# include <io.h>
#else
# include <pwd.h>
#endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
@ -85,58 +80,16 @@ struct QFile_s {
}; };
void
Qexpand_squiggle (const char *path, char *dest)
{
char *home;
#ifndef _WIN32
struct passwd *pwd_ent;
#endif
if (strncmp (path, "~/", 2) != 0) {
strcpy (dest, path);
return;
}
#ifdef _WIN32
// LordHavoc: first check HOME to duplicate previous version behavior
// (also handy if someone wants it elsewhere than their windows directory)
home = getenv ("HOME");
if (!home || !home[0])
home = getenv ("WINDIR");
#else
if ((pwd_ent = getpwuid (getuid ()))) {
home = pwd_ent->pw_dir;
} else
home = getenv ("HOME");
#endif
if (home) {
strcpy (dest, home);
strncat (dest, path + 1, MAX_OSPATH - strlen (dest));
// skip leading ~
} else
strcpy (dest, path);
}
int int
Qrename (const char *old, const char *new) Qrename (const char *old, const char *new)
{ {
char e_old[PATH_MAX]; return rename (old, new);
char e_new[PATH_MAX];
Qexpand_squiggle (old, e_old);
Qexpand_squiggle (new, e_new);
return rename (e_old, e_new);
} }
int int
Qremove (const char *path) Qremove (const char *path)
{ {
char e_path[PATH_MAX]; return remove (path);
Qexpand_squiggle (path, e_path);
return remove (e_path);
} }
int int
@ -184,10 +137,6 @@ Qopen (const char *path, const char *mode)
int reading = 0; int reading = 0;
int zip = 0; int zip = 0;
int size = -1; int size = -1;
char e_path[PATH_MAX];
Qexpand_squiggle (path, e_path);
path = e_path;
for (p = m; *mode && p - m < ((int) sizeof (m) - 1); mode++) { for (p = m; *mode && p - m < ((int) sizeof (m) - 1); mode++) {
if (*mode == 'z') { if (*mode == 'z') {

View file

@ -483,15 +483,13 @@ Sys_DebugLog (const char *file, const char *fmt, ...)
int fd; int fd;
char path[PATH_MAX]; char path[PATH_MAX];
Qexpand_squiggle (file, path);
if (!data) if (!data)
data = dstring_newstr (); data = dstring_newstr ();
va_start (args, fmt); va_start (args, fmt);
dvsprintf (data, fmt, args); dvsprintf (data, fmt, args);
va_end (args); va_end (args);
fd = open (path, O_WRONLY | O_CREAT | O_APPEND, 0666); fd = open (path, O_WRONLY | O_CREAT | O_APPEND, 0644);
write (fd, data->str, data->size - 1); write (fd, data->str, data->size - 1);
close (fd); close (fd);
} }

View file

@ -43,12 +43,14 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/console.h" #include "QF/console.h"
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/draw.h" #include "QF/draw.h"
#include "QF/dstring.h"
#include "QF/quakefs.h" #include "QF/quakefs.h"
#include "QF/render.h" #include "QF/render.h"
#include "QF/screen.h" #include "QF/screen.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "QF/texture.h" #include "QF/texture.h"
#include "QF/tga.h" #include "QF/tga.h"
#include "QF/va.h"
#include "QF/GL/defines.h" #include "QF/GL/defines.h"
#include "QF/GL/funcs.h" #include "QF/GL/funcs.h"
#include "QF/GL/qf_rmain.h" #include "QF/GL/qf_rmain.h"
@ -195,20 +197,22 @@ void
SCR_ScreenShot_f (void) SCR_ScreenShot_f (void)
{ {
byte *buffer; byte *buffer;
char pcxname[MAX_OSPATH]; dstring_t *pcxname = dstring_new ();
// find a file name to save it to // find a file name to save it to
if (!QFS_NextFilename (pcxname, "qf", ".tga")) { if (!QFS_NextFilename (pcxname,
va ("%s/qf", qfs_gamedir->dir.def), ".tga")) {
Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n"); Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");
return; } else {
buffer = malloc (glwidth * glheight * 3);
SYS_CHECKMEM (buffer);
qfglReadPixels (glx, gly, glwidth, glheight, GL_BGR_EXT,
GL_UNSIGNED_BYTE, buffer);
WriteTGAfile (pcxname->str, buffer, glwidth, glheight);
free (buffer);
Con_Printf ("Wrote %s\n", pcxname->str);
} }
buffer = malloc (glwidth * glheight * 3); dstring_delete (pcxname);
SYS_CHECKMEM (buffer);
qfglReadPixels (glx, gly, glwidth, glheight, GL_BGR_EXT, GL_UNSIGNED_BYTE,
buffer);
WriteTGAfile (pcxname, buffer, glwidth, glheight);
free (buffer);
Con_Printf ("Wrote %s\n", pcxname);
} }
static void static void

View file

@ -43,12 +43,14 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/console.h" #include "QF/console.h"
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/draw.h" #include "QF/draw.h"
#include "QF/dstring.h"
#include "QF/pcx.h" #include "QF/pcx.h"
#include "QF/quakefs.h" #include "QF/quakefs.h"
#include "QF/render.h" #include "QF/render.h"
#include "QF/screen.h" #include "QF/screen.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "QF/texture.h" #include "QF/texture.h"
#include "QF/va.h"
#include "compat.h" #include "compat.h"
#include "r_cvar.h" #include "r_cvar.h"
@ -234,29 +236,31 @@ SCR_ScreenShot (int width, int height)
void void
SCR_ScreenShot_f (void) SCR_ScreenShot_f (void)
{ {
char pcxname[MAX_OSPATH]; dstring_t *pcxname = dstring_new ();
pcx_t *pcx; pcx_t *pcx;
int pcx_len; int pcx_len;
// find a file name to save it to // find a file name to save it to
if (!QFS_NextFilename (pcxname, "qf", ".pcx")) { if (!QFS_NextFilename (pcxname,
va ("%s/qf", qfs_gamedir->dir.def), ".pcx")) {
Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX"); Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX");
return; } else {
// enable direct drawing of console to back buffer
D_EnableBackBufferAccess ();
// save the pcx file
pcx = EncodePCX (vid.buffer, vid.width, vid.height, vid.rowbytes,
vid.basepal, false, &pcx_len);
QFS_WriteFile (pcxname->str, pcx, pcx_len);
// for adapters that can't stay mapped in for linear writes all the
// time
D_DisableBackBufferAccess ();
Con_Printf ("Wrote %s\n", pcxname->str);
} }
dstring_delete (pcxname);
// enable direct drawing of console to back buffer
D_EnableBackBufferAccess ();
// save the pcx file
pcx = EncodePCX (vid.buffer, vid.width, vid.height, vid.rowbytes,
vid.basepal, false, &pcx_len);
QFS_WriteFile (pcxname, pcx, pcx_len);
// for adapters that can't stay mapped in for linear writes all the time
D_DisableBackBufferAccess ();
Con_Printf ("Wrote %s\n", pcxname);
} }
/* /*

View file

@ -43,12 +43,14 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/console.h" #include "QF/console.h"
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/draw.h" #include "QF/draw.h"
#include "QF/dstring.h"
#include "QF/pcx.h" #include "QF/pcx.h"
#include "QF/quakefs.h" #include "QF/quakefs.h"
#include "QF/render.h" #include "QF/render.h"
#include "QF/screen.h" #include "QF/screen.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "QF/texture.h" #include "QF/texture.h"
#include "QF/va.h"
#include "compat.h" #include "compat.h"
#include "r_cvar.h" #include "r_cvar.h"
@ -243,39 +245,42 @@ SCR_ScreenShot (int width, int height)
void void
SCR_ScreenShot_f (void) SCR_ScreenShot_f (void)
{ {
char pcxname[MAX_OSPATH]; dstring_t *pcxname = dstring_new ();
pcx_t *pcx; pcx_t *pcx;
int pcx_len; int pcx_len;
// find a file name to save it to // find a file name to save it to
if (!QFS_NextFilename (pcxname, "qf", ".pcx")) { if (!QFS_NextFilename (pcxname,
va ("%s/qf", qfs_gamedir->dir.def), ".pcx")) {
Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX"); Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX");
return; } else {
// enable direct drawing of console to back buffer
D_EnableBackBufferAccess ();
// save the pcx file
switch(r_pixbytes) {
case 1:
pcx = EncodePCX (vid.buffer, vid.width, vid.height, vid.rowbytes,
vid.basepal, false, &pcx_len);
break;
case 2:
Con_Printf("SCR_ScreenShot_f: FIXME - add 16bit support\n");
break;
case 4:
Con_Printf("SCR_ScreenShot_f: FIXME - add 32bit support\n");
break;
default:
Sys_Error("SCR_ScreenShot_f: unsupported r_pixbytes %i", r_pixbytes);
}
// for adapters that can't stay mapped in for linear writes all the time
D_DisableBackBufferAccess ();
QFS_WriteFile (pcxname->str, pcx, pcx_len);
Con_Printf ("Wrote %s\n", pcxname->str);
} }
dstring_delete (pcxname);
// enable direct drawing of console to back buffer
D_EnableBackBufferAccess ();
// save the pcx file
switch(r_pixbytes) {
case 1:
pcx = EncodePCX (vid.buffer, vid.width, vid.height, vid.rowbytes,
vid.basepal, false, &pcx_len);
break;
case 2:
Con_Printf("SCR_ScreenShot_f: FIXME - add 16bit support\n");
break;
case 4:
Con_Printf("SCR_ScreenShot_f: FIXME - add 32bit support\n");
break;
default:
Sys_Error("SCR_ScreenShot_f: unsupported r_pixbytes %i", r_pixbytes);
}
// for adapters that can't stay mapped in for linear writes all the time
D_DisableBackBufferAccess ();
Con_Printf ("Wrote %s\n", pcxname);
} }
/* /*

View file

@ -1,4 +1,3 @@
/* /*
cl_demo.c cl_demo.c
@ -253,7 +252,8 @@ CL_Record_f (void)
} else } else
track = -1; track = -1;
snprintf (name, sizeof (name), "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1)); snprintf (name, sizeof (name), "%s/%s",
qfs_gamedir->dir.def, Cmd_Argv (1));
// start the map up // start the map up
// //

View file

@ -729,7 +729,7 @@ Host_InitVCR (quakeparms_t *parms)
if (com_argc != 2) if (com_argc != 2)
Sys_Error ("No other parameters allowed with -playback"); Sys_Error ("No other parameters allowed with -playback");
vcrFile = Qopen ("quake.vcr", "rbz"); vcrFile = QFS_Open ("quake.vcr", "rbz");
if (!vcrFile) if (!vcrFile)
Sys_Error ("playback file not found"); Sys_Error ("playback file not found");
@ -757,7 +757,7 @@ Host_InitVCR (quakeparms_t *parms)
} }
if ((n = COM_CheckParm ("-record")) != 0) { if ((n = COM_CheckParm ("-record")) != 0) {
vcrFile = Qopen ("quake.vcr", "wb"); vcrFile = QFS_Open ("quake.vcr", "wb");
i = VCR_SIGNATURE; i = VCR_SIGNATURE;
Qwrite (vcrFile, &i, sizeof (int)); Qwrite (vcrFile, &i, sizeof (int));

View file

@ -465,7 +465,8 @@ Host_Savegame_f (void)
} }
} }
snprintf (name, sizeof (name), "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1)); snprintf (name, sizeof (name), "%s/%s",
qfs_gamedir->dir.def, Cmd_Argv (1));
QFS_DefaultExtension (name, ".sav"); QFS_DefaultExtension (name, ".sav");
Con_Printf ("Saving game to %s...\n", name); Con_Printf ("Saving game to %s...\n", name);
@ -529,7 +530,7 @@ Host_Loadgame_f (void)
cls.demonum = -1; // stop demo loop in case this fails cls.demonum = -1; // stop demo loop in case this fails
snprintf (name, sizeof (name), "%s/%s/%s", fs_userpath->string, snprintf (name, sizeof (name), "%s/%s",
qfs_gamedir->dir.def, Cmd_Argv (1)); qfs_gamedir->dir.def, Cmd_Argv (1));
QFS_DefaultExtension (name, ".sav"); QFS_DefaultExtension (name, ".sav");
@ -538,7 +539,7 @@ Host_Loadgame_f (void)
// SCR_BeginLoadingPlaque (); // SCR_BeginLoadingPlaque ();
Con_Printf ("Loading game from %s...\n", name); Con_Printf ("Loading game from %s...\n", name);
f = Qopen (name, "rz"); f = QFS_Open (name, "rz");
if (!f) { if (!f) {
Con_Printf ("ERROR: couldn't open.\n"); Con_Printf ("ERROR: couldn't open.\n");
return; return;

View file

@ -219,7 +219,7 @@ typedef struct client_s
qboolean upgradewarn; // did we warn him? qboolean upgradewarn; // did we warn him?
QFile *upload; QFile *upload;
char uploadfn[MAX_QPATH]; struct dstring_s *uploadfn;
netadr_t snap_from; netadr_t snap_from;
qboolean remote_snap; qboolean remote_snap;

View file

@ -848,7 +848,8 @@ CL_ReRecord_f (void)
if (cls.demorecording) if (cls.demorecording)
CL_Stop_f (); CL_Stop_f ();
snprintf (name, sizeof (name), "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1)); snprintf (name, sizeof (name), "%s/%s",
qfs_gamedir->dir.def, Cmd_Argv (1));
// open the demo file // open the demo file
QFS_DefaultExtension (name, ".qwd"); QFS_DefaultExtension (name, ".qwd");
@ -1075,7 +1076,6 @@ CL_TimeFrames_AddTimestamp (void)
static void static void
CL_TimeFrames_DumpLog (void) CL_TimeFrames_DumpLog (void)
{ {
char e_path[MAX_OSPATH];
const char *filename = "timeframes.txt"; const char *filename = "timeframes.txt";
int i; int i;
long frame; long frame;
@ -1084,9 +1084,8 @@ CL_TimeFrames_DumpLog (void)
if (cl_timeframes_isactive == 0) if (cl_timeframes_isactive == 0)
return; return;
Qexpand_squiggle (fs_userpath->string, e_path);
Con_Printf ("Dumping Timed Frames log: %s\n", filename); Con_Printf ("Dumping Timed Frames log: %s\n", filename);
outputfile = Qopen (va ("%s/%s", e_path, filename), "w"); outputfile = QFS_Open (filename, "w");
if (!outputfile) { if (!outputfile) {
Con_Printf ("Could not open: %s\n", filename); Con_Printf ("Could not open: %s\n", filename);
return; return;

View file

@ -305,12 +305,10 @@ SL_SaveF (QFile *f, server_entry_t *start)
void void
SL_Shutdown (void) SL_Shutdown (void)
{ {
char e_path[MAX_OSPATH];
QFile *f; QFile *f;
if (fav_slist) { if (fav_slist) {
Qexpand_squiggle (fs_userpath->string, e_path); if ((f = QFS_Open ("servers.txt", "w"))) {
if ((f = Qopen (va ("%s/servers.txt", e_path), "w"))) {
SL_SaveF (f, fav_slist); SL_SaveF (f, fav_slist);
Qclose (f); Qclose (f);
} }
@ -631,19 +629,11 @@ SL_LoadF (QFile *f, server_entry_t *start)
void void
SL_Init (void) SL_Init (void)
{ {
char e_path[MAX_OSPATH];
QFile *servlist; QFile *servlist;
Qexpand_squiggle (fs_userpath->string, e_path); if ((servlist = QFS_Open ("servers.txt", "r"))) {
if ((servlist = Qopen (va ("%s/servers.txt", e_path), "r"))) {
slist = SL_LoadF (servlist, slist); slist = SL_LoadF (servlist, slist);
Qclose (servlist); Qclose (servlist);
} else {
Qexpand_squiggle (fs_sharepath->string, e_path);
if ((servlist = Qopen (va ("%s/servers.txt", e_path), "r"))) {
slist = SL_LoadF (servlist, slist);
Qclose (servlist);
}
} }
fav_slist = slist; fav_slist = slist;
all_slist = NULL; all_slist = NULL;

View file

@ -144,7 +144,7 @@ CF_BuildQuota (void)
if (!path) if (!path)
path = dstring_new (); path = dstring_new ();
dsprintf (path, "%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, CF_DIR); dsprintf (path, "%s/%s/%s", qfs_userpath, qfs_gamedir->dir.def, CF_DIR);
dir = opendir (path->str); dir = opendir (path->str);
if (!dir) if (!dir)
@ -227,8 +227,7 @@ CF_Open (const char *path, const char *mode)
return -1; return -1;
} }
dsprintf (fullpath, "%s/%s/%s/%s", fs_userpath->string, dsprintf (fullpath, "%s/%s/%s", qfs_gamedir->dir.def, CF_DIR, path);
qfs_gamedir->dir.def, CF_DIR, path);
j = fullpath->str + strlen (fullpath->str) - strlen (path); j = fullpath->str + strlen (fullpath->str) - strlen (path);
for (i = 0; path[i]; i++, j++) // strcpy, but force lowercase for (i = 0; path[i]; i++, j++) // strcpy, but force lowercase
@ -245,7 +244,7 @@ CF_Open (const char *path, const char *mode)
else else
oldsize = 0; oldsize = 0;
file = Qopen (fullpath->str, mode); file = QFS_Open (fullpath->str, mode);
if (file) { if (file) {
if (cf_openfiles >= cf_filepcount) { if (cf_openfiles >= cf_filepcount) {
cf_filepcount++; cf_filepcount++;

View file

@ -203,9 +203,9 @@ locs_save (const char *filename, qboolean gz)
snprintf (locfile, sizeof (locfile), "%s.gz", filename); snprintf (locfile, sizeof (locfile), "%s.gz", filename);
else else
strcpy (locfile, filename); strcpy (locfile, filename);
locfd = Qopen (locfile, "z9w+"); locfd = QFS_Open (locfile, "z9w+");
} else } else
locfd = Qopen (filename, "w+"); locfd = QFS_Open (filename, "w+");
if (locfd == 0) { if (locfd == 0) {
Con_Printf ("ERROR: Unable to open %s\n", filename); Con_Printf ("ERROR: Unable to open %s\n", filename);
return; return;

View file

@ -173,11 +173,8 @@ static void Net_LogPrintf (const char *fmt, ...) __attribute__ ((format (printf,
static int static int
Net_LogStart (const char *fname) Net_LogStart (const char *fname)
{ {
char e_path[MAX_OSPATH];
Qexpand_squiggle (fs_userpath->string, e_path);
Con_Printf ("Opening packet logfile: %s\n", fname); Con_Printf ("Opening packet logfile: %s\n", fname);
Net_PacketLog = Qopen (va ("%s/%s", e_path, fname), "at"); Net_PacketLog = QFS_Open (fname, "at");
if (!Net_PacketLog) if (!Net_PacketLog)
return -1; return -1;
return 0; return 0;
@ -929,11 +926,8 @@ Net_PacketLog_Zap_f (void)
Qseek (Net_PacketLog, 0, 0); Qseek (Net_PacketLog, 0, 0);
Qwrite (Net_PacketLog, 0, 0); Qwrite (Net_PacketLog, 0, 0);
} else { } else {
char e_path[MAX_OSPATH];
Qexpand_squiggle (fs_userpath->string, e_path);
Con_Printf ("Deleting packet logfile: %s\n", "qfpacket.log"); Con_Printf ("Deleting packet logfile: %s\n", "qfpacket.log");
unlink (va ("%s/%s", e_path, "qfpacket.log")); QFS_Remove ("qfpacket.log");
} }
} }

View file

@ -1069,15 +1069,11 @@ Sbar_LogFrags (void)
player_info_t *s = NULL; player_info_t *s = NULL;
const char *t = NULL; const char *t = NULL;
time_t tt = time (NULL); time_t tt = time (NULL);
char e_path[MAX_OSPATH];
if (!cl_fraglog->int_val) if (!cl_fraglog->int_val)
return; return;
memset (&e_path, 0, MAX_OSPATH); if ((file = QFS_Open (fs_fraglog->string, "a")) == NULL)
Qexpand_squiggle (fs_userpath->string, e_path);
if ((file = Qopen (va ("%s/%s", e_path, fs_fraglog->string), "a")) == NULL)
return; return;
t = ctime (&tt); t = ctime (&tt);

View file

@ -44,6 +44,7 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/cmd.h" #include "QF/cmd.h"
#include "QF/console.h" #include "QF/console.h"
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/msg.h" #include "QF/msg.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/qendian.h" #include "QF/qendian.h"
@ -199,7 +200,7 @@ SV_Quit_f (void)
static void static void
SV_Fraglogfile_f (void) SV_Fraglogfile_f (void)
{ {
char name[MAX_OSPATH]; dstring_t *name;
if (sv_fraglogfile) { if (sv_fraglogfile) {
SV_Printf ("Frag file logging off.\n"); SV_Printf ("Frag file logging off.\n");
@ -207,13 +208,16 @@ SV_Fraglogfile_f (void)
sv_fraglogfile = NULL; sv_fraglogfile = NULL;
return; return;
} }
if (!QFS_NextFilename (name, "frag_", ".log")) { name = dstring_new ();
if (!QFS_NextFilename (name,
va ("%s/frag_", qfs_gamedir->dir.def), ".log")) {
SV_Printf ("Can't open any logfiles.\n"); SV_Printf ("Can't open any logfiles.\n");
sv_fraglogfile = NULL; sv_fraglogfile = NULL;
return; } else {
SV_Printf ("Logging frags to %s.\n", name->str);
sv_fraglogfile = QFS_WOpen (name->str, 0);
} }
dstring_delete (name);
SV_Printf ("Logging frags to %s.\n", name);
} }
/* /*
@ -1053,8 +1057,6 @@ SV_Floodprotmsg_f (void)
static void static void
SV_Snap (int uid) SV_Snap (int uid)
{ {
char pcxname[80];
char checkname[MAX_OSPATH];
client_t *cl; client_t *cl;
int i; int i;
@ -1069,25 +1071,17 @@ SV_Snap (int uid)
return; return;
} }
snprintf (pcxname, sizeof (pcxname), "%d-00.pcx", uid); if (!cl->uploadfn)
cl->uploadfn = dstring_new ();
snprintf (checkname, sizeof (checkname), "%s/%s/snap", fs_userpath->string, if (!QFS_NextFilename (cl->uploadfn,
qfs_gamedir->dir.def); va ("%s/snap/%d-", qfs_gamedir->dir.def, uid),
QFS_CreatePath (va ("%s/dummy", checkname)); ".pcx")) {
for (i = 0; i <= 99; i++) {
pcxname[strlen (pcxname) - 6] = i / 10 + '0';
pcxname[strlen (pcxname) - 5] = i % 10 + '0';
snprintf (checkname, sizeof (checkname), "%s/%s/snap/%s",
fs_userpath->string, qfs_gamedir->dir.def, pcxname);
if (Sys_FileTime (checkname) == -1)
break; // file doesn't exist
}
if (i == 100) {
SV_Printf ("Snap: Couldn't create a file, clean some out.\n"); SV_Printf ("Snap: Couldn't create a file, clean some out.\n");
dstring_delete (cl->uploadfn);
cl->uploadfn = 0;
return; return;
} }
strcpy (cl->uploadfn, checkname);
memcpy (&cl->snap_from, &net_from, sizeof (net_from)); memcpy (&cl->snap_from, &net_from, sizeof (net_from));
if (sv_redirected != RD_NONE) if (sv_redirected != RD_NONE)

View file

@ -591,11 +591,12 @@ SV_Stop (int reason)
if (demo.disk) if (demo.disk)
Qclose (demo.file); Qclose (demo.file);
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, demo.path->str, demo.name->str); sprintf (path, "%s/%s/%s", qfs_gamedir->dir.def, demo.path->str,
unlink (path); demo.name->str);
QFS_Remove (path);
strcpy (path + strlen (path) - 3, "txt"); strcpy (path + strlen (path) - 3, "txt");
unlink (path); QFS_Remove (path);
demo.file = NULL; demo.file = NULL;
sv.demorecording = false; sv.demorecording = false;
@ -825,7 +826,7 @@ SV_Record (char *name)
demo.datagram.maxsize = sizeof (demo.datagram_data); demo.datagram.maxsize = sizeof (demo.datagram_data);
demo.datagram.data = demo.datagram_data; demo.datagram.data = demo.datagram_data;
demo.file = Qopen (name, "wb"); demo.file = QFS_Open (name, "wb");
if (!demo.file) { if (!demo.file) {
Con_Printf ("ERROR: couldn't open %s\n", name); Con_Printf ("ERROR: couldn't open %s\n", name);
return; return;
@ -854,7 +855,7 @@ SV_Record (char *name)
if (sv_demotxt->int_val) { if (sv_demotxt->int_val) {
QFile *f; QFile *f;
f = Qopen (path, "w+t"); f = QFS_Open (path, "w+t");
if (f != NULL) { if (f != NULL) {
char buf[2000]; char buf[2000];
char date[20]; char date[20];
@ -1100,12 +1101,10 @@ SV_Record_f (void)
if (sv.demorecording) if (sv.demorecording)
SV_Stop_f (); SV_Stop_f ();
dsprintf (name, "%s/%s/%s/%s%s%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string, dsprintf (name, "%s/%s/%s%s%s", qfs_gamedir->dir.def, sv_demoDir->string,
sv_demoPrefix->string, SV_CleanName (Cmd_Argv (1)), sv_demoPrefix->string, SV_CleanName (Cmd_Argv (1)),
sv_demoSuffix->string); sv_demoSuffix->string);
QFS_CreatePath (name->str);
// open the demo file // open the demo file
name->size += 4; name->size += 4;
dstring_adjust (name); dstring_adjust (name);
@ -1221,7 +1220,7 @@ SV_EasyRecord_f (void)
} }
// Make sure the filename doesn't contain illegal characters // Make sure the filename doesn't contain illegal characters
dsprintf (name2, "%s/%s/%s/%s%s%s", fs_userpath->string, dsprintf (name2, "%s/%s/%s%s%s",
qfs_gamedir->dir.def, sv_demoDir->string, qfs_gamedir->dir.def, sv_demoDir->string,
sv_demoPrefix->string, SV_CleanName (name->str), sv_demoPrefix->string, SV_CleanName (name->str),
sv_demoSuffix->string); sv_demoSuffix->string);
@ -1232,8 +1231,8 @@ SV_EasyRecord_f (void)
name->size += 4; name->size += 4;
dstring_adjust (name); dstring_adjust (name);
QFS_DefaultExtension (name->str, ".mvd"); QFS_DefaultExtension (name->str, ".mvd");
if ((f = Qopen (name->str, "rb")) == 0) if ((f = QFS_Open (name->str, "rb")) == 0)
f = Qopen (va ("%s.gz", name->str), "rb"); f = QFS_Open (va ("%s.gz", name->str), "rb");
if (f) { if (f) {
i = 1; i = 1;
@ -1243,8 +1242,8 @@ SV_EasyRecord_f (void)
name->size += 4; name->size += 4;
dstring_adjust (name); dstring_adjust (name);
QFS_DefaultExtension (name->str, ".mvd"); QFS_DefaultExtension (name->str, ".mvd");
if ((f = Qopen (name->str, "rb")) == 0) if ((f = QFS_Open (name->str, "rb")) == 0)
f = Qopen (va ("%s.gz", name->str), "rb"); f = QFS_Open (va ("%s.gz", name->str), "rb");
i++; i++;
} while (f); } while (f);
} }
@ -1256,363 +1255,6 @@ SV_EasyRecord_f (void)
dstring_delete (name2); dstring_delete (name2);
} }
static void
SV_DemoList_f (void)
{
/*
float f;
int i, j, show;
dir_t dir;
file_t *list;
Con_Printf ("content of %s/%s/%s/ *.mvd\n", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string);
dir = Sys_listdir (va ("%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string), ".mvd");
list = dir.files;
if (!list->name[0]) {
Con_Printf ("no demos\n");
}
for (i = 1; list->name[0]; i++, list++) {
for (j = 1; j < Cmd_Argc (); j++)
if (strstr (list->name, Cmd_Argv (j)) == NULL)
break;
show = Cmd_Argc () == j;
if (show) {
if (sv.demorecording && !strcmp (list->name, demo.name->str))
Con_Printf ("*%d: %s %dk\n", i, list->name, demo.size / 1024);
else
Con_Printf ("%d: %s %dk\n", i, list->name, list->size / 1024);
}
}
if (sv.demorecording)
dir.size += demo.size;
Con_Printf ("\ndirectory size: %.1fMB\n", (float) dir.size / (1024 * 1024));
if (sv_demoMaxDirSize->int_val) {
f = (sv_demoMaxDirSize->int_val * 1024 - dir.size) / (1024 * 1024);
if (f < 0)
f = 0;
Con_Printf ("space available: %.1fMB\n", f);
}
*/
}
static char *
SV_DemoNum (int num)
{
/*
file_t *list;
dir_t dir;
dir = Sys_listdir (va ("%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string), ".mvd");
list = dir.files;
if (num <= 0)
return NULL;
num--;
while (list->name[0] && num) {
list++;
num--;
};
if (list->name[0])
return list->name;
*/
return NULL;
}
static char *
SV_DemoName2Txt (char *name)
{
char s[MAX_OSPATH];
if (!name)
return NULL;
strcpy (s, name);
if (strstr (s, ".mvd.gz") != NULL)
strcpy (s + strlen (s) - 6, "txt");
else
strcpy (s + strlen (s) - 3, "txt");
return va ("%s", s);
}
static char *
SV_DemoTxTNum (int num)
{
return SV_DemoName2Txt (SV_DemoNum (num));
}
static void
SV_DemoRemove_f (void)
{
dstring_t *name = dstring_newstr ();
const char *ptr;
char path[MAX_OSPATH];
if (Cmd_Argc () != 2) {
Con_Printf ("rmdemo <demoname> - removes the demo\n"
"rmdemo *<token> - removes demo with <token> in "
"the name\n"
"rmdemo * - removes all demos\n");
return;
}
ptr = Cmd_Argv (1);
/*
if (*ptr == '*') {
dir_t dir;
file_t *list;
int i;
// remove all demos with specified token
ptr++;
dir =
Sys_listdir (va ("%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string), ".mvd");
list = dir.files;
for (i = 0; list->name[0]; list++) {
if (strstr (list->name, ptr)) {
if (sv.demorecording && !strcmp (list->name, demo.name->str))
SV_Stop_f ();
// stop recording first;
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string,
list->name);
if (!unlink (path)) {
Con_Printf ("removing %s...\n", list->name);
i++;
}
unlink (SV_DemoName2Txt (path));
}
}
if (i) {
Con_Printf ("%d demos removed\n", i);
} else {
Con_Printf ("no matching found\n");
}
return;
}
*/
dsprintf (name, "%s", Cmd_Argv (1));
QFS_DefaultExtension (name->str, ".mvd");
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string, name->str);
if (sv.demorecording && !strcmp (name->str, demo.name->str))
SV_Stop_f ();
if (!unlink (path)) {
Con_Printf ("demo %s succesfully removed\n", name->str);
/*
if (*sv_ondemoremove->string) {
extern redirect_t sv_redirected;
int old = sv_redirected;
// this script is called always from the console
sv_redirected = RD_NONE;
Cmd_TokenizeString (va ("script %s \"%s\" \"%s\"",
sv_ondemoremove->string,
sv_demoDir->string, name->str));
SV_Script_f ();
sv_redirected = old;
}
*/
} else
Con_Printf ("unable to remove demo %s\n", name->str);
unlink (SV_DemoName2Txt (path));
}
static void
SV_DemoRemoveNum_f (void)
{
int num;
const char *val, *name;
char path[MAX_OSPATH];
if (Cmd_Argc () != 2) {
Con_Printf ("rmdemonum <#>\n");
return;
}
val = Cmd_Argv (1);
if ((num = atoi (val)) == 0 && val[0] != '0') {
Con_Printf ("rmdemonum <#>\n");
return;
}
name = SV_DemoNum (num);
if (name != NULL) {
if (sv.demorecording && !strcmp (name, demo.name->str))
SV_Stop_f ();
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string, name);
if (!unlink (path)) {
Con_Printf ("demo %s succesfully removed\n", name);
/*
if (*sv_ondemoremove->string) {
extern redirect_t sv_redirected;
int old = sv_redirected;
// this script is called always from the console
sv_redirected = RD_NONE;
Cmd_TokenizeString (va ("script %s \"%s\" \"%s\"",
sv_ondemoremove->string,
sv_demoDir->string, name));
SV_Script_f ();
sv_redirected = old;
}
*/
} else
Con_Printf ("unable to remove demo %s\n", name);
unlink (SV_DemoName2Txt (path));
} else
Con_Printf ("invalid demo num\n");
}
static void
SV_DemoInfoAdd_f (void)
{
const char *name = 0, *args;
char path[MAX_OSPATH];
QFile *f;
if (Cmd_Argc () < 3) {
Con_Printf ("usage:demoInfoAdd <demonum> <info string>\n"
"<demonum> = * for currently recorded demo\n");
return;
}
if (!strcmp (Cmd_Argv (1), "*")) {
if (!sv.demorecording) {
Con_Printf ("Not recording demo!\n");
return;
}
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, demo.path->str,
SV_DemoName2Txt (demo.name->str));
} else {
name = SV_DemoTxTNum (atoi (Cmd_Argv (1)));
if (!name) {
Con_Printf ("invalid demo num\n");
return;
}
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string, name);
}
if ((f = Qopen (path, "a+t")) == NULL) {
Con_Printf ("faild to open the file\n");
return;
}
// skip demonum
args = Cmd_Args (1);
while (*args > 32)
args++;
while (*args && *args <= 32)
args++;
Qwrite (f, args, strlen (args));
Qwrite (f, "\n", 1);
Qflush (f);
Qclose (f);
}
static void
SV_DemoInfoRemove_f (void)
{
char *name = 0, path[MAX_OSPATH];
if (Cmd_Argc () < 2) {
Con_Printf ("usage:demoInfoRemove <demonum>\n"
"<demonum> = * for currently recorded demo\n");
return;
}
if (!strcmp (Cmd_Argv (1), "*")) {
if (!sv.demorecording) {
Con_Printf ("Not recording demo!\n");
return;
}
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, demo.path->str,
SV_DemoName2Txt (demo.name->str));
} else {
name = SV_DemoTxTNum (atoi (Cmd_Argv (1)));
if (!name) {
Con_Printf ("invalid demo num\n");
return;
}
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string, name);
}
if (unlink (path))
Con_Printf ("failed to remove the file\n");
else
Con_Printf ("file removed\n");
}
static void
SV_DemoInfo_f (void)
{
const char *buf;
QFile *f = NULL;
char *name = 0, path[MAX_OSPATH];
if (Cmd_Argc () < 2) {
Con_Printf ("usage:demoinfo <demonum>\n"
"<demonum> = * for currently recorded demo\n");
return;
}
if (!strcmp (Cmd_Argv (1), "*")) {
if (!sv.demorecording) {
Con_Printf ("Not recording demo!\n");
return;
}
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, demo.path->str,
SV_DemoName2Txt (demo.name->str));
} else {
name = SV_DemoTxTNum (atoi (Cmd_Argv (1)));
if (!name) {
Con_Printf ("invalid demo num\n");
return;
}
sprintf (path, "%s/%s/%s/%s", fs_userpath->string, qfs_gamedir->dir.def, sv_demoDir->string, name);
}
if ((f = Qopen (path, "rt")) == NULL) {
Con_Printf ("(empty)\n");
return;
}
while ((buf = Qgetline (f))) {
Con_Printf ("%s", buf);
}
Qclose (f);
}
void void
Demo_Init (void) Demo_Init (void)
{ {
@ -1663,10 +1305,4 @@ Demo_Init (void)
Cmd_AddCommand ("easyrecord", SV_EasyRecord_f, "FIXME"); Cmd_AddCommand ("easyrecord", SV_EasyRecord_f, "FIXME");
Cmd_AddCommand ("stop", SV_Stop_f, "FIXME"); Cmd_AddCommand ("stop", SV_Stop_f, "FIXME");
Cmd_AddCommand ("cancel", SV_Cancel_f, "FIXME"); Cmd_AddCommand ("cancel", SV_Cancel_f, "FIXME");
Cmd_AddCommand ("demolist", SV_DemoList_f, "FIXME");
Cmd_AddCommand ("rmdemo", SV_DemoRemove_f, "FIXME");
Cmd_AddCommand ("rmdemonum", SV_DemoRemoveNum_f, "FIXME");
Cmd_AddCommand ("demoInfoAdd", SV_DemoInfoAdd_f, "FIXME");
Cmd_AddCommand ("demoInfoRemove", SV_DemoInfoRemove_f, "FIXME");
Cmd_AddCommand ("demoInfo", SV_DemoInfo_f, "FIXME");
} }

View file

@ -364,7 +364,9 @@ SV_DropClient (client_t *drop)
Qclose (drop->upload); Qclose (drop->upload);
drop->upload = NULL; drop->upload = NULL;
} }
*drop->uploadfn = 0; if (drop->uploadfn)
dstring_delete (drop->uploadfn);
drop->uploadfn = 0;
drop->state = cs_zombie; // become free in a few seconds drop->state = cs_zombie; // become free in a few seconds
drop->connection_started = realtime; // for zombie timeout drop->connection_started = realtime; // for zombie timeout
@ -1523,12 +1525,11 @@ SV_WriteIP_f (void)
QFile *f; QFile *f;
const char *type; const char *type;
snprintf (name, sizeof (name), "%s/%s/listip.cfg", fs_userpath->string, snprintf (name, sizeof (name), "%s/listip.cfg", qfs_gamedir->dir.def);
qfs_gamedir->dir.def);
SV_Printf ("Writing IP Filters to %s.\n", name); SV_Printf ("Writing IP Filters to %s.\n", name);
f = Qopen (name, "wb"); f = QFS_Open (name, "wb");
if (!f) { if (!f) {
SV_Printf ("Couldn't open %s\n", name); SV_Printf ("Couldn't open %s\n", name);
return; return;

View file

@ -592,7 +592,7 @@ SV_NextUpload (void)
{ {
int percent, size; int percent, size;
if (!*host_client->uploadfn) { if (!host_client->uploadfn) {
SV_ClientPrintf (1, host_client, PRINT_HIGH, "Upload denied\n"); SV_ClientPrintf (1, host_client, PRINT_HIGH, "Upload denied\n");
ClientReliableWrite_Begin (host_client, svc_stufftext, 8); ClientReliableWrite_Begin (host_client, svc_stufftext, 8);
ClientReliableWrite_String (host_client, "stopul"); ClientReliableWrite_String (host_client, "stopul");
@ -608,20 +608,21 @@ SV_NextUpload (void)
percent = MSG_ReadByte (net_message); percent = MSG_ReadByte (net_message);
if (!host_client->upload) { if (!host_client->upload) {
host_client->upload = Qopen (host_client->uploadfn, "wb"); host_client->upload = QFS_Open (host_client->uploadfn->str, "wb");
if (!host_client->upload) { if (!host_client->upload) {
SV_Printf ("Can't create %s\n", host_client->uploadfn); SV_Printf ("Can't create %s\n", host_client->uploadfn->str);
ClientReliableWrite_Begin (host_client, svc_stufftext, 8); ClientReliableWrite_Begin (host_client, svc_stufftext, 8);
ClientReliableWrite_String (host_client, "stopul"); ClientReliableWrite_String (host_client, "stopul");
*host_client->uploadfn = 0; dstring_delete (host_client->uploadfn);
host_client->uploadfn = 0;
return; return;
} }
SV_Printf ("Receiving %s from %d...\n", host_client->uploadfn, SV_Printf ("Receiving %s from %d...\n", host_client->uploadfn->str,
host_client->userid); host_client->userid);
if (host_client->remote_snap) if (host_client->remote_snap)
OutofBandPrintf (host_client->snap_from, OutofBandPrintf (host_client->snap_from,
"Server receiving %s from %d...\n", "Server receiving %s from %d...\n",
host_client->uploadfn, host_client->userid); host_client->uploadfn->str, host_client->userid);
} }
Qwrite (host_client->upload, net_message->message->data + Qwrite (host_client->upload, net_message->message->data +
@ -637,19 +638,21 @@ SV_NextUpload (void)
Qclose (host_client->upload); Qclose (host_client->upload);
host_client->upload = NULL; host_client->upload = NULL;
SV_Printf ("%s upload completed.\n", host_client->uploadfn); SV_Printf ("%s upload completed.\n", host_client->uploadfn->str);
if (host_client->remote_snap) { if (host_client->remote_snap) {
char *p; char *p;
if ((p = strchr (host_client->uploadfn, '/')) != NULL) if ((p = strchr (host_client->uploadfn->str, '/')) != NULL)
p++; p++;
else else
p = host_client->uploadfn; p = host_client->uploadfn->str;
OutofBandPrintf (host_client->snap_from, "%s upload completed.\n" OutofBandPrintf (host_client->snap_from, "%s upload completed.\n"
"To download, enter:\ndownload %s\n", "To download, enter:\ndownload %s\n",
host_client->uploadfn, p); host_client->uploadfn->str, p);
} }
dstring_delete (host_client->uploadfn);
host_client->uploadfn = 0;
} }
} }
@ -1149,8 +1152,9 @@ SV_ShowServerinfo_f (void *unused)
static void static void
SV_NoSnap_f (void *unused) SV_NoSnap_f (void *unused)
{ {
if (*host_client->uploadfn) { if (host_client->uploadfn) {
*host_client->uploadfn = 0; dstring_delete (host_client->uploadfn);
host_client->uploadfn = 0;
SV_BroadcastPrintf (PRINT_HIGH, "%s refused remote screenshot\n", SV_BroadcastPrintf (PRINT_HIGH, "%s refused remote screenshot\n",
host_client->name); host_client->name);
} }

View file

@ -353,7 +353,7 @@ locs_loc (void)
if (!mapname) if (!mapname)
Sys_Error ("Can't duplicate mapname!"); Sys_Error ("Can't duplicate mapname!");
map_to_loc (cl.worldmodel->name, mapname); map_to_loc (cl.worldmodel->name, mapname);
snprintf (locfile, sizeof (locfile), "%s/%s/%s", fs_userpath->string, snprintf (locfile, sizeof (locfile), "%s/%s",
qfs_gamedir->dir.def, mapname); qfs_gamedir->dir.def, mapname);
free (mapname); free (mapname);