mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
made COM_FindFile to accept both file and handle as NULL. Added
COM_FileExists as a new helper procedure which calls COM_FindFile with both file and handle parameters as NULL. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@373 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
db70c054fa
commit
ceb1dd2186
2 changed files with 29 additions and 9 deletions
|
@ -1451,6 +1451,8 @@ COM_FindFile
|
||||||
|
|
||||||
Finds the file in the search path.
|
Finds the file in the search path.
|
||||||
Sets com_filesize and one of handle or file
|
Sets com_filesize and one of handle or file
|
||||||
|
If neither of file or handle is set, this
|
||||||
|
can be used for detecting a file's presence.
|
||||||
===========
|
===========
|
||||||
*/
|
*/
|
||||||
static int COM_FindFile (const char *filename, int *handle, FILE **file,
|
static int COM_FindFile (const char *filename, int *handle, FILE **file,
|
||||||
|
@ -1464,8 +1466,6 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file,
|
||||||
|
|
||||||
if (file && handle)
|
if (file && handle)
|
||||||
Sys_Error ("COM_FindFile: both handle and file set");
|
Sys_Error ("COM_FindFile: both handle and file set");
|
||||||
if (!file && !handle)
|
|
||||||
Sys_Error ("COM_FindFile: neither handle or file set");
|
|
||||||
|
|
||||||
file_from_pak = 0;
|
file_from_pak = 0;
|
||||||
|
|
||||||
|
@ -1483,21 +1483,21 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file,
|
||||||
if (!strcmp (pak->files[i].name, filename))
|
if (!strcmp (pak->files[i].name, filename))
|
||||||
{ // found it!
|
{ // found it!
|
||||||
// Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename);
|
// Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename);
|
||||||
|
file_from_pak = 1;
|
||||||
|
com_filesize = pak->files[i].filelen;
|
||||||
|
if (path_id)
|
||||||
|
*path_id = search->path_id;
|
||||||
if (handle)
|
if (handle)
|
||||||
{
|
{
|
||||||
*handle = pak->handle;
|
*handle = pak->handle;
|
||||||
Sys_FileSeek (pak->handle, pak->files[i].filepos);
|
Sys_FileSeek (pak->handle, pak->files[i].filepos);
|
||||||
}
|
}
|
||||||
else
|
else if (file)
|
||||||
{ // open a new file on the pakfile
|
{ // open a new file on the pakfile
|
||||||
*file = fopen (pak->filename, "rb");
|
*file = fopen (pak->filename, "rb");
|
||||||
if (*file)
|
if (*file)
|
||||||
fseek (*file, pak->files[i].filepos, SEEK_SET);
|
fseek (*file, pak->files[i].filepos, SEEK_SET);
|
||||||
}
|
}
|
||||||
file_from_pak = 1;
|
|
||||||
com_filesize = pak->files[i].filelen;
|
|
||||||
if (path_id)
|
|
||||||
*path_id = search->path_id;
|
|
||||||
return com_filesize;
|
return com_filesize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1521,12 +1521,18 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file,
|
||||||
if (path_id)
|
if (path_id)
|
||||||
*path_id = search->path_id;
|
*path_id = search->path_id;
|
||||||
if (handle)
|
if (handle)
|
||||||
|
{
|
||||||
*handle = i;
|
*handle = i;
|
||||||
else
|
}
|
||||||
|
else if (file)
|
||||||
{
|
{
|
||||||
Sys_FileClose (i);
|
Sys_FileClose (i);
|
||||||
*file = fopen (netpath, "rb");
|
*file = fopen (netpath, "rb");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Sys_FileClose (i);
|
||||||
|
}
|
||||||
return com_filesize;
|
return com_filesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1536,13 +1542,26 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file,
|
||||||
|
|
||||||
if (handle)
|
if (handle)
|
||||||
*handle = -1;
|
*handle = -1;
|
||||||
else
|
else if (file)
|
||||||
*file = NULL;
|
*file = NULL;
|
||||||
com_filesize = -1;
|
com_filesize = -1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
===========
|
||||||
|
COM_FileExists
|
||||||
|
|
||||||
|
Returns com_filesize if file is found in the quake filesystem,
|
||||||
|
-1 if not. Closes the files it opens, if any.
|
||||||
|
===========
|
||||||
|
*/
|
||||||
|
int COM_FileExists (const char *filename, unsigned int *path_id)
|
||||||
|
{
|
||||||
|
return COM_FindFile (filename, NULL, NULL, path_id);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
===========
|
===========
|
||||||
COM_OpenFile
|
COM_OpenFile
|
||||||
|
|
|
@ -188,6 +188,7 @@ extern int file_from_pak; // global indicating that file came from a pak
|
||||||
void COM_WriteFile (const char *filename, const void *data, int len);
|
void COM_WriteFile (const char *filename, const void *data, int len);
|
||||||
int COM_OpenFile (const char *filename, int *handle, unsigned int *path_id);
|
int COM_OpenFile (const char *filename, int *handle, unsigned int *path_id);
|
||||||
int COM_FOpenFile (const char *filename, FILE **file, unsigned int *path_id);
|
int COM_FOpenFile (const char *filename, FILE **file, unsigned int *path_id);
|
||||||
|
int COM_FileExists (const char *filename, unsigned int *path_id);
|
||||||
void COM_CloseFile (int h);
|
void COM_CloseFile (int h);
|
||||||
|
|
||||||
// these procedures open a file using COM_FindFile and loads it into a proper
|
// these procedures open a file using COM_FindFile and loads it into a proper
|
||||||
|
|
Loading…
Reference in a new issue