Exemplo n.º 1
0
static qboolean S_MODPLUG_CodecOpenStream (snd_stream_t *stream)
{
/* need to load the whole file into memory and pass it to libmodplug */
	byte *moddata;
	long len;
	int mark;

	len = FS_filelength (&stream->fh);
	mark = Hunk_LowMark();
	moddata = (byte *) Hunk_Alloc(len);
	FS_fread(moddata, 1, len, &stream->fh);

	S_MODPLUG_SetSettings(stream);
	stream->priv = ModPlug_Load(moddata, len);
	Hunk_FreeToLowMark(mark); /* free original file data */
	if (!stream->priv)
	{
		Con_DPrintf("Could not load module %s\n", stream->name);
		return false;
	}

	ModPlug_Seek((ModPlugFile*)stream->priv, 0);
#if 0
	/* default volume (128) sounds rather low? */
	ModPlug_SetMasterVolume((ModPlugFile*)stream->priv, 384);	/* 0-512 */
#endif
	return true;
}
Exemplo n.º 2
0
static int FS_FOpenFileReadGOB( const char *filename, fileHandle_t f )
{
	char* gobname = FS_BuildGOBPath( filename );
	if (GOBOpen(gobname, &fsh[f].ghandle) == GOBERR_OK)
	{
		fsh[f].used = qtrue;
		fsh[f].gob = qtrue;
		return FS_filelength(f);
	}
	return -1;
}
Exemplo n.º 3
0
static qboolean S_XMP_CodecOpenStream (snd_stream_t *stream)
{
/* need to load the whole file into memory and pass it to libxmp
 * using xmp_load_module_from_memory() which requires libxmp >= 4.2.
 * libxmp-4.0/4.1 only have xmp_load_module() which accepts a file
 * name which isn't good with files in containers like paks, etc. */
	xmp_context c;
	byte *moddata;
	long len;
	int mark;

	c = xmp_create_context();
	if (c == NULL)
		return false;

	len = FS_filelength (&stream->fh);
	mark = Hunk_LowMark();
	moddata = (byte *) Hunk_Alloc(len);
	FS_fread(moddata, 1, len, &stream->fh);
	if (xmp_load_module_from_memory(c, moddata, len) != 0)
	{
		Con_DPrintf("Could not load module %s\n", stream->name);
		goto err1;
	}

	Hunk_FreeToLowMark(mark); /* free original file data */
	stream->priv = c;
	if (shm->speed > XMP_MAX_SRATE)
		stream->info.rate = 44100;
	else if (shm->speed < XMP_MIN_SRATE)
		stream->info.rate = 11025;
	else	stream->info.rate = shm->speed;
	stream->info.bits = shm->samplebits;
	stream->info.width = stream->info.bits / 8;
	stream->info.channels = shm->channels;

	if (S_XMP_StartPlay(stream) != 0)
		goto err2;
	/* percentual left/right channel separation, default is 70. */
	if (stream->info.channels == 2)
		if (xmp_set_player(c, XMP_PLAYER_MIX, 100) != 0)
			goto err3;
	/* interpolation type, default is XMP_INTERP_LINEAR */
	if (xmp_set_player(c, XMP_PLAYER_INTERP, XMP_INTERP_SPLINE) != 0)
		goto err3;

	return true;

err3:	xmp_end_player(c);
err2:	xmp_release_module(c);
err1:	xmp_free_context(c);
	return false;
}
Exemplo n.º 4
0
int FS_FOpenFile (char *filename, FILE **file)
{
	searchpath_t	*search;
	char			netpath[MAX_OSPATH];
	pack_t			*pak;
	int				i;

	file_from_pak = 0;

	// get config from directory, everything else from pak
	if (!strcmp(filename, "config.cfg") || !strncmp(filename, "players/", 8))
	{
		Com_sprintf (netpath, sizeof(netpath), "%s/%s",FS_Gamedir(), filename);
		
		*file = fopen (netpath, "rb");
		if (!*file)
			return -1;
		
		Com_DPrintf ("FindFile: %s\n",netpath);

		return FS_filelength (*file);
	}

	for (search = fs_searchpaths ; search ; search = search->next)
		if (search->pack)
			break;
	if (!search)
	{
		*file = NULL;
		return -1;
	}

	pak = search->pack;
	for (i=0 ; i<pak->numfiles ; i++)
		if (!Q_strcasecmp (pak->files[i].name, filename))
		{	// found it!
			file_from_pak = 1;
			Com_DPrintf ("PackFile: %s : %s\n",pak->filename, filename);
		// open a new file on the pakfile
			*file = fopen (pak->filename, "rb");
			if (!*file)
				Com_Error (ERR_FATAL, "Couldn't reopen %s", pak->filename);	
			fseek (*file, pak->files[i].filepos, SEEK_SET);
			return pak->files[i].filelen;
		}
	
	Com_DPrintf ("FindFile: can't find %s\n", filename);
	
	*file = NULL;
	return -1;
}
Exemplo n.º 5
0
/*
=============
ReadCommandLineParms

Read startup options from a text file or dialog box
=============
*/
char *ReadCommandLineParms( void ) {
	FILE	*f;
	int		len;
	char	*buf;
	EventRecord	   event;
	
	// flush out all the events and see if shift is held down
	// to bring up the args window
	while ( WaitNextEvent(everyEvent, &event, 0, nil) ) {
	}
	if ( event.modifiers & 512 ) {
		static char	text[1024];
		int		argc;
		char	**argv;
		int		i;
		
		argc = ccommand( &argv );
		text[0] = 0;
		// concat all the args into a string
		// quote each arg seperately, because metrowerks does
		// its own quote combining from the dialog
		for ( i = 1 ; i < argc ; i++ ) {
			if ( argv[i][0] != '+' ) {
				Q_strcat( text, sizeof(text), "\"" );
			}
			Q_strcat( text, sizeof(text), argv[i] );
			if ( argv[i][0] != '+' ) {
				Q_strcat( text, sizeof(text), "\"" );
			}
			Q_strcat( text, sizeof(text), " " );
		}		
		return text;
	}
	
	// otherwise check for a parms file
	f = fopen( "MacQuake3Parms.txt", "r" );
	if ( !f ) {
		return "";
	}
	len = FS_filelength( f );
	buf = malloc( len + 1 );
	if ( !buf ) {
		exit( 1 );
	}
	buf[len] = 0;
	fread( buf, len, 1, f );
	fclose( f );

	return buf;
}
Exemplo n.º 6
0
static int FS_FOpenFileReadOS( const char *filename, fileHandle_t f )
{
	if (Sys_GetFileCode(filename) != -1)
	{
		char* osname = FS_BuildOSPath( filename );
		fsh[f].whandle = WF_Open(osname, true, false);
		if (fsh[f].whandle >= 0)
		{
			fsh[f].used = qtrue;
			fsh[f].gob = qfalse;
			return FS_filelength(f);
		}
	}
	return -1;
}
Exemplo n.º 7
0
/*
===========
FS_SV_FOpenFileRead

===========
*/
int FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp ) {
  char *ospath;
	fileHandle_t	f;

	if ( !fs_searchpaths ) {
		Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
	}

	f = FS_HandleForFile();
	fsh[f].zipFile = qfalse;

	Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) );

	// don't let sound stutter
	S_ClearSoundBuffer();

