native loading modified to be in line with oal

This commit is contained in:
Brian Matzon 2004-09-19 11:17:28 +00:00
parent 4e81b3a458
commit e93393ef8a
5 changed files with 54 additions and 19 deletions

View File

@ -191,16 +191,16 @@ public class FMOD {
private static String JNI_LIBRARY_NAME = "lwjgl-fmod3";
/** The native library name on win32 */
private static String FMOD_WIN32_LIBRARY_NAME = "fmod.dll";
private static String FMOD_WIN32_LIBRARY_NAME = "fmod";
/** The native library name on win32 */
private static String FMOD_LINUX_LIBRARY_NAME = "libfmod.so.0";
private static String FMOD_LINUX_LIBRARY_NAME = "fmod";
/** The native library name on win32 */
private static String FMOD_OSX_LIBRARY_NAME = "fmod_cfm.shlb";
private static String FMOD_OSX_LIBRARY_NAME = "fmod";
/** Version of FMOD */
public static final String VERSION = "0.9a";
public static final String VERSION = "0.92";
static {
initialize();
@ -275,7 +275,8 @@ public class FMOD {
dllName = FMOD_LINUX_LIBRARY_NAME;
}
String jwsPath = getPathFromJWS(dllName.substring(0, dllName.indexOf(".")));
String jwsPath = getPathFromJWS(dllName);
Sys.log("getPathFromJWS: Paths found: " + jwsPath);
if (jwsPath != null) {
libpath += seperator
+ jwsPath.substring(0, jwsPath.lastIndexOf(File.separator));
@ -287,7 +288,11 @@ public class FMOD {
//build paths
for (int i = 0; i < paths.length - 1; i++) {
paths[i] = st.nextToken() + File.separator + dllName;
paths[i] = st.nextToken() + File.separator;
}
for(int i=0 ; i<paths.length; i++) {
Sys.log("Will search " + paths[i] + " for " + dllName);
}
//add cwd path
@ -323,7 +328,8 @@ public class FMOD {
* @return Absolute path to library if found, otherwise null
*/
private static String getPathFromJWS(String libname) {
try {
try {
Sys.log("getPathFromJWS: searching for: " + libname);
Object o = FMOD.class.getClassLoader();
Class c = o.getClass();
Method findLibrary =
@ -332,7 +338,7 @@ public class FMOD {
return (String) findLibrary.invoke(o, arguments);
} catch (Exception e) {
System.out.println("Failure locating FMOD using classloader:" + e);
Sys.log("Failure locating FMOD using classloader:" + e);
}
return null;
}

View File

@ -146,6 +146,7 @@ public final class AL {
}
String jwsPath = getPathFromJWS(jwsLibname);
Sys.log("getPathFromJWS: Paths found: " + jwsPath);
if (jwsPath != null) {
libpath += seperator
+ jwsPath.substring(0, jwsPath.lastIndexOf(File.separator));
@ -160,6 +161,10 @@ public final class AL {
for (int i = 0; i < oalPaths.length - 1; i++) {
oalPaths[i] = st.nextToken() + File.separator;
}
for(int i=0 ; i<oalPaths.length; i++) {
Sys.log("Will search " + oalPaths[i] + " for " + jwsLibname);
}
//add cwd path
oalPaths[oalPaths.length - 1] = "";
@ -238,9 +243,7 @@ public final class AL {
*/
private static String getPathFromJWS(String libname) {
try {
Sys.log("JWS Classloader looking for: " + libname);
Sys.log("getPathFromJWS: searching for: " + libname);
Object o = AL.class.getClassLoader();
Class c = o.getClass();
Method findLibrary =

View File

@ -77,9 +77,9 @@ BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
*
* @param path path to try to load dll
*/
void fmod_create(JNIEnv *env, char* path) {
void fmod_create(JNIEnv *env, const char* path) {
// try to create an instance using the supplied path
fmod_instance = FMOD_CreateInstance(path);
fmod_instance = FMOD_CreateInstance((char *)path);
// if we got one, we need to locate and cache jni stuff used for callbacks
if (fmod_instance != NULL) {

View File

@ -40,7 +40,7 @@
#include "fmod_errors.h"
// Called to create an FMOD instance
void fmod_create(JNIEnv *env, char*);
void fmod_create(JNIEnv *env, const char*);
// Called to destroy our FMOD instance
void fmod_destroy();

View File

@ -33,7 +33,19 @@
#include "org_lwjgl_fmod3_FMOD.h"
#include "extfmod3.h"
static const char* VERSION = "0.9a";
static const char* VERSION = "0.92";
/**
* Concatenate two strings
*/
static char *concatenate(const char *str1, const char *str2) {
int length1 = strlen(str1);
int length2 = strlen(str2);
char *str = (char *)calloc(length1 + length2 + 1, sizeof(char));
strncpy(str, str1, length1);
strncpy(str + length1, str2, length2 + 1);
return str;
}
/*
* Class: org_lwjgl_fmod3_FMOD
@ -52,11 +64,25 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_fmod3_FMOD_getNativeLibraryVersion(JNIE
JNIEXPORT void JNICALL Java_org_lwjgl_fmod3_FMOD_nCreate(JNIEnv *env, jclass clazz, jobjectArray paths) {
jsize pathcount = (*env)->GetArrayLength(env, paths);
int i;
jstring path;
const char *path_str;
char *lib_str;
for(i=0;i<pathcount;i++) {
jstring path = (jstring) (*env)->GetObjectArrayElement(env, paths, i);
char *path_str = (char *) (*env)->GetStringUTFChars(env, path, NULL);
printfDebug("Trying to load fmod_instance from %s\n", path_str);
fmod_create(env, path_str);
path = (jstring) (*env)->GetObjectArrayElement(env, paths, i);
path_str = (*env)->GetStringUTFChars(env, path, NULL);
#ifdef _WIN32
lib_str = concatenate(path_str, "fmod.dll");
#endif
#ifdef _X11
lib_str = concatenate(path_str, "libfmod.so");
#endif
#ifdef _AGL
lib_str = concatenate(path_str, "fmod_cfm.shlb");
#endif
printfDebug("Testing '%s'\n", lib_str);
fmod_create(env, lib_str);
free(lib_str);
(*env)->ReleaseStringUTFChars(env, path, path_str);
if(fmod_instance != NULL) {