mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: platform: android: strip library path when loading libraries from APK
This commit is contained in:
@@ -19,44 +19,37 @@ GNU General Public License for more details.
|
||||
#include "platform/android/lib_android.h"
|
||||
#include "platform/android/dlsym-weak.h" // Android < 5.0
|
||||
|
||||
void *ANDROID_LoadLibrary( const char *dllname )
|
||||
void *ANDROID_LoadLibrary( const char *path )
|
||||
{
|
||||
char path[MAX_SYSPATH];
|
||||
const char *libdir[2];
|
||||
int i;
|
||||
void *pHandle = NULL;
|
||||
const char *libdir[2], *name = COM_FileWithoutPath( path );
|
||||
char fullpath[MAX_SYSPATH];
|
||||
void *handle;
|
||||
|
||||
libdir[0] = getenv("XASH3D_GAMELIBDIR");
|
||||
libdir[1] = getenv("XASH3D_ENGLIBDIR");
|
||||
libdir[0] = getenv( "XASH3D_GAMELIBDIR" ); // TODO: remove this once distributing games from APKs will be deprecated
|
||||
libdir[1] = NULL; // TODO: put here data directory where libraries will be downloaded to
|
||||
|
||||
for( i = 0; i < 2; i++ )
|
||||
for( int i = 0; i < ARRAYSIZE( libdir ); i++ )
|
||||
{
|
||||
// this is an APK directory, get base path
|
||||
const char *p = i == 0 ? name : path;
|
||||
|
||||
if( !libdir[i] )
|
||||
continue;
|
||||
|
||||
Q_snprintf( path, MAX_SYSPATH, "%s/%s."OS_LIB_EXT, libdir[i], dllname );
|
||||
pHandle = dlopen( path, RTLD_NOW );
|
||||
if( pHandle )
|
||||
return pHandle;
|
||||
Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", libdir[i], p );
|
||||
|
||||
handle = dlopen( fullpath, RTLD_NOW );
|
||||
|
||||
if( handle )
|
||||
return handle;
|
||||
|
||||
COM_PushLibraryError( dlerror() );
|
||||
}
|
||||
|
||||
// HACKHACK: keep old behaviour for compatibility
|
||||
if( Q_strstr( dllname, "." OS_LIB_EXT ) || Q_strstr( dllname, "/" ))
|
||||
{
|
||||
pHandle = dlopen( dllname, RTLD_NOW );
|
||||
if( pHandle )
|
||||
return pHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_snprintf( path, MAX_SYSPATH, "%s."OS_LIB_EXT, dllname );
|
||||
pHandle = dlopen( path, RTLD_NOW );
|
||||
if( pHandle )
|
||||
return pHandle;
|
||||
}
|
||||
|
||||
// find in system search path, that includes our APK
|
||||
handle = dlopen( name, RTLD_NOW );
|
||||
if( handle )
|
||||
return handle;
|
||||
COM_PushLibraryError( dlerror() );
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user