#ifdef _XBOX
	ospath = FS_BuildOSPath( filename );
#else
	ospath = FS_BuildOSPath( fs_basepath->string, filename, "" );
#endif
	// remove trailing slash
  ospath[strlen(ospath)-1] = '\0';

	if ( fs_debug->integer ) {
		Com_Printf( "FS_SV_FOpenFileRead: %s\n", ospath );
	}

	fsh[f].handleFiles.file.o = fopen( ospath, "rb" );
	fsh[f].handleSync = qfalse;
	if (!fsh[f].handleFiles.file.o) {
		f = 0;
	}
  
  *fp = f;
  if (f) {
    return FS_filelength(f);
  }
  return 0;
}
Exemplo n.º 8
0
/*
===================
MP3_GetPlaylist

===================
*/
int MP3_GetPlaylist (char **buf)
{
	FILE			*file;
	char			path[512];
	int				pathlength;
	long			filelength;

	if (!MP3_Status())
		return -1;

	SendMessage (mywinamp.hWnd, WM_USER, 0, 120);
	Q_strncpyz (path, cl_winamp_dir->string, sizeof (path));
	pathlength = strlen(path);

	if (pathlength && (path[pathlength - 1] == '\\' || path[pathlength - 1] == '/'))
		path[pathlength - 1] = 0;

	Q_strncatz(path, "/winamp.m3u", sizeof(path));
	file = fopen (path, "rb");
	if (!file) {
		Com_Printf("Cant find winamp in \"%s\", use cl_winamp_dir to change dir\n", path);
		return -1;
	}
	filelength = FS_filelength (file);

	*buf = Z_TagMalloc (filelength, TAG_MP3LIST);
	if (filelength != fread (*buf, 1,  filelength, file))
	{
		Z_Free (*buf);
		fclose (file);
		return -1;
	}

	fclose (file);

	return filelength;
}
Exemplo n.º 9
0
/* Finds the file in the search path.
 * returns file size and an open FILE *
 * Used for streaming data.
 */
