0
0
Fork 0
mirror of https://github.com/DrBeef/ioq3quest.git synced 2025-02-26 05:42:40 +00:00

Patch by Simon McVittie to improve dynamic library loading ()

This commit is contained in:
Thilo Schulz 2011-02-04 17:47:57 +00:00
parent d2f8b9f4bb
commit 7bb5906599
3 changed files with 38 additions and 39 deletions

View file

@ -1220,6 +1220,32 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF
} }
char *FS_FindDll( const char *filename ) {
searchpath_t *search;
directory_t *dir;
if ( !fs_searchpaths ) {
Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
}
for ( search = fs_searchpaths ; search ; search = search->next ) {
if ( search->dir ) {
FILE *f;
char *netpath;
dir = search->dir;
netpath = FS_BuildOSPath( dir->path, dir->gamedir, filename );
f = fopen( netpath, "rb" );
if (f) {
fclose( f );
return netpath;
}
}
}
return NULL;
}
/* /*
================= =================
FS_Read FS_Read

View file

@ -606,6 +606,9 @@ void FS_FreeFileList( char **list );
qboolean FS_FileExists( const char *file ); qboolean FS_FileExists( const char *file );
qboolean FS_CreatePath (char *OSPath); qboolean FS_CreatePath (char *OSPath);
char *FS_FindDll( const char *filename );
char *FS_BuildOSPath( const char *base, const char *game, const char *qpath ); char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
qboolean FS_CompareZipChecksum(const char *zipfile); qboolean FS_CompareZipChecksum(const char *zipfile);

View file

@ -405,34 +405,6 @@ void Sys_UnloadDll( void *dllHandle )
Sys_UnloadLibrary(dllHandle); Sys_UnloadLibrary(dllHandle);
} }
/*
=================
Sys_TryLibraryLoad
=================
*/
static void* Sys_TryLibraryLoad(const char* base, const char* gamedir, const char* fname, char* fqpath )
{
void* libHandle;
char* fn;
*fqpath = 0;
fn = FS_BuildOSPath( base, gamedir, fname );
Com_Printf( "Sys_LoadDll(%s)... \n", fn );
libHandle = Sys_LoadLibrary(fn);
if(!libHandle) {
Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, Sys_LibraryError() );
return NULL;
}
Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
Q_strncpyz ( fqpath , fn , MAX_QPATH ) ;
return libHandle;
}
/* /*
================= =================
Sys_LoadDll Sys_LoadDll
@ -449,26 +421,24 @@ void *Sys_LoadDll( const char *name, char *fqpath ,
void *libHandle; void *libHandle;
void (*dllEntry)( intptr_t (*syscallptr)(intptr_t, ...) ); void (*dllEntry)( intptr_t (*syscallptr)(intptr_t, ...) );
char fname[MAX_OSPATH]; char fname[MAX_OSPATH];
char *basepath; char *netpath;
char *homepath;
char *gamedir;
assert( name ); assert( name );
Q_snprintf (fname, sizeof(fname), "%s" ARCH_STRING DLL_EXT, name); Q_snprintf (fname, sizeof(fname), "%s" ARCH_STRING DLL_EXT, name);
// TODO: use fs_searchpaths from files.c netpath = FS_FindDll(fname);
basepath = Cvar_VariableString( "fs_basepath" );
homepath = Cvar_VariableString( "fs_homepath" );
gamedir = Cvar_VariableString( "fs_game" );
libHandle = Sys_TryLibraryLoad(homepath, gamedir, fname, fqpath); if(!netpath) {
Com_Printf( "Sys_LoadDll(%s) could not find it\n", fname );
return NULL;
}
if(!libHandle && basepath) Com_Printf( "Loading DLL file: %s\n", netpath);
libHandle = Sys_TryLibraryLoad(basepath, gamedir, fname, fqpath); libHandle = Sys_LoadLibrary(netpath);
if(!libHandle) { if(!libHandle) {
Com_Printf ( "Sys_LoadDll(%s) failed to load library\n", name ); Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", netpath, Sys_LibraryError() );
return NULL; return NULL;
} }