*buf = FS_LoadFile(cls.demoname, tempmempool, false, filesize);
// restart the demo recording
- cls.demofile = FS_Open(cls.demoname, "wb", false, false);
+ cls.demofile = FS_OpenRealFile(cls.demoname, "wb", false);
if(!cls.demofile)
Host_Error("failed to reopen the demo file");
FS_Printf(cls.demofile, "%i\n", cls.forcetrack);
// open the demo file
Con_Printf("recording to %s.\n", name);
- cls.demofile = FS_Open (name, "wb", false, false);
+ cls.demofile = FS_OpenRealFile(name, "wb", false);
if (!cls.demofile)
{
Con_Print("ERROR: couldn't open.\n");
cls.protocol = PROTOCOL_QUAKE;
Con_Printf("Playing demo %s.\n", name);
- cls.demofile = FS_Open (name, "rb", false, false);
+ cls.demofile = FS_OpenVirtualFile(name, false);
if (!cls.demofile)
{
Con_Print("ERROR: couldn't open.\n");
FS_StripExtension(cl.worldmodel->name, locfilename, sizeof(locfilename));
strlcat(locfilename, ".loc", sizeof(locfilename));
- outfile = FS_Open(locfilename, "w", false, false);
+ outfile = FS_OpenRealFile(locfilename, "w", false);
if (!outfile)
return;
// if any boxes are used then this is a proquake-format loc file, which
qfile_t *file;
// see if the file already exists
- file = FS_Open(filename, "rb", true, false);
+ file = FS_OpenVirtualFile(filename, true);
if (file)
{
FS_Close(file);
Con_Printf ("Auto-recording to %s.\n", demofile);
- cls.demofile = FS_Open (demofile, "wb", false, false);
+ cls.demofile = FS_OpenRealFile(demofile, "wb", false);
if (cls.demofile)
{
cls.forcetrack = -1;
//else
{
cls.capturevideo.format = CAPTUREVIDEOFORMAT_AVI_I420;
- cls.capturevideo.videofile = FS_Open (va("%s.avi", cls.capturevideo.basename), "wb", false, true);
+ cls.capturevideo.videofile = FS_OpenRealFile(va("%s.avi", cls.capturevideo.basename), "wb", false);
SCR_CaptureVideo_RIFF_Start();
// enclosing RIFF chunk (there can be multiple of these in >1GB files, the later ones are "AVIX" instead of "AVI " and have no header/stream info)
SCR_CaptureVideo_RIFF_Push("RIFF", "AVI ");
if (logfile != NULL || log_file.string[0] == '\0')
return;
- logfile = FS_Open (log_file.string, "ab", false, false);
+ logfile = FS_OpenRealFile(log_file.string, "a", false);
if (logfile != NULL)
{
strlcpy (crt_log_file, log_file.string, sizeof (crt_log_file));
{
qfile_t *file;
- file = FS_Open (logfilename, "ab", true, false);
+ file = FS_OpenRealFile(logfilename, "a", true);
if (file != NULL)
{
va_list argptr;
Con_Printf("usage: condump <filename>\n");
return;
}
- file = FS_Open(Cmd_Argv(1), "wb", false, false);
+ file = FS_OpenRealFile(Cmd_Argv(1), "w", false);
if (!file)
{
Con_Printf("condump: unable to write file \"%s\"\n", Cmd_Argv(1));
char entfilename[MAX_QPATH];
strlcpy(message, "^1**ERROR**^7", sizeof(message));
p = 0;
- f = FS_Open(t->filenames[i], "rb", true, false);
+ f = FS_OpenVirtualFile(t->filenames[i], true);
if(f)
{
memset(buf, 0, 1024);
{
qfile_t *file;
hz_bitstream_read_t *stream;
- if ((file = FS_Open (filename, "rb", false, false)))
+ if ((file = FS_OpenVirtualFile(filename, false)))
{
stream = (hz_bitstream_read_t *)Z_Malloc(sizeof(hz_bitstream_read_t));
memset(stream, 0, sizeof(*stream));
============
FS_CreatePath
-Only used for FS_Open.
+Only used for FS_OpenRealFile.
============
*/
void FS_CreatePath (char *path)
/*
====================
-FS_Open
+FS_OpenRealFile
-Open a file. The syntax is the same as fopen
+Open a file in the userpath. The syntax is the same as fopen
+Used for savegame scanning in menu, and all file writing.
====================
*/
-qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet, qboolean nonblocking)
+qfile_t* FS_OpenRealFile (const char* filepath, const char* mode, qboolean quiet)
{
+ char real_path [MAX_OSPATH];
+
if (FS_CheckNastyPath(filepath, false))
{
- Con_Printf("FS_Open(\"%s\", \"%s\", %s): nasty filename rejected\n", filepath, mode, quiet ? "true" : "false");
+ Con_Printf("FS_OpenRealFile(\"%s\", \"%s\", %s): nasty filename rejected\n", filepath, mode, quiet ? "true" : "false");
return NULL;
}
- // If the file is opened in "write", "append", or "read/write" mode
+ dpsnprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath);
+
+ // If the file is opened in "write", "append", or "read/write" mode,
+ // create directories up to the file.
if (mode[0] == 'w' || mode[0] == 'a' || strchr (mode, '+'))
- {
- char real_path [MAX_OSPATH];
+ FS_CreatePath (real_path);
+ return FS_SysOpen (real_path, mode, false);
+}
- // Open the file on disk directly
- dpsnprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath);
- // Create directories up to the file
- FS_CreatePath (real_path);
+/*
+====================
+FS_OpenVirtualFile
- return FS_SysOpen (real_path, mode, nonblocking);
+Open a file. The syntax is the same as fopen
+====================
+*/
+qfile_t* FS_OpenVirtualFile (const char* filepath, qboolean quiet)
+{
+ if (FS_CheckNastyPath(filepath, false))
+ {
+ Con_Printf("FS_OpenVirtualFile(\"%s\", %s): nasty filename rejected\n", filepath, quiet ? "true" : "false");
+ return NULL;
}
- // Else, we look at the various search paths and open the file in read-only mode
- else
- return FS_OpenReadFile (filepath, quiet, nonblocking, 16);
+
+ return FS_OpenReadFile (filepath, quiet, false, 16);
}
unsigned char *buf = NULL;
fs_offset_t filesize = 0;
- file = FS_Open (path, "rb", quiet, false);
+ file = FS_OpenVirtualFile(path, quiet);
if (file)
{
filesize = file->real_length;
{
qfile_t *file;
- file = FS_Open (filename, "wb", false, false);
+ file = FS_OpenRealFile(filename, "wb", false);
if (!file)
{
Con_Printf("FS_WriteFile: failed on %s\n", filename);
// ------ Main functions ------ //
// IMPORTANT: the file path is automatically prefixed by the current game directory for
-// each file created by FS_WriteFile, or opened in "write" or "append" mode by FS_Open
+// each file created by FS_WriteFile, or opened in "write" or "append" mode by FS_OpenRealFile
qboolean FS_AddPack(const char *pakfile, qboolean *already_loaded, qboolean keep_plain_dirs); // already_loaded may be NULL if caller does not care
const char *FS_WhichPack(const char *filename);
-qfile_t *FS_Open (const char* filepath, const char* mode, qboolean quiet, qboolean nonblocking);
+qfile_t* FS_OpenRealFile (const char* filepath, const char* mode, qboolean quiet);
+qfile_t* FS_OpenVirtualFile (const char* filepath, qboolean quiet);
int FS_Close (qfile_t* file);
fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize);
fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize);
{
int i;
- qfile_t *file = FS_Open("glsl/default.glsl", "w", false, false);
+ qfile_t *file = FS_OpenRealFile("glsl/default.glsl", "w", false);
if(!file)
{
Con_Printf("failed to write to glsl/default.glsl\n");
// LordHavoc: don't save a config if it crashed in startup
if (host_framecount >= 3 && cls.state != ca_dedicated && !COM_CheckParm("-benchmark") && !COM_CheckParm("-capturedemo"))
{
- f = FS_Open (file, "wb", false, false);
+ f = FS_OpenRealFile(file, "wb", false);
if (!f)
{
Con_Printf("Couldn't write %s.\n", file);
isserver = !strcmp(PRVM_NAME, "server");
Con_Printf("Saving game to %s...\n", name);
- f = FS_Open (name, "wb", false, false);
+ f = FS_OpenRealFile(name, "wb", false);
if (!f)
{
Con_Print("ERROR: couldn't open.\n");
}
// Open the file
- file = FS_Open (filename, "wb", true, false);
+ file = FS_OpenRealFile(filename, "wb", true);
if (!file)
return false;
// reopen to enforce it to have zero bytes again
FS_Close(di->stream);
- di->stream = FS_Open(di->filename, "w", false, false);
+ di->stream = FS_OpenRealFile(di->filename, "wb", false);
break;
}
{
Con_Printf("Downloading %s -> %s", di->url, di->filename);
- di->stream = FS_Open(di->filename, "ab", false, false);
+ di->stream = FS_OpenRealFile(di->filename, "ab", false);
if(!di->stream)
{
Con_Printf("\nFAILED: Could not open output file %s\n", di->filename);
}
else
{
- qfile_t *f = FS_Open(fn, "rb", false, false);
+ qfile_t *f = FS_OpenVirtualFile(fn, false);
if(f)
{
char buf[4] = {0};
{
Con_DPrintf("Detected non-PAK %s, clearing and NOT resuming.\n", fn);
FS_Close(f);
- f = FS_Open(fn, "w", false, false);
+ f = FS_OpenRealFile(fn, "wb", false);
if(f)
FS_Close(f);
}
strlcpy (m_filenames[i], "--- UNUSED SLOT ---", sizeof(m_filenames[i]));
loadable[i] = false;
dpsnprintf (name, sizeof(name), "s%i.sav", (int)i);
- f = FS_Open (name, "rb", false, false);
+ f = FS_OpenRealFile (name, "rb", false);
if (!f)
continue;
// read enough to get the comment
VM_Warning("VM_fopen: %s ran out of file handles (%i)\n", PRVM_NAME, PRVM_MAX_OPENFILES);
return;
}
+ filename = PRVM_G_STRING(OFS_PARM0);
mode = (int)PRVM_G_FLOAT(OFS_PARM1);
switch(mode)
{
case 0: // FILE_READ
modestring = "rb";
+ prog->openfiles[filenum] = FS_OpenVirtualFile(va("data/%s", filename), false);
+ if (prog->openfiles[filenum] == NULL)
+ prog->openfiles[filenum] = FS_OpenVirtualFile(va("%s", filename), false);
break;
case 1: // FILE_APPEND
- modestring = "ab";
+ modestring = "a";
+ prog->openfiles[filenum] = FS_OpenRealFile(va("data/%s", filename), modestring, false);
break;
case 2: // FILE_WRITE
- modestring = "wb";
+ modestring = "w";
+ prog->openfiles[filenum] = FS_OpenRealFile(va("data/%s", filename), modestring, false);
break;
default:
PRVM_G_FLOAT(OFS_RETURN) = -3;
VM_Warning("VM_fopen: %s: no such mode %i (valid: 0 = read, 1 = append, 2 = write)\n", PRVM_NAME, mode);
return;
}
- filename = PRVM_G_STRING(OFS_PARM0);
-
- prog->openfiles[filenum] = FS_Open(va("data/%s", filename), modestring, false, false);
- if (prog->openfiles[filenum] == NULL && mode == 0)
- prog->openfiles[filenum] = FS_Open(va("%s", filename), modestring, false, false);
if (prog->openfiles[filenum] == NULL)
{
Con_Printf("Recording demo for # %d (%s) to %s\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress, name);
- client->sv_demo_file = FS_Open(name, "wb", false, false);
+ client->sv_demo_file = FS_OpenRealFile(name, "wb", false);
if(!client->sv_demo_file)
{
Con_Print("ERROR: couldn't open.\n");
}
}
- host_client->download_file = FS_Open(host_client->download_name, "rb", true, false);
+ host_client->download_file = FS_OpenVirtualFile(host_client->download_name, true);
if (!host_client->download_file)
{
SV_ClientPrintf("Download rejected: server could not open the file \"%s\"\n", host_client->download_name);
int numlumps;
mwad_t *w;
- file = FS_Open (filename, "rb", false, false);
+ file = FS_OpenVirtualFile(filename, false);
if (!file)
{
if (complain)