int FS_fopenfile( char *filename, FILE **file )
{
	t_searchpath    *search;
	char            netpath[MAX_OSPATH];
	t_pack          *pak;
	int             i;
	t_filelink      *link;

	file_from_pak = 0;

	for ( link = fs_links; link ; link = link->next )
	{
		if ( !strncmp( filename, link->from, link->fromlength ) )
		{
			sprintf( netpath, "%s%s", link->to, filename+link->fromlength);
			*file = fopen(netpath, "rb");
			if (*file)
			{
				printf( "link file: %s\n", netpath );
				return FS_filelength( *file );
			}
			return -1;
		}
	}
	/* search through the path, one element at a time */
	for ( search = fs_searchpaths; search ; search = search->next )
	{
		/* is file a pak file */
		if ( search->pack )
		{
			/* look through all the pak file elements */
			pak = search->pack;
			for ( i = 0; i < pak->numfiles; i++ )
				if ( !strcasecmp(pak->files[i].name, filename ) )
				{
					file_from_pak = 1;
					printf(" packfile: %s : %s\n", pak->filename, filename );
					*file = fopen( pak->filename, "rb" );
					if ( !*file )
						COM_error( ERR_FATAL, "Couldn't reopen %s", pak->filename );
					fseek ( *file, pak->files[i].filepos, SEEK_SET );
					return pak->files[i].filelen;
				}
		}
		else
		{
			/* check file in the directory tree */
			sprintf( netpath, "%s/%s", search->filename, filename );

			*file = fopen( netpath, "rb" );
			if (!*file)
				continue;

			printf( "findfile: %s\n", netpath );
			return FS_filelength(*file);
		}
	}

	printf("findfile: can't find %s\n", filename );
	*file = NULL;
	return -1;
}
Exemplo n.º 10
0
Arquivo: files.c Projeto: qbism/qbq2
int FS_FOpenFile(char *filename, FILE **file)
{
	searchpath_t	*search;
	char			netpath[MAX_OSPATH];
	pack_t			*pak;
	int				i;
	filelink_t		*link;
	// Knightmare added
	long			hash;
	unsigned int	typeFlag;

	file_from_pak = 0;
	// Knightmare added
	hash = Com_HashFileName(filename, 0, false);
	typeFlag = FS_TypeFlagForPakItem(filename);

	// check for links first
	for (link = fs_links; link; link = link->next)
	{
		if (!strncmp(filename, link->from, link->fromlength))
		{
			Com_sprintf(netpath, sizeof(netpath), "%s%s", link->to, filename + link->fromlength);
			*file = fopen(netpath, "rb");
			if (*file)
			{
				Com_DPrintf("link file: %s\n", netpath);
				return FS_filelength(*file);
			}
			return -1;
		}
	}

	//
	// search through the path, one element at a time
	//
	for (search = fs_searchpaths; search; search = search->next)
	{
		// is the element a pak file?
		if (search->pack)
		{
			// look through all the pak file elements
			pak = search->pack;

			// Knightmare- skip if pack doesn't contain this type of file
			if ((typeFlag != 0)) {
				if (!(pak->contentFlags & typeFlag))
					continue;
			}
#ifdef BINARY_PACK_SEARCH	// Knightmare- use new binary algorithm
			// find index of pack item
			i = FS_FindPackItem(pak, filename, hash);
			// found it!
			if (i != -1 && i >= 0 && i < pak->numfiles)
			{
#else
			for (i = 0; i<pak->numfiles; i++)
			{
				if (pak->files[i].ignore)	// Knightmare- skip blacklisted files
					continue;
				if (hash != pak->files[i].hash)	// Knightmare- compare hash first
					continue;
#endif	// 	BINARY_PACK_SEARCH
				if (!Q_strcasecmp(pak->files[i].name, filename))
				{	// found it!
					file_from_pak = 1;
					Com_DPrintf("PackFile: %s : %s\n", pak->filename, filename);
					// open a new file on the pakfile
					*file = fopen(pak->filename, "rb");
					if (!*file)
						Com_Error(ERR_FATAL, "Couldn't reopen %s", pak->filename);
					fseek(*file, pak->files[i].filepos, SEEK_SET);
					return pak->files[i].filelen;
				}
			}
		}
		else
		{
			// check a file in the directory tree

			Com_sprintf(netpath, sizeof(netpath), "%s/%s", search->filename, filename);

			*file = fopen(netpath, "rb");
			if (!*file)
				continue;

			Com_DPrintf("FindFile: %s\n", netpath);

			return FS_filelength(*file);
		}

	}

	Com_DPrintf("FindFile: can't find %s\n", filename);

	*file = NULL;
	return -1;
}

#else

// this is just for demos to prevent add on hacking

int FS_FOpenFile(char *filename, FILE **file)
{
	searchpath_t	*search;
	char			netpath[MAX_OSPATH];
	pack_t			*pak;
	int				i;
	// Knightmare added
	long			hash;

	file_from_pak = 0;
	// Knightmare added
	hash = Com_HashFileName(filename, 0, false);

	// get config from directory, everything else from pak
	if (!strcmp(filename, "config.cfg") || !strncmp(filename, "players/", 8))
	{
		Com_sprintf(netpath, sizeof(netpath), "%s/%s", FS_Gamedir(), filename);

		*file = fopen(netpath, "rb");
		if (!*file)
			return -1;

		Com_DPrintf("FindFile: %s\n", netpath);

		return FS_filelength(*file);
	}

	for (search = fs_searchpaths; search; search = search->next)
	if (search->pack)
		break;
	if (!search)
	{
		*file = NULL;
		return -1;
	}

	pak = search->pack;
	for (i = 0; i<pak->numfiles; i++)
	{
		if (pak->files[i].ignore)	// Knightmare- skip blacklisted files
			continue;
		if (hash != pak->files[i].hash)	// Knightmare- compare hash first
			continue;
		if (!Q_strcasecmp(pak->files[i].name, filename))
		{	// found it!
			file_from_pak = 1;
			Com_DPrintf("PackFile: %s : %s\n", pak->filename, filename);
			// open a new file on the pakfile
			*file = fopen(pak->filename, "rb");
			if (!*file)
				Com_Error(ERR_FATAL, "Couldn't reopen %s", pak->filename);
			fseek(*file, pak->files[i].filepos, SEEK_SET);
			return pak->files[i].filelen;
		}
	}

	Com_DPrintf("FindFile: can't find %s\n", filename);

	*file = NULL;
	return -1;
}
Exemplo n.º 11
0
int FS_FOpenFile (char *filename, FILE **file)
{
	searchpath_t	*search;
	char			netpath[MAX_OSPATH];
	pack_t			*pak;
	int				i;
	filelink_t		*link;

	file_from_pak = 0;

	// check for links first
	for (link = fs_links ; link ; link=link->next)
	{
		if (!strncmp (filename, link->from, link->fromlength))
		{
			Com_sprintf (netpath, sizeof(netpath), "%s%s",link->to, filename+link->fromlength);
			*file = fopen (netpath, "rb");
			if (*file)
			{		
				Com_DPrintf ("link file: %s\n",netpath);
				return FS_filelength (*file);
			}
			return -1;
		}
	}

//
// search through the path, one element at a time
//
	for (search = fs_searchpaths ; search ; search = search->next)
	{
	// is the element a pak file?
		if (search->pack)
		{
		// look through all the pak file elements
			pak = search->pack;
			for (i=0 ; i<pak->numfiles ; i++)
				if (!Q_strcasecmp (pak->files[i].name, filename))
				{	// found it!
					file_from_pak = 1;
					Com_DPrintf ("PackFile: %s : %s\n",pak->filename, filename);
				// open a new file on the pakfile
					*file = fopen (pak->filename, "rb");
					if (!*file)
						Com_Error (ERR_FATAL, "Couldn't reopen %s", pak->filename);	
					fseek (*file, pak->files[i].filepos, SEEK_SET);
					return pak->files[i].filelen;
				}
		}
		else
		{		
	// check a file in the directory tree
			
			Com_sprintf (netpath, sizeof(netpath), "%s/%s",search->filename, filename);
			
			*file = fopen (netpath, "rb");
			if (!*file)
				continue;
			
			Com_DPrintf ("FindFile: %s\n",netpath);

			return FS_filelength (*file);
		}
		
	}
	
	Com_DPrintf ("FindFile: can't find %s\n", filename);
	
	*file = NULL;
	return -1;
}
Exemplo n.º 12
0
   /*
         May not be correct for files in zip files
 */
   size_t Length(Rocket::Core::FileHandle file) {
       return (size_t) FS_filelength((fileHandle_t) file);
   }
Exemplo n.º 13
0
/*
===========
FS_SV_FOpenFileRead

===========
*/
int FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp ) {
	char *ospath;
	fileHandle_t	f = 0;

	if ( !fs_searchpaths ) {
		Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
	}

	f = FS_HandleForFile();
	fsh[f].zipFile = qfalse;

	Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) );

	// don't let sound stutter
	S_ClearSoundBuffer();

	ospath = FS_BuildOSPath( fs_homepath->string, filename, "" );
	// remove trailing slash
  ospath[strlen(ospath)-1] = '\0';

	if ( fs_debug->integer ) {
		Com_Printf( "FS_SV_FOpenFileRead: %s\n", ospath );
	}

	fsh[f].handleFiles.file.o = fopen( ospath, "rb" );
	fsh[f].handleSync = qfalse;
	if (!fsh[f].handleFiles.file.o) {
		// NOTE TTimo on non *nix systems, fs_homepath == fs_basepath, might want to avoid
		if (Q_stricmp(fs_homepath->string,fs_basepath->string))
		{
			// search basepath
			ospath = FS_BuildOSPath( fs_basepath->string, filename, "" );
			ospath[strlen(ospath)-1] = '\0';
			
			if ( fs_debug->integer )
			{
				Com_Printf( "FS_SV_FOpenFileRead (fs_basepath): %s\n", ospath );
			}
			
			fsh[f].handleFiles.file.o = fopen( ospath, "rb" );
			fsh[f].handleSync = qfalse;
			
			if ( !fsh[f].handleFiles.file.o )
			{
				f = 0;
			}
		}
	}
	
	if (!fsh[f].handleFiles.file.o) {
		// search cd path
		ospath = FS_BuildOSPath( fs_cdpath->string, filename, "" );
		ospath[strlen(ospath)-1] = '\0';
		
		if (fs_debug->integer)
		{
			Com_Printf( "FS_SV_FOpenFileRead (fs_cdpath) : %s\n", ospath );
		}
		
		fsh[f].handleFiles.file.o = fopen( ospath, "rb" );
		fsh[f].handleSync = qfalse;
		
		if( !fsh[f].handleFiles.file.o ) {
			f = 0;
		}
	}
  
  *fp = f;
  if (f) {
    return FS_filelength(f);
  }
  return 0;
}
Exemplo n.º 14
0
Arquivo: files.c Projeto: Slipyx/r1q2
int EXPORT FS_FOpenFile (const char *filename, FILE **file, handlestyle_t openHandle, qboolean *closeHandle)
{
	fscache_t		*cache;
	searchpath_t	*search;
	pack_t			*pak;
	filelink_t		*link;
	char			netpath[MAX_OSPATH];
	char			lowered[MAX_QPATH];

	// check for links firstal
	if (!fs_noextern->intvalue)
	{
		for (link = fs_links ; link ; link=link->next)
		{
			if (!strncmp (filename, link->from, link->fromlength))
			{
				Com_sprintf (netpath, sizeof(netpath), "%s%s",link->to, filename+link->fromlength);
				if (openHandle != HANDLE_NONE)
				{
					*file = fopen (netpath, "rb");
					if (*file)
					{	
						Com_DPrintf ("link file: %s\n",netpath);
						*closeHandle = true;
						return FS_filelength (*file);
					}
					return -1;
				}
				else
				{
					return Sys_FileLength (netpath);
				}
			}
		}
	}

#ifdef BTREE_SEARCH
	cache = rbfind (filename, rb);
	if (cache)
	{
		cache = *(fscache_t **)cache;
		if (cache->filepath[0] == 0)
		{
			*file = NULL;
			return -1;
		}
#ifdef _DEBUG
		Com_DPrintf ("File '%s' found in cache: %s\n", filename, cache->filepath);
#endif
		if (openHandle != HANDLE_NONE)
		{
			if (cache->pak)
			{
				if (openHandle == HANDLE_DUPE)
				{
					*file = fopen (cache->pak->filename, "rb");
					if (!*file)
					{
						Com_Printf ("WARNING: Cached pak '%s' failed to open! Did you delete it?\n", LOG_WARNING|LOG_GENERAL, cache->pak->filename);
						rbdelete (filename, rb);
						return -1;
					}
					*closeHandle = true;
				}
				else
				{
					*file = cache->pak->h.handle;
					*closeHandle = false;
				}
			}
			else
			{
				*file = fopen (cache->filepath, "rb");
				if (!*file)
				{
					Com_Printf ("WARNING: Cached file '%s' failed to open! Did you delete it?\n", LOG_WARNING|LOG_GENERAL, cache->filepath);
					rbdelete (filename, rb);
					return -1;
				}
					//Com_Error (ERR_FATAL, "Couldn't open %s (cached)", cache->filepath);	

				*closeHandle = true;
			}
			if (cache->fileseek && fseek (*file, cache->fileseek, SEEK_SET))
				Com_Error (ERR_FATAL, "Couldn't seek to offset %u in %s (cached)", cache->fileseek, cache->filepath);
		}
		return cache->filelen;
	}

#elif HASH_CACHE
	hash = hashify (filename);

	cache = &fscache;

	while (cache->next)
	{ 
		cache = cache->next;
		if (cache->hash == hash && !Q_stricmp (cache->filename, filename))
		{
			Com_Printf (" (cached) ", LOG_GENERAL);
			if (cache->filepath[0] == 0)
			{
				*file = NULL;
				return -1;
			}
			*file = fopen (cache->filepath, "rb");
			if (!*file)
				Com_Error (ERR_FATAL, "Couldn't open %s", cache->filepath);	
			fseek (*file, cache->fileseek, SEEK_SET);
			return cache->filelen;
		}
	}
#elif MAGIC_BTREE
	{
		magic_t *magic;

		hash = hashify (filename);

		magic = rbfind ((void *)hash, rb);
		if (magic)
		{
			magic = *(magic_t **)magic;

			do
			{
				cache = magic->entry;
				if (!Q_stricmp (cache->filename, filename))
				{
					if (cache->filepath[0] == 0)
					{
						*file = NULL;
						return -1;
					}
					*file = fopen (cache->filepath, "rb");
					if (!*file)
						Com_Error (ERR_FATAL, "Couldn't open %s", cache->filepath);	
					fseek (*file, cache->fileseek, SEEK_SET);
					return cache->filelen;
				}

				magic = magic->next;
			} while (magic);
		}
	}
#endif

#ifdef _DEBUG
	Com_DPrintf ("File '%s' not found in cache, searching fs_searchpaths\n", filename);
#endif

	Q_strncpy (lowered, filename, sizeof(lowered)-1);
	fast_strlwr (lowered);

	for (search = fs_searchpaths ; search ; search = search->next)
	{
		// is the element a pak file?
		if (search->pack)
		{
//			char		*lower;
			packfile_t	*entry;

			//r1: optimized btree search
			pak = search->pack;

			if (pak->type == PAK_QUAKE)
			{
				entry = rbfind (lowered, pak->rb);

				if (entry)
				{
					entry = *(packfile_t **)entry;

	#ifdef _DEBUG
					Com_DPrintf ("File '%s' found in %s, (%s)\n", filename, pak->filename, entry->name);
	#endif
					if (openHandle != HANDLE_NONE)
					{
						//*file = fopen (pak->filename, "rb");
						if (openHandle == HANDLE_DUPE)
						{
							*file = fopen (pak->filename, "rb");
							*closeHandle = true;	
						}
						else
						{
							*file = pak->h.handle;
							*closeHandle = false;
						}
						//if (!*file)
						//	Com_Error (ERR_FATAL, "Couldn't reopen pak file %s", pak->filename);	

						if (fseek (*file, entry->filepos, SEEK_SET))
							Com_Error (ERR_FATAL, "Couldn't seek to offset %u for %s in %s", entry->filepos, entry->name, pak->filename);
					}

					if (fs_cache->intvalue & 1)
					{
	#if BTREE_SEARCH
						FS_AddToCache (pak->filename, entry->filelen, entry->filepos, filename, pak);
	#elif HASH_CACHE
						FS_AddToCache (hash, pak->filename, entry->filelen, entry->filepos, cache, filename);
	#elif MAGIC_BTREE
						FS_AddToCache (pak->filename, entry->filelen, entry->filepos, filename, hash);
	#endif
					}

					return entry->filelen;
				}
			}
		}
		else if (!fs_noextern->intvalue)
		{
			struct stat	statInfo;
			int filelen;
			// check a file in the directory tree
			
			Com_sprintf (netpath, sizeof(netpath), "%s/%s",search->filename, filename);

			if (openHandle == HANDLE_NONE)
			{
				filelen = Sys_FileLength (netpath);
				if (filelen == -1)
					continue;
				
				if (fs_cache->intvalue & 4)
					FS_AddToCache (netpath, filelen, 0, filename, NULL);

				return filelen;
			}

			//fix for moronic implementations that allow fopen (FILE OPEN) to open a directory
			//(this means you linux and krew)
			if (stat (netpath, &statInfo))
				continue;

			if (statInfo.st_mode & S_IFDIR)
			{
				Com_Printf ("WARNING: Tried to open a directory as a file: %s\n", LOG_WARNING, netpath);
				continue;
			}

			*file = fopen (netpath, "rb");

			if (!*file)
				continue;

			*closeHandle = true;
			
			Com_DPrintf ("FindFile: %s\n",netpath);

			filelen = FS_filelength (*file);
			if (fs_cache->intvalue & 4)
			{
#if BTREE_SEARCH
				FS_AddToCache (netpath, filelen, 0, filename, NULL);
#elif HASH_CACHE
				FS_AddToCache (hash, netpath, filelen, 0, cache, filename);
#elif MAGIC_BTREE
				FS_AddToCache (netpath, filelen, 0, filename, hash);
#endif
			}
			return filelen;
		}
		
	}
	
	Com_DPrintf ("FindFile: can't find %s\n", filename);

	if (fs_cache->intvalue & 2)
	{
#if BTREE_SEARCH
		FS_AddToCache (NULL, 0, 0, filename, NULL);
#elif HASH_CACHE
		FS_AddToCache (hash, NULL, 0, 0, cache, filename);
#elif MAGIC_BTREE
		FS_AddToCache (NULL, 0, 0, filename, hash);
#endif
	}
	
	*file = NULL;
	return -1;
}